import{a as e}from"./chunk-Cyuzqnbw.js";import{i as t,r as n}from"./bundle-mjs-DssaXR6m.js";import{x as r}from"./useBaseUiId-DL38u1cQ.js";import{B as i,V as a,m as o}from"./api-DTaM-PBA.js";var s=r(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),c=e(t()),l=c.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},elementsRef:{current:[]},nextIndexRef:{current:0}});function u(){return c.useContext(l)}var d=n();function f(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:s}=e,u=o(s),f=c.useRef(0),g=a(m).current,_=a(p).current,[v,y]=c.useState(0),b=c.useRef(v),x=o((e,t)=>{_.set(e,t??null),b.current+=1,y(b.current)}),S=o(e=>{_.delete(e),b.current+=1,y(b.current)}),C=c.useMemo(()=>{let e=new Map;return Array.from(_.keys()).filter(e=>e.isConnected).sort(h).forEach((t,n)=>{let r=_.get(t)??{};e.set(t,{...r,index:n})}),e},[_,v]);i(()=>{if(typeof MutationObserver!=`function`||C.size===0)return;let e=new MutationObserver(e=>{let t=new Set,n=e=>t.has(e)?t.delete(e):t.add(e);e.forEach(e=>{e.removedNodes.forEach(n),e.addedNodes.forEach(n)}),t.size===0&&(b.current+=1,y(b.current))});return C.forEach((t,n)=>{n.parentElement&&e.observe(n.parentElement,{childList:!0})}),()=>{e.disconnect()}},[C]),i(()=>{b.current===v&&(n.current.length!==C.size&&(n.current.length=C.size),r&&r.current.length!==C.size&&(r.current.length=C.size),f.current=C.size),u(C)},[u,C,n,r,v]),i(()=>()=>{n.current=[]},[n]),i(()=>()=>{r&&(r.current=[])},[r]);let w=o(e=>(g.add(e),()=>{g.delete(e)}));i(()=>{g.forEach(e=>e(C))},[g,C]);let T=c.useMemo(()=>({register:x,unregister:S,subscribeMapChange:w,elementsRef:n,labelsRef:r,nextIndexRef:f}),[x,S,w,n,r,f]);return(0,d.jsx)(l.Provider,{value:T,children:t})}function p(){return new Map}function m(){return new Set}function h(e,t){let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING||n&Node.DOCUMENT_POSITION_CONTAINED_BY?-1:n&Node.DOCUMENT_POSITION_PRECEDING||n&Node.DOCUMENT_POSITION_CONTAINS?1:0}var g=function(e){return e[e.None=0]=`None`,e[e.GuessFromOrder=1]=`GuessFromOrder`,e}({});function _(e={}){let{label:t,metadata:n,textRef:r,indexGuessBehavior:a,index:o}=e,{register:s,unregister:l,subscribeMapChange:d,elementsRef:f,labelsRef:p,nextIndexRef:m}=u(),h=c.useRef(-1),[_,v]=c.useState(o??(a===g.GuessFromOrder?()=>{if(h.current===-1){let e=m.current;m.current+=1,h.current=e}return h.current}:-1)),y=c.useRef(null),b=c.useCallback(e=>{if(y.current=e,_!==-1&&e!==null&&(f.current[_]=e,p)){let n=t!==void 0;p.current[_]=n?t:r?.current?.textContent??e.textContent}},[_,f,p,t,r]);return i(()=>{if(o!=null)return;let e=y.current;if(e)return s(e,n),()=>{l(e)}},[o,s,l,n]),i(()=>{if(o==null)return d(e=>{let t=y.current?e.get(y.current)?.index:null;t!=null&&v(t)})},[o,d,v]),c.useMemo(()=>({ref:b,index:_}),[_,b])}export{s as i,_ as n,f as r,g as t};