import{i as e,n as t,t as n}from"./jsx-runtime-DG_AJzB_.js";import{t as r}from"./compiler-runtime-DCc3R3Xn.js";import{S as i,_ as a,a as o,d as s,f as c,h as l}from"./createReactComponent-_L2mp4Ui.js";import{t as u}from"./utils-C8DGLIgm.js";import{i as d}from"./getDisabledMountTransitionStyles-C-jmk481.js";import{C as f,D as p,E as m,O as h,S as g,T as _,_ as v,a as y,b,c as x,g as S,h as C,l as w,m as T,o as E,p as D,s as O,t as k,u as A,v as j,w as M,x as N,y as P}from"./CompositeList-DfjQy1zM.js";function F(e){return e==null||e.hasAttribute(`disabled`)||e.getAttribute(`aria-disabled`)===`true`}var I=`data-composite-item-active`,L=e(t()),R=[];function z(e){let{itemSizes:t,cols:n=1,loopFocus:r=!0,dense:a=!1,orientation:o=`both`,direction:s,highlightedIndex:c,onHighlightedIndexChange:u,rootRef:d,enableHomeAndEndKeys:C=!1,stopEventPropagation:k=!1,disabledIndices:I,modifierKeys:z=R}=e,[V,H]=L.useState(0),U=n>1,W=L.useRef(null),G=l(W,d),K=L.useRef([]),q=L.useRef(!1),J=c??V,Y=i((e,t=!1)=>{if((u??H)(e),t){let t=K.current[e];P(W.current,t,s,o)}}),X=i(e=>{if(e.size===0||q.current)return;q.current=!0;let t=Array.from(e.keys()),n=t.find(e=>e?.hasAttribute(`data-composite-item-active`))??null,r=n?t.indexOf(n):-1;r!==-1&&Y(r),P(W.current,n,s,o)}),Z=L.useMemo(()=>({"aria-orientation":o===`both`?void 0:o,ref:G,onFocus(e){!W.current||!j(e.target)||e.target.setSelectionRange(0,e.target.value.length??0)},onKeyDown(e){let i=C?y:O;if(!i.has(e.key)||B(e,z)||!W.current)return;let c=s===`rtl`,l=c?x:w,u={horizontal:l,vertical:E,both:l}[o],d=c?w:x,P={horizontal:d,vertical:A,both:d}[o];if(j(e.target)&&!F(e.target)){let t=e.target.selectionStart,n=e.target.selectionEnd,r=e.target.value??``;if(t==null||e.shiftKey||t!==n||e.key!==P&&t<r.length||e.key!==u&&t>0)return}let L=J,R=m(K,I),V=_(K,I);if(U){let i=t||Array.from({length:K.current.length},()=>({width:1,height:1})),s=b(i,n,a),l=s.findIndex(e=>e!=null&&!h(K,e,I)),u=s.reduce((e,t,n)=>t!=null&&!h(K,t,I)?n:e,-1);L=s[M({current:s.map(e=>e?K.current[e]:null)},{event:e,orientation:o,loopFocus:r,cols:n,disabledIndices:f([...I||K.current.map((e,t)=>h(K,t)?t:void 0),void 0],s),minIndex:l,maxIndex:u,prevIndex:g(J>V?R:J,i,s,n,e.key===`ArrowDown`?`bl`:e.key===`ArrowRight`?`tr`:`tl`),rtl:c})]}let H={horizontal:[l],vertical:[E],both:[l,E]}[o],G={horizontal:[d],vertical:[A],both:[d,A]}[o],q=U?i:{horizontal:C?T:D,vertical:C?v:S,both:i}[o];C&&(e.key===`Home`?L=R:e.key===`End`&&(L=V)),L===J&&(H.includes(e.key)||G.includes(e.key))&&(L=r&&L===V&&H.includes(e.key)?R:r&&L===R&&G.includes(e.key)?V:N(K,{startingIndex:L,decrement:G.includes(e.key),disabledIndices:I})),L!==J&&!p(K,L)&&(k&&e.stopPropagation(),q.has(e.key)&&e.preventDefault(),Y(L,!0),queueMicrotask(()=>{K.current[L]?.focus()}))}}),[n,a,s,I,K,C,J,U,t,r,G,z,Y,o,k]);return L.useMemo(()=>({props:Z,highlightedIndex:J,onHighlightedIndexChange:Y,elementsRef:K,disabledIndices:I,onMapChange:X,relayKeyboardEvent:Z.onKeyDown}),[Z,J,Y,K,I,X])}function B(e,t){for(let n of C.values())if(!t.includes(n)&&e.getModifierState(n))return!0;return!1}var V=n();function H(e){let{render:t,className:n,refs:r=s,props:i=s,state:l=c,stateAttributesMapping:u,highlightedIndex:f,onHighlightedIndexChange:p,orientation:m,dense:h,itemSizes:g,loopFocus:_,cols:v,enableHomeAndEndKeys:y,onMapChange:b,stopEventPropagation:x=!0,rootRef:S,disabledIndices:C,modifierKeys:w,highlightItemOnHover:T=!1,tag:E=`div`,...D}=e,{props:O,highlightedIndex:A,onHighlightedIndexChange:j,elementsRef:M,onMapChange:N,relayKeyboardEvent:P}=z({itemSizes:g,cols:v,loopFocus:_,dense:h,orientation:m,highlightedIndex:f,onHighlightedIndexChange:p,rootRef:S,stopEventPropagation:x,enableHomeAndEndKeys:y,direction:d(),disabledIndices:C,modifierKeys:w}),F=o(E,e,{state:l,ref:r,props:[O,...i,D],stateAttributesMapping:u}),I=L.useMemo(()=>({highlightedIndex:A,onHighlightedIndexChange:j,highlightItemOnHover:T,relayKeyboardEvent:P}),[A,j,T,P]);return(0,V.jsx)(a.Provider,{value:I,children:(0,V.jsx)(k,{elementsRef:M,onMapChange:e=>{b?.(e),N(e)},children:F})})}var U=r();function W(e){let t=(0,U.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=u(`border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-[3px] aria-invalid:ring-[3px] md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,V.jsx)(`textarea`,{"data-slot":`textarea`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}export{H as n,I as r,W as t};