import{i as Ee,at as Z,U as J,y as H,au as $e,av as ue,aw as se,ax as ve,o as g,ay as Ie,az as he,aA as Te,aB as we,aC as Oe,aD as A,aE as U,C as Q,I as K,c as Fe,aF as Pe,d as oe,s as ae,aG as be,aH as Ce,Q as ke,aI as L,aJ as _,aK as xe,aL as Be,aM as Me,e as G,r as me,aN as De,aO as R,aP as le}from"./index-BbBXKozi.js";const y=await Ee("react"),{createContext:ee,createRef:fe,useContext:te,useEffect:X,useMemo:M,useReducer:Ne,useRef:W,useState:Se}=y;var _e=(e=>(e[e.Open=0]="Open",e[e.Closed=1]="Closed",e))(_e||{}),Re=(e=>(e[e.TogglePopover=0]="TogglePopover",e[e.ClosePopover=1]="ClosePopover",e[e.SetButton=2]="SetButton",e[e.SetButtonId=3]="SetButtonId",e[e.SetPanel=4]="SetPanel",e[e.SetPanelId=5]="SetPanelId",e))(Re||{});let Ge={0:e=>{let o={...e,popoverState:A(e.popoverState,{0:1,1:0})};return o.popoverState===0&&(o.__demoMode=!1),o},1(e){return e.popoverState===1?e:{...e,popoverState:1}},2(e,o){return e.button===o.button?e:{...e,button:o.button}},3(e,o){return e.buttonId===o.buttonId?e:{...e,buttonId:o.buttonId}},4(e,o){return e.panel===o.panel?e:{...e,panel:o.panel}},5(e,o){return e.panelId===o.panelId?e:{...e,panelId:o.panelId}}},ie=ee(null);ie.displayName="PopoverContext";function ne(e){let o=te(ie);if(o===null){let v=new Error(`<${e} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(v,ne),v}return o}let pe=ee(null);pe.displayName="PopoverAPIContext";function ce(e){let o=te(pe);if(o===null){let v=new Error(`<${e} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(v,ce),v}return o}let de=ee(null);de.displayName="PopoverGroupContext";function ye(){return te(de)}let re=ee(null);re.displayName="PopoverPanelContext";function Le(){return te(re)}function Ae(e,o){return A(o.type,Ge,e,o)}let Ke="div";function He(e,o){var v;let{__demoMode:E=!1,...T}=e,a=W(null),t=H(o,$e(l=>{a.current=l})),f=W([]),P=Ne(Ae,{__demoMode:E,popoverState:E?0:1,buttons:f,button:null,buttonId:null,panel:null,panelId:null,beforePanelSentinel:fe(),afterPanelSentinel:fe()}),[{popoverState:b,button:s,buttonId:$,panel:r,panelId:D,beforePanelSentinel:O,afterPanelSentinel:m},u]=P,c=ue((v=a.current)!=null?v:s),w=M(()=>{if(!s||!r)return!1;for(let Y of document.querySelectorAll("body > *"))if(Number(Y?.contains(s))^Number(Y?.contains(r)))return!0;let l=se(),F=l.indexOf(s),j=(F+l.length-1)%l.length,z=(F+1)%l.length,V=l[j],ge=l[z];return!r.contains(V)&&!r.contains(ge)},[s,r]),C=ve($),x=ve(D),B=M(()=>({buttonId:C,panelId:x,close:()=>u({type:1})}),[C,x,u]),k=ye(),N=k?.registerPopover,i=g(()=>{var l;return(l=k?.isFocusWithinPopoverGroup())!=null?l:c?.activeElement&&(s?.contains(c.activeElement)||r?.contains(c.activeElement))});X(()=>N?.(B),[N,B]);let[I,d]=Ie(),n=he({mainTreeNodeRef:k?.mainTreeNodeRef,portals:I,defaultContainers:[s,r]});Te(c?.defaultView,"focus",l=>{var F,j,z,V;l.target!==window&&l.target instanceof HTMLElement&&b===0&&(i()||s&&r&&(n.contains(l.target)||(j=(F=O.current)==null?void 0:F.contains)!=null&&j.call(F,l.target)||(V=(z=m.current)==null?void 0:z.contains)!=null&&V.call(z,l.target)||u({type:1})))},!0),we(n.resolveContainers,(l,F)=>{u({type:1}),Be(F,Me.Loose)||(l.preventDefault(),s?.focus())},b===0);let p=g(l=>{u({type:1});let F=l?l instanceof HTMLElement?l:"current"in l&&l.current instanceof HTMLElement?l.current:s:s;F?.focus()}),h=M(()=>({close:p,isPortalled:w}),[p,w]),S=M(()=>({open:b===0,close:p}),[b,p]),q={ref:t};return y.createElement(re.Provider,{value:null},y.createElement(ie.Provider,{value:P},y.createElement(pe.Provider,{value:h},y.createElement(Oe,{value:A(b,{0:U.Open,1:U.Closed})},y.createElement(d,null,Q({ourProps:q,theirProps:T,slot:S,defaultTag:Ke,name:"Popover"}),y.createElement(n.MainTreeNode,null))))))}let Ue="button";function qe(e,o){let v=K(),{id:E=`headlessui-popover-button-${v}`,...T}=e,[a,t]=ne("Popover.Button"),{isPortalled:f}=ce("Popover.Button"),P=W(null),b=`headlessui-focus-sentinel-${K()}`,s=ye(),$=s?.closeOthers,r=Le()!==null;X(()=>{if(!r)return t({type:3,buttonId:E}),()=>{t({type:3,buttonId:null})}},[r,E,t]);let[D]=Se(()=>Symbol()),O=H(P,o,r?null:n=>{if(n)a.buttons.current.push(D);else{let p=a.buttons.current.indexOf(D);p!==-1&&a.buttons.current.splice(p,1)}a.buttons.current.length>1&&console.warn("You are already using a <Popover.Button /> but only 1 <Popover.Button /> is supported."),n&&t({type:2,button:n})}),m=H(P,o),u=ue(P),c=g(n=>{var p,h,S;if(r){if(a.popoverState===1)return;switch(n.key){case G.Space:case G.Enter:n.preventDefault(),(h=(p=n.target).click)==null||h.call(p),t({type:1}),(S=a.button)==null||S.focus();break}}else switch(n.key){case G.Space:case G.Enter:n.preventDefault(),n.stopPropagation(),a.popoverState===1&&$?.(a.buttonId),t({type:0});break;case G.Escape:if(a.popoverState!==0)return $?.(a.buttonId);if(!P.current||u!=null&&u.activeElement&&!P.current.contains(u.activeElement))return;n.preventDefault(),n.stopPropagation(),t({type:1});break}}),w=g(n=>{r||n.key===G.Space&&n.preventDefault()}),C=g(n=>{var p,h;me(n.currentTarget)||e.disabled||(r?(t({type:1}),(p=a.button)==null||p.focus()):(n.preventDefault(),n.stopPropagation(),a.popoverState===1&&$?.(a.buttonId),t({type:0}),(h=a.button)==null||h.focus()))}),x=g(n=>{n.preventDefault(),n.stopPropagation()}),B=a.popoverState===0,k=M(()=>({open:B}),[B]),N=Fe(e,P),i=r?{ref:m,type:N,onKeyDown:c,onClick:C}:{ref:O,id:a.buttonId,type:N,"aria-expanded":a.popoverState===0,"aria-controls":a.panel?a.panelId:void 0,onKeyDown:c,onKeyUp:w,onClick:C,onMouseDown:x},I=Pe(),d=g(()=>{let n=a.panel;if(!n)return;function p(){A(I.current,{[R.Forwards]:()=>L(n,_.First),[R.Backwards]:()=>L(n,_.Last)})===le.Error&&L(se().filter(h=>h.dataset.headlessuiFocusGuard!=="true"),A(I.current,{[R.Forwards]:_.Next,[R.Backwards]:_.Previous}),{relativeTo:a.button})}p()});return y.createElement(y.Fragment,null,Q({ourProps:i,theirProps:T,slot:k,defaultTag:Ue,name:"Popover.Button"}),B&&!r&&f&&y.createElement(oe,{id:b,features:ae.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:d}))}let ze="div",We=Z.RenderStrategy|Z.Static;function Je(e,o){let v=K(),{id:E=`headlessui-popover-overlay-${v}`,...T}=e,[{popoverState:a},t]=ne("Popover.Overlay"),f=H(o),P=be(),b=P!==null?(P&U.Open)===U.Open:a===0,s=g(r=>{if(me(r.currentTarget))return r.preventDefault();t({type:1})}),$=M(()=>({open:a===0}),[a]);return Q({ourProps:{ref:f,id:E,"aria-hidden":!0,onClick:s},theirProps:T,slot:$,defaultTag:ze,features:We,visible:b,name:"Popover.Overlay"})}let Qe="div",je=Z.RenderStrategy|Z.Static;function Ve(e,o){let v=K(),{id:E=`headlessui-popover-panel-${v}`,focus:T=!1,...a}=e,[t,f]=ne("Popover.Panel"),{close:P,isPortalled:b}=ce("Popover.Panel"),s=`headlessui-focus-sentinel-before-${K()}`,$=`headlessui-focus-sentinel-after-${K()}`,r=W(null),D=H(r,o,i=>{f({type:4,panel:i})}),O=ue(r),m=Ce();ke(()=>(f({type:5,panelId:E}),()=>{f({type:5,panelId:null})}),[E,f]);let u=be(),c=u!==null?(u&U.Open)===U.Open:t.popoverState===0,w=g(i=>{var I;switch(i.key){case G.Escape:if(t.popoverState!==0||!r.current||O!=null&&O.activeElement&&!r.current.contains(O.activeElement))return;i.preventDefault(),i.stopPropagation(),f({type:1}),(I=t.button)==null||I.focus();break}});X(()=>{var i;e.static||t.popoverState===1&&((i=e.unmount)==null||i)&&f({type:4,panel:null})},[t.popoverState,e.unmount,e.static,f]),X(()=>{if(t.__demoMode||!T||t.popoverState!==0||!r.current)return;let i=O?.activeElement;r.current.contains(i)||L(r.current,_.First)},[t.__demoMode,T,r,t.popoverState]);let C=M(()=>({open:t.popoverState===0,close:P}),[t,P]),x={ref:D,id:E,onKeyDown:w,onBlur:T&&t.popoverState===0?i=>{var I,d,n,p,h;let S=i.relatedTarget;S&&r.current&&((I=r.current)!=null&&I.contains(S)||(f({type:1}),((n=(d=t.beforePanelSentinel.current)==null?void 0:d.contains)!=null&&n.call(d,S)||(h=(p=t.afterPanelSentinel.current)==null?void 0:p.contains)!=null&&h.call(p,S))&&S.focus({preventScroll:!0})))}:void 0,tabIndex:-1},B=Pe(),k=g(()=>{let i=r.current;if(!i)return;function I(){A(B.current,{[R.Forwards]:()=>{var d;L(i,_.First)===le.Error&&((d=t.afterPanelSentinel.current)==null||d.focus())},[R.Backwards]:()=>{var d;(d=t.button)==null||d.focus({preventScroll:!0})}})}I()}),N=g(()=>{let i=r.current;if(!i)return;function I(){A(B.current,{[R.Forwards]:()=>{var d;if(!t.button)return;let n=se(),p=n.indexOf(t.button),h=n.slice(0,p+1),S=[...n.slice(p+1),...h];for(let q of S.slice())if(q.dataset.headlessuiFocusGuard==="true"||(d=t.panel)!=null&&d.contains(q)){let l=S.indexOf(q);l!==-1&&S.splice(l,1)}L(S,_.First,{sorted:!1})},[R.Backwards]:()=>{var d;L(i,_.Previous)===le.Error&&((d=t.button)==null||d.focus())}})}I()});return y.createElement(re.Provider,{value:E},c&&b&&y.createElement(oe,{id:s,ref:t.beforePanelSentinel,features:ae.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:k}),Q({mergeRefs:m,ourProps:x,theirProps:a,slot:C,defaultTag:Qe,features:je,visible:c,name:"Popover.Panel"}),c&&b&&y.createElement(oe,{id:$,ref:t.afterPanelSentinel,features:ae.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:N}))}let Ye="div";function Ze(e,o){let v=W(null),E=H(v,o),[T,a]=Se([]),t=xe(),f=g(m=>{a(u=>{let c=u.indexOf(m);if(c!==-1){let w=u.slice();return w.splice(c,1),w}return u})}),P=g(m=>(a(u=>[...u,m]),()=>f(m))),b=g(()=>{var m;let u=De(v);if(!u)return!1;let c=u.activeElement;return(m=v.current)!=null&&m.contains(c)?!0:T.some(w=>{var C,x;return((C=u.getElementById(w.buttonId.current))==null?void 0:C.contains(c))||((x=u.getElementById(w.panelId.current))==null?void 0:x.contains(c))})}),s=g(m=>{for(let u of T)u.buttonId.current!==m&&u.close()}),$=M(()=>({registerPopover:P,unregisterPopover:f,isFocusWithinPopoverGroup:b,closeOthers:s,mainTreeNodeRef:t.mainTreeNodeRef}),[P,f,b,s,t.mainTreeNodeRef]),r=M(()=>({}),[]),D=e,O={ref:E};return y.createElement(de.Provider,{value:$},Q({ourProps:O,theirProps:D,slot:r,defaultTag:Ye,name:"Popover.Group"}),y.createElement(t.MainTreeNode,null))}let Xe=J(He),et=J(qe),tt=J(Je),nt=J(Ve),rt=J(Ze),at=Object.assign(Xe,{Button:et,Overlay:tt,Panel:nt,Group:rt});export{at as C}; //# sourceMappingURL=popover-CCXjVi1j.js.map