import{d as V,D as q,j as m,k as o,B as J,p as Q,l as X,a as C,o as p,h as w,b as Y,F as L,r as P,n as y,u as Z,c as ee,g as te,H as se,R as le,I as ne}from"./index-IQ_epUwE.js";const re=V({__name:"RowAutoGrid",props:{cols:{},items:{},rowItemClass:{type:[Function,Array],default:()=>[]},makeKey:{type:Function,default:(k,x)=>x.toString()},centerIfLessThanCols:{type:Boolean,default:!1},gap:{default:"gap-6"},beforeUnfocusCallback:{},afterUnfocusCallback:{},beforeFocusCallback:{},afterFocusCallback:{},id:{},containerClass:{type:[Function,Array],default:()=>[]},innerContainerClass:{type:[Function,Array],default:()=>[]},unfocusClass:{type:[Function,Array],default:()=>[]},focusClass:{type:[Function,Array],default:()=>["outline","outline-2","outline-roon-primary"]},centerOnScreenWhenFocused:{type:Boolean,default:!0},shouldNudge:{type:Boolean,default:!1}},setup(k,{expose:x}){const e=k,{nudgeClasses:_,triggerNudge:R}=q(),f=m(!1),M=m(null),U=m(null),l=m(0),r=m({}),i=o(()=>Math.ceil(e.items.length/e.cols)),j=o(()=>e.cols),b=o(()=>e.items.length%e.cols===0),d=o(()=>Math.floor(l.value/e.cols)),h=o(()=>l.value%e.cols),F=o(()=>`${S(e.gap)}rem`),I=o(()=>{const t=[];for(let s=0;s<e.items.length;s+=e.cols){const n=e.items.slice(s,s+e.cols).map((u,a)=>({item:u,originalIndex:s+a}));t.push(n)}return t}),A=t=>e.centerIfLessThanCols&&t<e.cols?"justify-center":"justify-start",S=t=>({"gap-0":0,"gap-1":.25,"gap-2":.5,"gap-3":.75,"gap-4":1,"gap-5":1.25,"gap-6":1.5,"gap-7":1.75,"gap-8":2,"gap-9":2.25,"gap-10":2.5,"gap-11":2.75,"gap-12":3})[t]||1.5,O=o(()=>g(e.rowItemClass)),N=o(()=>g(e.focusClass)),T=o(()=>g(e.unfocusClass)),$=o(()=>({width:`calc((100% - ${(e.cols-1)*S(e.gap)}rem) / ${e.cols})`,flexShrink:0}));J(()=>{}),Q(()=>{r.value={}});const g=t=>t?typeof t=="function"?t():t:[],c=t=>{let s=l.value;if(t.index!==void 0&&t.index!==null?s=t.index:t.row!==void 0&&t.col!==void 0&&(s=t.row*e.cols+t.col),s<0||s>=Object.keys(r.value).length)return;const n=l.value,u=r.value[s];r.value[n],u.focus(),l.value=s,f.value=!0},z=()=>{const t=r.value[l.value];t&&t.element()?.blur(),f.value=!1},E=()=>{e.items.length!==0&&(h.value>0?c({index:l.value-1}):e.shouldNudge&&R("left"))},G=()=>{e.items.length!==0&&(h.value<e.cols-1&&l.value<e.items.length-1?c({index:l.value+1}):e.shouldNudge&&R("right"))},W=()=>{if(d.value>0){if(e.centerIfLessThanCols&&!b.value&&d.value===i.value-1){const s=e.cols-I.value[i.value-1].length,n=Math.floor(s/2),u=l.value-e.cols+n;if(u<e.items.length)return c({index:u}),!1}const t=l.value-e.cols;if(t>=0)return c({index:t}),!1}return!0},D=()=>{if(d.value<i.value-1){if(e.centerIfLessThanCols&&!b.value&&d.value===i.value-2){const n=I.value[i.value-1].length,u=h.value/(e.cols-1)*(n-1),a=Math.round(u),v=(i.value-1)*e.cols+a;if(v<e.items.length)return c({index:v}),!1}const t=l.value+e.cols;if(t<e.items.length)return c({index:t}),!1}return!0},K=()=>{const t=r.value[l.value];t&&t.click()};X(()=>e.items.length,()=>{l.value>=e.items.length&&(l.value=Math.max(0,e.items.length-1))},{immediate:!0});const B={id:e.id,isRowFocused:f,focusIndex:l,handleLeft:E,handleRight:G,handleUp:W,handleDown:D,handleEnter:K,doFocus:c,removeFocus:z,centerOnScreenWhenFocused:e.centerOnScreenWhenFocused,beforeUnfocusCallback:e.beforeUnfocusCallback||(()=>{}),afterUnfocusCallback:e.afterUnfocusCallback||(()=>{}),beforeFocusCallback:e.beforeFocusCallback||(()=>{}),afterFocusCallback:e.afterFocusCallback||(()=>{}),focusRow:d,focusCol:h,totalRows:i,totalCols:j,goToPosition:(t,s)=>{const n=t*e.cols+s;n>=0&&n<e.items.length&&c({index:n})},getItemAtPosition:(t,s)=>{const n=t*e.cols+s;return n>=0&&n<Object.keys(r.value).length?r.value[n]:void 0}};return ne("parent",B),x(B),(t,s)=>(p(),C("div",{class:w(["w-full",g(t.containerClass)]),ref_key:"rowParentRef",ref:M},[Y("div",{class:w(["w-full flex flex-col",[...g(t.innerContainerClass),Z(_)]]),ref_key:"rowRef",ref:U,style:y({gap:F.value})},[(p(!0),C(L,null,P(I.value,(n,u)=>(p(),C("div",{key:`row-${u}`,class:w(["flex",A(n.length)]),style:y({gap:F.value})},[(p(!0),C(L,null,P(n,(a,H)=>(p(),ee(le,{key:t.makeKey(a.item,a.originalIndex),ref_for:!0,ref:v=>{v?r.value[a.originalIndex]=v:delete r.value[a.originalIndex]},style:y($.value),class:w([...O.value,...f.value&&a.originalIndex===l.value?N.value:T.value])},{default:te(()=>[se(t.$slots,"default",{item:a.item,index:a.originalIndex,isFocused:a.originalIndex===l.value&&f.value})]),_:2},1032,["style","class"]))),128))],6))),128))],6)],2))}});export{re as _};
