@deslop/gateway 0.1.1232 → 0.1.1233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/apple-touch-icon.png +0 -0
- package/dist/client/assets/(home)-pbfIvNZe.js +1 -0
- package/dist/client/assets/effect-DJFrJOhz.js +17 -0
- package/dist/client/assets/icon-61pmFc-p.svg +1 -0
- package/dist/client/assets/index-GPYSTNwq.js +4 -0
- package/dist/client/assets/index-I1PNwXTF.css +2 -0
- package/dist/client/index.html +4 -5
- package/dist/server.js +8 -43
- package/package.json +2 -2
- package/dist/client/assets/(home)-CQVRM9XF.js +0 -1
- package/dist/client/assets/effect-Mq46Au9-.js +0 -17
- package/dist/client/assets/icon-CY0KDqY_.svg +0 -1
- package/dist/client/assets/icon-dark-B6bEETJE.svg +0 -1
- package/dist/client/assets/index-CiFa0j4x.js +0 -4
- package/dist/client/assets/index-JWBKvPy0.css +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{a as t,i as n,n as r,o as i,s as a,t as o}from"./react-BUjtWCUj.js";import{$ as s,$n as c,$r as l,$t as u,A as d,Ai as f,An as p,At as m,B as h,Bi as g,Bn as _,Bt as v,C as y,Ci as b,Cn as x,Cr as S,D as C,Di as w,Dn as T,E,Ei as D,En as O,Er as k,Et as A,F as j,Fi as M,Fn as N,Fr as P,Ft as F,G as I,Gi as L,Gn as R,Gr as ee,Gt as te,H as ne,Hi as z,Hn as re,Hr as ie,Ht as B,I as ae,Ii as oe,In as se,J as ce,Ji as le,Jn as ue,Jr as de,Jt as fe,K as pe,Ki as me,Kn as he,Kr as ge,Kt as _e,L as ve,Li as ye,Ln as be,Lt as xe,M as Se,Mi as Ce,Mn as we,Mr as Te,Mt as Ee,N as De,Ni as Oe,Nn as ke,Nr as Ae,Nt as je,O as Me,Oi as Ne,On as Pe,Or as Fe,P as Ie,Pi as Le,Pn as Re,Pr as ze,Pt as Be,Q as Ve,Qi as V,Qn as He,Qr as Ue,Qt as We,R as Ge,Ri as Ke,Rn as H,Rt as qe,S as Je,Si as Ye,Sn as Xe,Sr as Ze,St as Qe,T as $e,Ti as et,Tn as tt,Tr as nt,Tt as rt,U as it,Ui as at,Un as ot,Ur as st,Ut as ct,V as U,Vi as lt,Vn as ut,Vt as dt,W as ft,Wi as pt,Wn as mt,Wr as ht,Wt as gt,X as _t,Xi as vt,Xn as yt,Xr as bt,Xt as xt,Yi as St,Yn as Ct,Yr as wt,Yt as Tt,Z as Et,Zi as Dt,Zn as Ot,Zr as kt,Zt as At,_i as jt,_n as Mt,_r as W,_t as Nt,a as Pt,aa as Ft,ai as It,an as Lt,ar as Rt,at as zt,b as Bt,bi as Vt,bn as Ht,br as Ut,bt as Wt,cn as Gt,cr as Kt,d as qt,di as Jt,dn as Yt,dr as G,dt as Xt,ei as Zt,en as Qt,er as $t,f as en,fi as tn,fn as nn,fr as rn,ft as an,gi as on,gn as sn,gr as cn,gt as ln,h as un,hi as dn,hn as fn,hr as pn,ht as mn,i as hn,ia as gn,ii as _n,in as vn,ir as yn,it as bn,j as xn,ji as Sn,jn as Cn,jr as wn,jt as Tn,k as En,ki as Dn,kn as On,kt as kn,l as An,li as jn,ln as Mn,lr as Nn,lt as Pn,mi as Fn,mn as In,mr as Ln,mt as Rn,n as zn,ni as Bn,nn as Vn,nr as Hn,nt as Un,oa as Wn,oi as Gn,on as Kn,or as qn,ot as Jn,pn as Yn,pr as Xn,pt as Zn,q as Qn,qi as $n,qn as er,qr as tr,qt as nr,r as rr,ri as ir,rn as ar,rr as or,rt as sr,si as cr,sn as lr,sr as ur,st as dr,t as fr,ti as pr,tn as mr,tr as hr,tt as gr,u as _r,ui as vr,un as yr,ur as br,v as xr,vn as Sr,vr as Cr,vt as wr,w as Tr,wn as Er,wr as Dr,wt as Or,x as kr,xi as Ar,xn as jr,xr as Mr,xt as Nr,y as Pr,yi as Fr,yn as Ir,yr as Lr,z as Rr,zi as zr,zn as Br,zt as Vr}from"./effect-DJFrJOhz.js";import{$ as Hr,$n as Ur,$t as Wr,A as Gr,An as K,At as Kr,B as qr,Bn as Jr,Bt as Yr,C as Xr,Cn as Zr,Ct as Qr,D as $r,Dn as ei,Dt as ti,E as ni,En as ri,Et as ii,F as ai,Fn as oi,Ft as si,G as ci,Gn as li,Gt as ui,H as di,Hn as fi,Ht as pi,I as mi,In as hi,It as gi,J as _i,Jn as vi,Jt as q,K as yi,Kn as bi,Kt as xi,L as Si,Ln as Ci,Lt as wi,M as Ti,Mn as Ei,Mt as Di,N as Oi,Nn as ki,Nt as Ai,On as ji,Ot as Mi,P as Ni,Pn as Pi,Pt as Fi,Q as Ii,Qn as Li,Qt as Ri,R as zi,Rn as Bi,Rt as Vi,S as Hi,Sn as Ui,St as Wi,T as Gi,Tn as Ki,Tt as qi,U as Ji,Un as Yi,Ut as Xi,V as Zi,Vn as Qi,Vt as $i,W as ea,Wn as ta,Wt as na,X as ra,Xn as ia,Xt as aa,Y as oa,Yn as sa,Yt as ca,Z as la,Zn as ua,Zt as da,_ as fa,_n as pa,_t as ma,a as ha,an as ga,at as _a,b as va,bn as ya,bt as ba,c as xa,cn as Sa,ct as Ca,d as wa,dn as Ta,dt as Ea,en as Da,er as Oa,et as ka,f as Aa,fn as ja,ft as Ma,g as Na,gn as Pa,gt as Fa,h as Ia,hn as La,ht as Ra,i as za,in as Ba,it as Va,j as Ha,jn as J,jt as Ua,k as Wa,kn as Ga,kt as Ka,l as qa,ln as Ja,lt as Ya,m as Xa,mn as Za,mt as Qa,n as $a,nn as eo,nt as to,o as no,on as ro,ot as io,p as ao,pn as oo,pt as so,q as co,qn as lo,qt as uo,r as fo,rn as po,rt as mo,s as ho,sn as go,st as _o,t as vo,tn as yo,tr as bo,tt as xo,u as So,un as Co,ut as wo,v as To,vn as Eo,vt as Do,w as Y,wn as Oo,wt as ko,x as Ao,xn as jo,xt as Mo,y as No,yn as Po,yt as Fo,z as Io,zn as Lo}from"./index-GPYSTNwq.js";var Ro={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};Ro.node;var zo=Oa(Ro),Bo={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};Bo.node;var Vo=Oa(Bo),Ho={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Ho.node;var Uo=Oa(Ho),Wo={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};Wo.node;var Go=Oa(Wo),Ko={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Ko.node;var qo=Oa(Ko),Jo={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Jo.node;var Yo=Oa(Jo),Xo={name:`server`,size:24,node:[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]};Xo.node;var Zo=Oa(Xo),Qo=`data-open`,$o=`data-closed`,es=`data-anchor-hidden`,ts={[gi]:``},ns={[gi]:``,[wi]:``},rs={[Qo]:``},is={[$o]:``},as={[es]:``},os={open(e){return e?ts:null}},ss={open(e){return e?ns:null}},cs={open(e){return e?rs:is},anchorHidden(e){return e?as:null}},ls={...cs,...Vi};function us(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...us(e,t.id,n)])}function ds(e,t){let n=[],r=e.find(e=>e.id===t)?.parentId;for(;r;){let t=e.find(e=>e.id===r);r=t?.parentId,t&&(n=n.concat(t))}return n}function fs(e,t=!1){let{overflowY:n}=ki(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}function ps(e){let t=Ei(ms,e).current;return t.next=e,K(t.effect),t}function ms(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var hs=0;function gs(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(hs);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Ui;let o=requestAnimationFrame(a);return hs=o,()=>{hs===o&&(cancelAnimationFrame(o),hs=0)}}var _s=`data-base-ui-inert`,vs=new WeakMap,ys=new WeakSet,bs=new WeakMap,xs=0;function Ss(e){return e?lo(e)?e.host:Ss(e.parentNode):null}var Cs=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=Ss(t);return e.contains(n)?n:null}).filter(e=>e!=null),ws=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},Ts=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{Ci(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function Es(e,t,n,{mark:r=!0}){let i=Cs(t,e),a=r?Ts(t,ws(i),new Set(i)):[],o=[],s=[];if(n){let e=Cs(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);Ts(t,ws(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(vs.get(e)||0)+1;vs.set(e,r),o.push(e),r===1&&n&&ys.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(bs.get(e)||0)+1;bs.set(e,t),s.push(e),t===1&&e.setAttribute(_s,``)}),xs+=1,()=>{o.forEach(e=>{let t=(vs.get(e)||0)-1;vs.set(e,t),t||(ys.has(e)||e.removeAttribute(`aria-hidden`),ys.delete(e))}),r&&s.forEach(e=>{let t=(bs.get(e)||0)-1;bs.set(e,t),t||e.removeAttribute(_s)}),--xs,xs||(vs=new WeakMap,ys=new WeakSet,bs=new WeakMap)}}function Ds(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=ri(e[0]).body;return Es(e,i,n,{mark:r})}function Os(){let e=new Map;return{emit(t,n){e.get(t)?.forEach(e=>e(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}var ks=class{nodesRef={current:[]};events=Os();addNode(e){this.nodesRef.current.push(e)}removeNode(e){let t=this.nodesRef.current.findIndex(t=>t===e);t!==-1&&this.nodesRef.current.splice(t,1)}},X=e(a(),1),Z=i(),As=X.createContext(null),js=X.createContext(null),Ms=()=>X.useContext(As)?.id||null,Ns=e=>{let t=X.useContext(js);return e??t};function Ps(e){let t=ni(),n=Ns(e),r=Ms();return K(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function Fs(e){let{children:t,id:n}=e,r=Ms();return(0,Z.jsx)(As.Provider,{value:X.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Is(e){let{children:t,externalTree:n}=e,r=Ei(()=>n??new ks).current;return(0,Z.jsx)(js.Provider,{value:r,children:t})}function Ls(e,t){let n=Qi(ca(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(qi(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Rs=20,zs=[];function Bs(){zs=zs.filter(e=>e.deref()?.isConnected)}function Vs(e){Bs(),e&&Ci(e)!==`body`&&(zs.push(new WeakRef(e)),zs.length>Rs&&(zs=zs.slice(-20)))}function Hs(){return Bs(),zs[zs.length-1]?.deref()}function Us(e){return e?_i(e)?e:oa(e)[0]||e:null}function Ws(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Ji(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return _i(e)||e.hasAttribute(`data-tabindex`)&&!t.startsWith(`-`)}),n=e.getAttribute(`tabindex`);t.length===0?n!==`0`&&(e.setAttribute(`tabindex`,`0`),e.setAttribute(`data-tabindex`,`0`)):(n!==`-1`||e.hasAttribute(`data-tabindex`)&&e.getAttribute(`data-tabindex`)!==`-1`)&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`data-tabindex`,`-1`))}function Gs(e){let{context:t,children:n,disabled:r=!1,initialFocus:i=!0,returnFocus:a=!0,explicitReturnFocus:o,restoreFocus:s=!1,modal:c=!0,closeOnFocusOut:l=!0,openInteractionType:u=``,nextFocusableElement:d,previousFocusableElement:f,beforeContentFocusGuardRef:p,externalTree:m,getInsideElements:h}=e,g=t.useState(`open`),_=t.useState(`domReferenceElement`),v=t.useState(`floatingElement`),{events:y,dataRef:b}=t.context,x=J(()=>b.current.floatingContext?.nodeId),S=i===!1,C=Ai(_)&&S,w=ps(i),T=ps(a),E=ps(o),D=ps(u),O=ps(g),k=Ns(m),A=fo(),j=X.useRef(!1),M=X.useRef(!1),N=X.useRef(!1),P=X.useRef(null),F=X.useRef(``),I=X.useRef(``),L=X.useRef(null),R=X.useRef(null),ee=Zr(L,p,A?.beforeInsideRef),te=Zr(R,A?.afterInsideRef),ne=po(),z=po(),re=mi(),ie=A!=null,B=Mi(v),ae=J((e=B)=>e?oa(e):[]),oe=J(()=>h?.().filter(e=>e!=null)??[]);X.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&q(B,xi(ri(B)))&&ae().length===0&&!C&&ti(e)}let t=ri(B);return di(t,`keydown`,e)},[r,B,c,C,ae]),X.useEffect(()=>{if(r||!g)return;let e=ri(B);function t(){N.current=!1}function n(e){let t=ca(e),n=oe(),r=q(v,t)||q(_,t)||q(A?.portalNode,t)||n.some(e=>e===t||q(e,t));N.current=!r,I.current=e.pointerType||`keyboard`,uo(t,`[data-base-ui-click-trigger]`)&&(M.current=!0,z.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return Zi(di(e,`pointerdown`,n,!0),di(e,`pointerup`,t,!0),di(e,`pointercancel`,t,!0),di(e,`keydown`,i,!0),t)},[r,v,_,B,g,A,z,oe]),X.useEffect(()=>{if(r||!l)return;let e=ri(B);function n(){M.current=!0,z.start(0,()=>{M.current=!1})}function i(e){let t=ca(e);_i(t)&&(P.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=ca(n);c&&r==null&&a!=null&&q(v,a)&&Vs(a),queueMicrotask(()=>{let o=x(),l=t.context.triggerElements,u=oe(),p=r?.hasAttribute(za(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Ni(f),Ni(d)].includes(r),m=!(q(_,r)||q(v,r)||q(r,v)||q(A?.portalNode,r)||u.some(e=>e===r||q(e,r))||l.hasMatchingElement(e=>q(e,r))||p||k&&(us(k.nodesRef.current,o).find(e=>q(e.context?.elements.floating,r)||q(e.context?.elements.domReference,r))||ds(k.nodesRef.current,o).find(e=>[e.context?.elements.floating,Mi(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===_&&B&&Ws(B),s&&i!==_&&!ka(a)&&xi(e)===e.body){if(ta(B)&&(B.focus(),s===`popup`)){re.request(()=>{B.focus()});return}let e=ae(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||B;ta(n)&&n.focus()}b.current.insideReactTree?b.current.insideReactTree=!1:(C||!c)&&r&&m&&!M.current&&(C||r!==Hs())&&(j.current=!0,t.setOpen(!1,Y(qa,n)))})}function o(){N.current||(b.current.insideReactTree=!0,ne.start(0,()=>{b.current.insideReactTree=!1}))}let u=ta(_)?_:null;if(v||u)return Zi(u&&di(u,`focusout`,a),u&&di(u,`pointerdown`,n),v&&di(v,`focusin`,i),v&&di(v,`focusout`,a),v&&A&&di(v,`focusout`,o,!0))},[r,_,v,B,c,k,A,t,l,s,ae,C,x,b,ne,z,re,d,f,oe]),X.useEffect(()=>{if(r||!v||!g)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${za(`portal`)}]`)||[]),t=(k?ds(k.nodesRef.current,x()):[]).find(e=>Ai(e.context?.elements.domReference||null))?.context?.elements.domReference,n=Ds([v,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...oe(),t,Ni(f),Ni(d),C?_:null].filter(e=>e!=null),{ariaHidden:c||C,mark:!1}),i=Ds([v,...e].filter(e=>e!=null));return()=>{i(),n()}},[g,r,_,v,c,A,C,k,x,d,f,oe]),K(()=>{if(!g||r||!ta(B))return;F.current=``,I.current=``;let e=ri(B),t=xi(e);queueMicrotask(()=>{let n=w.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||q(B,t))return;let i=null,a=()=>(i??=ae(B),i[0]||B),o;o=r===!0||r===null?a():Ni(r),o||=a();let s=q(B,xi(e)),c=b.current.openEvent,l=c?.type===`mousedown`&&qi(c);gs(o,{sync:l,preventScroll:o===B,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=xi(e);return!(t!==o&&q(B,t))}})})},[r,g,B,ae,w,D,O,b]);let se=X.useRef(null);K(()=>{if(r||!B){se.current=null;return}se.current&&=(se.current.cancelled=!0,null);let e=ri(B),t=xi(e),n=D.current==null;Vs(t);function i(e){if(e.open||(F.current=Ls(e.nativeEvent,I.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(za(`focus-guard`))||e.reason===`trigger-hover`&&e.nativeEvent.type===`mouseleave`)&&(j.current=!0),e.reason===`outside-press`){if(e.nested)j.current=!1;else if(qi(e.nativeEvent)||ii(e.nativeEvent))j.current=!1;else{let e=!1;ri(B).createElement(`div`).focus({get preventScroll(){return e=!0,!1}}),e?j.current=!1:j.current=!0}}}y.on(`openchange`,i);function a(e){let r=T.current,i=typeof r==`function`?r(e):r;if(i===void 0||i===!1)return null;i===null&&(i=!0);let a=_?.isConnected?_:null,o=t?.isConnected&&Ci(t)!==`body`?t:null,s=n?o||a:a||o;return s||=Hs()||null,typeof i==`boolean`?s:Ni(i)||s||null}return()=>{y.off(`openchange`,i);let t=xi(e),n=oe(),r=q(v,t)||n.some(e=>e===t||q(e,t))||k&&us(k.nodesRef.current,x(),!1).some(e=>q(e.context?.elements.floating,t)),o=T.current,s=F.current,c=a(s),l={cancelled:!1};se.current=l,queueMicrotask(()=>{se.current===l&&(se.current=null);let n=Us(c),i=E.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!j.current&&ta(n)&&(i||n===t||t===e.body||r)){let e={preventScroll:!0};s===`keyboard`&&(e.focusVisible=!0),n.focus(e)}j.current=!1})}},[r,v,B,T,E,D,y,k,_,x,oe]),K(()=>{if(!Ri||g||!v)return;let e=xi(ri(v));ta(e)&&Fi(e)&&q(v,e)&&e.blur()},[g,v]),K(()=>{if(!r&&A)return A.setFocusManagerState({modal:c,closeOnFocusOut:l,open:g,onOpenChange:t.setOpen,domReference:_}),()=>{A.setFocusManagerState(null)}},[r,A,c,g,t,l,_]),K(()=>{if(!r&&B)return Ws(B),()=>{queueMicrotask(Bs)}},[r,B]);let ce=!r&&(!c||!C)&&(ie||c);return(0,Z.jsxs)(X.Fragment,{children:[ce&&(0,Z.jsx)(zi,{"data-type":`inside`,ref:ee,onFocus:e=>{if(c){let e=ae();gs(e[e.length-1])}else A?.portalNode&&(j.current=!1,co(e,A.portalNode)?ea(_)?.focus():Ni(f??A.beforeOutsideRef)?.focus())}}),n,ce&&(0,Z.jsx)(zi,{"data-type":`inside`,ref:te,onFocus:e=>{c?gs(ae()[0]):A?.portalNode&&(l&&(j.current=!0),co(e,A.portalNode)?ci(_)?.focus():Ni(d??A.afterOutsideRef)?.focus())}})]})}function Ks(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=Xr}=t,l=e.context.dataRef,u=X.useRef(void 0),d=mi(),f=po(),p=X.useMemo(()=>{function t(t,n,r,i){let a=Y(c,n,r);t&&i===`touch`&&s>0?f.start(s,()=>{e.setOpen(!0,a)}):e.setOpen(t,a)}function n(t,n,r){let a=l.current.openEvent,s=e.select(`domReferenceElement`)!==n;return t&&s||!t||!i?!0:a&&(typeof o==`function`?o():o)?!r(a.type):!1}return{onPointerDown(e){u.current=Qr(e.pointerType,!0)&&ii(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||Qr(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=ca(s),p=Fi(f);if(p||o===`virtual`){t(l,s,p?f:i.currentTarget,o);return}let m=i.currentTarget;d.request(()=>{t(l,s,m,o)})},onClick(i){if(r===`mousedown-only`)return;let o=u.current;r===`mousedown`&&o?u.current=void 0:Qr(o,!0)&&a||t(n(e.select(`open`),i.currentTarget,e=>e===`click`||e===`mousedown`||e===`keydown`||e===`keyup`),i.nativeEvent,i.currentTarget,o)},onKeyDown(){u.current=void 0}}},[l,r,a,c,e,o,i,d,f,s]);return X.useMemo(()=>n?{reference:p}:jo,[n,p])}function qs(){return!1}function Js(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function Ys(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=qs,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:f}=e.context,p=Ns(c),m=J(typeof i==`function`?i:()=>!1),h=typeof i==`function`?m:i,g=h!==!1,_=J(()=>a),{escapeKey:v,outsidePress:y}=Js(s),b=X.useRef(!1),x=X.useRef(!1),S=X.useRef(!1),C=X.useRef(!1),w=X.useRef(!1),T=X.useRef(``),E=X.useRef(null),D=po(),O=po(),k=po(),A=J(()=>{O.clear(),d.current.insideReactTree=!1}),j=J(e=>{let t=d.current.floatingContext?.nodeId;return(p?us(p.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),M=J(t=>Ka(t,e.select(`floatingElement`))||Ka(t,e.select(`domReferenceElement`))),N=J(t=>{o()&&e.setOpen(!1,Y(Xr,t.nativeEvent))}),P=J(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=ko(t)?t.nativeEvent:t;if(w.current||i.isComposing||!v&&j(`__escapeKeyBubbles`))return;let a=Y(xa,i);e.setOpen(!1,a),a.isCanceled||t.preventDefault(),!v&&!a.isPropagationAllowed&&t.stopPropagation()}),F=J(()=>{d.current.insideReactTree=!0,O.start(0,A)}),I=J(t=>{if(!l||!n||t.button!==0)return;let r=ca(t.nativeEvent);q(e.select(`floatingElement`),r)&&(b.current||(b.current=!0,x.current=!1))}),L=J(e=>{l&&n&&(e.defaultPrevented||e.nativeEvent.defaultPrevented)&&b.current&&(x.current=!0)});X.useEffect(()=>{function e(e){e.open||(C.current=!1)}return f.on(`openchange`,e),()=>{f.off(`openchange`,e)}},[f]),X.useEffect(()=>A,[A]),X.useEffect(()=>{if(!l||!n)return l||(C.current=!1,w.current=!1,T.current=``,E.current=null),A;d.current.__escapeKeyBubbles=v,d.current.__outsidePressBubbles=y;let t=new eo,i=ri(u);function a(){k.clear(),w.current=!0}function o(){w.current=!0,k.start(Ri?5:0,()=>{w.current=!1})}function s(){S.current=!0,t.start(0,()=>{S.current=!1})}function c(){b.current=!1,x.current=!1}function f(){let e=T.current,t=e===`pen`||!e?`mouse`:e,n=_(),r=typeof n==`function`?n():n;return typeof r==`string`?r:r[t]}function m(e){let t=f();return t===`intentional`&&e.type!==`click`||t===`sloppy`&&e.type===`click`}function O(e){let t=d.current.floatingContext?.nodeId,n=p&&us(p.nodesRef.current,t).some(t=>Ka(e,t.context?.elements.floating));return M(e)||n}function N(n){if(m(n)){n.type!==`click`&&!M(n)&&(t.clear(),S.current=!1),A();return}if(d.current.insideReactTree){A();return}let r=ca(n),i=`[${za(`inert`)}]`,a=Yi(r)?r.getRootNode():null,o=Array.from((lo(a)?a:ri(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>q(e,r))))return;let c=Yi(r)?r:null;for(;c&&!li(c);){let e=Jr(c);if(li(e)||!Yi(e))break;c=e}if(!(o.length&&Yi(r)&&!Ua(r)&&!q(r,e.select(`floatingElement`))&&o.every(e=>!q(c,e)))){if(ta(r)&&!(`touches`in n)){let e=li(r),t=ki(r),i=/auto|scroll/,a=e||i.test(t.overflowX),o=e||i.test(t.overflowY),s=a&&r.clientWidth>0&&r.scrollWidth>r.clientWidth,c=o&&r.clientHeight>0&&r.scrollHeight>r.clientHeight,l=t.direction===`rtl`,u=c&&(l?n.offsetX<=r.offsetWidth-r.clientWidth:n.offsetX>r.clientWidth),d=s&&n.offsetY>r.clientHeight;if(u||d)return}if(!O(n)){if(f()===`intentional`){if(n.detail!==0&&!qi(n)&&!C.current)return;if(S.current){t.clear(),S.current=!1;return}}typeof h==`function`&&!h(n)||j(`__outsidePressBubbles`)||(e.setOpen(!1,Y(To,n)),A())}}}function F(t){f()===`sloppy`&&t.pointerType!==`touch`&&e.select(`open`)&&n&&!M(t)&&N(t)}function I(t){if(f()!==`sloppy`||!e.select(`open`)||!n||M(t))return;let r=t.touches[0];r&&(E.current={startTime:Date.now(),startX:r.clientX,startY:r.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},D.start(1e3,()=>{E.current&&(E.current.dismissOnTouchEnd=!1,E.current.dismissOnMouseDown=!1)}))}function L(e,t){let n=ca(e);if(!n)return;let r=di(n,e.type,()=>{t(e),r()})}function R(e){T.current=`touch`,L(e,I)}function ee(e){D.clear(),e.type===`pointerdown`&&(e.button===0&&(C.current=!0),T.current=e.pointerType),(e.type!==`mousedown`||!E.current||E.current.dismissOnMouseDown)&&L(e,e=>{e.type===`pointerdown`?F(e):N(e)})}function te(e){if(e.type===`pointercancel`&&(C.current=!1),!b.current)return;let n=x.current;c(),f()===`intentional`&&(e.type===`pointercancel`?n&&s():O(e)||(n?s():(typeof h!=`function`||h(e))&&(t.clear(),S.current=!0,A())))}function ne(e){if(f()!==`sloppy`||!E.current||M(e))return;let t=e.touches[0];if(!t)return;let n=Math.abs(t.clientX-E.current.startX),r=Math.abs(t.clientY-E.current.startY),i=Math.sqrt(n*n+r*r);i>5&&(E.current.dismissOnTouchEnd=!0),i>10&&(N(e),D.clear(),E.current=null)}function z(e){L(e,ne)}function re(e){f()===`sloppy`&&E.current&&!M(e)&&(E.current.dismissOnTouchEnd&&N(e),D.clear(),E.current=null)}function ie(e){L(e,re)}let B=Zi(r&&Zi(di(i,`keydown`,P),di(i,`compositionstart`,a),di(i,`compositionend`,o)),g&&Zi(di(i,`click`,ee,!0),di(i,`pointerdown`,ee,!0),di(i,`pointerup`,te,!0),di(i,`pointercancel`,te,!0),di(i,`mousedown`,ee,!0),di(i,`mouseup`,te,!0),di(i,`touchstart`,R,{capture:!0,passive:!0}),di(i,`touchmove`,z,{capture:!0,passive:!0}),di(i,`touchend`,ie,{capture:!0,passive:!0})));return()=>{B(),t.clear(),c(),S.current=!1}},[d,u,r,g,h,l,n,v,y,P,A,_,j,M,p,e,D,k]);let R=X.useMemo(()=>({onKeyDown:P,onPointerDown:N,onClick:N}),[P,N]),ee=X.useMemo(()=>({onKeyDown:P,onPointerDown:L,onMouseDown:L,onClickCapture:F,onMouseDownCapture(e){F(),I(e)},onPointerDownCapture(e){F(),I(e)},onMouseUpCapture:F,onTouchEndCapture:F,onTouchMoveCapture:F}),[P,F,I,L]);return X.useMemo(()=>n?{reference:R,floating:ee,trigger:R}:{},[n,R,ee])}function Xs(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),l=t.useState(n?`popupElement`:`positionerElement`),u=o;return t.useSyncedValue(`floatingId`,i),K(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:l};Yi(c)&&(e.domReferenceElement=c),r.state.positionReference===r.state.referenceElement&&(e.positionReference=c),r.update(e)},[s,i,c,l,r]),r.context.onOpenChange=u,r.context.nested=a,r}function Zs(e,t=!1,n=!1,r=!1){let[i,a]=X.useState(e&&t?`idle`:void 0),[o,s]=X.useState(e&&!r);return e&&!o&&(s(!0),a(`starting`)),!e&&o&&i!==`ending`&&!n&&a(`ending`),!e&&!o&&i===`ending`&&a(void 0),K(()=>{if(!e&&o&&i!==`ending`&&n){let e=ai.request(()=>{a(`ending`)});return()=>{ai.cancel(e)}}},[e,o,i,n]),K(()=>{if(!e||t||i===void 0)return;let n=ai.request(()=>{a(void 0)});return()=>{ai.cancel(n)}},[t,e,i]),K(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=ai.request(()=>{a(`idle`)});return()=>{ai.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function Qs(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=J(i),{mounted:c,setMounted:l,transitionStatus:u}=Zs(t,!1,!1,o),d=!t&&r;K(()=>{t&&s(!1)},[t,s]);let f=X.useRef(c),p=X.useRef(!1),m=$r(),h=()=>{f.current=!1,l(!1),a()};K(()=>{f.current=c,p.current&&(p.current=!1,!t&&c&&h())});let g=J(()=>{f.current&&(t?(p.current=!0,m()):h())});return Ti({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||g()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:g}}var $s=e(n(),1),ec={tabIndex:-1,[ui]:``};function tc(e){return t=>t!==`touch`||e.current}function nc(e,t=!1){let n=ni(),r=Ms()!=null,i=Ei(()=>e(n,r)).current;return Xs({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function rc({handle:e,store:t}){return K(()=>e.attachStore(t),[e,t]),null}function ic(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function ac(e,t){let n=X.useRef(null);return J(r=>{let i=n.current;if(i!==null){if(i.element===r&&i.store===t&&i.id===e)return;n.current=null;let a=i.store;a.context.triggerElements.getById(i.id)===i.element&&(a.context.triggerElements.delete(i.id),ic(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),ic(t))})}function oc(e,t,n,r=!1){let i=e.preventUnmountingOnClose;t?i=!1:r&&(i=!0);let a=n?.id??null,o=e.activeTriggerId,s=e.activeTriggerElement;return(a||t)&&(o=a,s=n??null),{open:t,preventUnmountingOnClose:i,activeTriggerId:o,activeTriggerElement:s,openedWithoutTrigger:t?n==null:e.openedWithoutTrigger}}function sc(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function cc(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=ac(e,n),o=J(t=>{let i=n.select(`open`),a=n.select(`activeTriggerId`);if(a===e){let e={activeTriggerElement:t,...i?r:null};n.update(e)}else if(a==null&&i&&!n.state.openedWithoutTrigger){let i={activeTriggerId:e??null,activeTriggerElement:t,...r};n.update(i)}}),s=J(e=>{a(e),e&&o(e)});return K(()=>(s(t.current),()=>s(null)),[s,t,n,e]),K(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function lc(e,t={}){let{closeOnActiveTriggerUnmount:n=!1}=t,r=X.useRef(null),i=e.useState(`open`),a=e.useState(`triggerCount`),o=e.useState(`activeTriggerId`),s=e.useState(`activeTriggerElement`);K(()=>{if(!i){r.current=null,e.state.triggerCount!==0&&e.set(`triggerCount`,0),e.state.openedWithoutTrigger&&e.set(`openedWithoutTrigger`,!1);return}let t=e.context.triggerElements.size,a={};e.state.triggerCount!==t&&(a.triggerCount=t);let o=e.select(`activeTriggerId`),s=null;if(o){let t=e.context.triggerElements.getById(o);if(t)r.current=o,t!==e.state.activeTriggerElement&&(a.activeTriggerElement=t);else{for(let[t,n]of e.context.triggerElements.entries())if(n===e.state.activeTriggerElement){a.activeTriggerId=t,a.activeTriggerElement=n,r.current=t;break}a.activeTriggerId===void 0&&(r.current===o?s=o:r.current=null)}}else r.current=null;if(!s&&!o&&!e.state.openedWithoutTrigger&&t===1){let t=e.context.triggerElements.entries().next();if(!t.done){let[e,n]=t.value;a.activeTriggerId=e,a.activeTriggerElement=n,r.current=e}}(a.triggerCount!==void 0||a.activeTriggerId!==void 0||a.activeTriggerElement!==void 0)&&e.update(a),s&&n&&queueMicrotask(()=>{if(e.select(`open`)&&e.select(`activeTriggerId`)===s&&!e.context.triggerElements.getById(s)){let t=Y(fa);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,a,o,s,n])}function uc(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=Qs({open:e,ref:t.context.popupRef,preventUnmountOnClose:t.useState(`preventUnmountingOnClose`),setPreventUnmountOnClose:e=>t.set(`preventUnmountingOnClose`,e),animateInitialOpen:r,onUnmount(){t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)}});return Ei(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function dc(e,t){e.useSyncedValues(t),K(()=>()=>{e.update({activeTriggerProps:jo,inactiveTriggerProps:jo,popupProps:jo})},[e])}function fc(e,t){K(()=>{!t&&e.state.openMethod!==null&&e.set(`openMethod`,null)},[t,e]),K(()=>()=>{e.state.openMethod!==null&&e.set(`openMethod`,null)},[e])}var pc=class{idMap=new Map;add(e,t){this.idMap.set(e,t)}delete(e){this.idMap.delete(e)}hasElement(e){for(let t of this.idMap.values())if(t===e)return!0;return!1}hasMatchingElement(e){for(let t of this.idMap.values())if(e(t))return!0;return!1}getById(e){return this.idMap.get(e)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}},mc={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId},hc=class extends Ba{constructor(e){let{syncOnly:t,nested:n,onOpenChange:r,triggerElements:i,...a}=e;super({...a,positionReference:a.referenceElement,domReferenceElement:a.referenceElement},{onOpenChange:r,dataRef:{current:{}},events:Os(),nested:n,triggerElements:i},mc),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&Wi(t))&&(this.context.dataRef.current.openEvent=e?t:void 0)};dispatchOpenChange=(e,t)=>{this.syncOpenEvent(e,t.event);let n={open:e,reason:t.reason,nativeEvent:t.event,nested:this.context.nested,triggerElement:t.trigger};this.context.events.emit(`openchange`,n)};setOpen=(e,t)=>{this.syncOnly||this.dispatchOpenChange(e,t),this.context.onOpenChange?.(e,t)}};function gc(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new hc({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,openedWithoutTrigger:!1,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:jo,inactiveTriggerProps:jo,popupProps:jo}}var _c=e=>e.triggerIdProp??e.activeTriggerId,vc=e=>e.openProp??e.open,yc=e=>(e.popupElement?.id??e.floatingId)||void 0;function bc(e,t){return t!==void 0&&vc(e)&&_c(e)===t}function xc(e,t){return bc(e,t)?!0:t!==void 0&&vc(e)&&_c(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var Sc={open:vc,mounted:e=>e.mounted,transitionStatus:e=>vc(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:_c,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:yc,isTriggerActive:(e,t)=>t!==void 0&&_c(e)===t,isOpenedByTrigger:(e,t)=>bc(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&_c(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>xc(e,t)?yc(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement},Cc=bo();function wc(e){let t=X.useCallback(t=>e===void 0?Ui:e.subscribeStore(t),[e]),n=X.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Cc.useSyncExternalStore)(t,n,()=>e?.serverStore)}function Tc(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=ni(),a=Ms()!=null,o=Ei(()=>new hc({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new pc,floatingId:i,syncOnly:!1,nested:a})).current;return K(()=>{let e={open:t,floatingId:i};r.reference!==void 0&&(e.referenceElement=r.reference,e.domReferenceElement=Yi(r.reference)?r.reference:null),r.floating!==void 0&&(e.floatingElement=r.floating),o.update(e)},[t,i,r.reference,r.floating,o]),o.context.onOpenChange=n,o.context.nested=a,o}var Ec=yo&&Ri;function Dc(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=X.useRef(!1),s=X.useRef(null),c=X.useRef(!0),l=po();X.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=Qi(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&ta(t)&&t===xi(ri(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return Zi(di(r,`blur`,i),Ec&&di(r,`keydown`,a,!0),Ec&&di(r,`pointerdown`,l,!0))},[e,n]),X.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);Yi(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=X.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=ca(n.nativeEvent);if(Yi(a)){if(Ec&&!n.relatedTarget){if(!c.current&&!Fi(a))return}else if(!si(a))return}let u=Di(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,Y(Ao,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,Y(Ao,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=Yi(r)&&r.hasAttribute(za(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=xi(ri(t));!r&&n===t||q(a.current.floatingContext?.refs.floating.current,n)||q(t,n)||o||Di(r??n,e.context.triggerElements)||e.setOpen(!1,Y(Ao,i))})}}},[a,r,e,l]);return X.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var Oc=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new eo;restTimeout=new eo;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},kc=new WeakMap;function Ac(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&kc.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),kc.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function jc(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=kc.get(n);a&&a!==e&&Ac(a),Ac(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,kc.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Mc(e){let t=e.context.dataRef.current,n=Ei(()=>t.hoverInteractionState??Oc.create()).current;return t.hoverInteractionState||=n,go(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Nc(e,t){return t!=null&&!Qr(t)?0:typeof e==`function`?e():e}function Pc(e,t,n){let r=Nc(e,n);return typeof r==`number`?r:r?.[t]}function Fc(e){return typeof e==`function`?e():e}function Ic(e,t){return t||e===`click`||e===`mousedown`}function Lc(e){return e?.includes(`mouse`)&&e!==`mousedown`}function Rc(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=e.useState(`open`),o=e.useState(`floatingElement`),s=e.useState(`domReferenceElement`),{dataRef:c}=e.context,l=Ns(),u=Ms(),d=Mc(e),f=po(),p=J(()=>Ic(c.current.openEvent?.type,d.interactedInside)),m=J(()=>Lc(c.current.openEvent?.type)),h=J(()=>{Ac(d)});K(()=>{a||(d.pointerType=void 0,d.restTimeoutPending=!1,d.interactedInside=!1,h())},[a,d,h]),X.useEffect(()=>h,[h]),K(()=>{if(n&&a&&d.handleCloseOptions?.blockPointerEvents&&m()&&Yi(s)&&o){let e=s,t=o,n=ri(o),r=l?.nodesRef.current.find(e=>e.id===u)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=d.pointerEventsScopeElement===t?null:d.pointerEventsScopeElement,a=r===t?null:r,c=d.handleCloseOptions?.getScope?.()??i??a??uo(e,`[data-rootownerid]`)??n.body;return jc(d,{scopeElement:c,referenceElement:e,floatingElement:t}),()=>{h()}}},[n,a,s,o,d,m,l,u,h]),X.useEffect(()=>{if(!n)return;function t(){return!!(l&&u&&us(l.nodesRef.current,u).length>0)}function a(t){let n=Pc(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,Y(Hi,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=ca(e);Kr(t)?d.interactedInside=uo(t,`[aria-haspopup]`)!=null:d.interactedInside=!1}function g(){d.openChangeTimeout.clear(),f.clear(),l?.events.off(`floating.closed`,v),h()}function _(n){if(t()&&l){l.events.on(`floating.closed`,v);return}if(Di(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&Yi(o)&&us(l.nodesRef.current,r,!1).some(e=>q(e.context?.elements.floating,o))||(d.handler?d.handler(n):(h(),m()&&!p()&&a(n)))}function v(n){l&&u&&!t()&&f.start(0,()=>{l.events.off(`floating.closed`,v),e.setOpen(!1,Y(Hi,n)),l.events.emit(`floating.closed`,n)})}let y=o;return Zi(y&&di(y,`mouseenter`,g),y&&di(y,`mouseleave`,_),y&&di(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var zc={current:null};function Bc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=zc,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=Ns(l),v=Mc(e),y=X.useRef(!1),b=ps(i),x=ps(r),S=ps(o),C=ps(n),w=ps(p),T=ps(f),E=J(()=>Ic(h.current.openEvent?.type,v.interactedInside)),D=J(()=>w.current?.()!==!1),O=J((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!q(t,n);if(!Yi(r))return!1;let a=r;return i.hasMatchingElement(e=>q(e,a))&&(!t||!q(t,a))}),k=J(()=>{v.handler&&=(ri(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=J(()=>{Ac(v)});return u&&(v.handleCloseOptions=i?.__options),X.useEffect(()=>k,[k]),X.useEffect(()=>{if(!n)return;function e(e){e.open?y.current=!1:(y.current=e.reason===Hi,k(),v.openChangeTimeout.clear(),v.restTimeout.clear(),v.blockMouseMove=!0,v.restTimeoutPending=!1)}return g.on(`openchange`,e),()=>{g.off(`openchange`,e)}},[n,g,v,k]),X.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=Pc(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,Y(Hi,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,Y(Hi,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!Yi(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!Qr(v.pointerType))return;let n=Fc(S.current),r=Pc(x.current,`open`,v.pointerType),i=ca(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(Yi(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(q(t,i)){c=t;break}}Yi(o)&&Yi(s)&&!e.context.triggerElements.hasElement(o)&&q(o,s)&&(c=s);let l=c!=null&&O(s,c,i),u=e.select(`open`),d=T.current?.()??e.select(`transitionStatus`)===`ending`,f=!u&&d&&y.current,p=!l&&Yi(c)&&Yi(s)&&q(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,Y(Hi,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,Y(Hi,t,c))}):g&&D()&&e.setOpen(!0,Y(Hi,t,c)))}function o(n){if(E()){A();return}k();let r=e.select(`domReferenceElement`),i=ri(r);v.restTimeout.clear(),v.restTimeoutPending=!1;let a=h.current.floatingContext??d?.();if(!Di(n.relatedTarget,e.context.triggerElements)){if(b.current&&a){e.select(`open`)||v.openChangeTimeout.clear();let r=c.current;v.handler=b.current({...a,tree:_,x:n.clientX,y:n.clientY,onClose(){A(),k(),C.current&&!E()&&r===e.select(`domReferenceElement`)&&t(n,!0)}}),i.addEventListener(`mousemove`,v.handler),v.handler(n)}else v.pointerType===`touch`&&q(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){q(r,e.relatedTarget)||(v.openChangeTimeout.clear(),v.restTimeout.clear(),v.restTimeoutPending=!1)}let f=m?di(r,`mouseout`,l):void 0;return s?Zi(di(r,`mousemove`,i,{once:!0}),di(r,`mouseenter`,i),di(r,`mouseleave`,o),f):Zi(di(r,`mouseenter`,i),di(r,`mouseleave`,o),f)},[k,A,h,x,e,n,b,v,u,O,E,a,s,S,c,_,C,d,T,D,m]),X.useMemo(()=>{if(!n)return;function t(e){v.pointerType=e.pointerType}return{onPointerDown:t,onPointerEnter:t,onMouseMove(t){let{nativeEvent:n}=t,r=t.currentTarget,i=e.select(`domReferenceElement`),o=e.select(`open`),s=O(i,r,t.target);if(a&&!Qr(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;jc(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=Fc(S.current);if(o&&!s||c===0||!s&&v.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;v.restTimeout.clear();function l(){if(v.restTimeoutPending=!1,E())return;let t=e.select(`open`);!v.blockMouseMove&&(!t||s)&&D()&&e.setOpen(!0,Y(Hi,n,r))}v.pointerType===`touch`?$s.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}function Vc(e){return Ri&&e.movementX===0&&e.movementY===0}function Hc(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function Uc(e,t){return Hc(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Wc(e,t,n){return Hc(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function Gc(e,t,n){return Hc(t,n?e===pi:e===Xi,e===$i)}function Kc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Hc(t,n?e===Xi:e===pi,e===na)}function qc(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:l=!1,rtl:u=!1,virtual:d=!1,focusItemOnOpen:f=`auto`,focusItemOnHover:p=!0,openOnArrowKeyDown:m=!0,disabledIndices:h=void 0,orientation:g=`vertical`,triggerOrientation:_=g,parentOrientation:v,id:y,resetOnPointerLeave:b=!0,externalTree:x,nestedReturnFocusRef:S,grid:C}=t,w=C!=null,T=e.useState(`open`),E=e.useState(`floatingElement`),D=e.useState(`domReferenceElement`),O=e.context.dataRef,k=Mi(E),A=Ai(D),j=ps(k),M=Ms(),N=Ns(x),P=X.useRef(f),F=X.useRef(o??-1),I=X.useRef(null),L=X.useRef(!0),R=J(e=>{i(F.current===-1?null:F.current,e)}),ee=X.useRef(!!E),te=X.useRef(T),ne=X.useRef(!1),z=X.useRef(!1),re=X.useRef(null),ie=ps(h),B=ps(T),ae=ps(o),oe=ps(b),se=mi(),ce=mi(),le=J(()=>{se.cancel();function e(e){d||(re.current=gs(e,{sync:ne.current,preventScroll:!0}))}let t=n.current[F.current],r=z.current;t&&e(t),(ne.current?e=>e():e=>se.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),he&&(r||!L.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});K(()=>{O.current.orientation=g},[O,g]),K(()=>{T||(I.current=null),T&&f===`auto`||(P.current=f)},[T,f]),K(()=>{a&&(T&&E?(F.current=o??-1,P.current&&o!=null&&(z.current=!0,R())):ee.current&&(F.current=-1,R()))},[a,T,E,o,R]),K(()=>{if(a){if(!T)ne.current=!1;else if(E){if(r==null){if(ne.current=!1,ae.current!=null)return;if(ee.current&&(F.current=-1,le()),(!te.current||!ee.current)&&P.current&&(I.current!=null||P.current===!0&&I.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ce.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||Wc(I.current,_,u)||l?Ii(n):la(n),I.current=null,R())};t()}}else xo(n.current,r)||(F.current=r,le(),z.current=!1)}}},[a,T,E,r,ae,l,n,_,u,R,le,ce]),K(()=>{if(!a||E||!N||d||!ee.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=xi(ri(D??t??null)),r=e.some(e=>e.context&&q(e.context.elements.floating,n));t&&!r&&L.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,d]),K(()=>{te.current=T,ee.current=!!E});let ue=r!=null,de=J(e=>{if(!B.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(F.current!==t||r!==t)&&(F.current=t,R(e))}),fe=J(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),pe=J(()=>Ii(n,ie.current)),me=J(t=>{if(L.current=!1,ne.current=!0,t.which===229||!B.current&&t.currentTarget===j.current)return;if(l&&Kc(t.key,g,u,w)){Uc(t.key,fe())||ti(t),e.setOpen(!1,Y(Na,t.nativeEvent));let n=S?.current??D;ta(n)&&n.focus();return}r!=null&&r!==F.current&&!xo(n.current,r)&&(F.current=r);let i=F.current,a=Ii(n,h),o=la(n,h);if(A||(t.key===`Home`&&(ti(t),F.current=a,R(t)),t.key===`End`&&(ti(t),F.current=o,R(t))),C!=null){let e=C(t,F.current,n,g,c,u,h,a,o);if(e!=null&&e!==F.current&&(F.current=e,R(t)),g===`both`)return}if(Uc(t.key,g)){ti(t);let e=xi(t.currentTarget.ownerDocument);if(T&&!d&&q(t.currentTarget,e)&&!n.current.some(t=>t!=null&&q(t,e))){F.current=Wc(t.key,g,u)?a:o,R(t),r===F.current&&le();return}let{index:l,wrapped:f}=Hr(n.current,i,{decrement:!Wc(t.key,g,u),loopFocus:c,allowEscape:s,disabledIndices:h,minIndex:a,maxIndex:o});f&&(ne.current=!1),F.current=l,R(t)}}),he=X.useMemo(()=>({onFocus(e){ne.current=!0,de(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){Vc(e)||(ne.current=!0,z.current=!1,p&&de(e))},onPointerLeave(e){if(!B.current||!L.current||e.pointerType===`touch`)return;ne.current=!0;let t=e.relatedTarget;if(p&&!n.current.includes(t)&&oe.current&&(re.current?.(),re.current=null,F.current=-1,R(e),!d)){let e=j.current,t=xi(ri(e));e&&q(e,t)&&e.focus({preventScroll:!0})}}}),[de,B,j,p,n,R,oe,d]),ge=X.useMemo(()=>d&&T&&ue&&{"aria-activedescendant":`${y}-${r}`},[d,T,ue,y,r]),_e=X.useMemo(()=>({...A?{}:ge,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&T&&!d){let n=ca(t.nativeEvent);if(n&&!q(j.current,n))return;ti(t);let r=Y(qa,t.nativeEvent);e.setOpen(!1,r);let i=S?.current??D;!r.isCanceled&&ta(i)&&i.focus()}else me(t)},onPointerMove(e){Vc(e)||(L.current=!0)}}),[ge,me,j,A,e,T,d,D,S]),ve=X.useMemo(()=>{function t(t){e.setOpen(!0,Y(Na,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&qi(e.nativeEvent)&&(P.current=!d)}function r(e){P.current=f,f===`auto`&&ii(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(n){let r=e.select(`open`);L.current=!1;let i=n.key.startsWith(`Arrow`),a=Gc(n.key,fe(),u),o=Uc(n.key,r?g:_),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||Fi(n.currentTarget)))return me(n);if(r||m||!i){if(s){let e=Uc(n.key,fe());I.current=l&&e?null:n.key}l?a&&(ti(n),r?(F.current=pe(),R(n),d&&j.current?.focus()):t(n)):o&&(ae.current!=null&&(F.current=ae.current),ti(n),!r&&m?t(n):me(n),r&&R(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!d&&(F.current=-1,R(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[me,f,pe,l,R,e,m,g,_,fe,u,ae,d,j]),ye=X.useMemo(()=>({...ge,...ve}),[ge,ve]);return X.useMemo(()=>a?{reference:ye,floating:_e,item:he,trigger:ve}:{},[a,ye,_e,ve,he])}function Jc(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=J(s),f=e.useState(`open`),p=po(),m=X.useRef(``),h=X.useRef(u??i??-1),g=X.useRef(null),_=J(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!ka(n)||n?.matches(`:disabled`)?!1:o==null||!to(ya,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(e[n]?.toLowerCase().startsWith(i)&&s(n))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(ti(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(ti(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=J(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);q(r,n)||q(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});K(()=>{(f||u===null)&&(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=X.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return X.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}var Yc=.1,Xc=Yc*Yc,Zc=.5;function Qc(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function $c(e,t,n,r,i,a,o,s,c,l){let u=!1;return Qc(e,t,n,r,i,a)&&(u=!u),Qc(e,t,i,a,o,s)&&(u=!u),Qc(e,t,o,s,c,l)&&(u=!u),Qc(e,t,c,l,n,r)&&(u=!u),u}function el(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function tl(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function nl(e={}){let{blockPointerEvents:t=!1}=e,n=new eo,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*Xc;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=ca(r),g=r.type===`mouseleave`,_=q(u,h),v=q(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&Yi(r.relatedTarget)&&q(u,r.relatedTarget))return;function y(){return!!(s&&us(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=tl(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=tl(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=tl(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=tl(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!el(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?Zc/2:Zc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+Zc+1,o=C||T?S.bottom-Zc:S.top,s=C?T?S.bottom-Zc:S.top:S.bottom-Zc;M=$c(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?Zc/2:Zc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-Zc,o=C||T?S.top+Zc:S.bottom,s=C?T?S.top+Zc:S.bottom:S.top+Zc;M=$c(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?Zc/2:Zc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+Zc+1,o=w||E?S.right-Zc:S.left,s=w?E?S.right-Zc:S.left:S.right-Zc;M=$c(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?Zc/2:Zc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-Zc,o=w||E?S.left+Zc:S.right,s=w?E?S.left+Zc:S.right:S.left+Zc;M=$c(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}function rl(e,t,n){let{reference:r,floating:i}=e,a=ma(t),o=Ca(t),s=wo(o),c=Fa(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=_o(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function il(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=_a(t,e),p=Ra(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ba(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ba(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var al=50,ol=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:il},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=rl(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<al&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=rl(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},sl=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=_a(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Fa(r),_=ma(o),v=Fa(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Qa(o)]:Ea(o)),x=p!==`none`;!d&&x&&b.push(...so(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=Ya(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===ma(t)||T.every(e=>ma(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=ma(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},cl=new Set([`left`,`top`]);async function ll(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Fa(n),s=_o(n),c=ma(n)===`y`,l=cl.has(o)?-1:1,u=a&&c?-1:1,d=_a(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var ul=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await ll(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},dl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=_a(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=ma(i),p=Ma(f),m=u[p],h=u[f],g=(e,t)=>mo(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},fl=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=_a(e,t),u={x:n,y:r},d=ma(i),f=Ma(d),p=u[f],m=u[d],h=_a(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=cl.has(Fa(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},pl=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=_a(e,t),c=await i.detectOverflow(t,s),l=Fa(n),u=_o(n),d=ma(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Fo(p-c[m],g),y=Fo(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Do(c.left,c.right):S=p-2*Do(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function ml(e){let t=ki(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=ta(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Mo(n)!==a||Mo(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function hl(e){return Yi(e)?e:e.contextElement}function gl(e){let t=hl(e);if(!ta(t))return Va(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=ml(t),o=(a?Mo(n.width):n.width)/r,s=(a?Mo(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var _l=Va(0);function vl(e){let t=Qi(e);return!ia()||!t.visualViewport?_l:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function yl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Qi(e)}function bl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=hl(e),o=Va(1);t&&(r?Yi(r)&&(o=gl(r)):o=gl(e));let s=yl(a,n,r)?vl(a):Va(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=Qi(a),t=Yi(r)?Qi(r):r,n=e,i=hi(n);for(;i&&t!==n;){let e=gl(i),t=i.getBoundingClientRect(),r=ki(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Qi(i),i=hi(n)}}return ba({width:u,height:d,x:c,y:l})}function xl(e,t){let n=Bi(e).scrollLeft;return t?t.left+n:bl(oi(e)).left+n}function Sl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-xl(e,n),y:n.top+t.scrollTop}}function Cl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=oi(r),s=t?sa(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Va(1),u=Va(0),d=ta(r);if((d||!a)&&((Ci(r)!==`body`||bi(o))&&(c=Bi(r)),d)){let e=bl(r);l=gl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Sl(o,c):Va(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function wl(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Tl(e){let t=Bi(e),n=e.ownerDocument.body,r=Do(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Do(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+xl(e),o=-t.scrollTop;return ki(n).direction===`rtl`&&(a+=Do(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var El=25;function Dl(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=Qi(e),a=oi(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!ia()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(xl(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=El&&(s-=o)}return{width:s,height:c,x:l,y:u}}function Ol(e,t){let n=bl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=gl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function kl(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=Dl(e,n,t);else if(t===`document`)r=Tl(oi(e));else if(Yi(t))r=Ol(t,n);else{let n=vl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ba(r)}function Al(e,t){let n=t.get(e);if(n)return n;let r=Lo(e,[],!1).filter(e=>Yi(e)&&Ci(e)!==`body`),i=null,a=ki(e).position===`fixed`,o=a?Jr(e):e;for(;Yi(o)&&!li(o);){let e=ki(o),t=fi(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Jr(o)}return t.set(e,r),r}function jl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?sa(t)?[]:Al(t,this._c):[].concat(n),r],o=kl(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=kl(t,a[e],i);s=Do(n.top,s),c=Fo(n.right,c),l=Fo(n.bottom,l),u=Do(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Ml(e){let{width:t,height:n}=ml(e);return{width:t,height:n}}function Nl(e,t,n){let r=ta(t),i=oi(t),a=n===`fixed`,o=bl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Va(0);if((r||!a)&&((Ci(t)!==`body`||bi(i))&&(s=Bi(t)),r)){let e=bl(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=xl(i));let l=i&&!r&&!a?Sl(i,s):Va(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function Pl(e){return ki(e).position===`static`}function Fl(e,t){if(!ta(e)||ki(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return oi(e)===n&&(n=n.ownerDocument.body),n}function Il(e,t){let n=Qi(e);if(sa(e))return n;if(!ta(e)){let t=Jr(e);for(;t&&!li(t);){if(Yi(t)&&!Pl(t))return t;t=Jr(t)}return n}let r=Fl(e,t);for(;r&&vi(r)&&Pl(r);)r=Fl(r,t);return r&&li(r)&&Pl(r)&&!fi(r)?n:r||Pi(e)||n}var Ll=async function(e){let t=this.getOffsetParent||Il,n=this.getDimensions,r=await n(e.floating);return{reference:Nl(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Rl(e){return ki(e).direction===`rtl`}var zl={convertOffsetParentRelativeRectToViewportRelativeRect:Cl,getDocumentElement:oi,getClippingRect:jl,getOffsetParent:Il,getElementRects:Ll,getClientRects:wl,getDimensions:Ml,getScale:gl,isElement:Yi,isRTL:Rl};function Bl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Vl(e,t,n){let r=null,i,a=oi(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=io(d),h=io(a.clientWidth-(u+f)),g=io(a.clientHeight-(d+p)),_=io(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Do(0,Fo(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Bl(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=Qi(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Hl(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=hl(e),u=i||a?[...l?Lo(l):[],...t?Lo(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Vl(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?bl(e):null;c&&g();function g(){let t=bl(e);h&&!Bl(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Ul=ul,Wl=dl,Gl=sl,Kl=pl,ql=fl,Jl=(e,t,n)=>{let r=new Map,i=n??{},a={...zl,...i.platform,_c:r};return ol(e,t,{...i,platform:a})},Yl=typeof document<`u`?X.useLayoutEffect:function(){};function Xl(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Xl(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Xl(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Zl(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ql(e,t){let n=Zl(e);return Math.round(t*n)/n}function $l(e){let t=X.useRef(e);return Yl(()=>{t.current=e}),t}function eu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=X.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=X.useState(r);Xl(f,r)||p(r);let[m,h]=X.useState(null),[g,_]=X.useState(null),v=X.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=X.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=X.useRef(null),C=X.useRef(null),w=X.useRef(u),T=c!=null,E=$l(c),D=$l(i),O=$l(l),k=X.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Jl(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Xl(w.current,t)&&(w.current=t,$s.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Yl(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=X.useRef(!1);Yl(()=>(A.current=!0,()=>{A.current=!1}),[]),Yl(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=X.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=X.useMemo(()=>({reference:b,floating:x}),[b,x]),N=X.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=Ql(M.floating,u.x),r=Ql(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Zl(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return X.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:N}),[u,k,j,M,N])}var tu=(e,t)=>{let n=Ul(e);return{name:n.name,fn:n.fn,options:[e,t]}},nu=(e,t)=>{let n=Wl(e);return{name:n.name,fn:n.fn,options:[e,t]}},ru=(e,t)=>({fn:ql(e).fn,options:[e,t]}),iu=(e,t)=>{let n=Gl(e);return{name:n.name,fn:n.fn,options:[e,t]}},au=(e,t)=>{let n=Kl(e);return{name:n.name,fn:n.fn,options:[e,t]}};function ou(e){let{nodeId:t,externalTree:n,rootContext:r}=e,i=r.useState(`referenceElement`),a=r.useState(`floatingElement`),o=r.useState(`domReferenceElement`),s=r.useState(`open`),c=r.useState(`floatingId`),[l,u]=X.useState(null),d=X.useRef(null),f=Ns(n),p=X.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),m=eu({...e,elements:{...p,...l&&{reference:l}}}),h=X.useCallback(e=>{let t=Yi(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;u(t),m.refs.setReference(t)},[m.refs]),g=X.useMemo(()=>({...m.refs,setPositionReference:h,domReference:d}),[m.refs,h]),_=X.useMemo(()=>({...m.elements,domReference:o}),[m.elements,o]),v=X.useMemo(()=>({...m,dataRef:r.context.dataRef,open:s,onOpenChange:r.setOpen,events:r.context.events,floatingId:c,refs:g,elements:_,nodeId:t,rootStore:r}),[m,g,_,t,r,s,c]);return K(()=>{o&&(d.current=o)},[o]),K(()=>{r.context.dataRef.current.floatingContext=v;let e=f?.nodesRef.current.find(e=>e.id===t);e&&(e.context=v)}),X.useMemo(()=>({...m,context:v,refs:g,elements:_,rootStore:r}),[m,g,_,v,r])}var su=X.createContext(void 0);function cu(){return X.useContext(su)?.direction??`ltr`}var lu=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=_a(e,t)||{};if(l==null)return{};let d=Ra(u),f={x:n,y:r},p=Ca(i),m=wo(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=s.floating[y]||a.floating[m],C=b/2-x/2,w=S/2-h[m]/2-1,T=Math.min(d[_],w),E=Math.min(d[v],w),D=T,O=S-h[m]-E,k=S/2-h[m]/2+C,A=mo(D,k,O),j=!c.arrow&&_o(i)!=null&&k!==A&&a.reference[m]/2-(k<D?T:E)-h[m]/2<0,M=j?k<D?k-D:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),uu=(e,t)=>{let{name:n,fn:r}=lu(e);return{name:n,fn:r,options:[e,t]}},du={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},fu={sideX:`left`,sideY:`top`},pu=`--available-width`,mu=`--available-height`,hu=`--anchor-width`,gu=`--anchor-height`,_u=`--transform-origin`,vu=pu,yu=mu;function bu(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function xu(e,t,n){let{rects:r,placement:i}=e;return{side:bu(t,Fa(i),n),align:_o(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Su(e){return Cu(e,ou)}function Cu(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:l=5,sticky:u=!1,arrowPadding:d=5,disableAnchorTracking:f=!1,inline:p,keepMounted:m=!1,floatingRootContext:h,mounted:g,collisionAvoidance:_,shift:v,nodeId:y,adaptiveOrigin:b,lazyFlip:x=!1,externalTree:S}=e,C=_.side||`flip`,w=_.align||`flip`,T=_.fallbackAxisSide||`end`,E=v?.crossAxis??!1,D=v?.rootBoundary,O=typeof n==`function`?n:void 0,k=J(O),A=O?k:n,j=ps(n),M=ps(g),N=cu()===`rtl`,[P,F]=X.useState(null);!g&&P!==null&&F(null);let I=x===`placement`,L=P?Fa(P):null,R=P&&I?_o(P)||`center`:null,ee=L||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":N?`left`:`right`,"inline-start":N?`right`:`left`}[i],te=R||o,ne=te===`center`?ee:`${ee}-${te}`,z=l;typeof z==`number`?z={top:z,right:z,bottom:z,left:z}:z&&={top:z.top||0,right:z.right||0,bottom:z.bottom||0,left:z.left||0};let re=+(i===`bottom`),ie=+(i===`top`),B=+(i===`right`),ae=+(i===`left`),oe={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:z},se=X.useRef(null),ce=ps(a),le=ps(s),ue=typeof a==`function`?0:a,de=typeof s==`function`?0:s,fe=[];p&&fe.push(p),fe.push(tu(e=>{let t=xu(e,i,N),n=typeof ce.current==`function`?ce.current(t):ce.current,r=typeof le.current==`function`?le.current(t):le.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ue,de,N,i]));let pe=w===`none`&&C!==`shift`,me=!pe&&(u||E||C===`shift`),he=C===`none`?null:iu({...oe,padding:{top:z.top+1+re,right:z.right+1+ae,bottom:z.bottom+1+ie,left:z.left+1+B},mainAxis:!E&&C===`flip`,crossAxis:w===`flip`&&`alignment`,fallbackAxisSideDirection:T}),ge=pe?null:nu({...oe,rootBoundary:D,mainAxis:w!==`none`,crossAxis:me,limiter:u||E?void 0:ru(e=>{if(!se.current)return{};let{width:t,height:n}=se.current.getBoundingClientRect(),r=ma(Fa(e.placement)),i=r===`y`?t:n,a=r===`y`?z.left+z.right:z.top+z.bottom;return{offset:i/2+a/2}})},[oe,u,E,D,z,w]);C===`shift`||w===`shift`||te===`center`?fe.push(ge,he):fe.push(he,ge),fe.push(au({...oe,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!M.current)return;let i=e.style;i.setProperty(vu,`${t}px`),i.setProperty(yu,`${n}px`);let a=Qi(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(hu,`${u}px`),i.setProperty(gu,`${d}px`)}}),uu(e=>({element:se.current||ri(e.elements.floating).createElement(`div`),padding:se.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=Fa(r),u=_o(r),d=ma(l)===`y`,f=se.current,p=typeof a==`function`?a(xu(e,i,N)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return me&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(_u,d?`${m} ${h}`:`${h} ${m}`),{}}},du,b),K(()=>{!g&&h&&h.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[g,h]);let _e=X.useMemo(()=>({ancestorScroll:!f,elementResize:!f&&typeof ResizeObserver<`u`,layoutShift:!f&&typeof IntersectionObserver<`u`}),[f]),{refs:ve,elements:ye,x:be,y:xe,middlewareData:Se,update:Ce,placement:we,context:Te,isPositioned:Ee,floatingStyles:De}=t({rootContext:h,open:m?g:void 0,placement:ne,middleware:fe,strategy:r,whileElementsMounted:m?void 0:(...e)=>Hl(...e,_e),nodeId:y,externalTree:S}),{sideX:Oe,sideY:ke}=Se.adaptiveOrigin||fu,Ae=Ee?r:`fixed`,je=X.useMemo(()=>{let e;return e=Ee?b?{position:Ae,[Oe]:be,[ke]:xe}:{...De,position:Ae}:{position:Ae,top:0,left:0},e[vu]=`100vw`,e[yu]=`100vh`,Ee||(e.opacity=0),e},[b,Ae,Oe,be,ke,xe,De,Ee]),Me=X.useRef(null);K(()=>{if(!g)return;let e=j.current,t=typeof e==`function`?e():e,n=(wu(t)?t.current:t)||null;n!==Me.current&&(ve.setPositionReference(n),Me.current=n)},[g,ve,A,j]),X.useEffect(()=>{if(!g)return;let e=j.current;typeof e!=`function`&&wu(e)&&e.current!==Me.current&&(ve.setPositionReference(e.current),Me.current=e.current)},[g,ve,A,j]),X.useEffect(()=>{if(m&&g&&ye.reference&&ye.floating)return Hl(ye.reference,ye.floating,Ce,_e)},[m,g,ye,Ce,_e]);let Ne=Fa(we),Pe=bu(i,Ne,N),Fe=_o(we)||`center`,Ie=!!Se.hide?.referenceHidden;K(()=>{x&&g&&Ee&&(Ne!==ee||I&&Fe!==te)&&F(we)},[x,I,g,Ee,we,Ne,Fe,ee,te]);let Le=X.useMemo(()=>({position:`absolute`,top:Se.arrow?.y,left:Se.arrow?.x}),[Se.arrow]),Re=Se.arrow?.centerOffset!==0;return X.useMemo(()=>({positionerStyles:je,arrowStyles:Le,arrowRef:se,arrowUncentered:Re,side:Pe,align:Fe,physicalSide:Ne,anchorHidden:Ie,refs:ve,context:Te,isPositioned:Ee,update:Ce}),[je,Le,se,Re,Pe,Fe,Ne,Ie,ve,Te,Ee,Ce])}function wu(e){return e!=null&&`current`in e}function Tu(e){return e===`starting`?Wa:jo}function Eu(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),Eo(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Tu(r),i],stateAttributesMapping:cs})}var Du=e(o(),1);function Ou(e){let t=Du.unstable_scheduleCallback(4,e);return()=>Du.unstable_cancelCallback(t)}var ku=X.createContext(Ie({scheduleTask:Ou,defaultIdleTTL:400})),Au=new WeakMap,ju=0,Mu=new Set;function Nu(e){ju++;try{return e()}finally{ju--}}function Pu(e){if(ju===0)return e();Mu.size===0&&queueMicrotask(Fu),Mu.add(e)}function Fu(){for(let e of Mu)Mu.delete(e),e()}function Iu(e,t){let n=Au.get(e);n===void 0&&(n=new WeakMap,Au.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=0,a,o={subscribe(n){i++;let r=e.subscribe(t,()=>Pu(n));return()=>{i--,Mu.delete(n),r()}},snapshot(){return Nu(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Nu(()=>kr(t,e))}),a.value}};return n.set(t,o),o}function Lu(e,t){let n=Iu(e,t);return X.useEffect(Fu),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Ru(e,t,n){let r=Iu(e,t),i=X.useMemo(()=>{let e;return t=>(e!==void 0&&Object.is(e.source,t)||(e={source:t,value:n(t)}),e.value)},[n]);return X.useEffect(Fu),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var zu=(e,t)=>{let n=X.useContext(ku);return t?Ru(n,e,t):Lu(n,e)};function Bu(e,t){X.useEffect(()=>e.mount(t),[t,e])}function Vu(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=or(De(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Hu):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Hu=e=>{if(It(e))return e.value;throw Fr(e.cause)},Uu=(e,t)=>{let n=X.useContext(ku);return Bu(n,e),Vu(n,e,t)},Wu=(e,t)=>{let n=X.useContext(ku);return[Lu(n,e),Vu(n,e,t)]},Gu={suspendOnWaiting:new WeakMap,default:new WeakMap};function Ku(e,t,n){let r=n?Gu.suspendOnWaiting:Gu.default,i=r.get(e);i===void 0&&(i=new WeakMap,r.set(e,i));let a=i.get(t);return a===void 0&&(a=new Promise(r=>{let a=e.subscribe(t,e=>{e._tag===`Initial`||n&&e.waiting||(setTimeout(a,1e3),r(),i.delete(t))})}),i.set(t,a)),a}function qu(e,t,n){let r=Lu(e,t);if(r._tag===`Initial`||n&&r.waiting)throw Ku(e,t,n);return r}var Ju=(e,t)=>{let n=qu(X.useContext(ku),e,t?.suspendOnWaiting??!1);if(n._tag===`Failure`&&!t?.includeFailure)throw Fr(n.cause);return n};Vt(`MachineSchemaEncodeError`);var Yu=class extends Vt(`MachineSchemaDecodeError`){},Xu=class extends Vt(`InfiniteTransitionError`){},Zu=class extends Vt(`StartupError`){},Qu=class extends Vt(`ChildAlreadyExistsError`){};Vt(`ProcessLocalError`);var $u=class extends Vt(`StoppedError`){},ed=e=>e instanceof Xu||e instanceof Yu,td=e=>ed(e)?H(e):N(e),nd=e=>ed(e)||e instanceof Zu?e:new Zu({cause:jn(e)}),rd=e=>e,id=`~effect/Machine/Target`,ad=Symbol(`effect/Machine/TargetSnapshot`),od=Symbol(`effect/Machine/StateInput`),sd=Symbol(`effect/Machine/HistoryTarget`),cd=Symbol(`effect/Machine/InitialTarget`),ld=Symbol(`effect/Machine/ChoiceTarget`),ud=Symbol(`effect/Machine/NoTarget`),dd=Symbol(`effect/Machine/Declined`),fd=Symbol(`effect/Machine/TargetSelection`),pd=Symbol(`effect/Machine/StateUpdate`),md=Symbol(`effect/Machine/CombinedTarget`),hd=Symbol(`effect/Machine/SelectedBranch`),gd=(e,t,n,r)=>Object.freeze({[fd]:fd,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),_d=gd(`none`,void 0,`local`),vd=e=>V(e,fd),yd=(e,t)=>Object.freeze({[pd]:pd,path:e,value:t}),bd=e=>V(e,pd),xd=(e,t)=>Object.freeze({[md]:md,target:e,update:t}),Sd=e=>V(e,md),Cd=(e,t,n,r)=>Object.freeze({[hd]:hd,owner:e,branchIndex:t,branchKey:n,result:r}),wd=e=>V(e,hd),Td=Object.freeze({[ud]:ud}),Ed=()=>Td,Dd=e=>V(e,ud),Od=Object.freeze({[dd]:dd}),kd=()=>Od,Ad=e=>V(e,dd),jd=(e,t)=>({[sd]:sd,path:e,parent:t}),Md=e=>V(e,sd),Nd=(e,t,n)=>({[cd]:cd,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),Pd=e=>V(e,cd),Fd=(e,t,n)=>({[ld]:ld,path:e,parent:t,...n===void 0?{}:{values:n}}),Id=e=>V(e,ld),Ld=(e,t)=>{if(!je(t)&&t.type===`history`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`history`,history:t.history===`deep`?`deep`:`shallow`,initial:void 0,states:void 0};if(!je(t)&&t.type===`choice`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`choice`,history:void 0,initial:void 0,states:void 0};if(je(t))return{schema:t,output:void 0,annotations:qe(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=V(t,`schema`)&&je(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:qe(n);if(t.type===`parallel`&&!V(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(V(t,`states`)){if(t.type===`final`)throw Error(`Machine.make expected compound state "${e}" to be active`);if(t.type===`parallel`)return{schema:n,output:je(t.output)?t.output:void 0,annotations:r,type:`parallel`,history:void 0,initial:void 0,states:t.states};let i=`initial`in t?t.initial:void 0;if(typeof i!=`string`)throw Error(`Machine.make expected compound state "${e}" to declare an initial child`);return{schema:n,output:void 0,annotations:r,type:`compound`,history:void 0,initial:i,states:t.states}}let i=je(t.output)?t.output:void 0;return t.type===`final`?{schema:n,output:i,annotations:r,type:`final`,history:void 0,initial:void 0,states:void 0}:{schema:n,output:void 0,annotations:r,type:`atomic`,history:void 0,initial:void 0,states:void 0}},Rd=e=>{let t=new Map,n=0,r=(e,i)=>{let a=[];for(let o of Object.keys(e)){if(o.includes(`.`))throw Error(`Machine state keys cannot contain ".": "${o}"`);let s=i===void 0||i===``?o:`${i}.${o}`,c=Ld(s,e[o]),l,u,d={path:s,key:o,annotations:c.annotations,order:n};switch(c.type){case`atomic`:l={...d,type:`atomic`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:void 0};break;case`compound`:l={...d,type:`compound`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:s===``?c.initial:`${s}.${c.initial}`},u=c.states;break;case`parallel`:l={...d,type:`parallel`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0},u=c.states;break;case`final`:l={...d,type:`final`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0};break;case`history`:if(i===void 0)throw Error(`Machine history state "${s}" must belong to a parent state`);l={...d,type:`history`,schema:void 0,output:void 0,history:c.history,parent:i,children:[],initial:void 0};break;case`choice`:if(i===void 0)throw Error(`Machine choice state "${s}" must belong to a parent state`);l={...d,type:`choice`,schema:void 0,output:void 0,history:void 0,parent:i,children:[],initial:void 0}}if(t.set(s,l),n+=1,c.type!==`history`&&c.type!==`choice`&&(a.push(s),u!==void 0)){let e=r(u,s);if(l.type===`compound`){if(!e.includes(l.initial)&&t.get(l.initial)?.type!==`choice`)throw Error(`Machine.make expected compound state "${s}" initial child to exist`);l={...l,children:e}}else if(l.type===`parallel`)l={...l,children:e};else throw Error(`Machine state "${s}" cannot declare child states`);t.set(s,l)}}return a};return{byPath:t,roots:r(e,void 0)}},zd=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],Bd=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,Vd=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=rd(e).handlers[n.path];if(r===void 0)continue;if(n.type===`choice`){let e=r.choice;e!==void 0&&t.push({source:n.path,trigger:{type:`choice`},reenter:!1,acceptance:`required`,branches:zd(e)});continue}for(let e of Reflect.ownKeys(r.on??{})){let i=r.on?.[e];t.push({source:n.path,trigger:{type:`event`,event:e},reenter:V(i,`reenter`)&&i.reenter===!0,acceptance:Bd(i),branches:zd(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:Bd(r.always),branches:zd(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:Bd(r.onDone),branches:zd(r.onDone)});let i=r.invoke===void 0?[]:Array.isArray(r.invoke)?r.invoke:[r.invoke];for(let e of i){let r=`child`in e?String(e.child.id):String(e.id);for(let i of[`element`,`done`,`failure`,`snapshot`]){let a=i===`element`?e.onElement:i===`done`?e.onDone:i===`failure`?e.onFailure:e.onSnapshot;a!==void 0&&t.push({source:n.path,trigger:{type:`invoke`,id:r,outcome:i},reenter:typeof a==`object`&&!!a&&a.reenter===!0,acceptance:Bd(a),branches:zd(a)})}}}return t},Hd=(e,t,n)=>({[id]:id,[ad]:n?.snapshot,path:e,value:t,values:n?.values}),Ud=e=>V(e,id),Wd=e=>({[od]:od,input:e}),Gd=e=>V(e,od),Kd=e=>V(e,`path`)&&V(e,`value`),qd=(e,t,n)=>{if(e.path===t)return me(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return pt();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),V(e,`state`)&&Kd(e.state))return qd(e.state,t,n);if(V(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if(Kd(r)){let e=qd(r,t,n);if(lt(e))return e}}return pt()},Q=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},Jd=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},Yd=new WeakMap,Xd=Symbol(`effect/Machine/EventConstruction`),Zd=new WeakMap,Qd=new WeakMap,$d=new WeakMap,ef=e=>{let t=e,n=Qd.get(t);if(n!==void 0)return n;let r=rt(v(e));return Qd.set(t,r),r},tf=e=>{let t=e,n=$d.get(t);if(n!==void 0)return n;let r=A(v(e));return $d.set(t,r),r},nf=Symbol.for(`effect/Machine/protocol`),rf=e=>{let t=e[nf];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},af=(e,t)=>{Object.defineProperty(e,nf,{value:t,enumerable:!1})},of=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),V(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&V(t,`make`)&&n(t)};for(let t of e)n(t);return t},sf=(e,t)=>{let n=Yd.get(e);if(n===void 0)throw Error(`Machine expected an event protocol created with Machine.events, Machine.internalEvents, or Machine.emittedEvents`);if(t!==void 0&&n.kind!==t)throw Error(`Machine expected a ${t} event protocol`);return n},cf=e=>sf(e.events,`public`).schemas,lf=e=>sf(e.internalEvents,`internal`).schemas,uf=e=>sf(e.emittedEvents,`emitted`).schemas,df=e=>{let t=cf(e),n=lf(e),r=uf(e),i=new Set(Reflect.ownKeys(e.events));for(let t of Reflect.ownKeys(e.internalEvents))if(i.has(t))throw Error(`Public and internal machine event tags must be disjoint: ${String(t)}`);let a=[...t,...n];af(e,{event:Qe(a),emit:Qe(r),eventConstructors:of(a),emissionConstructors:of(r)})},ff=(e,t)=>af(t,rf(e)),pf=e=>V(e,`_tag`)?String(e._tag):void 0,mf=(e,t,n,r)=>{let i=r,a;if(typeof r==`object`&&r)try{i={...r}}catch(e){i=void 0,a=e}let o={[Xd]:Xd,_tag:n};return Zd.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},hf=e=>typeof e==`object`&&!!e&&Zd.has(e),gf=(e,t)=>{let n=[],r=e=>{if(V(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null)for(let t of Reflect.ownKeys(e.cases))r(Reflect.get(e.cases,t));else if(V(e,`members`)&&Array.isArray(e.members))for(let t of e.members)r(t);else n.push(e)};for(let e of t)r(e);let i=Object.create(null),a=e=>ct(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:We(e)?[e.symbol]:B(e)?e.enums.map(([,e])=>e):At(e)?e.types.flatMap(a):fe(e)?a(e.thunk()):[],o=e=>{let t=u(e.ast);if(te(t)){let e=t.propertySignatures.find(({name:e})=>e===`_tag`),n=e===void 0?[]:a(e.type);if(n.length>0)return n}try{return Qe([e]).pipe(Vr(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(V(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>mf(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},_f=(e,t)=>{let n=Object.freeze(Array.from(t)),r=gf(e,n);return Yd.set(r,{kind:e,schemas:n}),Object.freeze(r)},vf=(e,t,n,r)=>ef(t)(n).pipe(Ct(t=>new Yu({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),yf=(e,t,n,r)=>{let i=tf(t)(n);if(M(i))throw new Yu({machineId:e.id,boundary:r.boundary,cause:i.failure,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}});return i.success},bf=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new Yu({machineId:e.id,boundary:r.boundary,cause:Be(t)?t:V(n,`~effect/SchemaIssue/Issue`)?new ln(n):jn(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},xf=(e,t,n)=>new Yu({machineId:e.id,boundary:n,event:String(t._tag),cause:jn(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),Sf=(e,t)=>{if(t.inputError!==void 0)throw t.inputError;return typeof t.input==`object`&&t.input!==null?{...t.input,_tag:e._tag}:{_tag:e._tag}},Cf=(e,t,n,r)=>new Yu({machineId:e.id,boundary:n,event:String(t._tag),cause:jn(r)}),wf=(e,t,n,r)=>{let i=Zd.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;return i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema)?H(xf(e,n,r)):Ln({try:()=>Sf(n,i),catch:t=>Cf(e,n,r,t)}).pipe(_(t=>i.schema.makeEffect(t).pipe(Ct(t=>new Yu({machineId:e.id,boundary:r,event:String(n._tag),cause:new ln(t)})))))},Tf=(e,t,n,r)=>{let i=Zd.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;if(i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema))throw xf(e,n,r);let o;try{o=Sf(n,i)}catch(t){throw Cf(e,n,r,t)}return bf(e,i.schema,o,{boundary:r,event:String(n._tag)})},Ef=(e,t)=>{let n=rf(e);if(hf(t))return wf(e,n,t,`event`);let r=pf(t);return vf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Df=(e,t)=>{let n=rf(e);if(hf(t))return Tf(e,n,t,`event`);let r=pf(t);return yf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Of=(e,t)=>{let n=rf(e);if(hf(t))return wf(e,n,t,`emission`);let r=pf(t);return vf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},kf=(e,t)=>{let n=rf(e);if(hf(t))return Tf(e,n,t,`emission`);let r=pf(t);return yf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Af=(e,t,n)=>yf(e,t,n,{boundary:`input`}),jf=(e,t,n)=>Gd(n)?Jd(t).makeEffect(n.input).pipe(Ct(n=>new Yu({machineId:e.id,boundary:`state`,state:t.path,cause:new ln(n)}))):vf(e,Jd(t),n,{boundary:`state`,state:t.path}),Mf=(e,t,n)=>Gd(n)?bf(e,Jd(t),n.input,{boundary:`state`,state:t.path}):yf(e,Jd(t),n,{boundary:`state`,state:t.path}),Nf=(e,t,n)=>t.output===void 0?Nn(n):vf(e,t.output,n,{boundary:`output`,state:t.path}),Pf=(e,t,n)=>t.output===void 0?n:yf(e,t.output,n,{boundary:`output`,state:t.path}),Ff=(e,t)=>{let n=new Set(Gf(e,t.parent)),r=n=>{let i=Q(e,n);if(i.type===`compound`){let e=i.children.filter(e=>t.active.has(e));if(e.length!==1)throw Error(`Machine history expected compound state "${n}" to retain one active child`);t.mode===`deep`&&r(e[0])}else if(i.type===`parallel`)for(let e of i.children){if(!t.active.has(e))throw Error(`Machine history expected parallel state "${n}" to retain region "${e}"`);t.mode===`deep`&&r(e)}};r(t.parent);for(let r of t.active){if(!n.has(r)&&!Wf(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&Uf(r,t.parent)&&Q(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},If=(e,t)=>{let n=new Map;for(let[r,i]of Object.entries(t.history??{})){let t=Q(e,r);if(t.type!==`history`||t.parent===void 0||t.history!==i.mode)throw Error(`Machine snapshot contains invalid history record "${r}"`);let a=new Set,o=new Map;for(let n of i.active){if(a.has(n))throw Error(`Machine snapshot contains invalid remembered state "${n}"`);let r=Q(e,n);if(r.type===`history`||r.type===`choice`||!(Wf(n,t.parent)||Gf(e,t.parent).includes(n)))throw Error(`Machine snapshot contains invalid remembered value for "${n}"`);a.add(n);let s=Object.prototype.hasOwnProperty.call(i.values,n);if(r.schema===void 0){if(s)throw Error(`Machine snapshot contains a value for structural state "${n}"`)}else{if(!s)throw Error(`Machine snapshot omits remembered value for "${n}"`);o.set(n,Mf(e,r,i.values[n]))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)throw Error(`Machine snapshot contains incomplete history record "${r}"`);n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o}),Ff(e,n.get(r))}return n},Lf=ut(function*(e,t){let n=new Map;for(let[r,i]of Object.entries(t.history??{})){let t=e.stateNodes.byPath.get(r);if(t===void 0||t.type!==`history`||t.parent===void 0||t.history!==i.mode)return yield*H(new Yu({machineId:e.id,boundary:`history`,state:r,cause:jn(Error(`Machine snapshot contains invalid history record "${r}"`))}));let a=new Set,o=new Map;for(let n of i.active){let r=e.stateNodes.byPath.get(n);if(a.has(n)||r===void 0||r.type===`history`||r.type===`choice`||!(Wf(n,t.parent)||Gf(e,t.parent).includes(n)))return yield*H(new Yu({machineId:e.id,boundary:`history`,state:n,cause:jn(Error(`Machine snapshot contains invalid remembered state "${n}"`))}));a.add(n);let s=Object.prototype.hasOwnProperty.call(i.values,n);if(r.schema===void 0){if(s)return yield*H(new Yu({machineId:e.id,boundary:`history`,state:n,cause:jn(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!s)return yield*H(new Yu({machineId:e.id,boundary:`history`,state:n,cause:jn(Error(`Machine snapshot omits remembered value for "${n}"`))}));o.set(n,yield*vf(e,Jd(r),i.values[n],{boundary:`history`,state:n}))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)return yield*H(new Yu({machineId:e.id,boundary:`history`,state:r,cause:jn(Error(`Machine snapshot contains incomplete history record "${r}"`))}));n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o});try{Ff(e,n.get(r))}catch(t){return yield*H(new Yu({machineId:e.id,boundary:`history`,state:r,cause:jn(t)}))}}return n}),Rf=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>qf(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},zf=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),Bf=e=>e.machineReferences,Vf=new WeakMap,Hf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Uf=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),Wf=(e,t)=>e===t||Uf(e,t),Gf=(e,t)=>{let n=Vf.get(e.stateNodes);n===void 0&&(n=new Map,Vf.set(e.stateNodes,n));let r=n.get(t);if(r!==void 0)return r;let i=[],a=t;for(;a!==void 0;)i.unshift(a),a=Q(e,a).parent;return n.set(t,i),i},Kf=(e,t)=>Gf(e,t).length,qf=(e,t,n)=>Q(e,t).order-Q(e,n).order,Jf=(e,t,n)=>Q(e,n).children.some(e=>t.active.has(e)),Yf=(e,t)=>{let n=Array.from(t.active).filter(n=>!Jf(e,t,n)).sort((t,n)=>qf(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},Xf=(e,t)=>Yf(e,t)[0],Zf=(e,t,n)=>{let r=Yf(e,t).filter(e=>Wf(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},Qf=(e,t)=>{for(let n of t.active)if(Q(e,n).parent===void 0)return n;throw Error(`Machine expected an active root state`)},$f=(e,t,n)=>{let r={},i=Gf(e,n);for(let e=0;e<i.length-1;e++){let n=i[e];t.values.has(n)&&(r[n]=t.values.get(n))}return r},ep=(e,t,n)=>{let r=Q(e,n).parent;return r===void 0?void 0:t.values.get(r)},tp=(e,t)=>{let n=r=>t.active.has(r)?[r,...Q(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},np=(e,t,n)=>{let r=Q(e,n),i={path:n,value:t.values.get(n)};if(r.type===`compound`){let a=r.children.find(e=>t.active.has(e));if(a===void 0)throw Error(`Machine expected compound state "${n}" to have an active child`);i.state=np(e,t,a)}if(r.type===`parallel`){let a={};for(let i of r.children){if(!t.active.has(i))throw Error(`Machine expected parallel state "${n}" to have active child region "${i}"`);let r=Q(e,i);a[r.key]=np(e,t,i)}i.states=a}return i},rp=(e,t)=>{let n=np(e,t,Qf(e,t)),r=Array.from(t.outputs).map(([e,t])=>({path:e,output:t}));return r.length>0&&(n.completed=r),t.history.size>0&&Object.assign(n,{history:Rf(e,t.history)}),n},ip=(e,t,n)=>{let r=np(e,t,n);return t.history.size>0&&Object.assign(r,{history:Rf(e,t.history)}),r},ap=(e,t,n)=>{if(!V(n,`state`)||!Kd(n.state))throw Error(`Machine expected compound snapshot "${t.path}" to include an active child state`);let r=Q(e,String(n.state.path));if(r.parent!==t.path)throw Error(`Machine expected snapshot "${r.path}" to be a child of "${t.path}"`);return n.state},op=(e,t)=>{if(!V(t,`states`)||typeof t.states!=`object`||t.states===null)throw Error(`Machine expected parallel snapshot "${e.path}" to include active child regions`);return t.states},sp=(e,t,n,r)=>{let i=Q(e,n),a=r[i.key];if(!Hf(r,i.key)||!Kd(a))throw Error(`Machine expected parallel snapshot "${t.path}" to include region "${i.key}"`);let o=Q(e,String(a.path));if(o.path!==i.path)throw Error(`Machine expected snapshot "${o.path}" to be region "${i.path}"`);return a},cp=(e,t)=>{let n=new Set,r=new Map,i=t.completed,a=t=>{let i=Q(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,Mf(e,i,t.value));if(i.type===`compound`&&a(ap(e,i,t)),i.type===`parallel`){let n=op(i,t);for(let t of i.children)a(sp(e,i,t,n))}};a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:If(e,t)}},lp=(e,t)=>cp(e,t),up=(e,t)=>{try{return cp(e,t)}catch(t){throw t instanceof Yu?t:new Yu({machineId:e.id,boundary:`configuration`,cause:jn(t)})}},dp=ut(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=ut(function*(t){let i=Q(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,yield*jf(e,i,t.value));if(i.type===`compound`&&(yield*a(ap(e,i,t))),i.type===`parallel`){let n=op(i,t);for(let t of i.children)yield*a(sp(e,i,t,n))}});yield*a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:yield*Lf(e,t)}}),fp=(e,t)=>dp(e,t).pipe(we(t=>{if(tn(t))return Br(jt(t,t=>t instanceof Yu?t:new Yu({machineId:e.id,boundary:`configuration`,cause:vr(t)})));let n=Jt(t);return lt(n)&&n.value instanceof Yu?H(n.value):H(new Yu({machineId:e.id,boundary:`configuration`,cause:t}))})),pp=(e,t,n,r)=>{if(r.length===0)return n;let i=new Set(r),a=new Map(n.history);for(let n of e.stateNodes.byPath.values()){if(n.type!==`history`||n.parent===void 0||!i.has(n.parent))continue;let r=n.history===`deep`?`deep`:`shallow`,o=new Set;for(let r of Gf(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&Uf(i,n.parent)||r===`shallow`&&Q(e,i).parent===n.parent)&&o.add(i);let s=new Map;for(let e of o)t.values.has(e)&&s.set(e,t.values.get(e));a.set(n.path,{mode:r,parent:n.parent,active:o,values:s})}return{active:n.active,values:n.values,outputs:n.outputs,history:a}},mp=(e,t)=>e.history.get(t),hp=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=Gf(e,n.parent),s=new Set(o);for(let c of o){let o=Q(e,c);if(o.type===`parallel`){for(let e of o.children)if(!(s.has(e)||n.active.has(e)||!t.active.has(e)))for(let n of t.active)Wf(n,e)&&(r.add(n),t.values.has(n)&&i.set(n,t.values.get(n)),t.outputs.has(n)&&a.set(n,t.outputs.get(n)))}}return{active:r,values:i,outputs:a,history:t.history}};ut(function*(e,t,n,r,i){let a=Q(e,n),o=new Set,s=new Map,c=new Map,l=Gf(e,a.path),u=new Set(l);for(let n of l){let c=Q(e,n);if(o.add(n),c.schema===void 0){if((n===a.path?r:i!==void 0&&Hf(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===a.path)s.set(n,yield*jf(e,c,r));else if(i!==void 0&&Hf(i,n))s.set(n,yield*jf(e,c,i[n]));else if(t.values.has(n))s.set(n,t.values.get(n));else throw Error(`Machine target "${a.path}" requires a value for ancestor state "${n}"`)}for(let n of l){let r=Q(e,n);if(r.type===`parallel`){for(let e of r.children)if(!u.has(e)&&t.active.has(e))for(let n of t.active)Wf(n,e)&&(o.add(n),t.values.has(n)&&s.set(n,t.values.get(n)),t.outputs.has(n)&&c.set(n,t.outputs.get(n)))}}if(a.type===`compound`||a.type===`parallel`)throw Error(`Machine target "${a.path}" must include an active child state`);return{active:o,values:s,outputs:c,history:t.history}}),ut(function*(e,t,n,r){let i=yield*dp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Gf(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=Q(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&Hf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Hf(r,i))o.set(i,yield*jf(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=Q(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)Wf(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&Hf(r,n))for(let[t,i]of Object.entries(r)){if(!Wf(t,n))continue;let r=Q(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,yield*jf(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var gp=(e,t,n,r,i,a=!1)=>{let o=Q(e,n),s=new Set,c=new Map,l=new Map,u=Gf(e,o.path),d=new Set(u);for(let n of u){let a=Q(e,n);if(s.add(n),a.schema===void 0){if((n===o.path?r:i!==void 0&&Hf(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===o.path)c.set(n,Mf(e,a,r));else if(i!==void 0&&Hf(i,n))c.set(n,Mf(e,a,i[n]));else if(t.values.has(n))c.set(n,t.values.get(n));else throw Error(`Machine target "${o.path}" requires a value for ancestor state "${n}"`)}for(let n of u){let r=Q(e,n);if(r.type===`parallel`&&n!==o.path){for(let e of r.children)if(!d.has(e)&&t.active.has(e))for(let n of t.active)Wf(n,e)&&(s.add(n),t.values.has(n)&&c.set(n,t.values.get(n)),t.outputs.has(n)&&l.set(n,t.outputs.get(n)))}}if(!a&&(o.type===`compound`||o.type===`parallel`))throw Error(`Machine target "${o.path}" must include an active child state`);return{active:s,values:c,outputs:l,history:t.history}},_p=(e,t,n)=>{let r=gp(e,t,n.path,n.value,n.values,!0);if(n.children===void 0)return r;let i=new Set(r.active),a=new Map(r.values);for(let[t,r]of n.children){let n=Q(e,t);i.add(t),n.schema!==void 0&&a.set(t,Mf(e,n,r))}return{...r,active:i,values:a}},vp=(e,t,n,r)=>{let i=cp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Gf(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=Q(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&Hf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Hf(r,i))o.set(i,Mf(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=Q(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)Wf(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&Hf(r,n))for(let[t,i]of Object.entries(r)){if(!Wf(t,n))continue;let r=Q(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,Mf(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},yp=(e,t,n)=>{if(Ud(n)){let r=n[ad];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return vp(e,t,r,n.values)}return gp(e,t,n.path,n.value,n.values)}if(Kd(n)){let r=up(e,n);return{...r,history:new Map([...t.history,...r.history])}}throw Error(`Machine expected transition target to be a snapshot or target builder result`)},bp=(e,t)=>rd(e).handlers[t],xp=(e,t,n)=>Q(e,n).children.find(e=>t.active.has(e)),Sp=(e,t)=>Q(e,t).type===`final`,Cp=(e,t)=>bp(e,t)?.onDone!==void 0,wp=(e,t,n)=>{if(!t.active.has(n))return!1;let r=Q(e,n);if(r.type===`compound`){let r=xp(e,t,n);return r!==void 0&&(n===``?!Cp(e,r)&&wp(e,t,r):Sp(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!wp(e,t,n))return!1;return!0}return Sp(e,n)},Tp=(e,t)=>{let n=Qf(e,t);return wp(e,t,n)&&!Cp(e,n)},Ep=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),Dp=ut(function*(e,t,n,r,i){let a=Q(e,n),o=bp(e,n)?.output?.({state:t.values.get(n),containingState:ep(e,t,n),ancestors:$f(e,t,n),event:r,outputs:i});return yield*Nf(e,a,o)}),Op=ut(function*(e,t,n,r,i,a){if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=Q(e,n);if(o.type===`compound`){let o=xp(e,t,n);if(o===void 0||(n===``?Cp(e,o):!Sp(e,o)))return;let s=yield*Op(e,t,o,r,i,a);if(s===void 0)return;let c=Ep(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=yield*Op(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Ep(i,n,yield*Dp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Sp(e,n))return;let s=Ep(i,n,yield*Dp(e,t,n,r));return s.isNew&&a.push(s),s}),kp=ut(function*(e,t,n){let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=Kf(e,n)-Kf(e,t);return r===0?qf(e,t,n):r}))yield*Op(e,a,t,n,r,i);return{configuration:a,completions:i}}),Ap=(e,t,n,r,i)=>{let a=Q(e,n),o=bp(e,n)?.output?.({state:t.values.get(n),containingState:ep(e,t,n),ancestors:$f(e,t,n),event:r,outputs:i});return Pf(e,a,o)},jp=(e,t,n,r,i,a)=>{if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=Q(e,n);if(o.type===`compound`){let o=xp(e,t,n);if(o===void 0||(n===``?Cp(e,o):!Sp(e,o)))return;let s=jp(e,t,o,r,i,a);if(s===void 0)return;let c=Ep(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=jp(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Ep(i,n,Ap(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Sp(e,n))return;let s=Ep(i,n,Ap(e,t,n,r));return s.isNew&&a.push(s),s},Mp=(e,t,n)=>{let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=Kf(e,n)-Kf(e,t);return r===0?qf(e,t,n):r}))jp(e,a,t,n,r,i);return{configuration:a,completions:i}},Np=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},Pp=(e,t)=>{if(t.decoded!==void 0&&typeof t.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.schema===void 0){if(Object.hasOwn(t,`data`)||Object.hasOwn(t,`decoded`))throw Error(`Machine structural state "${e.path}" cannot construct data`)}else{if(t.decoded===!0){if(!Object.hasOwn(t,`data`))throw Error(`Machine decoded construction requires data`);return t.data}return Wd(Object.hasOwn(t,`data`)?t.data:{})}},Fp=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=Np(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return Hd(t,Pp(i,e))}let a=new Map,o=(t,n)=>{let i=Np(n);if(Reflect.ownKeys(i).some(e=>e!==`data`&&e!==`decoded`&&e!==`states`))throw Error(`Machine state construction accepts only data, decoded, and states`);let s=e.byPath.get(t);if(s===void 0||s.type===`history`)throw Error(`Machine invalid construction state "${t}"`);let c=Pp(s,i);if(Object.hasOwn(i,`states`)){if(s.type!==`compound`&&s.type!==`parallel`)throw Error(`Machine state "${t}" has no child construction`);let n=Np(i.states),c=Reflect.ownKeys(n),l=s.children.filter(t=>e.byPath.get(t)?.type!==`history`);if(s.type===`compound`?c.length!==1:c.length!==l.length&&(c.length!==1||r===void 0||r!==t&&!r.startsWith(`${t}.`)))throw Error(`Machine explicit states for "${t}" must select ${s.type===`compound`?`one child`:`every region`}`);for(let r of c){let i=t===``?String(r):`${t}.${String(r)}`;if(typeof r!=`string`||e.byPath.get(i)?.parent!==t||e.byPath.get(i)?.type===`history`)throw Error(`Machine unknown child "${String(r)}"`);a.set(i,o(i,n[r]))}}return c},s=o(t,n),c=new Map(a);c.set(t,s);let l=t,u=Np(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=Np(u.states),i=Object.keys(n);if(i.length!==1||t.type===`parallel`&&(r===void 0||r!==l&&!r.startsWith(`${l}.`)))break;let a=i[0];l=l===``?a:`${l}.${a}`,u=Np(n[a])}let d=e.byPath.get(l),f=c.get(l),p=Object.fromEntries([...c].filter(([e,t])=>t!==void 0&&e!==l&&!e.startsWith(`${l}.`)));if(d.type===`choice`)return Fd(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return Hd(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...Nd(l,f,p),...m.size===0?{}:{children:m}}},Ip=(e,t,n)=>{let r=Np(n);if(Reflect.ownKeys(r).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine update construction accepts only data and decoded`);let i=e.byPath.get(t);if(i?.schema===void 0)throw Error(`Machine update requires a valued state`);return yd(t,Pp(i,r))},Lp=(e,t,n=``)=>{let r=Np(t),i=e.byPath.get(n);Fp(e,n,r);let a=Pp(i,r);if(i.type===`choice`)return Fd(n,i.parent);if(i.type===`atomic`||i.type===`final`)return{path:n,value:a};if(r.states===void 0)throw Error(`Machine history fallback requires a complete explicit tree`);let o=Np(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,Lp(e,r,n===``?t:`${n}.${t}`)]));return i.type===`parallel`?{path:n,value:a,states:s}:{path:n,value:a,state:Object.values(s)[0]}},Rp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},zp=`root`,Bp=e=>{let t=new Map,n=(e,r)=>{let i=!je(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!je(e)&&`states`in e)for(let[t,i]of Object.entries(e.states))n(i,r===``?t:`${r}.${t}`)};if(n(e.node,``),t.has(`root`))throw Error(`Machine top-level state name "${zp}" is reserved for the root`);return t},Vp=(e,t)=>{let n=Bp(e),r=t.input!==void 0,i=new Map;for(let e of[`effects`,`streams`,`timers`,`logic`,`children`])if(t[e]!==void 0)for(let[n,r]of Object.entries(Rp(t[e],`Machine ${e} must be a source map`))){if(i.has(n))throw Error(`Machine source name "${n}" is registered more than once`);i.set(n,Object.freeze({kind:e,value:r}))}let a=new Map;if(t.branches!==void 0)for(let[o,s]of Object.entries(Rp(t.branches,`Machine branches must be a map`))){let t=Rp(s,`Machine branches "${o}" must be a branch record`);for(let e of Reflect.ownKeys(t)){if(typeof e!=`string`)throw Error(`Machine branches cannot use symbol keys`);if(e.length===0||String(Number(e))===e)throw Error(`Machine branches require non-index string branch keys`)}let c=Object.entries(t);if(c.length===0)throw Error(`Machine branches "${o}" requires a branch`);a.set(o,Object.freeze(Object.fromEntries(c.map(([t,s])=>{let c={...Rp(s,`Machine branch "${o}.${t}" must be a declaration`)};for(let e of Reflect.ownKeys(c))if(typeof e!=`string`||![`target`,`update`,`history`,`none`,`initialize`,`title`].includes(e))throw Error(`Machine branch "${o}.${t}" contains an unknown declaration field`);if(c.initialize!==void 0&&c.initialize!==!0)throw Error(`Machine branch "${o}.${t}" declares initialize: true; its resolver supplies input`);if(c.title!==void 0&&(typeof c.title!=`string`||c.title.length===0))throw Error(`Machine branch title must be a non-empty string`);return Up({root:e,input:r,paths:n,sources:i,branches:a},c),[t,Object.freeze(c)]}))))}return{root:e,input:r,paths:n,sources:i,branches:a}},Hp=(e,t)=>{let n=e===`root`?``:typeof e==`string`&&e!==``?e:void 0,r=n===void 0?void 0:t.paths.get(n);if(n===void 0||r===void 0)throw Error(`Machine target ${String(e)} is not a declared state path`);return{path:n,kind:r}},Up=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=Hp(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return gd(`update`,n.path,`branch`)}if(n.length!==1)throw Error(`Machine transition must declare exactly one destination operation`);let r=n[0];if(r===`none`){if(t.none!==!0||t.update!==void 0)throw Error(`Machine targetless transition requires none: true`);return _d}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return gd(`state`,``,`branch`)}let i=Hp(t[r],e);if(r===`target`&&i.path===``)throw Error(`Machine root is not a destination; use initialize to reconstruct it from machine input`);if(r===`history`!=(i.kind===`history`))throw Error(`Machine history references require a history transition`);let a=t.update===void 0?void 0:Hp(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return gd(i.kind,i.path,r===`history`?`full`:`branch`,a)},Wp=(e,t,n,r)=>{let i=Rp(t,`Machine invocation for "${n}" must be an object`),a=typeof i.src==`string`?e.sources.get(i.src):void 0;if(a===void 0)throw Error(`Machine invocation for "${n}" names an unknown source`);let{src:o,input:s,...c}=i,l=typeof s==`function`?e=>s(r(e)):s;if(a.kind===`children`)return{...c,child:a.value,...l===void 0?{}:{input:l}};let u=typeof a.value==`function`&&!(a.kind===`effects`&&er(a.value))&&!(a.kind===`streams`&&lr(a.value));if(u!==(typeof l==`function`))throw Error(`Machine invocation "${o}" requires input exactly when its source takes an argument`);let d=u?e=>a.value(l(e)):()=>a.value,f={effects:`effect`,streams:`stream`,timers:`after`,logic:`logic`}[a.kind];return{...c,sourceName:o,id:c.id??o,[f]:!u&&(a.kind===`timers`||a.kind===`logic`)?a.value:d}},Gp=Symbol(`effect/Machine/InitialEvent`),Kp=Symbol(`effect/Machine/SnapshotBuilderState`),qp=Symbol(`effect/Machine/ChildMachineLogic`),Jp=new WeakSet,Yp=e=>Jp.has(e),Xp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},Zp=e=>typeof e==`function`?e:()=>e,Qp=e=>{if(typeof e==`object`&&e&&V(e,`decoded`)&&e.decoded===!0&&V(e,`data`)){let t=Xp(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return Zp(t.data)}let t=Zp(e);return n=>Wd(e===void 0?{}:t(n))},$p=e=>{if(e.decoded!==void 0&&typeof e.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.decoded===!0){if(!V(e,`data`))throw Error(`Machine decoded construction requires data`);return Zp(e.data)}let t=Zp(e.data);return n=>Wd(V(e,`data`)?t(n):{})},em=(e,t)=>{let n=(e,t,r)=>{if(V(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&V(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(je(e)||!(`states`in e)){if(i!==void 0)throw Error(`Machine state "${r}" cannot declare initial children`);if(o!==void 0)throw Error(`Machine state "${r}" has no children`);return{node:e,handlers:s}}let c=o===void 0?{}:Xp(o,`child handlers`);for(let t of Object.keys(c))if(!Object.prototype.hasOwnProperty.call(e.states,t))throw Error(`Machine unknown child "${t}"`);let l=Object.create(null),u=Object.create(null),d=Object.create(null),f=e.type===`parallel`,p;if(f){let t=i===void 0?{}:Xp(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!je(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!je(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=Qp(r)}}else{let t=Xp(i,`initial edge for "${r}"`);if(Reflect.ownKeys(t).some(e=>![`target`,`data`,`decoded`].includes(String(e))))throw Error(`Machine initial edge accepts only target, data, and decoded`);let n=r===``?``:`${r}.`,a=typeof t.target==`string`&&t.target.startsWith(n)?t.target.slice(n.length):void 0,o=a===void 0||!Object.hasOwn(e.states,a)?void 0:e.states[a],s=o===void 0||je(o)?`state`:o.type;if(a===void 0||o===void 0||s===`history`)throw Error(`Machine initial target must be a direct child of "${r===``?`root`:r}"`);if(p=a,s===`choice`&&(V(t,`data`)||V(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=$p(t),l=e.states[a];if(V(t,`data`)&&!je(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);V(t,`data`)&&(d[a]=c)}for(let[t,i]of Object.entries(e.states)){let e=r===``?t:`${r}.${t}`,a=n(i,c[t]===void 0?{}:Xp(c[t],`state handler`),e);l[t]=a.node,(je(i)||i.type!==`history`)&&(c[t]!==void 0||!je(i)&&`states`in i)&&(u[t]=a.handlers)}let m=Object.freeze({...e,states:Object.freeze(l),...f?{}:{initial:p}}),h=Object.entries(d),g=e=>{let t=typeof e.ancestors==`object`&&e.ancestors!==null?e.ancestors:{},n={...e,root:r===``?e.state:t[``]},i=Object.fromEntries(h.map(([e,t])=>[e,t(n)]));return{[Kp]:i}};return Jp.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},tm=(e,t)=>{let n=[`effect`,`stream`,`after`,`logic`,`child`].filter(t=>t in e);if(n.length!==1)throw Error(`Machine invocation for state "${t}" must define exactly one source`);if(n[0]!==`child`&&typeof e.id!=`string`)throw Error(`Machine invocation for state "${t}" requires a string id`);if((n[0]===`effect`||n[0]===`stream`)&&typeof e[n[0]]!=`function`)throw Error(`Machine invocation for state "${t}" requires a source callback`);return Object.freeze(e)},nm=e=>`child`in e?e.child.id:e.id,rm=(e,t)=>{let n=new Set;for(let r of e){let e=nm(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},im=e=>e===void 0?[]:Array.isArray(e)?e:[e],am=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(Df(e,t))},emit:t=>{r.push(kf(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},om=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},sm=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(Wd(t.length===0?{}:t[0])),enumerable:!1}),t},cm=e=>{let t={};return Object.defineProperty(t,Kp,{value:e,enumerable:!1}),t},lm=(e,t,n)=>{let r=cm(n);for(let i of t.children){let a=om(e,i);a.schema===void 0||V(n,a.key)||(r[a.key]=sm(r=>{let i=Object.assign({},n);return i[a.key]=r,lm(e,t,i)}))}return r},um=(e,t)=>{let n=om(e,t);if(n.type===`parallel`)return lm(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=om(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return sm(e=>cm({[r.key]:e}))},dm=(e,t)=>{if(typeof t!=`object`||!t||!V(t,Kp))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[Kp]},fm=Symbol(`effect/Machine/InvocationEvent`),pm=(e,t,n)=>({[fm]:!0,path:e,id:t,type:`done`,output:n}),mm=(e,t,n)=>({[fm]:!0,path:e,id:t,type:`element`,element:n}),hm=(e,t,n)=>({[fm]:!0,path:e,id:t,type:`failure`,error:n}),gm=(e,t,n)=>({[fm]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),_m=e=>typeof e==`object`&&!!e&&fm in e,vm=new WeakMap,ym=new WeakMap,bm=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},xm=(e,t)=>{let n=Object.create(e);return ym.set(n,bm(e,t)),n},Sm=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return bm(e,n);let r=ym.get(e);if(r!==void 0)return r;let i=vm.get(e);if(i!==void 0)return i;let a=bm(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>H(new $u)},parent:void 0});return vm.set(e,a),a},Cm=e=>{if(e!==void 0)return typeof e==`function`?{reenter:!1,declinable:!1,targets:void 0,transition:e,evaluate:void 0}:{reenter:e.reenter===!0,declinable:e.declinable===!0,targets:e.targets,transition:e.transition,evaluate:e.evaluate}},wm=(e,t,n)=>{let r=am(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Tm=(e,t,n,r)=>{let i=am(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Ad(a.result)?{declined:!0}:{declined:!1,state:Dd(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},Em=(e,t,n)=>{let r=am(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Dm=(e,t,n,r)=>{let i=new Set(t.active),a=new Map(t.values),o=[],s=[],c=[],l=[],u=!0;for(;u;){u=!1;for(let d of Array.from(i).sort((t,n)=>qf(e,t,n))){let f=Q(e,d);if(f.type===`compound`&&!f.children.some(e=>i.has(e))){if(f.initial===void 0)throw Error(`Machine shallow history expected compound state "${d}" to have an initial child`);let p=Q(e,f.initial),m={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences};if(p.type===`choice`){let t=rh(e,m,Fd(p.path,d,Object.fromEntries(a)),n),r=m;for(let i of[t.target,...t.additionalTargets]){if(i===void 0)throw Error(`Machine initial choice "${p.path}" must resolve to an active state target`);let t=Pd(i)?km(e,r,i,n):Md(i)?Am(e,r,i,n):void 0;r=yp(e,r,t?.target??i),t!==void 0&&(o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions))}i.clear(),a.clear();for(let e of r.active)i.add(e);for(let[e,t]of r.values)a.set(e,t);o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions),u=!0;continue}if(i.add(p.path),p.schema!==void 0){let t=rd(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,Mf(e,p,Wd({}))),u=!0;continue}let i=Em(e,t,{...Sm(e,m),state:m.values.get(d),containingState:ep(e,m,d),ancestors:$f(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...Yp(t)?{}:{builder:um(e,d)}}),l=dm(d,i.value);a.set(p.path,Mf(e,p,l[p.key])),o.push(...i.commands),s.push(...i.raisedEvents),c.push(...i.emittedEvents)}u=!0}if(f.type===`parallel`){let l=f.children.filter(e=>!i.has(e));if(l.length>0){let f=l.filter(t=>Q(e,t).schema!==void 0),p={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences},m=f.length===0?void 0:rd(e).handlers[d]?.initialize,h=m===void 0?void 0:Em(e,m,{...Sm(e,p),state:p.values.get(d),containingState:ep(e,p,d),ancestors:$f(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...Yp(m)?{}:{builder:um(e,d)}}),g=h===void 0?void 0:dm(d,h.value);for(let t of l){let n=Q(e,t);if(i.add(n.path),n.schema!==void 0){if(h===void 0){a.set(n.path,Mf(e,n,Wd({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&Yp(m)){a.set(n.path,Mf(e,n,Wd({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,Mf(e,n,g[n.key]))}}h!==void 0&&(o.push(...h.commands),s.push(...h.raisedEvents),c.push(...h.emittedEvents)),u=!0}}}}return{configuration:{active:i,values:a,outputs:new Map,history:t.history},commands:o,raisedEvents:s,emittedEvents:c,transitions:l}};function Om(e,t,n,r){let i=_p(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>Q(e,t).type===`choice`))return Dm(e,i,r,n.input);let a=[],o=[],s=[],c=[];for(let t of n.children?.keys()??[]){let n=Q(e,t);if(n.type!==`choice`)continue;let l=rh(e,i,Fd(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=Pd(t)?km(e,i,t,r):Md(t)?Am(e,i,t,r):void 0;i=yp(e,i,n?.target??t),n!==void 0&&(a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents),c.push(...n.transitions))}a.push(...l.commands),o.push(...l.raisedEvents),s.push(...l.emittedEvents),c.push(...l.transitions)}let l=Dm(e,i,r,n.input);return c.length===0?l:{...l,commands:[...a,...l.commands],raisedEvents:[...o,...l.raisedEvents],emittedEvents:[...s,...l.emittedEvents],transitions:[...c,...l.transitions]}}function km(e,t,n,r){let i=Om(e,t,n,r),a=ip(e,i.configuration,n.path);return{target:Hd(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Am(e,t,n,r){let i=Q(e,n.path);if(i.type!==`history`||i.parent!==n.parent)throw Error(`Machine expected history target "${n.path}" to resolve to its declared parent`);let a=mp(t,n.path);if(a!==void 0){let i=Dm(e,hp(e,t,a),r),o=ip(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:Hd(n.parent,o.value,{snapshot:o,values:s}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}let o=i.key,s=rd(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=Tm(e,s,{event:r,target:t=>Lp(e.stateNodes,t),owner:n.parent});if(c.state===void 0||Md(c.state)||!Kd(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=th(c.state)===void 0?void 0:rh(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?up(e,c.state):yp(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=yp(e,u,t);if(!u.active.has(n.parent))throw Error(`Machine history default for "${n.path}" returned a configuration that does not contain owner state "${n.parent}"`);let d=ip(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:Hd(n.parent,d.value,{snapshot:d,values:f}),commands:[...c.commands,...l?.commands??[]],raisedEvents:[...c.raisedEvents,...l?.raisedEvents??[]],emittedEvents:[...c.emittedEvents,...l?.emittedEvents??[]],transitions:l?.transitions??[]}}var jm=(e,t)=>{if(!t.transition.declinable)return t;let n=Tm(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},Mm=(e,t)=>[...Gf(e,t)].reverse(),Nm=(e,t,n)=>{let r=Gf(e,t),i=Gf(e,n),a,o=Math.min(r.length,i.length);for(let e=0;e<o&&r[e]===i[e];e++)a=r[e];return a},Pm=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||Uf(e,t)?t:e},Fm=(e,t,n)=>Rm(e,Array.from(t.active).filter(e=>n===void 0||Uf(e,n))),Im=(e,t,n)=>zm(e,Array.from(t.active).filter(e=>n===void 0||Uf(e,n))),Lm=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),Rm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Gf(e,n).length-Gf(e,t).length;return r===0?Q(e,n).order-Q(e,t).order:r}),zm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Gf(e,t).length-Gf(e,n).length;return r===0?qf(e,t,n):r}),Bm=(e,t,n,r)=>({...Sm(e,t),state:t.values.get(n),containingState:ep(e,t,n),ancestors:$f(e,t,n),event:r}),Vm=(e,t,n,r,i)=>({...Sm(e,t),state:t.values.get(n),containingState:ep(e,t,n),ancestors:$f(e,t,n),event:r,snapshot:i}),Hm=(e,t,n,r,i,a)=>({...Sm(e,t),state:t.values.get(n),containingState:ep(e,t,n),ancestors:$f(e,t,n),event:r,output:i,snapshot:a}),Um=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=wm(e,rd(e).handlers[c]?.[i],Bm(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},Wm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=rp(e,t);for(let o of Yf(e,t))for(let c of Mm(e,o)){let l=Cm(rd(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=jm(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...Sm(e,t),state:t.values.get(c),containingState:ep(e,t,c),ancestors:$f(e,t,c),event:n,snapshot:s()}}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},Gm=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=rp(e,t);for(let o of r){let r=Cm(rd(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=jm(e,{sourcePath:o.path,leafPath:Zf(e,t,o.path),trigger:{type:`done`},transition:r,context:Hm(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},Km=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=rp(e,t);for(let o of Yf(e,t))for(let c of Mm(e,o)){let l=Cm(rd(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=jm(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:Vm(e,t,c,n,s())}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},qm=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=rd(e).handlers[n.path],i=im(r?.invoke).find(e=>{let t=`child`in e?e.child?.id:e.id;return String(t)===n.id});if(i===void 0)return[];let a=Cm(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=rp(e,t),s={...Sm(e,t),state:t.values.get(n.path),containingState:ep(e,t,n.path),ancestors:$f(e,t,n.path),snapshot:o,id:n.id,...n.type===`element`?{element:n.element}:n.type===`done`?{output:n.output}:n.type===`failure`?{error:n.error}:{snapshot:n.snapshot}},c=jm(e,{sourcePath:n.path,leafPath:Zf(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},Jm=e=>{if(Md(e)||Id(e)||Ud(e)||Kd(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},Ym=(e,t,n,r)=>{if(n===void 0||r===void 0)return;let i=typeof r==`object`&&r&&`path`in r?String(r.path):`<unknown>`;if(!n.some(e=>i===e||e===``||i.startsWith(`${e}.`))){let r=t.type===`event`?String(t.event):t.type;throw Error(`Machine transition from "${e}" on "${r}" returned target "${i}" outside declared targets: ${n.length===0?`none`:n.map(e=>`"${e}"`).join(`, `)}`)}},Xm=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},Zm=(e,t)=>Array.from(t).sort((t,n)=>qf(e,t.selection.sourcePath,n.selection.sourcePath)),Qm=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&Uf(e.sourcePath,t.sourcePath))),$m=(e,t)=>{let n=[];for(let r of Zm(e,t)){let e=!1,t=new Set;for(let i of n){let n=r.update!==void 0&&i.update!==void 0&&r.update.path===i.update.path;if(Xm(r.exitPaths,i.exitPaths)||n){if(Uf(r.selection.sourcePath,i.selection.sourcePath))t.add(i);else{e=!0;break}}}if(!e){for(let e of t){let t=n.indexOf(e);t>=0&&n.splice(t,1)}n.push(r)}}return n},eh=(e,t={})=>{let n={...t},r=[],i=e=>{if(Id(e))Object.assign(n,e.values??{}),r.push(e);else if(typeof e==`object`&&e&&`path`in e&&`value`in e&&(e.value!==void 0&&(n[String(e.path)]=e.value),`state`in e&&i(e.state),`states`in e&&typeof e.states==`object`&&e.states!==null))for(let t of Object.values(e.states))i(t)};return i(e),r.map(e=>({target:Fd(e.path,e.parent,n),values:n}))},th=(e,t={})=>eh(e,t)[0],nh=(e,t)=>{if(Id(e))return Fd(e.path,e.parent,{...t,...e.values??{}});if(Pd(e))return{...e,values:{...t,...e.values}};if(!Ud(e)||Object.keys(t).length===0)return e;let n=e[ad];return Hd(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function rh(e,t,n,r){let i=[n],a=[],o=[],s=[],c=[],l=[],u=0;for(;i.length>0;){let n=i.shift();for(;;){let a=eh(n),d=a[0];if(d===void 0)break;if(i.unshift(...a.slice(1).map(({target:e})=>e)),u+=1,u>1e3)throw new Xu({machineId:e.id,state:d.target.path,maxIterations:ah});let f=Q(e,d.target.path);if(f.type!==`choice`||f.parent!==d.target.parent)throw Error(`Machine expected choice target "${d.target.path}" to resolve to its declared parent`);let p=rd(e).handlers[f.path]?.choice;if(p===void 0||typeof p.transition!=`function`)throw Error(`Machine choice state "${f.path}" requires an implementation`);let m=new Map(t.values);for(let[t,n]of Object.entries(d.values)){let r=Q(e,t);r.schema!==void 0&&m.set(t,Mf(e,r,n))}let h={active:new Set([...t.active,...Object.keys(d.values)]),values:m,outputs:t.outputs,history:t.history,...t.machineReferences===void 0?{}:{machineReferences:t.machineReferences}},g=Tm(e,p.transition,{...Sm(e,h),containingState:ep(e,h,f.path),ancestors:$f(e,h,f.path),event:r},p.evaluate);if(g.state===void 0)throw Error(`Machine choice resolver for "${f.path}" must return a target`);Ym(f.path,{type:`choice`},p.targets,g.state);let _=Jm(g.state);n=nh(g.state,d.values);let v=th(n);l.push({source:f.path,trigger:{type:`choice`},reenter:!1,branchIndex:g.branchIndex,branchKey:g.branchKey,target:_,resolvedTarget:v?.target.path??_,updates:[]}),o.push(...g.commands),s.push(...g.raisedEvents),c.push(...g.emittedEvents)}if(!Ud(n)&&!Kd(n)&&!Md(n)&&!Pd(n))throw Error(`Machine choice resolver must return a concrete typed target`);a.push(n)}return{target:a[0],additionalTargets:a.slice(1),commands:o,raisedEvents:s,emittedEvents:c,transitions:l}}var ih=(e,t,n)=>{let r=n.leafPath,i=n.collected??Tm(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=Sd(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||bd(o)?void 0:o;Ym(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(bd(o)?o:void 0),l=c===void 0?void 0:(()=>{let n=Q(e,c.path);if(!t.active.has(n.path)||n.schema===void 0)throw Error(`Machine state update owner "${n.path}" must be an active valued state`);return{path:n.path,value:Mf(e,n,c.value)}})(),u=l!==void 0&&(Pd(s)||Id(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:rh(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&Pd(f)?km(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=Md(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&Md(m)){let i=n.transition.reenter?Q(e,n.sourcePath).parent:Nm(e,r,m.parent),a=g===void 0?Fm(e,t,i):Rm(e,Array.from(t.active).filter(e=>Wf(e,m.parent)));h=Am(e,a.includes(m.parent)?pp(e,t,t,a):t,m,n.context.event)}let _=h===void 0?m:h.target,v=[],y=[],b=[],x=[],S=[];for(let r of d?.additionalTargets??[]){if(Pd(r)){let i=km(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions);continue}if(!Md(r)){S.push(r);continue}let i=Am(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions)}let C=_===void 0?void 0:S.length===0||s===void 0?Jm(_):Jm(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:yp(e,t,_);for(let t of S)w=yp(e,w,t);if(a!==void 0&&l!==void 0&&!w.active.has(l.path))throw Error(`Machine combined target exited its updating owner "${l.path}"`);l!==void 0&&(w={...w,values:new Map(w.values).set(l.path,l.value)});let T=n.transition.reenter||!Lm(t,w),E=T||l!==void 0;if(!T)return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:T,stabilize:E,exitPaths:[],entryPaths:[],choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]};let D=C===void 0?Q(e,n.sourcePath).parent:Nm(e,r,C),O=Q(e,n.sourcePath).parent,k=n.transition.reenter?Pm(D,O):D;return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:T,stabilize:E,exitPaths:g===void 0?Fm(e,t,k):Rm(e,Array.from(t.active).filter(e=>Wf(e,g.parent))),entryPaths:g===void 0?Im(e,w,k):zm(e,Array.from(w.active).filter(e=>Wf(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},ah=1e3,oh={_tag:Gp},sh=(e,t)=>Tp(e,lp(e,t)),ch=(e,t,n)=>fp(e,t).pipe(_(t=>kp(e,t,n)),_(t=>{let n=Qf(e,t.configuration);return!Tp(e,t.configuration)||!t.configuration.outputs.has(n)?N(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):Nn(t.configuration.outputs.get(n))})),lh=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Af(e,e.input,void 0),t):[Af(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=km(e,i,r,oh),o=yp(e,i,a.target),s=rp(e,o),c=tp(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=Um(e,o,c,oh,`entry`),p=dh(e,o,oh,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:oh,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:rp(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:rp(e,t.next),event:t.event,transitions:t.transitions,commands:t.commands,raisedEvents:t.raisedEvents,emittedEvents:t.emittedEvents,exitPaths:t.exitPaths,entryPaths:t.entryPaths,changed:t.changed}))};return p.done?{...m,done:!0,output:p.output}:{...m,done:!1,output:void 0}},uh=(e,t,n,r)=>{if(r.length===0)return{next:t,event:n,transitions:[],commands:[],raisedEvents:[],emittedEvents:[],exitPaths:[],entryPaths:[],changed:!1,stabilize:!1};let i=Qm(r),a=[];for(let n of i)a.push(ih(e,t,n));let o=$m(e,a),s=Zm(e,o),c=s.flatMap(e=>[{source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:Jm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Jm(e.target),updates:e.update===void 0?[]:[e.update.path]},...e.choiceTransitions]),l=t;for(let e of s)e.update!==void 0&&(l={...l,values:new Map(l.values).set(e.update.path,e.update.value)});let u=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let t of u)t.target!==void 0&&(l=yp(e,l,t.target));let d=o.some(e=>e.changed),f=o.some(e=>e.stabilize),p=s.flatMap(e=>e.commands),m=s.flatMap(e=>e.raisedEvents),h=s.flatMap(e=>e.emittedEvents);if(!d)return{next:l,event:n,transitions:c,commands:p,raisedEvents:m,emittedEvents:h,exitPaths:[],entryPaths:[],changed:!1,stabilize:f};let g=Rm(e,s.flatMap(e=>e.exitPaths)),_=zm(e,s.flatMap(e=>e.entryPaths));l=pp(e,t,l,g);let v=Um(e,t,g,n,`exit`),y=Um(e,l,_,n,`entry`);return{next:l,event:n,transitions:c,commands:[...v.commands,...p,...y.commands],raisedEvents:[...v.raisedEvents,...m,...y.raisedEvents],emittedEvents:[...v.emittedEvents,...h,...y.emittedEvents],exitPaths:g,entryPaths:_,changed:!0,stabilize:f}},dh=(e,t,n,r,i,a,o)=>{let s=t,c=n,l=!0,u=0,d=0,f=!1,p,m=[];for(;;){if(u+=1,u>1e3)throw new Xu({machineId:e.id,state:String(Xf(e,s)),maxIterations:ah});let t=Mp(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>rd(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=Gm(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=uh(e,s,c,n);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}if(Tp(e,s)){let t=Qf(e,s);if(!s.outputs.has(t))throw Error(`Machine reached a terminal configuration without a completed root output`);f=!0,p=s.outputs.get(t);break}let h=l?Wm(e,s,c):[];if(h.length>0){let t=uh(e,s,c,h);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}let g=i[d];if(g===void 0)break;d+=1;let _=g;c=_;let v=Km(e,s,_);if(v.length===0){l=!0;continue}let y=uh(e,s,_,v);r.push(...y.commands),i.push(...y.raisedEvents),a.push(...y.emittedEvents),o.push(y),s=y.next,l=!0}let h={next:s,commands:r,emittedEvents:a,microsteps:o};return f?{...h,done:!0,output:p}:{...h,done:!1,output:void 0}},fh=(e,t,n)=>{let r=_m(n)?n:Df(e,n);if(Tp(e,t)){let n=Mp(e,t,r),i=Qf(e,n.configuration);if(!n.configuration.outputs.has(i))throw Error(`Machine reached a terminal configuration without a completed root output`);return{event:r,next:n.configuration,commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.configuration.outputs.get(i)}}let i=_m(r)?qm(e,t,r):Km(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=uh(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...dh(e,a.next,r,o,s,c,l),event:r}},ph=(e,...t)=>Ln({try:()=>lh(e,...t),catch:nd}),mh=(e,t)=>({raise:n=>Ef(e,n).pipe(_(e=>t.sendTo(t.self,e))),emit:n=>Of(e,n).pipe(_(e=>t.emit(e)))}),hh=(e,t)=>re(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),gh=(e,t)=>O(Array.from(e,e=>t.emit(e)),{discard:!0}),_h=new WeakMap,vh=e=>{let t=_h.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>H(new $u)},parent:void 0};return _h.set(e,n),n},yh=(e,t)=>{let n=t===void 0?vh(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},bh=new Set([`initialize`,`invoke`,`on`,`output`]),xh=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!bh.has(t))return!1;return!0},Sh=e=>{let t=[],n=[],r=[],i=new Map;for(let a of e.stateNodes.byPath.values()){if(t.push(a),a.type===`choice`||a.type===`history`)return;(a.type===`atomic`||a.type===`final`)&&n.push(a.path),a.type===`final`&&r.push(a.path);let o=rd(e).handlers[a.path];if(!xh(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=Cm(o.on[e]);if(t!==void 0){if(t.declinable)return;s.set(e,t)}}s.size>0&&i.set(a.path,s)}n.sort((t,n)=>qf(e,t,n)),r.sort((t,n)=>qf(e,t,n)),t.sort((e,t)=>e.order-t.order);let a=new Map(t.map((e,t)=>[e.path,t])),o=e=>{let t=a.get(e);if(t===void 0)throw Error(`Machine expected compiled state path "${e}"`);return t},s=n.map(o),c=t.map(e=>e.parent===void 0?-1:o(e.parent)),l=t.map(e=>e.children.map(o)),u=t.map(t=>Gf(e,t.path).slice(0,-1).map(o)),d=t.map(e=>i.get(e.path)),f=new Map;for(let e of s){let t=new Map,n=[e,...u[e].slice().reverse()];for(let e of n)for(let[n,r]of d[e]??[])t.has(n)||t.set(n,{sourceIndex:e,transition:r});f.set(e,t)}return{valued:Object.freeze(t.map(e=>e.schema!==void 0)),flat:t.every(e=>e.parent===void 0&&(e.type===`atomic`||e.type===`final`))||t[0]?.path===``&&t[0].type===`compound`&&t[0].schema===void 0&&(rd(e).handlers[``]===void 0||Reflect.ownKeys(rd(e).handlers[``]).every(e=>e===`initialize`))&&t.slice(1).every(e=>e.parent===``&&(e.type===`atomic`||e.type===`final`))&&[...i.values()].every(e=>[...e.values()].every(e=>e.targets!==void 0&&e.targets.every(e=>e!==``))),nodes:t,indexByPath:a,parentIndices:c,childIndices:l,ancestorIndices:u,rootIndices:t.flatMap((e,t)=>e.parent===void 0?[t]:[]),leafIndices:s,finalIndices:r.map(o),dispatchByLeaf:f}},Ch=e=>({active:e.active.slice(),activeLeaves:e.activeLeaves.slice(),values:e.values.slice(),completed:e.completed.slice(),outputs:e.outputs.slice(),completedOrder:e.completedOrder.slice()}),wh=(e,t)=>t?{...e,next:Ch(e.next)}:e,Th=(e,t,n)=>{e.values[t]=n},Eh=(e,t)=>{let n=new Uint8Array(e.nodes.length),r=Array(e.nodes.length),i=new Uint8Array(e.nodes.length),a=Array(e.nodes.length),o=[];for(let i of t.active){let a=e.indexByPath.get(i);if(a===void 0)throw Error(`Machine expected indexed active path "${i}"`);n[a]=1,e.valued[a]&&(r[a]=t.values.get(i))}for(let[n,r]of t.outputs){let t=e.indexByPath.get(n);if(t===void 0)throw Error(`Machine expected indexed completed path "${n}"`);i[t]=1,a[t]=r,o.push(t)}return{active:n,activeLeaves:e.leafIndices.filter(e=>n[e]===1),values:r,completed:i,outputs:a,completedOrder:o}},Dh=(e,t)=>{let n=new Set,r=new Map,i=new Map;for(let i=0;i<e.nodes.length;i++){if(t.active[i]!==1)continue;let a=e.nodes[i].path;n.add(a),e.valued[i]&&r.set(a,t.values[i])}for(let n of t.completedOrder)t.completed[n]===1&&i.set(e.nodes[n].path,t.outputs[n]);return{active:n,values:r,outputs:i,history:new Map}},Oh=(e,t,n)=>{let r=e.nodes[n],i={path:r.path,value:e.valued[n]?t.values[n]:void 0};if(r.type===`compound`){let a=e.childIndices[n].find(e=>t.active[e]===1);if(a===void 0)throw Error(`Machine expected indexed compound state "${r.path}" to have an active child`);i.state=Oh(e,t,a)}else if(r.type===`parallel`){let a={};for(let i of e.childIndices[n]){if(t.active[i]!==1)throw Error(`Machine expected indexed parallel state "${r.path}" to have active region "${e.nodes[i].path}"`);a[e.nodes[i].key]=Oh(e,t,i)}i.states=a}return i},kh=(e,t)=>{let n=e.rootIndices.find(e=>t.active[e]===1);if(n===void 0)throw Error(`Machine expected an active indexed root state`);let r=Oh(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Ah=(e,t,n,r,i,a)=>{let o=t.parentIndices[r],s={};for(let e of t.ancestorIndices[r])t.valued[e]&&(s[t.nodes[e].path]=n.values[e]);return{...yh(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:kh(t,n)}},jh=Object.freeze([]),Mh=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(Df(e,t))},emit:t=>{(o??=[]).push(kf(e,t))},sendTo:(e,t)=>{(i??=[]).push({_tag:`SendTo`,target:e,event:t})},stop:e=>{(i??=[]).push({_tag:`Stop`,child:e})}},c=r===void 0?{result:t(n,s),branchIndex:0,branchKey:void 0}:r(n,s);return{state:Dd(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??jh,raisedEvents:a??jh,emittedEvents:o??jh}},Nh=(e,t,n,r,i)=>{let a=[];for(let o of n.activeLeaves){let s=t.dispatchByLeaf.get(o).get(r._tag);if(s!==void 0){let{sourceIndex:c,transition:l}=s;if(!a.some(e=>e.sourceIndex===c)){let s=t.nodes[c].path;a.push({sourceIndex:c,leafIndex:o,sourcePath:s,leafPath:t.nodes[o].path,trigger:{type:`event`,event:r._tag},transition:l,context:Ah(e,t,n,c,r,i)})}}}return a},Ph=(e,t)=>{if(e.active===t.active)return!0;for(let n=0;n<e.active.length;n++)if(e.active[n]!==t.active[n])return!1;return!0},Fh=(e,t,n,r,i)=>{if((Ud(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&Ud(r)&&r[ad]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=Mf(e,t.nodes[i],r.value),{...n,values:a}}return Eh(t,yp(e,Dh(t,n),r))},Ih=(e,t,n,r)=>{let i=Mh(e,r.transition.transition,r.context,r.transition.evaluate),a=Sd(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(bd(o)?o:void 0),c=s===void 0?void 0:(()=>{let r=t.indexByPath.get(s.path),i=r===void 0?void 0:t.nodes[r];if(r===void 0||i===void 0||n.active[r]!==1||i.schema===void 0)throw Error(`Machine state update owner "${s.path}" must be an active valued state`);return{path:i.path,value:Mf(e,i,s.value)}})(),l=o===void 0||bd(o)?void 0:o;Ym(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&Pd(l)?km(e,(()=>{let e=Dh(t,n);return c===void 0?e:{...e,values:new Map(e.values).set(c.path,c.value)}})(),l,r.context.event):void 0,d=u?.target??l;if(d!==void 0&&!Ud(d)&&!Kd(d))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let f=d===void 0?c===void 0?n:(()=>{let e=Ch(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():Fh(e,t,n,d,r.leafIndex);if(a!==void 0&&c!==void 0){let e=t.indexByPath.get(c.path);if(f.active[e]!==1)throw Error(`Machine combined target exited its updating owner "${c.path}"`);let n=f.values.slice();n[e]=c.value,f={...f,values:n}}let p=r.transition.reenter||!Ph(n,f),m=p||c!==void 0;if(!p)return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!1,stabilize:m,exitPaths:[],entryPaths:[],choiceTransitions:u?.transitions??[]};let h=d===void 0?void 0:Jm(d),g=h===void 0?t.nodes[r.sourceIndex].parent:Nm(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?Pm(g,_):g;return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!0,stabilize:m,exitPaths:Fm(e,Dh(t,n),v),entryPaths:Im(e,Dh(t,f),v),choiceTransitions:u?.transitions??[]}},Lh=(e,t,n,r,i,a)=>{let o=e=>({source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:Jm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Jm(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=Ih(e,t,n,i[0]);return{next:s.next,event:r,...a?{transitions:[o(s)]}:void 0,commands:s.commands,raisedEvents:s.raisedEvents,emittedEvents:s.emittedEvents,exitPaths:s.exitPaths,entryPaths:s.entryPaths,changed:s.changed}}let s=Zm(e,$m(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&Uf(t.sourcePath,e.sourcePath))).map(r=>Ih(e,t,n,r)))),c=n;if(s.length===1)c=s[0].next;else{for(let e of s)if(e.update!==void 0){let n=c.values.slice();n[t.indexByPath.get(e.update.path)]=e.update.value,c={...c,values:n}}let n=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let r of n)r.target!==void 0&&(c=Fh(e,t,c,r.target,r.selection.leafIndex))}let l=s.flatMap(e=>e.commands),u=s.flatMap(e=>e.raisedEvents),d=s.flatMap(e=>e.emittedEvents),f=s.some(e=>e.changed);return{next:c,event:r,...a?{transitions:s.map(o)}:void 0,commands:l,raisedEvents:u,emittedEvents:d,exitPaths:f?Rm(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?zm(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},Rh=(e,t,n,r,i,a)=>{let o=n,s=r,c,l,u,d,f=0,p=0;for(;;){if(p+=1,p>1e3)throw new Xu({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:ah});let n=o.activeLeaves[0];if(n===void 0)throw Error(`Machine expected an active indexed root state`);if(t.nodes[n].type===`final`){let n=Mp(e,Dh(t,o),s).configuration,i=Qf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:Eh(t,n),commands:c??jh,emittedEvents:u??jh,microsteps:d??jh,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=Cm(rd(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=Mh(e,h.transition,{...yh(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:kh(t,o)},h.evaluate),f=bd(r.state)?r.state:void 0,p=f===void 0?r.state:void 0;if(f!==void 0){let r=t.nodes[n];if(f.path!==m||r.schema===void 0)throw Error(`Machine state update owner "${f.path}" must be the active valued state`);Th(o,n,Mf(e,r,f.value))}if(Ym(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!Ud(p)&&!Kd(p))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let g=o;if(p!==void 0){let r=t.indexByPath.get(String(p.path)),i=Ud(p)?p[ad]===void 0&&p.values===void 0:!(`state`in p)&&!(`states`in p)&&!(`completed`in p)&&!(`history`in p);r===n&&i&&o.completedOrder.length===0&&t.valued[n]?Th(o,n,Mf(e,t.nodes[n],p.value)):g=Fh(e,t,o,p,n)}let _=h.reenter||!Ph(o,g),v=g.activeLeaves[0];if(v===void 0)throw Error(`Machine expected an active indexed transition target`);let y={next:g,event:s,...i?{transitions:[{source:m,trigger:{type:`event`,event:s._tag},reenter:h.reenter,branchIndex:r.branchIndex,branchKey:r.branchKey,target:p===void 0?void 0:Jm(p),resolvedTarget:p===void 0?void 0:Jm(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:jh,entryPaths:_?[t.nodes[v].path]:jh,changed:_};o=g,(d??=[]).push(wh(y,i)),r.commands.length>0&&(c??=[]).push(...r.commands),r.raisedEvents.length>0&&(l??=[]).push(...r.raisedEvents),r.emittedEvents.length>0&&(u??=[]).push(...r.emittedEvents)}if(t.nodes[o.activeLeaves[0]].type===`final`)continue;let g=l?.[f];if(g===void 0)return{event:r,next:o,commands:c??jh,emittedEvents:u??jh,microsteps:d??jh,done:!1,output:void 0};f+=1,s=g}},zh=(e,t,n,r,i,a)=>{if(_m(r)){let i=fh(e,a===void 0?Dh(t,n):zf(Dh(t,n),a),r);return{event:i.event,next:Eh(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:Eh(t,e.next),event:e.event,transitions:e.transitions,commands:e.commands,raisedEvents:e.raisedEvents,emittedEvents:e.emittedEvents,exitPaths:e.exitPaths,entryPaths:e.entryPaths,changed:e.changed})),done:i.done,output:i.output}}let o=Df(e,r);if(t.flat)return Rh(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=Dh(t,n);if(Tp(e,r)){let n=Mp(e,r,o).configuration,i=Qf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:Eh(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=Nh(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=Lh(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[wh(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new Xu({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:ah});if(t.finalIndices.some(e=>l.active[e]===1)){let n=Mp(e,Dh(t,l),u).configuration;if(l=Eh(t,n),Tp(e,n)){let t=Qf(e,n);if(!n.outputs.has(t))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!0,output:n.outputs.get(t)}}}let n=f[h];if(n===void 0)return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!1,output:void 0};h+=1,u=n;let r=Nh(e,t,l,n,a);if(r.length===0)continue;let s=Lh(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(wh(s,i))}},Bh=new WeakMap,Vh=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>rp(e,t),plan:(t,n,r,i)=>fh(e,i===void 0?t:zf(t,i),n)}),Hh=(e,t)=>({fromConfiguration:e=>Eh(t,e),toConfiguration:e=>Dh(t,e),snapshot:e=>kh(t,e),plan:(n,r,i=!1,a)=>zh(e,t,n,r,i,a),...Object.values(rd(e).handlers).some(e=>e.initialize!==void 0&&!Yp(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Af(e,e.input,void 0),n):[Af(e,e.input,n[0])],a=e.initial(...i),o=Pd(a)?Om(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,oh).configuration:up(e,a),s=Mp(e,r===void 0?o:zf(o,r),oh).configuration,c=Eh(t,s),l=kh(t,c);if(!Tp(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:tp(e,s),done:!1,output:void 0};let u=Qf(e,s);if(!s.outputs.has(u))throw Error(`Machine reached a terminal configuration without a completed root output`);return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:tp(e,s),done:!0,output:s.outputs.get(u)}}}}),Uh=e=>{let t=Bh.get(e);if(t!==void 0)return t;let n=Sh(e),r=n===void 0?Vh(e):Hh(e,n);return Bh.set(e,r),r},Wh=`Machine.invocation:`,Gh=e=>e.startsWith(Wh),Kh=(e,t)=>{if(e.values===void 0?e.values=[t]:e.values.push(t),e.waiter!==void 0){let t=e.waiter;e.waiter=void 0,wt(t,W)}},qh=e=>br(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,Nn(t)}let t=l();return e.waiter=t,tr(t).pipe(T(qh(e)))}),Jh=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),Yh=(e,t,n)=>{if(e.closed)return pt();let r=e.children.get(t);return r!==void 0&&Jh(r,n)?me(r.ref):pt()},Xh=e=>{if(e.observers!==void 0)for(let t of e.observers)Kh(t,Yh(e,t.id,t.child))},Zh=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&Xh(e))},Qh=(e,t,n,r,i)=>{let a=e.children.get(t);if(e.closed||a===void 0||a._tag!==`Starting`||a.token!==n)return!1;e.children.delete(t);let o=a.ownerKey===void 0?{_tag:`Started`,token:n,descriptor:i,ref:r}:{_tag:`Started`,token:n,descriptor:i,ref:r,ownerKey:a.ownerKey,ownerPath:a.ownerPath,ownerActive:a.ownerActive===!0};return e.children.set(t,o),typeof t==`string`&&Xh(e),!0},$h=e=>R(function*(){let t=yield*x(),n=0,r=0,i=0,a=0;return{rootSessionId:e,stream:Kn(t).pipe(yr(G(()=>{n+=1})),ar(G(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>a++,publishUnsafe:i=>{n!==0&&Ir(t,{...i,sequence:r++,rootSessionId:e})},close:Ht(t)}}),eg=e=>({id:e.id,sessionId:e.sessionId}),tg=e=>e.flatMap(e=>{if(typeof e!=`object`||!e||!(`_tag`in e))return[];if(e._tag===`SendTo`&&`target`in e&&`event`in e){let t=e.target;return typeof t==`object`&&t&&`id`in t?[{_tag:`SendTo`,target:`sessionId`in t?eg(t):{id:String(t.id)},event:e.event}]:[]}if(e._tag===`Stop`&&`child`in e){let t=e.child;return typeof t==`string`?[{_tag:`Stop`,target:{id:t}}]:typeof t==`object`&&t&&`id`in t?[{_tag:`Stop`,target:`sessionId`in t?eg(t):{id:String(t.id)}}]:[]}return[]}),ng=e=>typeof e!=`object`||!e||!(`microsteps`in e)||!Array.isArray(e.microsteps)?[]:e.microsteps.map(e=>({event:e.event,transitions:Array.isArray(e.transitions)?e.transitions:[],raisedEvents:Array.isArray(e.raisedEvents)?e.raisedEvents:[],emittedEvents:Array.isArray(e.emittedEvents)?e.emittedEvents:[],commands:tg(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),rg=Symbol.for(`effect/Machine/activeSnapshotObserver`),ig=Symbol.for(`effect/Machine/snapshotObserver`),ag=e=>typeof e==`object`&&!!e&&ig in e,og=Symbol.for(`effect/Machine/sendParentOverride`),sg=Symbol.for(`effect/Machine/acknowledgedSend`),cg=Symbol(`effect/Machine/AcknowledgedMessage`),lg=e=>typeof e==`object`&&!!e&&cg in e,ug=e=>lg(e)?e.event:e,dg=(e,t)=>{e!==void 0&&lg(e)&&(e.deferred!==void 0&&wt(e.deferred,Nn(t)),e.inspection?.complete(t))},fg=(e,t)=>{e!==void 0&&lg(e)&&e.deferred!==void 0&&wt(e.deferred,Br(t))},pg=e=>{e!==void 0&&lg(e)&&e.deferred!==void 0&&wt(e.deferred,H(new $u))},mg=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,hg=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),gg=e=>e?._tag===`Childless`||e?.childless===!0,_g=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},vg=e=>{if(e.items===void 0)return pt();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),me(t)},yg=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)pg(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},bg=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),xg=(e,t,n)=>{if(e.closed)return!1;for(_g(e,t),n?.();e.items!==void 0&&e.receivers.size>0;){let t=e.receivers.values().next().value;e.receivers.delete(t),t(W)}return!0},Sg=e=>br(()=>{let t=vg(e);return lt(t)?Nn(t.value):e.closed?he:Cn(t=>(e.receivers.add(t),G(()=>{e.receivers.delete(t)}))).pipe(T(Sg(e)))}),Cg=e=>{yg(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(he)},wg=class extends Ar()(`effect/Machine/MachineRuntime`){},Tg=(e,t)=>$t(e,wg,t),Eg=e=>{switch(e.status){case`active`:return;case`done`:return{_tag:`Done`,output:e.output,snapshot:e};case`error`:{let t=e.cause.reasons.find(dn);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(Fn);return n===void 0?e.cause.reasons.find(on)===void 0?{_tag:`Cause`,cause:e.cause,snapshot:e}:{_tag:`Interrupted`,cause:e.cause,snapshot:e}:{_tag:`Defect`,defect:n.defect,cause:e.cause,snapshot:e}}case`stopped`:return{_tag:`Stopped`,snapshot:e}}},Dg=(e,t)=>br(()=>e(t)).pipe(be,On),Og=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=G(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return G(()=>new n)},kg=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Ag=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&lg(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,jg=(e,t,n,r,i,a)=>{let o=e.nextDeliveryId(),s=e.nextMacrostepId(),c={deliveryId:o,macrostepId:s,source:r,event:n,causedBy:i,complete:i=>{let a=ng(i.plan);e.publishUnsafe({_tag:`EventProcessed`,subject:t,macrostepId:s,deliveryId:o,source:r,event:n,before:{status:`active`,state:i.before},after:{status:`active`,state:i.after},handled:a.some(e=>e.transitions.length>0),configurationChanged:a.some(e=>e.changed),microsteps:a})}};return{[cg]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},Mg=(e,t,n)=>{if(!lg(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:eg(t),event:r.event,causedBy:r.causedBy})},Ng=class{registry;self;runtime;services;sendAcknowledged;scopedServices;constructor(e,t,n,r,i){this.registry=e,this.self=t,this.runtime=n,this.services=r,this.sendAcknowledged=i}has(e){for(let t of this.registry.children.values())if(t.ownerActive&&t.ownerKey===e)return!0;return!1}stopEntry(e){return e.ownerActive=!1,e._tag===`Started`?e.ref.stop:W}spawn(e,t){let n=Symbol(),r,i=()=>{let e=this.registry.children.get(t.id);return e?.token===n&&e.ownerKey===t.key&&e.ownerActive===!0};return br(()=>{if(this.registry.closed)return he;if(this.has(t.key)||this.registry.children.has(t.id))return H(new Qu({id:t.duplicateId}));let a=e(),o=this.registry.scope??=ee(`parallel`);this.registry.children.set(t.id,{_tag:`Starting`,token:n,ownerKey:t.key,ownerPath:t.path,ownerActive:!0});let s={...this.self,send:e=>t.sendParent(i,e),sendInspected:(e,t,n)=>i()?hg(this.self,e,t,n):W,...this.sendAcknowledged===void 0?void 0:{[sg]:e=>i()?this.sendAcknowledged(e):he}},c={detached:!0,id:t.id,sendParent:e=>t.sendParent(i,e),onOutcome:e=>t.onOutcome(i,e,r?.sessionId),...t.onSnapshot===void 0?void 0:{onSnapshot:e=>t.onSnapshot(i,e)},onReadySync:e=>(r=e,Qh(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>Zh(this.registry,t.id,n),skipStoppedOutcome:!0,parent:s,runtime:this.runtime,origin:{_tag:`Invoke`,ownerPath:t.path,invokeId:t.duplicateId},...t.activityKind===void 0||this.runtime.inspection===void 0||this.self.inspectionSubject===void 0?void 0:{activity:{id:t.duplicateId,owner:this.self.inspectionSubject,ownerPath:t.path,kind:t.activityKind}}},l=a.execution,u=this.services!==void 0&&t.onSnapshot===void 0&&l?._tag===`Compiled`&&l.childless&&l.drain._tag===`Owned`&&l.initialSync!==void 0,d=(u?_(this.runtime.nextSessionId,e=>this.runtime.startCompiledSync(a,c,this.scopedServices??=Ye(this.services,ie,o),e)):this.runtime.start(a,c)).pipe(He(e=>It(e)?W:(Zh(this.registry,t.id,n),r===void 0?W:r.stop)));return(u?d:ge(d,o)).pipe(On)})}stopAll(){return br(()=>{let e=[];for(let t of this.registry.children.values())t.ownerActive&&e.push(this.stopEntry(t));return e.length===0?W:e.length===1?e[0]:O(e,{concurrency:`unbounded`,discard:!0})})}stopPaths(e){if(e.length===0)return;let t=new Set(e),n=[];for(let e of this.registry.children.values())e.ownerActive&&e.ownerPath!==void 0&&t.has(e.ownerPath)&&n.push(this.stopEntry(e));return n.length===0?void 0:n.length===1?n[0]:O(n,{concurrency:`unbounded`,discard:!0})}},Pg=Yn(pt()).pipe(mr(Mn)),Fg=e=>W,Ig=(e,t)=>{},Lg=()=>void 0,Rg=Symbol(`effect/Machine/EmissionsClosed`),zg=()=>{let e,t=br(()=>{let t=e;return t===Rg?Nn(void 0):t===void 0?x().pipe(_(t=>G(()=>{let n=e;return n===Rg?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(_(([e,n])=>n?Ht(t).pipe(Pe(e)):Nn(e))))):Nn(t)});return{emit:t=>br(()=>e===void 0||e===Rg?W:Sr(e,t).pipe(On)),close:()=>{let t=e;return e=Rg,t===void 0||t===Rg?W:Ht(t)},stream:In(t.pipe(ue(e=>e===void 0?Vn:Kn(e))))}},Bg={close:()=>W,spawn:(()=>N(Error(`Childless machine logic cannot spawn a process`))),get:()=>Nn(pt()),changes:()=>Pg,sendTo:()=>W,stop:()=>W,owned:{spawn:()=>N(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>W,stopPaths:()=>void 0}},Vg=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>br(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return W;let t=ht(i.scope,e),n,r;for(let e of i.children.values())e._tag===`Started`&&(n===void 0?n=e.ref.stop:(r??=[n],r.push(e.ref.stop)));t!==void 0&&(n===void 0?n=t:(r??=[n],r.push(t)));let a=r??n;return a===void 0?W:Array.isArray(a)?O(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>G(()=>Zh(i,e,t)),s=(e,t,n,r)=>G(()=>Qh(i,e,t,n,r)),c=e=>{let t=typeof e==`string`?e:e.id;return G(()=>{if(i.closed)return pt();let n=i.children.get(t);return n!==void 0&&Jh(n,e)?me(n.ref):pt()})},l=e=>{let t=typeof e==`string`?e:e.id;return Lt(Mt((n,r)=>G(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(_(n=>{let a=G(()=>{i.observers!==void 0&&(i.observers.delete(n),i.observers.size===0&&(i.observers=void 0)),n.values=void 0,n.waiter=void 0});return st(r,a).pipe(T(G(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),Kh(n,Yh(i,t,e))})),Pe(qh(n)))}))))},u=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return br(()=>{if(i.closed)return W;let o=i.children.get(a);return o!==void 0&&Jh(o,e)?hg(o.ref,t,n,r):W})},d=e=>{let t=typeof e==`string`?e:e.id;return br(()=>{if(i.closed)return W;let n=i.children.get(t);return n!==void 0&&Jh(n,e)?n.ref.stop:W})};function f(n,r){let a=typeof n==`object`&&n&&qp in n?n:void 0,c=a===void 0?n:a[qp](r?.input),l=a===void 0?r:{id:a.id,descriptor:a},u=Symbol(),d=l?.id??u,f;return br(()=>i.closed?he:typeof d==`string`&&(i.children.has(d)||Gh(d))?H(new Qu({id:d})):(i.scope??=ee(`parallel`),i.children.set(d,{_tag:`Starting`,token:u}),t.start(c,{detached:!0,...l?.id===void 0?void 0:{id:l.id},...l?.onOutcome===void 0?void 0:{onOutcome:l.onOutcome},...l?.[rg]===void 0?void 0:{onSnapshot:l[rg]},...l?.[og]===void 0?void 0:{sendParent:l[og]},onReady:(e,t)=>G(()=>{f=e}).pipe(T(s(d,u,e,l?.descriptor)),_(e=>e?W:t)),onStop:o(d,u),parent:e,runtime:t,origin:{_tag:`Spawn`,address:l?.id}}).pipe(He(e=>_n(e)?o(d,u).pipe(T(f===void 0?W:f.stop)):W),ge(i.scope))))}return{close:a,spawn:f,get:c,changes:l,sendTo:u,stop:d,owned:new Ng(i,e,t,n,r)}},Hg=(e,t,n,r)=>G(()=>Vg(e,t,n,r)),Ug=(e,t)=>`${e.length}:${e}${t}`,Wg=(e,t)=>`${Wh}${Ug(e,t)}`,Gg=e=>({initial:()=>W,run:()=>e}),Kg=(e,t,n)=>({initial:()=>W,run:({parent:r})=>{let i=r?.[sg];return i===void 0?N(Error(`Stream invocation requires an acknowledged parent machine`)):nn(e,e=>i(mm(t,n,e)).pipe(On,we(()=>he)))}}),qg=(e,t)=>typeof e==`function`?e(t):e,Jg=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),Yg=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Gg(e.effect(t)),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot,activityKind:`Effect`};if(`after`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Gg(Kt(qg(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>Kg(e.stream(t),n,r),onDone:e.onDone,onFailure:e.onFailure,activityKind:`Stream`}}if(`logic`in e)return{id:String(e.id),address:String(e.address),src:()=>qg(e.logic,t),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot};if(`child`in e){let n=e.child;return{id:n.id,address:n.id,descriptor:n,src:()=>n[qp](`input`in e?qg(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},Xg=e=>e.length===0?W:e.length===1?e[0]:O(e,{discard:!0}),Zg=(e,t,n)=>(n===void 0||e.self.sendInspected===void 0?e.self.send(t):e.self.sendInspected(t,e.self.inspectionSubject,{_tag:`Activity`,activitySessionId:n})).pipe(ke(`StoppedError`,()=>W)),Qg=e=>e instanceof Xu||e instanceof Yu||e instanceof $u,$g=(e,t,n,r,i,a,o,s,c,l,u,d)=>br(()=>{let f=Ug(n,r),p=u===void 0?o:()=>{let t=o();return{...t,run:i=>Lr(br(()=>t.run(i)),`Machine.invoke`,{attributes:{"machine.id":e.self.id,"machine.sessionId":e.self.sessionId,"machine.state.path":n,"machine.invoke.id":r,"machine.invoke.source":d??r,"machine.invoke.kind":u,"machine.invoke.sessionId":i.self.sessionId},captureStackTrace:!1})}};return t.spawn(p,{key:f,path:n,id:i,duplicateId:r,...a===void 0?void 0:{descriptor:a},...u===void 0?void 0:{activityKind:u},sendParent:(t,n)=>t()?e.self.send(n):W,onOutcome:(t,i,o)=>T(Ut,br(()=>i._tag===`Stopped`||!t()?W:i._tag===`Done`?s===void 0?e.failCause(jn(Error(`Invocation "${r}" completed without the required onDone handler`))):Zg(e,pm(n,r,i.output),u===void 0?void 0:o):i._tag===`Failure`&&c!==void 0&&(a===void 0||!Qg(i.error))?Zg(e,hm(n,r,i.error),u===void 0?void 0:o):e.failCause(i.cause))),...l===void 0?void 0:{onSnapshot:(t,i)=>t()?Zg(e,gm(n,r,i)):W}})}),e_=(e,t)=>Gh(e)?H(new Qu({id:t})):void 0,t_=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:e_(String(r.address),i);return a===void 0?$g(e,t,n,i,r.address===void 0?Wg(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},n_=(e,t,n,r)=>{let i=r.child,a=e_(i.id,i.id);return a===void 0?$g(e,t,n,i.id,i.id,i,i[qp],r.onDone,r.onFailure,r.onSnapshot,void 0):a},r_=(e,t,n,r,i,a)=>{let o=Jg(t),s=zm(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...Bf(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:ep(e,r,i),ancestors:$f(e,r,i),event:a};return im(bp(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?n_(t,n,i,e):t_(t,n,i,Yg(e,s,i)))});return s.length===0?void 0:Xg(s)},i_=Symbol(`effect/Machine/CompiledStoppedCompletion`),a_=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[sg](e){return this.sendAcknowledgedEffect(e)}[ig](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=Bg;processScope;processContext;compiledContext;current;lifecycle=`Active`;runState=`Initializing`;completion;waiter;termination;terminationSnapshot;worker;interruptRequested=!1;offerRevision=0;snapshotObservers;changesFlushScheduled=!1;inFlightMessage;externalEmissions;emissionsPubSub;activity;initialEntryPaths;initialMicrosteps;initializing;constructor(e,t,n,r){this.logic=e,this.options=t,this.services=n,this.sessionId=r,this.id=t.id??r;let i=t.runtime.inspection;i!==void 0&&(this.inspectionSubject=kg(e,this.id,r),this.initializing=!0,t.activity!==void 0&&(this.activity={...t.activity,sessionId:r})),this.externalEmissions=t.emissions,this.send=i===void 0?e=>this.offerMessage(e):e=>this.offerEvent(e,void 0,void 0),this.address={id:this.id,sessionId:r,stop:br(()=>this.stopFromProcess()),send:this.send,...i===void 0?void 0:{inspectionSubject:this.inspectionSubject,sendInspected:(e,t,n)=>this.offerEvent(e,t,n)}}}get inspector(){return this.options.runtime.inspection}causation(){return Ag(this.inFlightMessage,this.initializing===!0)}publishCreated(){let e=this.inspector,t=this.inspectionSubject;e!==void 0&&t!==void 0&&e.publishUnsafe(this.activity===void 0?{_tag:`Created`,subject:t,parent:this.options.parent?.inspectionSubject,origin:this.options.origin??{_tag:`Root`},definition:this.logic.inspection?.definition}:{_tag:`ActivityStarted`,subject:this.activity.owner,activity:this.activity})}publishInitialized(e){if(this.initializing=!1,this.activity!==void 0)return;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe({_tag:`Initialized`,subject:n,snapshot:{status:`active`,state:e},initialEntryPaths:this.initialEntryPaths??[],microsteps:ng({microsteps:this.initialMicrosteps??[]})})}publishStartFailed(e){this.initializing=!1;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe(this.activity===void 0?{_tag:`StartFailed`,subject:n,cause:e}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:Bn(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=Vg(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?Fg:this.inspector===void 0?e.send:t=>hg(e,t,this.inspectionSubject,this.causation()));this.processScope={self:this.address,parent:e,spawn:this.childRuntime.spawn,sendParent:t,emit:e=>this.emitEvent(e),sendTo:((e,t)=>mg(e)?this.inspector===void 0?e.send(t):hg(e,t,this.inspectionSubject,this.causation()):this.childRuntime.sendTo(e,t,this.inspectionSubject,this.causation())),stopChild:this.childRuntime.stop,failCause:e=>this.failCause(e),inspectInitial:this.inspector===void 0?Ig:(e,t=[])=>{this.initialEntryPaths=e,this.initialMicrosteps=t}};let n=this.execution.initialSync,r;try{r=n(this.processScope)}catch(e){return this.runState=`Idle`,this.publishStartFailed(vr(e)),H(e)}return this.runState=`Idle`,this.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:r.state}},this.publishInitialized(r.state),this.compiledContext=new o_(this.processScope,this.childRuntime.owned,this),`executionState`in r&&(this.compiledContext.executionState=r.executionState),this.options.onReadySync!==void 0&&!this.options.onReadySync(this)&&this.requestTerminationSync({_tag:`Stopped`}),r.done===!0&&this.lifecycle===`Active`&&this.requestTerminationSync({_tag:`Done`,output:r.output}),r.done===!1&&this.execution.childless&&this.lifecycle===`Active`&&this.mailbox.items===void 0?Nn(this):(this.runState=`Draining`,c(this.drainRuntime(),this.services).pipe(Pe(this)))}initialize(){let e=this;return R(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*Hg(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?Fg:e.inspector===void 0?t.send:n=>hg(t,n,e.inspectionSubject,e.causation()));e.processScope={self:e.address,parent:t,spawn:e.childRuntime.spawn,sendParent:n,emit:t=>e.emitEvent(t),sendTo:((t,n)=>mg(t)?e.inspector===void 0?t.send(n):hg(t,n,e.inspectionSubject,e.causation()):e.childRuntime.sendTo(t,n,e.inspectionSubject,e.causation())),stopChild:e.childRuntime.stop,failCause:t=>e.failCause(t),inspectInitial:e.inspector===void 0?Ig:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>_n(t)?e.childRuntime.close(t):W,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(ue(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(He(t=>(_n(t)&&e.publishStartFailed(t.cause),r(t))),se(G(()=>{e.runState=`Idle`}))),o=a.state;return e.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:o}},e.publishInitialized(o),e.execution.drain._tag===`Process`?e.processContext={...e.processScope,receive:Ot,poll:G(()=>z(vg(e.mailbox),ug)),receiveMessage:Ot,pollMessage:G(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:G(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new o_(e.processScope,e.childRuntime.owned,e),`executionState`in a&&(e.compiledContext.executionState=a.executionState)),e.options.onReadySync!==void 0&&!e.options.onReadySync(e)?yield*e.requestTermination({_tag:`Stopped`}):e.options.onReady!==void 0&&(yield*e.options.onReady(e,e.requestTermination({_tag:`Stopped`}).pipe(On))),e.options.onSnapshot!==void 0&&(yield*Dg(e.options.onSnapshot,{status:`active`,state:o})),a.done===!0&&e.lifecycle===`Active`&&(yield*e.requestTermination({_tag:`Done`,output:a.output})),a.done===!1&&e.execution.childless&&e.lifecycle===`Active`&&e.mailbox.items===void 0||(e.runState=`Draining`,yield*e.drainRuntime()),e})}get state(){return G(()=>this.current.snapshot.state)}get snapshot(){return G(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return br(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=l(),tr(this.waiter)))}get stop(){return pn(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return G(()=>this.requestTerminationSync(e))}hasTerminationRequest(){return this.lifecycle===`TerminationRequested`}requestTerminationSync(e){return this.lifecycle===`Active`&&(this.lifecycle=`TerminationRequested`,this.termination=e,this.terminationSnapshot=this.reserveTermination(e),!0)}reserveTermination(e){let t=this.current;if(t===void 0||t.terminalizing||t.snapshot.status!==`active`)return;let n=e._tag===`Stopped`?{status:`stopped`,state:t.snapshot.state}:e._tag===`Done`?{status:`done`,state:t.snapshot.state,output:e.output}:{status:`error`,state:t.snapshot.state,cause:e.cause};return this.current={...t,terminalizing:!0},n}stopFromProcess(){let e=this.requestTermination({_tag:`Stopped`}).pipe(On);return this.runState===`Initializing`?e:e.pipe(T(he))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(_(e=>e?mt(this.settleRequestedTermination()).pipe(On):W))}sendAcknowledgedEffect(e){return cn(t=>Ue().pipe(_(n=>this.offerEvent(e,void 0,void 0,n).pipe(T(t(tr(n)))))))}offerEvent(e,t,n,r){return br(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?jg(i,a,e,t,n,r):r===void 0?e:{[cg]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return pn(Cr(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return H(new $u);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&Mg(n,r,e),this.offerRevision+=1;let i=this.execution.drain,a=this.compiledContext,o=this.runState===`Idle`&&a!==void 0&&i._tag===`Owned`?i.runSync:void 0;if(o===void 0&&_g(this.mailbox,e),this.runState!==`Idle`)return W;if(this.runState=`Draining`,o!==void 0){let n;try{n=o(a,e)}catch(e){n=N(e)}return n!==void 0||this.hasTerminationRequest()?this.startWorker(n):(this.runState=`Idle`,this.scheduleChangesFlush(t.currentDispatcher),W)}return this.startWorker(void 0)}))}startWorker(e){let t=c(this.drainRuntime(e),this.services);return(this.options.detached===!0?mt(t,{startImmediately:!0}):ot(t,{startImmediately:!0})).pipe(_(e=>G(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(_(t=>t?mt(this.interruptAndFinish(e)):W))),On)}stopEffect(){return br(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?W:this.requestTermination({_tag:`Stopped`}).pipe(_(e=>e?this.settleRequestedTermination():this.awaitCompletion())))}finishIdleChildlessStop(){if(!this.execution.childless||this.runState!==`Idle`||this.worker!==void 0||this.lifecycle!==`Active`||this.options.onOutcome!==void 0&&this.options.skipStoppedOutcome!==!0||this.options.onStop!==void 0||this.inspector!==void 0||this.current.changes!==void 0||this.externalEmissions!==void 0||this.emissionsPubSub!==void 0&&this.emissionsPubSub!==Rg||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=Rg;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,yg(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),pg(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=i_,this.lifecycle=`Completed`,this.waiter!==void 0&&(wt(this.waiter,this.resolveCompletion(i_)),this.waiter=void 0),!0}settleRequestedTermination(){return br(()=>this.runState===`Draining`?this.worker===void 0?(this.interruptRequested=!0,this.awaitCompletion()):this.interruptAndFinish(this.worker).pipe(T(this.awaitCompletion())):this.finishRequestedTermination())}interruptAndFinish(e){return Er(e).pipe(T(br(()=>this.lifecycle===`Completed`?W:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?W:this.join.pipe(be,On)}resolveCompletion(e){if(e!==i_)return e;let t=H(new $u);return this.completion=t,t}drainRuntime(e){let t=this;return cn(n=>R(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(br(()=>{if(i!==void 0){let e=i;return i=void 0,e}let e=t.execution.drain;return e._tag===`Process`?e.run(t.processContext):e.run(t.compiledContext)})).pipe(be);if(t.flushPendingChanges(),_n(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(lt(e.value))return yield*t.requestTermination({_tag:`Done`,output:e.value.value}),yield*t.finishRequestedTermination();if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();if(t.offerRevision!==r)r=t.offerRevision;else{t.runState=`Idle`,t.worker=void 0;return}}}))}finishRequestedTermination(){return br(()=>{if(this.lifecycle!==`TerminationRequested`)return W;let e=this.termination;if(e===void 0)return W;let t=this.terminationSnapshot??this.reserveTermination(e);if(t===void 0)return this.awaitCompletion();let n=e._tag===`Stopped`?cr:e._tag===`Done`?Gn(e.output):Bn(e.cause),r=e._tag===`Stopped`?i_:e._tag===`Done`?Nn(e.output):Br(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?W:br(()=>this.options.onOutcome(Eg(t))).pipe(be,On),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(T(G(()=>a.publishUnsafe(this.activity===void 0?{_tag:`Terminated`,subject:o,snapshot:t}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:t.status===`stopped`?ir():n}))));return pn(G(()=>{yg(this.mailbox)}).pipe(T(this.childRuntime.close(n)),T(this.setAndPublishSnapshot(t)),T(s),T(G(()=>{e._tag===`Failure`?fg(this.inFlightMessage,e.cause):pg(this.inFlightMessage),this.inFlightMessage=void 0})),T(i),T(this.options.onStop??W),T(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:W),T(G(()=>{this.options.onStopSync?.(this),this.runState=`Idle`,this.worker=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.completion=r,this.lifecycle=`Completed`,this.waiter!==void 0&&(wt(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?Nn(e):Sr(e.changes,[e]).pipe(Pe(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe(rn(()=>Dg(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?W:Sr(e.changes,Gn(void 0)).pipe(On)}emitEvent(e){let t=this.externalEmissions===void 0?br(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===Rg?W:Sr(this.emissionsPubSub,e).pipe(On)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe(rn(()=>G(()=>n.publishUnsafe({_tag:`Emitted`,subject:r,emission:e,causedBy:this.causation()}))))}shutdownEmissions(){return this.closeEmissions()}closeEmissions(){if(this.externalEmissions!==void 0)return this.externalEmissions.close();let e=this.emissionsPubSub;return this.emissionsPubSub=Rg,e===void 0||e===Rg?W:Ht(e)}getOrCreateEmissions(){return br(()=>{let e=this.emissionsPubSub;return e===Rg?Nn(void 0):e===void 0?x().pipe(_(e=>G(()=>{let t=this.emissionsPubSub;return t===Rg?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(_(([t,n])=>n?Ht(e).pipe(Pe(t)):Nn(t))))):Nn(e)})}emissionsStream(){return In(this.getOrCreateEmissions().pipe(ue(e=>e===void 0?Vn:Kn(e))))}setAndPublishSnapshot(e){return br(()=>{this.flushPendingChanges();let t={revision:this.current.revision+1,snapshot:e,terminalizing:!0,changes:this.current.changes};return this.current=t,this.notifySnapshotObservers(),this.publishSnapshot(t).pipe(_(e=>this.completeChanges(e)),On)})}setActiveState(e){return br(()=>this.commitActiveState(e)??W)}pollCompiledMessage(){let e=vg(this.mailbox);return lt(e)&&(this.inFlightMessage=lg(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=lg(e)?e:void 0}completeCompiledMessage(e){dg(this.inFlightMessage,e),this.inFlightMessage=void 0}compiledState(){return this.current.snapshot.state}commitCompiledState(e){return this.commitActiveState(e,!0)}commitActiveState(e,t=!1){let n=this.current;if(n.terminalizing||n.snapshot.status!==`active`)return;let r=n.pendingChanges;r!==void 0&&(n.pendingChanges=void 0);let i={status:`active`,state:e},a={revision:n.revision+1,snapshot:i,terminalizing:!1,changes:n.changes};return this.current=a,a.changes!==void 0&&(r===void 0?t?a.pendingChanges=[a]:Ir(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:Ir(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:Dg(this.options.onSnapshot,i)}notifySnapshotObservers(){if(this.snapshotObservers!==void 0)for(let e of this.snapshotObservers)e()}scheduleChangesFlush(e){this.changesFlushScheduled||this.current.pendingChanges===void 0||(this.changesFlushScheduled=!0,e.scheduleTask(()=>{this.changesFlushScheduled=!1,this.flushPendingChanges()},0))}flushPendingChanges(){let e=this.current,t=e?.pendingChanges;t!==void 0&&e.changes!==void 0&&(e.pendingChanges=void 0,Ir(e.changes,t))}updateState(e){return br(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?W:e(t.snapshot.state).pipe(_(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?W:this.setActiveState(e)}))})}getOrCreateChanges(){return br(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?x({replay:1}).pipe(_(e=>G(()=>{let t=this.current;return t.snapshot.status===`active`?t.changes===void 0?(this.current={...t,changes:e},[e,!1]):[t.changes,!0]:[void 0,!0]}).pipe(_(([t,n])=>n?Ht(e).pipe(Pe(t)):Nn(t))))):Nn(e.changes):Nn(void 0)})}changesStream(){let e=this;return In(R(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return Yn(e.current.snapshot);let n=yield*jr(t),r=e.current;return r.snapshot.status===`active`?Yn(r.snapshot).pipe(mr(Lt(sn(Xe(n))).pipe(vn(e=>e.revision>r.revision),Gt(e=>e.snapshot)))):Yn(r.snapshot)}))}},o_=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return z(this.process.pollCompiledMessage(),ug)}pollMessage(){return this.process.pollCompiledMessage()}beginMessage(e){this.process.beginCompiledMessage(e)}state(){return this.process.compiledState()}completeMessage(e){this.process.completeCompiledMessage(e)}commit(e){return this.process.commitCompiledState(e)}runAfterChanges(e){return this.process.flushPendingChanges(),e}},s_=ut(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*Re(),i=e.execution,a=new a_(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(He(e=>_n(e)?a.shutdownEmissions().pipe(T(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:W)):W))}),c_=(e,t,n,r)=>new a_(e,t,n,r).initializeCompiledSync(),l_=ut(function*(e,t){let{detached:n,id:r,onOutcome:i,onReady:a,onReadySync:o,onSnapshot:s,onStop:c,onStopSync:l,parent:u,runtime:d,sendParent:f}=t,p=t.sessionId??(yield*d.nextSessionId),m=r??p,h=d.inspection,v=h===void 0?void 0:kg(e,m,p),y=h===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:p},b,S,C=bg(),w=t.emissions??zg(),E=yield*Ue(),D=yield*Ue(),O=tr(D).pipe(be,On),k=!0,A,j=pr(E,{_tag:`Stopped`}).pipe(On),M=(e,t)=>br(()=>xg(C,e,t)?W:H(new $u)),N=h===void 0?void 0:(e,t,n,r)=>br(()=>{let i=h.isActive()?jg(h,v,e,t,n,r):r===void 0?e:{[cg]:!0,event:e,deferred:r};return M(i,()=>Mg(h,v,i))}),P=e.execution?._tag===`Compiled`?e=>cn(t=>Ue().pipe(_(n=>(h===void 0?M({[cg]:!0,event:e,deferred:n}):N(e,void 0,void 0,n)).pipe(T(t(tr(n))))),ue(e=>e))):void 0,F={id:m,sessionId:p,stop:br(()=>k?j:j.pipe(T(Ot))),send:h===void 0?e=>M(e):e=>N(e,void 0,void 0),...h===void 0?void 0:{inspectionSubject:v,sendInspected:N}},{changes:I,close:L,get:ee,owned:te,sendTo:ne,spawn:re,stop:ie}=Bg;gg(e.execution)||({changes:I,close:L,get:ee,owned:te,sendTo:ne,spawn:re,stop:ie}=yield*Hg(F,d,void 0,P===void 0?void 0:e=>P(e)));let B=e=>It(e)?W:(h!==void 0&&h.publishUnsafe(y===void 0?{_tag:`StartFailed`,subject:v,cause:e.cause}:{_tag:`ActivityStopped`,subject:y.owner,activity:y,exit:e}),L(e).pipe(T(w.close()),T(t.inspectionRoot===!0&&h!==void 0?h.close:W))),ae=l===void 0?c??W:G(()=>l(ze)),oe=h===void 0?Lg:()=>Ag(A,k),ce=f??(u===void 0?Fg:h===void 0?u.send:e=>hg(u,e,v,oe())),le=h===void 0?w.emit:e=>w.emit(e).pipe(rn(()=>G(()=>h.publishUnsafe({_tag:`Emitted`,subject:v,emission:e,causedBy:oe()})))),de={self:F,parent:u,spawn:re,sendParent:ce,emit:le,sendTo:h===void 0?((e,t)=>mg(e)?e.send(t):ne(e,t)):((e,t)=>mg(e)?hg(e,t,v,oe()):ne(e,t,v,oe())),stopChild:ie,failCause:e=>pr(E,{_tag:`Failure`,cause:e}).pipe(On),inspectInitial:h===void 0?Ig:(e,t=[])=>{b=e,S=t}};h!==void 0&&h.publishUnsafe(y===void 0?{_tag:`Created`,subject:v,parent:u?.inspectionSubject,origin:t.origin??{_tag:`Root`},definition:e.inspection?.definition}:{_tag:`ActivityStarted`,subject:y.owner,activity:y});let fe=yield*e.initial(de).pipe(He(B),se(G(()=>{k=!1}))),pe=yield*zn({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:fe}});y===void 0&&h?.publishUnsafe({_tag:`Initialized`,subject:v,snapshot:{status:`active`,state:fe},initialEntryPaths:b??[],microsteps:ng({microsteps:S??[]})});let me=s===void 0?e=>e.changes===void 0?Nn(e):Sr(e.changes,[e]).pipe(Pe(e)):e=>{let t=e.changes===void 0?Nn(e):Sr(e.changes,[e]).pipe(Pe(e)),n=e.snapshot;return n.status===`active`?t.pipe(rn(()=>Dg(s,n))):t},he=e=>e.changes===void 0?W:Sr(e.changes,Gn(void 0)).pipe(On),ge=e=>e.snapshot.status===`active`?Nn(e):he(e).pipe(Pe(e)),_e=e=>fr(pe).pipe(_(t=>t.revision===e.revision?me(e).pipe(_(ge)):Nn(void 0))),ve=e=>hn(pe,t=>t.terminalizing?Nn([void 0,t]):ue(e(t.snapshot),e=>{if(e===void 0)return[void 0,t];let n={revision:t.revision+1,snapshot:e,terminalizing:!1,changes:t.changes};return[n,n]})).pipe(_(e=>e===void 0?Nn(void 0):_e(e)),ue(e=>e?.snapshot)),ye=e=>rr(pe,t=>t.terminalizing||t.snapshot.status!==`active`?[void 0,t]:[{revision:t.revision+1,snapshot:e(t.snapshot),terminalizing:!0,changes:t.changes},{...t,terminalizing:!0}]).pipe(ue(e=>e?.snapshot)),xe=e=>Pt(pe,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(_(me),_(ge),On),Se=h===void 0?e=>ve(t=>Nn(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(On):t=>fr(pe).pipe(_(n=>ve(e=>Nn(e.status===`active`?{status:`active`,state:t}:void 0)).pipe(rn(r=>G(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&h.publishUnsafe({_tag:`StateChanged`,subject:v,before:n.snapshot.state,after:t,causedByDeliveryId:A!==void 0&&lg(A)?A.inspection?.deliveryId:void 0})})))),On),Ce=(e,n,r)=>{let a=i===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?W:br(()=>i(Eg(e))).pipe(be,On),o=h===void 0?w.close():w.close().pipe(T(G(()=>h.publishUnsafe(y===void 0?{_tag:`Terminated`,subject:v,snapshot:e}:{_tag:`ActivityStopped`,subject:y.owner,activity:y,exit:e.status===`stopped`?ir():n}))));return pn(G(()=>Cg(C)).pipe(T(L(n)),T(xe(e)),T(o),T(G(()=>{_n(n)?fg(A,n.cause):pg(A),A=void 0})),T(a),T(ae),T(t.inspectionRoot===!0&&h!==void 0?h.close:W),T(r)))},we=ye(e=>({status:`stopped`,state:e.state})),Te=e=>ye(t=>({status:`error`,state:t.state,cause:e})),Ee=e=>ye(t=>({status:`done`,state:t.state,output:e})),De=e=>Ce(e,cr,bt(D,new $u)),Oe=(e,t)=>{let n=Bn(t);return Ce(e,n,kt(D,t))},ke=(e,t)=>{let n=Gn(t);return Ce(e,n,pr(D,t))},Ae=pn(j.pipe(T(O))),je=e.execution?._tag===`Compiled`?{receiveMessage:Sg(C).pipe(rn(e=>G(()=>{A=lg(e)?e:void 0}))),pollMessage:G(()=>vg(C)).pipe(rn(e=>G(()=>{lt(e)&&(A=lg(e.value)?e.value:void 0)}))),completeMessage:e=>{dg(A,e),A=void 0}}:void 0,Me=h===void 0||e.execution?._tag===`Compiled`?Sg(C).pipe(ue(ug)):Sg(C).pipe(rn(e=>G(()=>{A=e})),ue(ug)),Ne=h===void 0||e.execution?._tag===`Compiled`?G(()=>vg(C)).pipe(ue(z(ug))):G(()=>vg(C)).pipe(rn(e=>G(()=>{lt(e)&&(A=e.value)})),ue(z(ug))),Fe=h===void 0?e=>ve(t=>t.status===`active`?e(t.state).pipe(ue(e=>({status:`active`,state:e}))):Nn(void 0)).pipe(On):t=>fr(pe).pipe(_(n=>ve(e=>e.status===`active`?t(e.state).pipe(ue(e=>({status:`active`,state:e}))):Nn(void 0)).pipe(rn(t=>G(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&h.publishUnsafe({_tag:`StateChanged`,subject:v,before:n.snapshot.state,after:t.state,causedByDeliveryId:A!==void 0&&lg(A)?A.inspection?.deliveryId:void 0})})))),On),Ie={...de,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:te}:void 0,...je,receive:Me,poll:Ne,state:fr(pe).pipe(ue(e=>e.snapshot.state)),setState:Se,updateState:Fe},Le=hn(pe,e=>e.snapshot.status===`active`?e.changes===void 0?x({replay:1}).pipe(ue(t=>[t,{...e,changes:t}])):Nn([e.changes,e]):Nn([void 0,e])),Re=In(R(function*(){let e=yield*Le;if(e===void 0)return Yn((yield*fr(pe)).snapshot);let t=yield*jr(e),n=yield*fr(pe);return n.snapshot.status===`active`?Yn(n.snapshot).pipe(mr(Lt(sn(Xe(t))).pipe(vn(e=>e.revision>n.revision),Gt(e=>e.snapshot)))):Yn(n.snapshot)})),ze={id:m,sessionId:p,...h===void 0?void 0:{inspectionSubject:v,sendInspected:N},state:fr(pe).pipe(ue(e=>e.snapshot.state)),snapshot:fr(pe).pipe(ue(e=>e.snapshot)),changes:Re,emissions:w.stream,join:tr(D),stop:Ae,send:F.send,...P===void 0?void 0:{[sg]:P},child:ee,childChanges:I};o!==void 0&&!o(ze)?yield*j:a!==void 0&&(yield*a(ze,j)),s!==void 0&&(yield*Dg(s,{status:`active`,state:fe}));let Be=e=>{switch(e._tag){case`Stopped`:return we;case`Done`:return Ee(e.output);case`Failure`:return Te(e.cause)}},Ve=(e,t)=>{switch(e._tag){case`Stopped`:return De(t);case`Done`:return ke(t,e.output);case`Failure`:return Oe(t,e.cause)}},V=e=>n===!0?mt(e,{startImmediately:!0}):ot(e,{startImmediately:!0}),We=yield*Zt(E),Ge=g(We)?yield*cn(t=>t(br(()=>e.run(Ie))).pipe(be,_(e=>pr(E,_n(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(V):void 0;return yield*V(cn(e=>R(function*(){let t=lt(We)?yield*We.value:yield*e(tr(E)),n=yield*Be(t);return Ge!==void 0&&(yield*Er(Ge)),n===void 0?yield*O:yield*Ve(t,n)}))),ze}),u_=((e,t)=>e.execution?._tag===`Compiled`?s_(e,t):l_(e,t)),d_=Og(u_,c_),f_=new WeakMap,p_=e=>br(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),re(t,e=>e.stop,{discard:!0})}),m_=()=>{let e=new Set,t={live:e,hooks:{onReadySync:n=>!t.closed&&(e.add(n),!0),onStopSync:t=>{e.delete(t)}},closed:!1};return t},h_=e=>_(qn,t=>{let n=f_.get(t);if(n!==void 0)return e(n.hooks);let r=m_();return f_.set(t,r),T(st(t,p_(r)),e(r.hooks))});ut(function*(e,t,n){let r=yield*d_,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*h_(t=>l_(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*h_(t=>s_(e,{...i,...t})):yield*N(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*h_(t=>u_(e,{...i,...t}))});var g_=ut(function*(e,t){let n=yield*d_;return yield*h_(r=>u_(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),__=ut(function*(e,t,n){let r=yield*d_,i=yield*r.nextSessionId,a=yield*$h(i);r.inspection=a;let o=zg(),s=yield*Ue(),c=n===void 0?{detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}}:{...n,detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}},l=yield*p(h_(n=>{let r={...c,...n};return t===`generic`?l_(e,r):t===`compiled`?e.execution?._tag===`Compiled`?s_(e,r):N(Error(`Machine cannot force the compiled runtime for generic process logic`)):u_(e,r)}).pipe(He(e=>de(s,e))));return{id:n?.id??i,sessionId:i,changes:In(tr(s).pipe(ue(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),v_=((e,t)=>__(e,`auto`,t));wr({_tag:an(`MachineSnapshot`),version:an(2),active:Jn(wr({path:Nt,value:xe(Xt)})),completed:xe(Jn(wr({path:Nt,output:xe(Xt)}))),history:xe(mn(Nt,wr({mode:Zn([`shallow`,`deep`]),active:Jn(Nt),values:mn(Nt,Xt)})))});var y_=(e,t,n)=>{let r=Q(e,n);if(r.type===`compound`){let r=xp(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return y_(e,t,r)}return r.output},b_=(e,t)=>R(function*(){let n=yield*fp(e,t),r=new Map,i=new Set,a=t.completed??[];if(!Array.isArray(a))throw Error(`Machine snapshot completion metadata must be an array`);for(let t of a){if(typeof t!=`object`||!t||typeof t.path!=`string`)throw Error(`Machine snapshot contains malformed completion metadata`);let a=t.path;if(i.has(a))throw Error(`Machine snapshot contains duplicate completion "${a}"`);if(!n.active.has(a)||!wp(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=y_(e,n,a);if(o===void 0){if(t.output!==void 0)throw Error(`Machine snapshot contains an output for state "${a}" without an output schema`);r.set(a,void 0)}else r.set(a,yield*vf(e,o,t.output,{boundary:`output`,state:a}))}return rp(e,{...n,outputs:r})}).pipe(we(t=>x_(e,t))),x_=(e,t)=>{if(tn(t))return Br(jt(t,t=>t instanceof Yu?t:new Yu({machineId:e.id,boundary:`configuration`,cause:vr(t)})));let n=Jt(t);return lt(n)&&n.value instanceof Yu?H(n.value):H(new Yu({machineId:e.id,boundary:`configuration`,cause:t}))},S_=e=>e.length===0?W:e.length===1?e[0]:O(e,{discard:!0}),C_=(e,t)=>({event:e.event,next:t(e.next),commands:e.commands,emittedEvents:e.emittedEvents,microsteps:e.microsteps.map(e=>({...e,transitions:e.transitions??[],next:t(e.next)})),done:e.done,output:e.output}),w_=new WeakMap,T_=e=>{let t=w_.get(e);if(t!==void 0)return t;let n=Object.values(rd(e).handlers).some(e=>e.invoke!==void 0);return w_.set(e,n),n},E_=Nn(pt()),D_=(e,t)=>{let n=Uh(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=mh(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return sh(e,r)?ch(e,r,oh).pipe(ue(me)):void 0},o=e=>br(()=>c(e)??E_),s=(e,t,r,a,s)=>{let c=a.commands.length===0?void 0:hh(a.commands,e.scope),l=a.emittedEvents.length===0?void 0:gh(a.emittedEvents,i(e)),u=()=>{let i=br(()=>(t&&e.completeMessage({before:r,plan:C_(a,n.snapshot),after:s}),a.done?Nn(me(a.output)):o(e)));return l===void 0?i:l.pipe(T(i))},d=()=>{let t=e.commit(s),n=u(),r=t===void 0?n:t.pipe(T(n));return t===void 0&&l===void 0?r:e.runAfterChanges(r)};return c===void 0?d():e.runAfterChanges(c.pipe(T(br(d))))},c=(t,r)=>{let i=r;for(;;){let r;if(i!==void 0)r=i,i=void 0,t.beginMessage(r);else{let e=t.pollMessage();if(g(e))return;r=e.value}let a=lg(r),c=a?r.event:r,l=t.state(),u;try{u=n.plan(t.executionState??n.fromConfiguration(up(e,l)),c,a,t.scope)}catch(e){return td(e)}if(t.executionState=u.next,u.microsteps.length===0){a&&t.completeMessage({before:l,plan:C_(u,n.snapshot),after:l});continue}let d=n.snapshot(u.next);if(u.commands.length>0||u.emittedEvents.length>0||u.done)return s(t,a,l,u,d);let f=t.commit(d);if(f!==void 0)return t.runAfterChanges(f.pipe(T(br(()=>(a&&t.completeMessage({before:l,plan:C_(u,n.snapshot),after:d}),o(t))))));a&&t.completeMessage({before:l,plan:C_(u,n.snapshot),after:d})}};return{run:e=>Tg(a(e)??o(e),e.scope),runSync:(e,t)=>{let n=a(e);n!==void 0&&e.beginMessage(t);let r=n??c(e,t);return r===void 0?void 0:Tg(r,e.scope)}}},O_=class{initialized=!1;initial;constructor(e){this.initial=e}},k_=(e,t)=>{let n=Uh(e);return r=>{let i=r.state();if(t&&sh(e,i))return ch(e,i,oh).pipe(ue(me));let a=r.scope,o=r.executionState,s=o instanceof O_?o:new O_;r.executionState=s;let c,l,u;return u=br(()=>{let t=r.pollMessage();if(g(t))return l=void 0,Nn(pt());let o=t.value,s=lg(o),d=s?o.event:o,f=i,p;try{p=n.plan(l??n.fromConfiguration(up(e,i)),d,s,a)}catch(e){return td(e)}if(l=p.next,p.microsteps.length===0)return s&&r.completeMessage({before:f,plan:C_(p,n.snapshot),after:i}),u;let m=p.microsteps.some(e=>e.changed),h=m?p.microsteps.flatMap(e=>e.exitPaths):[],_=new Map;if(m){for(let e of p.microsteps)if(e.changed)for(let t of e.entryPaths)_.set(t,e.event)}let v=n.toConfiguration(p.next),y=n.snapshot(p.next),b=[];if(p.commands.length>0&&b.push(hh(p.commands,a)),m){let e=r.ownedChildren.stopPaths(h);e!==void 0&&b.push(e)}let x=[];if(p.emittedEvents.length>0&&x.push(gh(p.emittedEvents,c??=mh(e,a))),p.done)x.push(r.ownedChildren.stopAll());else if(m)for(let[t,n]of _){let i=r_(e,a,r.ownedChildren,v,[t],n);i!==void 0&&x.push(i)}let S=()=>{let e=r.commit(y);return i=y,e},C=()=>{let e=br(()=>(s&&r.completeMessage({before:f,plan:C_(p,n.snapshot),after:y}),p.done?Nn(me(p.output)):u));return x.length===0?e:S_(x).pipe(T(e))},w=()=>{let e=S(),t=C(),n=e===void 0?t:e.pipe(T(t));return e===void 0&&x.length===0?n:r.runAfterChanges(n)};return b.length===0?w():r.runAfterChanges(S_(b).pipe(T(br(w))))}),Tg(br(()=>{if(s.initialized)return u;let t=s.initial,o=t?.activeConfiguration??up(e,i);l=t?.configuration??n.fromConfiguration(o);let c=r_(e,a,r.ownedChildren,o,t?.entryPaths??tp(e,o),oh);return s.initial=void 0,s.initialized=!0,c===void 0?u:c.pipe(T(u))}),a)}},A_=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},j_=(e,t)=>{let n=T_(e),r=Uh(e),i=t._tag===`Initial`?t.args:[],a=t._tag===`Initial`?r.initial:void 0,o=a===void 0?void 0:e=>{try{let t=a(i,e);e.inspectInitial(t.initialEntryPaths);let r=A_(t);return n?{...r,executionState:new O_({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw nd(e)}},s=t=>a===void 0?Tg(ph(xm(e,t),...i).pipe(_(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:hh(n.commands,t),i=n.emittedEvents.length===0?void 0:gh(n.emittedEvents,mh(e,t)),a=Nn(A_(n));return r===void 0?i===void 0?a:i.pipe(T(a)):i===void 0?r.pipe(T(a)):r.pipe(T(i),T(a))})),t):Ln({try:()=>o(t),catch:nd});return{inspection:{kind:`Machine`,definition:e},execution:{_tag:`Compiled`,childless:!n,...t._tag===`Initial`?{initial:s}:{},...o===void 0?{}:{initialSync:o},drain:n?{_tag:`Owned`,run:k_(e,t._tag===`Resume`)}:{_tag:`Owned`,...D_(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?Tg(b_(e,t.snapshot),n):s(n).pipe(ue(e=>e.state)),run:t=>Tg(R(function*(){let{completeMessage:r,pollMessage:i,receiveMessage:a,state:o,setState:s}=t;if(r===void 0||i===void 0||a===void 0)return yield*N(Error(`Machine statechart started without acknowledged mailbox access`));let c,l=yield*o;if(sh(e,l))return yield*ch(e,l,oh);if(!n){let n,o=pt(),u;for(;c===void 0;){let d=lt(o)?o.value:yield*a;o=pt();let f=lg(d),p=f?d.event:d,m=l,h;try{h=fh(e,zf(n??up(e,l),t),p)}catch(e){return yield*td(e)}if(n=h.next,h.microsteps.length>0){let n=rp(e,h.next);yield*hh(h.commands,t),yield*s(n),l=n,h.emittedEvents.length>0&&(yield*gh(h.emittedEvents,u??=mh(e,t))),h.done&&(c={output:h.output})}f&&r({before:m,plan:C_(h,t=>rp(e,t)),after:l}),c===void 0&&(o=yield*i,g(o)&&(n=void 0))}return c===void 0?yield*N(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}let u=t.ownedChildren;if(u===void 0)return yield*N(Error(`Invoking statechart started without an owned child runtime`));let d=(n,r,i)=>r_(e,t,u,n,r,i)??W,f=e=>u.stopPaths(e)??W;return yield*R(function*(){let n=yield*fp(e,l);yield*d(n,tp(e,n),oh),n=void 0;let o=pt(),p;for(;c===void 0;){let m=lt(o)?o.value:yield*a;o=pt();let h=lg(m),_=h?m.event:m,v=l,y;try{y=fh(e,zf(n??up(e,l),t),_)}catch(e){return yield*td(e)}if(n=y.next,y.microsteps.length>0){let n=y.microsteps.some(e=>e.changed),r=y.microsteps.flatMap(e=>e.exitPaths),i=new Map;for(let e of y.microsteps)if(e.changed)for(let t of e.entryPaths)i.set(t,e.event);let a=rp(e,y.next);if(yield*hh(y.commands,t),n&&(yield*f(r)),yield*s(a),l=a,y.emittedEvents.length>0&&(yield*gh(y.emittedEvents,p??=mh(e,t))),y.done)c={output:y.output},yield*u.stopAll();else if(n)for(let[e,t]of i)yield*d(y.next,[e],t)}h&&r({before:v,plan:C_(y,t=>rp(e,t)),after:l}),c===void 0&&(o=yield*i,g(o)&&(n=void 0))}return c===void 0?yield*N(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}).pipe(He(()=>u.stopAll()))}),t)}},M_=new WeakMap,N_=(e,...t)=>{if(t.length>0)return j_(e,{_tag:`Initial`,args:t});let n=M_.get(e);if(n!==void 0)return n;let r=j_(e,{_tag:`Initial`,args:t});return M_.set(e,r),r},P_=(e,t)=>j_(e,{_tag:`Resume`,snapshot:t}),F_=(e,...t)=>v_(N_(e,...t),e.id===void 0?void 0:{id:e.id}),I_=(e,t)=>g_(P_(e,t),e.id===void 0?void 0:{id:e.id}),L_={atomic:[`schema`,`type`,`annotations`],final:[`schema`,`type`,`output`,`annotations`],compound:[`schema`,`type`,`states`,`annotations`],parallel:[`schema`,`type`,`output`,`states`,`annotations`],history:[`type`,`history`,`annotations`],choice:[`type`,`annotations`]},R_=[`title`,`description`,`documentation`],z_=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),B_=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},V_=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},H_=e=>Number.isFinite(Number(e)),U_=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,W_=(e,t)=>{if(t.has(e))return`opaque`;if(nr(e)||gt(e)||Tt(e)||xt(e)||We(e)||B(e))return`tagged`;if(ct(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return At(e)?U_(e.types.map(e=>W_(e,n))):fe(e)?W_(e.thunk(),n):dt(e)?`opaque`:`untagged`},G_=(e,t=new Set)=>{if(t.has(e))return`opaque`;if(te(e)){let n=e.propertySignatures.find(({name:e})=>e===`_tag`)?.type;return n===void 0||_e(n)?`untagged`:W_(n,new Set(t).add(e))}let n=new Set(t).add(e);return At(e)?U_(e.types.map(e=>G_(e,n))):fe(e)?G_(e.thunk(),n):dt(e)?`opaque`:`untagged`},K_=e=>je(e)&&G_(u(e.ast))!==`untagged`,q_=(e,t,n)=>{let r=B_(t,n);return typeof n==`symbol`?V_(e,r,`state keys must be strings, not symbols`):typeof n==`number`?V_(e,r,`state keys cannot use numeric forms`):n===``?V_(e,r,`state keys cannot be empty`):n===`__proto__`?V_(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?V_(e,r,`state keys cannot contain "."`):H_(n)?V_(e,r,`state keys cannot use numeric forms`):r},J_=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&V_(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&V_(e,B_(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},Y_=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!z_(n,r))return;let a=n[r];(typeof a!=`object`||!a||je(a)||a.type!==`history`)&&V_(e,`${t}.${r}`,i)},X_=(e,t,n,r)=>{let i=L_[r];for(let a of Reflect.ownKeys(n))i.includes(a)||V_(e,t,`${r} states cannot declare property "${String(a)}"`)},Z_=(e,t,n)=>{J_(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))R_.includes(r)||V_(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&V_(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},Q_=(e,t,n,r,i=!1)=>{J_(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:q_(e,n,a),s=t[a];if(je(s)){K_(s)||V_(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}J_(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:z_(s,`states`)?`compound`:`atomic`;if(X_(e,o,s,l),l===`history`||l===`choice`){r||V_(e,o,`${l} states must be declared below an active parent state`),z_(s,`annotations`)&&Z_(e,o,s.annotations),l===`history`&&z_(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&V_(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=z_(s,`schema`);u&&!K_(s.schema)&&V_(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&z_(s,`annotations`)&&V_(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&z_(s,`annotations`)&&Z_(e,o,s.annotations),l===`atomic`&&z_(s,`type`)&&s.type!==`active`&&V_(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&V_(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&z_(s,`type`)&&s.type!==`active`&&V_(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&V_(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&z_(s,`output`)&&!je(s.output)&&V_(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?(Y_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&Y_(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),Q_(e,s.states,o,!0)):l===`parallel`&&(z_(s,`states`)||V_(e,`${o}.states`,`parallel states must declare child regions`),Y_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),Q_(e,s.states,o,!0))}},$_=e=>typeof e==`object`&&e?Object.freeze({...e}):e,ev=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(je(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=ev(i.states)),`annotations`in i&&(a.annotations=$_(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},tv=e=>ev(e),nv=(e,t=``)=>{if(je(e)||typeof e!=`object`||!e)return e;if(`~effect/Machine/State`in e&&e[`~effect/Machine/State`]===`~effect/Machine/State`&&`node`in e)return e.node;let n=e,r={...n};if(z_(n,`fields`)&&(z_(n,`schema`)&&V_(`Machine.state`,t,`declare fields or schema, not both`),J_(`Machine.state`,t,n.fields,`state fields`),z_(n.fields,`_tag`)&&V_(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=Wt(t,n.fields),delete r.fields),z_(n,`states`)){J_(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))q_(`Machine.state`,t,r),e[r]=nv(n.states[r],r);r.states=e}return t===``?(Q_(`Machine.state`,{"":r},``,!1,!0),tv({"":r})[``]):r},rv=`~effect/Machine`,iv=`~effect/Machine/ChildMachine`,av={...vt,...Wn,[rv]:rv,toJSON(){return{_id:`Machine`}}},ov=(e,t)=>{let n=Object.create(av);return n.states=e.states,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents,n.emittedEvents=e.emittedEvents,n.parent=e.parent,n.input=e.input,n.id=e.id,n.initial=e.initial,n.initialDefinition=e.initialDefinition,n.stateNodes=e.stateNodes,n.handlers=t,ff(e,n),n},sv=e=>e.kind===`none`?_d:gd(e.kind,e.path,e.scope,e.updatePath),cv=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),lv=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],uv=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!V(e,`target`)||typeof e.target!=`function`)throw Error(`Machine transition for state "${r}" on "${String(i)}" requires a target selector`);let a=e.target(t);if(!vd(a))throw Error(`Machine transition for state "${r}" on "${String(i)}" must select exactly one target`);if(a.updatePath!==void 0){let e=n.byPath.get(a.updatePath);if(a.kind!==`state`&&a.kind!==`choice`||a.scope!==`local`&&a.scope!==`branch`||a.path===void 0||e===void 0||e.schema===void 0||e.type!==`compound`&&e.type!==`parallel`||!Uf(r,e.path)||!Uf(a.path,e.path))throw Error(`Machine updating owner "${a.updatePath}" must be a valued ancestor retained by source "${r}" and target "${a.path}"`)}return{...e,selection:a}},dv=(e,t,n)=>{if(t.kind===`none`){if(e!==void 0)throw Error(`Machine targetless transition resolver must return undefined`);return}if(t.kind===`update`){if(!bd(e)||e.path!==t.path)throw Error(`Machine state update for "${t.path}" must return its selected update builder`);return}if(t.updatePath!==void 0){if(!Sd(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(Sd(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=Sd(e)?e.target:e,i=typeof r==`object`&&r&&V(r,`path`)&&typeof r.path==`string`?r.path:void 0,a=t.path===void 0?void 0:n.byPath.get(t.path),o=(t.scope===`local`||t.scope===`branch`)&&(a?.type===`compound`||a?.type===`parallel`);if(i===void 0||i!==t.path&&!(o&&Uf(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},fv=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:kd};delete a.target;let o=e.resolve(a,n);if(Ad(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return dv(o,e.selection,r),o},pv=e=>e.kind===`update`?void 0:e.path,mv=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},hv=(e,t,n)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch record`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" cannot use symbol keys`);let r=Object.keys(e);if(r.length===0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch`);return Object.freeze(r.map(r=>{if(r.length===0||mv(r))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires non-index string branch keys`);let i=e[r];if(typeof i!=`object`||!i||!V(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!vd(a))throw Error(`Machine transition branch "${r}" must select exactly one target`);if(o!==void 0&&(typeof o!=`string`||o.length===0))throw Error(`Machine transition branch "${r}" title must be a non-empty string`);return Object.freeze({key:r,title:o??r,selection:sv(a)})}))},gv=(e,t,n,r={},i)=>{let a=Np(r);if(e.kind===`choice`&&e.updatePath!==void 0){let{update:n,...r}=a;if(Reflect.ownKeys(r).length>0)throw Error(`Machine pseudo-state construction accepts no data`);let i=t.byPath.get(e.path);return xd(Fd(i.path,i.parent),Ip(t,e.updatePath,n))}if(e.kind===`none`||e.kind===`history`||e.kind===`choice`){if(Reflect.ownKeys(a).length>0)throw Error(`Machine pseudo-state construction accepts no data`);if(e.kind===`none`)return;let n=t.byPath.get(e.path);return e.kind===`history`?jd(n.path,n.parent):Fd(n.path,n.parent)}if(e.kind===`update`)return Ip(t,e.path,a);if(e.path===``){if(Reflect.ownKeys(a).some(e=>e!==`input`))throw Error(`Machine initialize branches accept input only`);if(n.initialize===void 0)throw Error(`Machine root initialization is unavailable`);return n.initialize(a.input)}if(e.updatePath!==void 0){let{update:n,...r}=a;return xd(Fp(t,e.path,r,i),Ip(t,e.updatePath,n))}return Fp(t,e.path,a,i)},_v=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>Cd(t,a,e.key,e.selection.kind===`none`?Ed():gv(e.selection,n,r,o,i))]))),vv=(e,t,n)=>{if(t.kind===`none`){if(!Dd(e))throw Error(`Machine targetless branch must return its selected targetless builder`)}else{if(e===void 0)throw Error(`Machine transition branch selected "${t.path}" without constructing its target`);dv(e,t,n)}},yv=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),bv=(e,t,n,r)=>{if(typeof e!=`object`||!e)throw Error(`Machine transition for "${n}" must be an object`);let i={...e},a=[`target`,`update`,`initialize`,`history`,`none`,`branches`,`data`,`decoded`,`resolve`,`guard`,`reenter`,`declinable`];for(let e of Reflect.ownKeys(i))if(typeof e!=`string`||!a.includes(e))throw Error(`Machine transition contains an unknown field`);for(let e of[`resolve`,`guard`])if(i[e]!==void 0&&typeof i[e]!=`function`)throw Error(`Machine transition ${e} must be a function`);let o=typeof i.guard==`function`?i.guard:void 0,s=typeof i.resolve==`function`?i.resolve:void 0;if(i.decoded!==void 0&&typeof i.decoded!=`boolean`)throw Error(`Machine decoded must be a boolean construction flag`);let c=Object.prototype.hasOwnProperty.call(i,`data`);if(i.decoded===!0&&!c)throw Error(`Machine decoded construction requires data`);if(c&&s!==void 0)throw Error(`Machine data and resolve are mutually exclusive`);let l=i.data,u=typeof l==`function`?l:()=>l,d=o!==void 0,f=d||i.declinable===!0;if(typeof i.branches==`string`){let e=t.branches.get(i.branches);if(e===void 0||s===void 0)throw Error(`Machine branching transition requires a registered group and resolver`);if([`target`,`update`,`initialize`,`history`,`none`,`data`,`decoded`].some(e=>i[e]!==void 0))throw Error(`Machine branching transition cannot redeclare its destination`);let a=Object.fromEntries(Object.entries(e).map(([e,i])=>[e,{title:i.title,target:uv({target:()=>Up(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?kd():s(e,t)}}let p=Up(t,i);if(s!==void 0&&p.kind!==`none`)throw Error(`Machine advanced construction requires a declared branch group`);let m=i.initialize,h=m!==void 0;if(h&&(c||i.decoded!==void 0))throw Error(`Machine initialize accepts machine input instead of data`);if(h&&!t.input&&m!==!0)throw Error(`Machine initialize requires true when the machine declares no input`);let g=t.input?typeof m==`function`?m:()=>m:()=>void 0;return{target:()=>p,reenter:i.reenter,declinable:f,resolve:(e,a)=>{if(d&&!o(e))return kd();if(s!==void 0)return s(e,a);if(h)return gv(p,r,t,{input:g(e)});let l=u(e);return gv(p,r,t,p.updatePath===void 0?{...c?{data:l}:{},...i.decoded===void 0?{}:{decoded:i.decoded}}:p.kind===`choice`?{update:{data:l,decoded:i.decoded}}:{...l.target===void 0?{}:{data:l.target,decoded:i.decoded},update:{data:l.update,decoded:i.decoded}},n)}}},xv=(e,t,n,r,i)=>{let a=bv(e,r,n,t);if(typeof a!=`object`||!a)throw Error(`Machine transition for state "${n}" on "${String(i)}" must be an object`);let o=a,s=o.reenter===!0,c=o.declinable===!0;if(V(o,`branches`)){let e=o;if(typeof e.branches!=`function`||typeof e.resolve!=`function`)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" requires branches and resolve`);let a=e.resolve,l=hv(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:kd};delete s.target,s.select=_v(l,u,t,r,n);let d=a(s,o);if(Ad(d)){if(!c)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" returned decline without declaring declinable: true`);return{result:d,branchIndex:-1,branchKey:void 0}}if(!wd(d)||d.owner!==u)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" must select one declared branch`);let f=l[d.branchIndex];if(f===void 0||d.branchKey!==f.key)throw Error(`Machine branching transition returned invalid branch evidence`);return vv(d.result,f.selection,t),{result:d.result,branchIndex:d.branchIndex,branchKey:d.branchKey}};return{reenter:s,declinable:c,targets:[...new Set(l.flatMap(e=>pv(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:pv(e.selection),selection:cv(e.selection),updates:lv(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=uv(a,void 0,t,n,i),u=(e,r)=>({result:fv(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:pv(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:pv(l.selection),selection:cv(l.selection),updates:lv(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},Sv=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=xv(e[a],t,n,r,a);return i},Cv=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=Wp(r,e,n,e=>yv(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=xv(i[e],t,n,r,e));return tm(i,n)});return rm(i,n),Array.isArray(e)?Object.freeze(i):i[0]},wv=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!V(n,o))throw Error(`Machine received handler for unknown state "${s}"`);let c=a[o];if(typeof c!=`object`||!c)throw Error(`Machine expected state "${s}" handler to be an object`);let{states:l,...u}=c;typeof u.history==`object`&&u.history!==null&&(u.history=Object.freeze(Object.fromEntries(Object.entries(u.history).map(([e,t])=>[e,typeof t==`object`&&t?Object.freeze({...t}):t]))));let d=u.on;if(typeof d==`object`&&d&&(u.on=Sv(d,t,s,i)),u.always!==void 0&&(u.always=xv(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=xv(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=xv(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=Cv(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!V(u.choice,`transition`)||typeof u.choice.transition!=`function`||!V(u.choice,`targets`)||!Array.isArray(u.choice.targets)||u.choice.targets.length===0))throw Error(`Machine choice state "${s}" requires a transition`);if(e[s]=u,l!==void 0){let r=Ld(s,n[o]);if(r.states===void 0)throw Error(`Machine expected state "${s}" to declare child states`);if(typeof l!=`object`||!l)throw Error(`Machine expected state "${s}" child handlers to be an object`);wv(e,t,r.states,s,i,l)}}},Tv=e=>e===``?zp:e,Ev=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=Vd(e),r=new Map;for(let e of n)e.trigger.type===`choice`&&r.set(e.source,e);for(let e of n)for(let t of e.branches){let n=t.updates[0],i=t.selection.path;if(t.selection.kind!==`choice`||n===void 0||i===void 0)continue;let a=[i],o=new Set;for(;a.length>0;){let t=a.shift();if(!o.has(t)){o.add(t);for(let i of r.get(t)?.branches??[]){let{kind:r,path:o}=i.selection;if(o!==void 0&&r!==`none`&&r!==`update`){if(r===`choice`)a.push(o);else if(!Uf(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${Tv(e.source)}" updates "${Tv(n)}" before choice "${t}", whose ${r} targets "${Tv(o)}" outside that owner`)}}}}}}},Dv=(e,t)=>(n=>{let r=em(t.root,n),i=Object.assign(Object.create(av),e);if(ff(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=Rd(i.states),i.stateNodes.byPath.get(``).schema===void 0&&n.root!==void 0)throw Error(`Machine schema-less root cannot construct data`);let a=i.stateNodes.byPath.get(``).schema===void 0?()=>void 0:Qp(n.root);i.initial=e=>({...Nd(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);wv(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Af(i,i.input,e))},{"":r.handlers});let s=ov(i,o);return Ev(s),s}),Ov=e=>{let t=nv(e),n=kv();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},kv=()=>({path:(e=>e),get:((e,t)=>qd(e,t).pipe(z(e=>e.value))),getWithParents:((e,t)=>{let n={};return qd(e,t,n).pipe(z(e=>({value:e.value,parents:n})))}),getSnapshot:qd,matches:((e,t)=>lt(qd(e,t)))}),Av=e=>{if(Object.hasOwn(e,`initial`)||Object.hasOwn(e,`initialConfiguration`))throw Error(`Machine initial edges and root data belong in handle`);let t=Object.freeze({"":e.root.node}),n=Object.create(Wn);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??_f(`internal`,[]),n.emittedEvents=e.emittedEvents??_f(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=Dv(n,Vp(e.root,e)),df(n),n},jv=e=>{for(let[t,n]of Object.entries(e))if(Object.hasOwn(n,`_tag`))throw Error(`Machine event "${t}" fields cannot declare _tag`);return Object.keys(e).length===0?[]:[Nr(e)]},Mv=e=>_f(`public`,jv(e)),Nv=(e,t)=>Pv(e,t,e=>t.input===void 0?N_(t):N_(t,e)),Pv=(e,t,n)=>({[iv]:iv,id:e,machine:t,[qp]:n}),Fv=F_,Iv=I_,Lv=(e,t)=>{try{let n=lh(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},Rv=(e,t)=>{try{let n=Rt(b_(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!sh(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=Rt(ch(e,r,oh));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},zv={spawn:()=>N(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>H(new $u),stop:()=>W},Bv=(e,t)=>{if(e.snapshot.status!==`active`)return pt();try{let n=e.machine,r=up(n,e.snapshot.state);for(let e of tp(n,r)){let i=bp(n,e);for(let a of im(i?.invoke)){if(!(`child`in a)||a.child.id!==t.id||a.child.machine!==t.machine)continue;let i=t.machine,o;`input`in a&&(o=typeof a.input==`function`?a.input({...Bf(r)??Sm(n,r),children:zv,state:r.values.get(e),containingState:ep(n,r,e),ancestors:$f(n,r,e),event:oh}):a.input);let s=Lv(i,i.input===void 0?[]:[o]);return s===void 0?void 0:me(s)}}return pt()}catch{return}},Vv=class extends Vt(`ChildNotActiveError`){},Hv=new WeakMap,Uv=new WeakMap,Wv=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return Pr(e);let t=Mr(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=Ze(t,n);lt(r)&&r.value===e&&S(t,n)});return r=>{let i=Ze(t,r);if(lt(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return Dr(t,r,o),n.register(a,{key:r,entry:o}),a}},Gv=(e,t)=>ur(tt(t,e=>e.stop).pipe(rn(t=>G(()=>e.setSelf(pe(t)))),_(()=>Ot))),Kv=(e,t)=>Gv(e,e.result(t).pipe(_(e=>e.start))),qv=(e,t,n)=>Gv(e,Iv(t,n)),Jv=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[xr](t):t(e),Yv=(e,t)=>{let n;return r=>{let i=e(r);return n!==void 0&&n.inputs.length===i.length&&n.inputs.every((e,t)=>Object.is(e,i[t]))||(n={inputs:i,value:t(...i)}),n.value}},Xv=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},Zv=e=>e.snapshot,Qv=$e(e=>e.registry).pipe(Je),$v=e=>br(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,W):T(t,$v(e))}),ey=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},ty=(e,t,n)=>Se(n=>{let r=ft(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:Ke(z(n.self(),Qn),()=>Rr(!0))},(r,i)=>{let a=r.get(e),o=r.get(Qv),s=ey(t,o);U(a)||s.draining?(r.setSelf(Rr(!0)),s.pending.push(De(o,e).pipe(_(e=>n(e,i)),be,ue(e=>{let t=ve(e);r.setSelf(s.pending.length===0?t:Qn(t))}))),s.draining||(s.draining=!0,Hn($v(s)))):h(a)?r.setSelf(ft(a,()=>void 0)):hr(n(a.value,i),{onExit:e=>r.setSelf(ve(e))})}).pipe(xn),ny=e=>$e(t=>{let n=t(e);return U(n)?Rr(n.waiting):h(n)?ae(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?ae(n.value.cause,{previous:t.self(),waiting:n.waiting}):pe(n.value.state,{waiting:n.waiting})}).pipe(Me(Dt),d(Yv(t=>[Jv(e,t)],e=>ft(e,e=>e.state)))),ry=e=>$e(t=>{let n=t(e);if(U(n))return Rr(n.waiting);if(h(n))return ae(n.cause,{previous:t.self(),waiting:n.waiting});if(g(n.value)){let e=t.self();return lt(e)&&h(e.value)?e.value:pe(pt(),{waiting:n.waiting})}return n.value.value.status===`error`?ae(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):pe(me(n.value.value.state),{waiting:n.waiting})}).pipe(Me(Dt),d(Yv(t=>[Jv(e,t)],e=>ft(e,z(e=>e.state))))),iy=(e,t)=>$e(n=>{let r=n(e);if(U(r))return Rr(r.waiting);if(h(r))return ae(r.cause,{previous:n.self(),waiting:r.waiting});if(g(r.value))return pe(pt());let i=r.value.value,a=yn(i.child(t)),o=hr(Ut.pipe(T(i.childChanges(t).pipe(nn(e=>G(()=>n.setSelf(pe(e))))))));return n.addFinalizer(o),pe(a)}).pipe(xn),ay=(e,t)=>ag(e)?e[ig](()=>t(yn(e.snapshot))):hr(e.changes.pipe(nn(e=>G(()=>t(e))))),oy=(e,t,n)=>{let r=$e(t=>{let n=t(e);if(U(n))return Rr(n.waiting);if(h(n))return ae(n.cause,{previous:t.self(),waiting:n.waiting});if(g(n.value))return pe(pt());let r=n.value.value;return t.addFinalizer(ay(r,e=>t.setSelf(pe(me(e))))),pe(me(yn(r.snapshot)))}).pipe(d(Yv(()=>[],()=>{let e=n();return e===void 0?Rr(!0):pe(z(e,Zv),{waiting:!0})}))),i=new WeakMap,a=e=>lt(e)?Nn(e.value):H(new Vv({id:t.id})),o=ty(e,i,(e,t)=>_(a(e),e=>e.send(t))),s=ty(e,i,(e,t)=>_(a(e),e=>e.stop)),c=sy(e,n);return{ref:e,snapshot:r,result:ry(r),send:o,stop:s,child:c}},sy=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=Pr(n=>{let r=Nv(n,a);return oy(iy(e,r),r,Xv(()=>{let e=t();return e===void 0||g(e)?e:Bv(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},cy=(e,t,n)=>{let r=xn(e),i=$e(e=>{let t=e(r);if(U(t))return Rr(t.waiting);if(h(t))return ae(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(ay(n,t=>e.setSelf(pe(t,{waiting:t.status===`active`}))));let i=yn(n.snapshot);return pe(i,{waiting:i.status===`active`})}).pipe(d(Yv(()=>[],()=>{let e=n();return e===void 0?Rr(!0):pe(Zv(e),{waiting:!0})}))),a=new WeakMap,o=ty(r,a,(e,t)=>e.send(t)),s=ty(r,a,(e,t)=>e.stop),c=sy(Tr(r,me),()=>{let e=n();return e===void 0?void 0:me(e)}),l={ref:r,snapshot:i,result:ny(i),send:o,stop:s,child:c};return Uv.set(l,t),l},ly=(e,t)=>qd(e,t).pipe(z(e=>e.value)),uy=(e,t)=>qd(e,t),dy=(e,t)=>Tr(e,t).pipe(Me(Dt),d(Yv(t=>[Jv(e,t)],e=>ft(e,t)))),fy=new WeakMap,py=(e,t,n,r)=>{let i=fy.get(e);i===void 0&&(i=new Map,fy.set(e,i));let a=i.get(t);a===void 0&&(a=new Map,i.set(t,a));let o=a.get(n);if(o!==void 0)return o;let s=r();return a.set(n,s),s},my=(e,t)=>py(e,`select`,t,()=>dy(e.result,e=>ly(e,t))),hy=(e,t)=>py(e,`selectSnapshot`,t,()=>dy(e.result,e=>uy(e,t))),gy=(e,t)=>py(e,`selectChild`,t,()=>dy(e.result,ye(e=>ly(e,t)))),_y=(e,t)=>py(e,`selectSnapshotChild`,t,()=>dy(e.result,ye(e=>uy(e,t)))),vy=(e,t)=>py(e,`matches`,t,()=>dy(e.result,e=>lt(qd(e,t)))),yy=(e,t)=>py(e,`matchesChild`,t,()=>dy(e.result,oe(e=>lt(qd(e,t))))),by=(e,t,n)=>{let r=e.atom(()=>Fv(t,...n)),i=cy(e.atom(e=>Kv(e,r)),t,Xv(()=>Lv(t,n)));return Hv.set(i,r),i},xy=(e,t,n)=>cy(e.atom(e=>qv(e,t,n)),t,Xv(()=>Rv(t,n))),Sy=(e,t,n)=>{let r={owner:e,source:t},i=C(t,e=>e(r.source),{initialValueTarget:t}).pipe(Me((e,t)=>r.source.equals(e,t)),d(e=>Jv(r.source,e)));return n!==void 0&&(i=i.pipe(En(n))),i},Cy=(e,t)=>{let n=Wv(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=Wv(r=>{let a=n(r);return Sy(a,i(a.bridge),t.label?.(r,e))})}return r},wy=e=>{let t=((t,...n)=>by(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>xy(e,t,n)),family:((t,n)=>Cy(n=>by(e,t,[n]),n))}},Ty=gn(2,my);gn(2,hy),gn(2,gy),gn(2,_y),gn(2,vy),gn(2,yy);var Ey=wy,Dy=e=>Oy(X.useContext(ku),e),Oy=(e,t)=>{let n=X.useMemo(()=>{let n,r,i=e=>ne(e)?(n=e,e):U(e)&&n!==void 0?n:e;return{subscribe:n=>e.subscribe(t,n),snapshot:()=>i(e.get(t)),serverSnapshot:()=>r??=i(kr(t,e))}},[e,t]);return X.useSyncExternalStore(n.subscribe,n.snapshot,n.serverSnapshot)},ky=Dy,Ay=e(t(),1);function jy(e){let t=Ay.unstable_scheduleCallback(4,e);return()=>Ay.unstable_cancelCallback(t)}var My=X.createContext(Ie({scheduleTask:jy,defaultIdleTTL:400})),Ny=new WeakMap,Py=0,Fy=new Set;function Iy(e){Py++;try{return e()}finally{Py--}}function Ly(e){if(Py===0)return e();Fy.size===0&&queueMicrotask(Ry),Fy.add(e)}function Ry(){for(let e of Fy)Fy.delete(e),e()}function zy(e,t){let n=Ny.get(e);n===void 0&&(n=new WeakMap,Ny.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=0,a,o={subscribe(n){i++;let r=e.subscribe(t,()=>Ly(n));return()=>{i--,Fy.delete(n),r()}},snapshot(){return Iy(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Iy(()=>kr(t,e))}),a.value}};return n.set(t,o),o}function By(e,t){let n=zy(e,t);return X.useEffect(Ry),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Vy(e,t,n){let r=zy(e,t),i=X.useMemo(()=>{let e;return t=>(e!==void 0&&Object.is(e.source,t)||(e={source:t,value:n(t)}),e.value)},[n]);return X.useEffect(Ry),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Hy=(e,t)=>{let n=X.useContext(My);return t?Vy(n,e,t):By(n,e)};function Uy(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=or(De(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Wy):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Wy=e=>{if(It(e))return e.value;throw Fr(e.cause)},Gy=(e,t)=>{let n=X.useContext(My);return[By(n,e),Uy(n,e,t)]};function Ky({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=X.useRef(e!==void 0),[a,o]=X.useState(()=>t);return[i&&e!==void 0?e:a,X.useCallback(e=>{i||o(e)},[])]}function qy(e){let t=X.useRef(!0);t.current&&(t.current=!1,e())}function Jy(e,t,n,r,i,a,o,s,c,l=2){let u=ra(n.current,{event:e,orientation:r,loopFocus:i,rtl:a,cols:l,disabledIndices:o,minIndex:s,maxIndex:c,prevIndex:t>c?s:t,stopEvent:!0});return xo(n.current,u)?void 0:u}function Yy(e){return e==null?fa:e.type.startsWith(`key`)?Ia:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?No:fa}var Xy=X.createContext(void 0),Zy=X.createContext(void 0),Qy=X.createContext(void 0),$y=X.createContext(!1),eb=X.createContext(``);function tb(){let e=X.useContext(Xy);if(!e)throw Error(ji(22));return e}function nb(){let e=X.useContext(Zy);if(!e)throw Error(ji(23));return e}function rb(){let e=X.useContext(Qy);if(!e)throw Error(ji(24));return e}function ib(){return X.useContext(eb)}function ab(){return X.useContext($y)}function ob(e,t,n=Object.is){let{length:r}=e;if(r!==t.length)return!1;for(let i=0;i<r;i+=1)if(!n(e[i],t[i]))return!1;return!0}var sb=(e,t)=>Object.is(e,t);function cb(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function lb(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!ob(e,t,(e,t)=>cb(e,t,n)):e!==t}function ub(e,t,n){return e?e.some(e=>e!==void 0&&cb(t,e,n)):!1}function db(e,t,n){return e?e.findIndex(e=>e!==void 0&&cb(e,t,n)):-1}function fb(e,t){if(t!==sb)return n=>ub(e,n,t);let n=new Set(e);return n.delete(void 0),t=>n.has(t)&&(t!==0||e.some(e=>Object.is(t,e)))}function pb(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(fb(t,n)):db(e,t,n);return i===-1?null:i}function mb(e,t,n,r,i,a){return ub(r,t,i)?a!=null&&e>a&&ub(r,n[a],i)?a:e:e===a?pb(n,r,i,!0):a}function hb(e,t,n){return e.filter(e=>!cb(t,e,n))}function gb(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function _b(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function vb(e){return _b(e?.[0])}function yb(e){return vb(e)?e.flatMap(e=>e.items):e}function bb(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(vb(t)){for(let e of t)for(let t of e.items)if(t&&t.value==null&&t.label!=null)return!0;return!1}for(let e of t)if(e&&e.value==null&&e.label!=null)return!0;return!1}function xb(e,t){if(t&&e!=null)return t(e)??``;if(e&&typeof e==`object`){if(`label`in e&&e.label!=null)return String(e.label);if(`value`in e)return String(e.value)}return gb(e)}function Sb(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?gb(e.value):gb(e)}var Cb={id:e=>e.id,labelId:e=>e.labelId,items:e=>e.items,selectedValue:e=>e.selectedValue,hasSelectionChips:e=>{let t=e.selectedValue;return Array.isArray(t)&&t.length>0},hasSelectedValue:e=>{let{selectedValue:t,selectionMode:n}=e;return t==null?!1:n===`multiple`&&Array.isArray(t)?t.length>0:!0},hasNullItemLabel:(e,t)=>t?bb(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMounted:e=>e.forceMounted,inline:e=>e.inline,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{let n=e.isItemEqualToValue,r=e.selectedValue;return Array.isArray(r)?r.some(e=>cb(t,e,n)):cb(t,r,n)},transitionStatus:e=>e.transitionStatus,popupProps:e=>e.popupProps,listProps:e=>e.listProps,inputProps:e=>e.inputProps,triggerProps:e=>e.triggerProps,itemRoot:e=>e.itemRoot,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupId:e=>e.popupId,triggerElement:e=>e.triggerElement,inputElement:e=>e.inputElement,inputGroupElement:e=>e.inputGroupElement,popupSide:e=>e.popupSide,openMethod:e=>e.openMethod,inputInsidePopup:e=>e.inputInsidePopup,inputOwnsFormValue:e=>e.inputOwnsFormValue,selectionMode:e=>e.selectionMode,name:e=>e.name,form:e=>e.form,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,grid:e=>e.grid,virtualized:e=>e.virtualized,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,modal:e=>e.modal,autoHighlight:e=>e.autoHighlight},wb=`data-valid`,Tb=`data-invalid`,Eb={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},Db={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Ob={disabled:!1,...Db},kb={valid(e){return e===null?null:e?{[wb]:``}:{[Tb]:``}}},Ab={invalid:void 0,name:void 0,validityData:{state:Eb,errors:[],error:``,value:``,initialValue:null},setValidityData:Ui,disabled:void 0,setTouched:Ui,setDirty:Ui,setFilled:Ui,setFocused:Ui,focusOwnerRef:{current:void 0},validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Ob,registerFieldControl:Ui,validation:{getValidationProps:(e,t=jo)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Ui,getInputControl:()=>null,commit:async()=>{},change:Ui}},jb=X.createContext(Ab);function Mb(e=!0){let t=X.useContext(jb);if(t.setValidityData===Ui&&!e)throw Error(ji(28));return t}function Nb(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Mb(),s=Ei(()=>Symbol());K(()=>{let c=s.current;i?o(c,{controlRef:e,getValue:r,id:t,name:a,value:n}):o(c,void 0)},[e,i,r,t,a,o,s,n]),K(()=>{let e=s.current;return()=>{o(e,void 0)}},[o,s])}var Pb=X.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Ui,validationMode:`onSubmit`,submitCountRef:{current:0}});function Fb(){return X.useContext(Pb)}function Ib(e){return ni(e,`base-ui`)}var Lb=X.createContext({controlId:void 0,registerControlId:Ui,resetControlId:Ui,labelId:void 0,setLabelId:Ui,messageIds:[],setMessageIds:Ui,getDescriptionProps:e=>e});function Rb(){return X.useContext(Lb)}function zb(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=Rb(),o=Ib(),s=Ei(()=>Symbol()),c=X.useRef(!1),l=X.useRef(!1),u=J(()=>{c.current&&i!==Ui&&(c.current=!1,i(s.current,void 0))});return K(()=>{if(!n||i===Ui){u();return}let e;if(t!==void 0)l.current=!0,e=t;else if(l.current)e=o;else{a();return}e===void 0?u():(c.current=!0,i(s.current,e))},[t,n,i,a,o,s,u]),K(()=>u,[u]),(n?r:void 0)??t??o}function Bb(e){return e==null?void 0:`${e}-popup`}function Vb(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function Hb(e){return Array.isArray(e)?e.map(e=>Hb(e)).join(`,`):e==null?``:String(e)}var Ub=new Map;function Wb(e={}){let{locale:t,...n}=e,r={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...n},i=`${Hb(t)}|${JSON.stringify(r)}`,a=Ub.get(i);if(a)return a;let o=new Intl.Collator(t,r),s={contains(e,t,n){if(!t)return!0;let r=xb(e,n);for(let e=0;e<=r.length-t.length;e+=1)if(o.compare(r.slice(e,e+t.length),t)===0)return!0;return!1},startsWith(e,t,n){if(!t)return!0;let r=xb(e,n);return o.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=xb(e,n),i=t.length;return r.length>=i&&o.compare(r.slice(r.length-i),t)===0}};return Ub.set(i,s),s}var Gb=Wb;function Kb(e){let t=X.useRef(``),n=X.useCallback(n=>{n.defaultPrevented||(t.current=n.pointerType,e(n,n.pointerType))},[e]);return{onClick:X.useCallback(n=>{n.detail===0?e(n,`keyboard`):(`pointerType`in n?e(n,n.pointerType):e(n,t.current),t.current=``)},[e]),onPointerDown:n}}function qb(e,t){let n=X.useRef(e),r=J(t);K(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Jb(e,t){let{onClick:n,onPointerDown:r}=Kb(J((n,r)=>{(typeof e==`function`?e():e)||t(r||(Da?`touch`:``))}));return X.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function Yb(e){let[t,n]=X.useState(null),r=Jb(e,n);return qb(e,t=>{t&&!e&&n(null)}),X.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var Xb=Symbol(`none`),Zb={value:Xb,index:-1};function Qb(e,t,n){let r=e.get(t);if(r!==void 0||n===sb)return r;for(let[r,i]of e)if(cb(r,t,n))return i}function $b(e){let{id:t,onOpenChangeComplete:n,defaultSelectedValue:r=null,selectedValue:i,onSelectedValueChange:a,defaultInputValue:o,inputValue:s,open:c,defaultOpen:l=!1,selectionMode:u,onItemHighlighted:d,name:f,form:p,disabled:m=!1,readOnly:h=!1,required:g=!1,inputRef:_,grid:v=!1,items:y,filteredItems:b,filter:x,filterQuery:S,openOnInputClick:C=!0,autoHighlight:w=!1,keepHighlight:T=!1,highlightItemOnHover:E=!0,loopFocus:D=!0,itemToStringLabel:O,itemToStringValue:k,isItemEqualToValue:A=sb,virtualized:j=!1,inline:M=!1,fillInputOnItemPress:N=!0,modal:P=!1,limit:F=-1,autoComplete:I=`list`,formAutoComplete:L,locale:R,submitOnItemClick:ee=!1}=e,{clearErrors:te}=Fb(),{setDirty:ne,validityData:z,setFilled:re,name:ie,disabled:B,setTouched:ae,setFocused:oe,validationMode:se,validation:ce}=Mb(),le=cu(),ue=zb({id:t}),de=Gb({locale:R}),fe=Array.isArray(y)?null:y;if(fe&&typeof fe.label!=`function`)throw Error(ji(100));let pe=fe?fe.data:y,me=fe?.value,he=me?void 0:pe,ge=X.useMemo(()=>{if(!b||!me)return;let e=yb(b),t=e.map(me),n;return{values:t,findItem(r,i){if(!n){n=new Map;for(let r=0;r<t.length;r+=1)n.has(t[r])||n.set(t[r],e[r])}return Qb(n,r,i)}}},[b,me]),_e=X.useMemo(()=>fe?e=>fe.label(e,A,e=>{let t=ge?.findItem(e,A);return t==null?xb(e,O):fe.itemLabel(t)}):O,[fe,O,ge,A]),ve=X.useMemo(()=>fe?Object.assign(e=>fe.itemLabel(e),{selected:e=>xb(e,_e)}):O,[fe,_e,O]);function ye(e){return xb(e,_e)}let[be,xe]=X.useState(!1),[Se,Ce]=X.useState(null),we=X.useRef(Se),Te=X.useRef([]),Ee=X.useRef([]),De=X.useRef(null),Oe=X.useRef(null),ke=X.useRef(null),Ae=X.useRef(null),je=X.useRef(null),Me=X.useRef(!1),Ne=X.useRef(null),Pe=X.useRef(null),Fe=X.useRef(null),Ie=X.useRef(Zb),Le=X.useRef(null),Re=X.useRef([]),ze=X.useRef(null),Be=B||m,Ve=ie??f,V=u===`multiple`,He=u===`single`,Ue=s!==void 0||o!==void 0,We=pe!==void 0,Ge=b!==void 0,Ke;Ke=w===`always`?`always`:w?`input-change`:!1;let[H,qe]=Ky({controlled:i,default:V?r??ya:r,name:`Combobox`,state:`selectedValue`}),Je=X.useMemo(()=>x===null?()=>!0:x===void 0?Vb(de,ve):x,[x,de,ve]),Ye=Ei(()=>Ue?o??``:He?ye(H):``).current,[Xe,Ze]=Ky({controlled:s,default:Ye,name:`Combobox`,state:`inputValue`}),[Qe,$e]=Ky({controlled:c,default:l,name:`Combobox`,state:`open`}),et=vb(pe),tt=!Qe&&Se!==null?Se:String(Xe).trim(),nt=He?ye(H):``,rt=He&&!be&&tt!==``&&nt.length===tt.length&&de.contains(nt,tt),it=rt?``:S??tt,at=We&&Ge&&rt&&(!fe||fe.hasValue(H,A)),ot=X.useMemo(()=>pe?yb(pe):ya,[pe]),st=X.useMemo(()=>{if(b&&!at)return b;if(!pe)return ya;if(et){let e=pe,t=[],n=0;for(let r of e){if(F>-1&&n>=F)break;let e=F>-1?F-n:1/0,i=it===``?r.items.slice(0,e):[];if(it!==``)for(let t of r.items){if(i.length>=e)break;Je(t,it,ve)&&i.push(t)}if(i.length>0){let e={...r,items:i};t.push(e),n+=i.length}}return t}if(it===``)return F>-1?ot.slice(0,F):ot;let e=[];for(let t of ot){if(F>-1&&e.length>=F)break;Je(t,it,ve)&&e.push(t)}return e},[b,at,pe,et,it,F,Je,ve,ot]),ct=X.useMemo(()=>{if(ge&&st===b)return ge.values;let e=yb(st);return me?e.map(e=>me(e)):e},[st,b,ge,me]),U=Ei(()=>{let e=null;return M&&Qe&&We&&u!==`none`&&(e=pb(ct,H,A,V)),new Ba({id:ue,labelId:void 0,selectedValue:H,open:Qe,items:he,selectionMode:u,name:Ve,form:p,disabled:Be,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:_e,isItemEqualToValue:A,modal:P,autoHighlight:Ke,submitOnItemClick:ee,hasInputValue:Ue,mounted:!1,forceMounted:!1,transitionStatus:`idle`,inline:M,activeIndex:null,selectedIndex:e,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemRoot:{props:jo,id:ue,selectionMode:u,disabled:Be,readOnly:h,isItemEqualToValue:A},positionerElement:null,listElement:null,popupId:void 0,triggerElement:null,inputElement:null,inputGroupElement:null,popupSide:null,openMethod:null,inputInsidePopup:!0,inputOwnsFormValue:u===`none`},{onOpenChangeComplete:Ui,setOpen:Ui,setInputValue:Ui,setSelectedValue:Ui,setIndices:Ui,handleSelection:Ui,forceMount:Ui,requestSubmit:Ui,listRef:Te,labelsRef:Ee,popupRef:De,emptyRef:je,inputRef:Oe,startDismissRef:ke,endDismissRef:Ae,chipsContainerRef:Ne,clearRef:Pe,valuesRef:Re,pointerDownItemRef:ze,selectionEventRef:Fe},Cb)}).current,lt=u===`none`?Xe:H,ut=X.useMemo(()=>u===`none`?lt:Array.isArray(H)?H.map(e=>Sb(e,k)):Sb(H,k),[lt,k,u,H]),dt=J(d),ft=J(n),pt=U.useState(`activeIndex`),mt=U.useState(`selectedIndex`),ht=U.useState(`positionerElement`),gt=U.useState(`listElement`),_t=U.useState(`triggerElement`),vt=U.useState(`inputElement`),yt=U.useState(`inputGroupElement`),bt=U.useState(`inline`),xt=U.useState(`inputInsidePopup`),St=U.useState(`inputOwnsFormValue`),Ct=He&&!xt&&Xe===nt,wt=ps(_t),{openMethod:Tt,triggerProps:Et}=Yb(Qe),Dt=J(()=>ut);Nb(xt?wt:Oe,ue,lt,Dt,!Be,f);let Ot=J(()=>{pe?Ee.current=ct.map(ye):U.set(`forceMounted`,!0)}),kt=J((e,t,n,r)=>{if(t===-1){if(Ie.current===Zb)return;Ie.current=Zb}else Ie.current={value:e,index:t};dt(e,Gi(n,r,{index:t}))}),At=J(e=>{let t={};e.activeIndex!==void 0&&(t.activeIndex=e.activeIndex),e.selectedIndex!==void 0&&(t.selectedIndex=e.selectedIndex),U.update(t);let n=e.activeIndex;if(n===void 0)return;let r=e.type||`none`;n===null?kt(void 0,-1,r,e.event):kt(Re.current[n],n,r,e.event)}),jt=J((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(Me.current=n.reason===Aa,n.reason===`input-change`){Qe&&Se!==null&&Ce(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&xe(!0),Le.current={hasQuery:e};let n=U.state.listElement;if(!U.state.virtualized&&n){let e=De.current;for(let t of Lo(n.firstElementChild??n)){if(!ta(t)||(e?!q(e,t):t.getAttribute(`role`)===`dialog`))break;if(fs(t)){t.scrollTop=0;break}}}e&&Ke&&U.state.activeIndex==null&&(Qe||bt)&&U.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&U.state.inputInsidePopup&&(Le.current={hasQuery:!1,selection:!0});Ze(t)}}),Mt=J(e=>{let t=!e&&xt&&!bt&&Xe!==``&&(String(Xe).trim()===Se||Xe===nt);!e&&(t||Xe===``||Ct)&&xe(!1),Ce(null),t&&jt(``,Y(Aa))}),[W,Nt]=X.useState(!1),Pt=J((t,n)=>{if(Qe===t)return;n.reason===`escape-key`&&We&&ct.length===0&&!je.current&&n.allowPropagation();let r=n,i=sc(r);if(e.onOpenChange?.(t,r),Le.current?.hasQuery&&n.reason===`input-change`===n.isCanceled&&(Le.current=null),!n.isCanceled&&(t&&Se!==null&&Mt(n.reason===wa),!t&&be&&(He?(bt||Ce(tt),tt===``&&xe(!1)):V&&(bt||Ce(tt),xt&&At({activeIndex:null}),(!xt||bt)&&jt(``,Y(Aa,n.event,void 0,{isItemPress:n.reason===Xa})))),t||Nt(i()),$e(t),!t&&xt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(ae(!0),oe(!1),se===`onBlur`))){let e=u===`none`?Xe:H;ce.commit(e)}}),Ft=J((e,t)=>{a?.(e,t),!t.isCanceled&&(qe(e),(u===`none`&&De.current&&N||He&&!U.state.inputInsidePopup)&&jt(ye(e),Y(t.reason,t.event)))}),It=J((e,t)=>{let n=ca(e),r=Fe.current??e;Fe.current=null;let i=Y(Xa,r),a=uo(n,`a`)?.getAttribute(`href`);if(a)a.startsWith(`#`)&&Pt(!1,i);else if(V){let e=Array.isArray(H)?H:[],n=ub(e,t,A),r=n?hb(e,t,A):[...e,t];if(Ft(r,i),i.isCanceled||!(Oe.current&&Oe.current.value.trim()!==``))return;if(U.state.inputInsidePopup){jt(``,Y(Aa,i.event,void 0,{isItemPress:!0}));let e=Le.current;e&&!n&&(e.toggledValue=t)}else Pt(!1,i)}else{if(Ft(t,i),i.isCanceled)return;Pt(!1,i)}}),Lt=J(()=>{let e=ce.inputRef.current?.form??U.state.inputElement?.form;e&&typeof e.requestSubmit==`function`&&e.requestSubmit()}),Rt=J(()=>{if(ft?.(!1),xe(!1),Ce(null),At(u===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),V&&Oe.current&&Oe.current.value!==``&&!Me.current&&jt(``,Y(Aa)),He){if(U.state.inputInsidePopup)Oe.current&&Oe.current.value!==``&&jt(``,Y(Aa));else{let e=ye(H);Oe.current&&Oe.current.value!==e&&jt(e,Y(e===``?Aa:fa))}}}),zt=X.useMemo(()=>bt&&ht?{current:uo(ht,`[role="dialog"]`)}:De,[bt,ht]),{mounted:Bt,transitionStatus:Vt,forceUnmount:Ht}=Qs({open:Qe,ref:zt,preventUnmountOnClose:W,setPreventUnmountOnClose:Nt,onUnmount:Rt});X.useImperativeHandle(e.actionsRef,()=>({unmount:Ht,close:()=>Pt(!1,Y(So))}),[Ht,Pt]),K(function(){let e=we.current!==null&&Se===null;if(we.current=Se,Qe&&(!e||!We)||(Qe||(ze.current=null),u===`none`))return;let t=We?ct:Re.current;At({selectedIndex:pb(t,H,A,V)})},[Qe,Se,H,u,V,We,ct,A,At]),K(()=>{pe&&(Re.current=ct,Te.current.length=ct.length)},[pe,ct]),K(()=>{!Qe&&Le.current?.hasQuery&&(Le.current=null)},[Qe]),K(()=>{if(!Qe&&bt&&zt.current){Le.current=null;return}let e=We||Ge?ct:Re.current,t=Le.current;if(t){let n=Qe||bt||U.state.positionerElement?.hidden===!1;if(t.hasQuery){let t=Oe.current;!Ke||String(Xe).trim()===``||bt&&Ke!==`always`&&(!t||xi(t.ownerDocument)!==t)?Le.current=null:n&&(e[0]!==void 0||!We&&!Ge)&&(U.set(`activeIndex`,0),Le.current=null)}else if(String(Xe).trim()===``&&(Le.current=null,n)){let e=t.selection;Ke===`always`&&!e&&U.state.selectionMode===`none`&&U.set(`activeIndex`,0),queueMicrotask(()=>{if(!U.state.open&&(!U.state.inline||zt.current)||Oe.current&&Oe.current.value.trim()!==``)return;let n=U.state.selectedValue,r=U.state.selectionMode===`multiple`;if(r&&Array.isArray(n)?n.length>0:U.state.selectionMode!==`none`&&n!=null){let e=We||Ge?ct:Re.current,i=db(e,t.toggledValue,U.state.isItemEqualToValue);U.set(`activeIndex`,i===-1?pb(e,n,U.state.isItemEqualToValue,r):i)}else e?U.set(`activeIndex`,null):Ke===`always`&&U.set(`activeIndex`,0)})}}if(!Qe&&!bt)return;let n=U.state.activeIndex;if(n==null){if(Ke===`always`&&e.length>0){U.set(`activeIndex`,0);return}kt(void 0,-1,fa);return}if(n>=e.length){kt(void 0,-1,fa),U.set(`activeIndex`,null);return}let r=e[n],i=Ie.current.value,a=i!==Xb&&cb(r,i,U.state.isItemEqualToValue);Ie.current.index===n&&a||kt(r,n,fa)},[pt,Ke,kt,Ge,We,ct,bt,Qe,zt,U,Xe]),K(()=>{re(u===`none`?String(Xe)!==``:V?Array.isArray(H)&&H.length>0:H!=null)},[re,u,Xe,H,V]),X.useEffect(()=>{We&&Ke&&ct.length===0&&At({activeIndex:null})},[We,Ke,ct.length,At]);function Ut(){Qe&&tt!==``&&tt!==String(Ye)&&!Ct&&xe(!0)}function Wt(){Qe&&Se!==null&&Mt(!1)}let Gt=!1;function Kt(){!Gt&&Xe!==nt&&(Gt=!0,jt(nt,Y(fa)))}function qt(){u!==`none`&&(te(Ve),ne(lb(H,z.initialValue,A)),ce.change(H),He&&!Ue&&!xt&&Kt())}function Jt(){He&&!Ue&&!xt&&!be&&Kt()}function Yt(){u===`none`&&(te(Ve),ne(Xe!==z.initialValue),ce.change(Xe))}qb(tt,Ut),qb(Qe,Wt),qb(H,qt),qb(nt,Jt),qb(pe,Jt),qb(Xe,Yt);let G=Tc({open:bt?!0:Qe,onOpenChange:Pt,elements:{reference:xt?_t:vt,floating:ht}}),Xt=v?`grid`:`listbox`,Zt=Qe||bt,Qt=Zt?`true`:`false`,$t=X.useMemo(()=>{let e=vt?.tagName===`INPUT`,t=vt==null||e,n=t||Zt,r=t?{autoComplete:`off`,spellCheck:`false`,autoCorrect:`off`,autoCapitalize:`none`}:{};return n&&(r.role=`combobox`,r[`aria-expanded`]=Qt,r[`aria-haspopup`]=Xt,r[`aria-controls`]=Zt?gt?.id:void 0,r[`aria-autocomplete`]=h?`none`:I),{reference:r,floating:{role:`presentation`}}},[vt,Zt,Qt,Xt,gt?.id,I,h]),en=Ks(G,{enabled:!Be&&C,event:`mousedown-only`,toggle:!1,touchOpenDelay:xt?0:100,reason:ao}),tn=Ys(G,{enabled:!Be&&!bt,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:bt?!0:void 0,outsidePress(e){let t=ca(e);return!q(_t,t)&&!q(Pe.current,t)&&!q(Ne.current,t)&&!q(yt,t)}}),nn=qc(G,{enabled:!Be,id:ue,listRef:Te,activeIndex:pt,selectedIndex:mt,virtual:!0,loopFocus:D,allowEscape:D&&!Ke,focusItemOnOpen:be||u===`none`&&!Ke?!1:`auto`,focusItemOnHover:E,resetOnPointerLeave:!T,orientation:v?`horizontal`:void 0,rtl:le===`rtl`,disabledIndices:ya,grid:v?Jy:void 0,onNavigate(e,t){(t||Qe||bt&&e===null)&&Vt!==`ending`&&At({activeIndex:e,type:Yy(t),event:t?.nativeEvent})}}),rn=X.useMemo(()=>Ga(nn.reference,{onKeyDown(e){v&&U.state.activeIndex==null&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.preventBaseUIHandler()}},tn.reference,en.reference,$t.reference),[nn.reference,tn.reference,en.reference,$t.reference,v,U]),an=X.useMemo(()=>Ga(ec,tn.floating),[tn.floating]),on=X.useMemo(()=>Ga(nn.floating,$t.floating),[nn.floating,$t.floating]),sn=X.useMemo(()=>{let e=nn.item;return{props:e?{...e,onFocus:void 0}:jo,id:ue,selectionMode:u,disabled:Be,readOnly:h,isItemEqualToValue:A}},[nn.item,ue,u,Be,h,A]);U.useContextCallback(`setOpen`,Pt),U.useContextCallback(`setInputValue`,jt),U.useContextCallback(`setSelectedValue`,Ft),U.useContextCallback(`setIndices`,At),U.useContextCallback(`handleSelection`,It),U.useContextCallback(`forceMount`,Ot),U.useContextCallback(`requestSubmit`,Lt),U.useContextCallback(`onOpenChangeComplete`,n),qy(()=>{U.update({inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Et,itemRoot:sn})});let cn={id:ue,selectedValue:H,open:Qe,mounted:Bt,transitionStatus:Vt,items:he,inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Et,itemRoot:sn,openMethod:Tt,selectionMode:u,name:Ve,form:p,disabled:Be,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:_e,modal:P,autoHighlight:Ke,isItemEqualToValue:A,submitOnItemClick:ee,hasInputValue:Ue};K(()=>{U.update({...cn,inputOwnsFormValue:u===`none`&&(M||!U.state.inputInsidePopup)})},[U,...Object.values(cn)]);let ln=Zr(_,ce.inputRef),un=X.useMemo(()=>({query:tt,hasItems:We,filteredItems:st,flatFilteredValues:ct}),[tt,We,st,ct]),dn=X.useMemo(()=>Array.isArray(lt)?``:Sb(lt,k),[lt,k]),fn=V&&Array.isArray(H)&&H.length>0,pn=V||u===`none`&&St?void 0:Ve,mn=X.useMemo(()=>!V||!Array.isArray(H)||!Ve?null:H.map(e=>{let t=Sb(e,k);return(0,Z.jsx)(`input`,{type:`hidden`,form:p,name:Ve,value:t,disabled:Be},t)}),[V,H,p,Ve,k,Be]),hn=(0,Z.jsxs)(X.Fragment,{children:[e.children,(0,Z.jsx)(`input`,{...ce.getValidationProps(Be,{onFocus(){xt?_t?.focus():(Oe.current||_t)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||Be||h)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Y(fa,e.nativeEvent),i=()=>Re.current.findIndex(e=>Sb(e,k).toLowerCase()===n||ye(e).toLowerCase()===n);function a(){if(V)return;if(u===`none`){jt(t,r);return}let e=i();e===-1&&(e=Re.current.findIndex((e,t)=>{let r=Ee.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Re.current[e];a!=null&&Ft?.(a,r)}He&&(Ot(),pe&&i()===-1&&U.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:ue&&pn==null?`${ue}-hidden-input`:void 0,form:p,name:pn,autoComplete:L,disabled:Be,required:g&&!fn,readOnly:h,value:dn,ref:ln,style:pn?qr:Io,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),mn]});return(0,Z.jsx)(Xy.Provider,{value:U,children:(0,Z.jsx)(Zy.Provider,{value:G,children:(0,Z.jsx)($y.Provider,{value:We,children:(0,Z.jsx)(Qy.Provider,{value:un,children:(0,Z.jsx)(eb.Provider,{value:Xe,children:hn})})})})})}function ex(e){let{openOnInputClick:t=!1,value:n,defaultValue:r,onValueChange:i,mode:a=`list`,itemToStringValue:o,...s}=e,c=(a===`inline`||a===`both`)&&!e.readOnly,l=a===`inline`||a===`none`,u=n!==void 0,[d,f]=X.useState(r??``),[p,m]=X.useState(``);X.useEffect(()=>{(u||!c)&&m(``)},[n,u,c]);let h;h=c&&p!==``?p:u?n??``:d;let g=Gb({locale:s.locale}),_=String((u?n:d)??``).trim(),v=l||s.filter===null?null:s.filter??g.contains;function y(e,t){m(``),u||f(e),i?.(e,t)}function b(t,n){e.onItemHighlighted?.(t,n),n.reason!==`pointer`&&m(c&&t!=null?xb(t,o):``)}return(0,Z.jsx)($b,{...s,itemToStringLabel:o,openOnInputClick:t,selectionMode:`none`,fillInputOnItemPress:!0,filter:v,filterQuery:a===`both`?_:void 0,autoComplete:a,inputValue:h,defaultInputValue:r,onInputValueChange:y,onItemHighlighted:b})}var tx=`data-popup-side`,nx=`data-list-empty`,rx={...ss,...kb,popupSide:e=>e?{[tx]:e}:null,listEmpty:e=>e?{[nx]:``}:null};function ix(e,t,n){let{setFocused:r,focusOwnerRef:i}=Mb(),a=J(t=>{(t?!e:i.current===a)&&(i.current=t&&a,n?.(t),r(t))});return K(()=>{let e=t.current;return e?.getRootNode()?.activeElement===e&&a(!0),()=>a(!1)},[e,t,a]),a}var ax=5;function ox(e,t){let n=sx(t);return e.clientX>=n.left-ax&&e.clientX<=n.right+ax&&e.clientY>=n.top-ax&&e.clientY<=n.bottom+ax}function sx(e){let t=e.getBoundingClientRect(),n=Qi(e);if(aa)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function cx(e,t){return e??t}function lx(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function ux(){return rb().filteredItems.length===0}function dx(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function fx(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var px=X.forwardRef(function(e,t){let{render:n,className:r,nativeButton:i=!0,disabled:a=!1,id:o,style:s,...c}=e,{state:l,disabled:u,setTouched:d,validationMode:f,validation:p}=Mb(),{labelId:m}=Rb(),h=tb(),g=h.useState(`selectionMode`),_=h.useState(`disabled`),v=h.useState(`readOnly`),y=h.useState(`required`),b=h.useState(`positionerElement`),x=h.useState(`listElement`),S=h.useState(`popupId`),C=h.useState(`triggerProps`),w=h.useState(`inputInsidePopup`),T=h.useState(`id`),E=h.useState(`labelId`),D=h.useState(`open`),O=h.useState(`selectedValue`),k=h.useState(`activeIndex`),A=h.useState(`selectedIndex`),j=h.useState(`hasSelectedValue`),M=nb(),N=ib(),P=po(),F=u||_||a,I=ux(),L=lx(h),R=X.useRef(null),ee=ix(F,R);zb({id:w?o:void 0});let te=w?o??T:o,ne=cx(m,E),z;D&&w?z=S??Bb(T):D&&(z=x?.id);let re=X.useRef(``);function ie(e){re.current=e.pointerType}let{reference:B}=Jc(M,{enabled:!D&&!v&&!_&&g===`single`,listRef:h.context.labelsRef,activeIndex:k,selectedIndex:A,onMatch(e){let t=h.context.valuesRef.current[e];t!==void 0&&h.context.setSelectedValue(t,Y(fa))}}),{reference:ae}=Ks(M,{enabled:!_,event:`mousedown`}),{buttonRef:oe,getButtonProps:se}=Oo({native:i,disabled:F}),ce={...l,readOnly:v,open:D,disabled:F,popupSide:L,listEmpty:I,placeholder:g!==`none`&&!j},le=J(e=>{h.set(`triggerElement`,e)});return Eo(`button`,e,{ref:[t,oe,R,le],state:ce,props:[C,ae,B,{id:te,tabIndex:w?0:-1,role:w?`combobox`:void 0,"aria-expanded":D,"aria-haspopup":w?`dialog`:`listbox`,"aria-controls":z,"aria-required":w&&y||void 0,"aria-readonly":w&&v||void 0,"aria-labelledby":ne,onPointerDown:ie,onPointerEnter:ie,onFocus(){ee(!0),!F&&P.start(0,h.context.forceMount)},onBlur(e){if(!q(b,e.relatedTarget)&&(d(!0),ee(!1),f===`onBlur`)){let e=g===`none`?N:O;p.commit(e)}},onMouseDown(e){if(F||(w||M.set(`domReferenceElement`,e.currentTarget),h.context.forceMount(),re.current!==`touch`&&(h.context.inputRef.current?.focus(),w||e.preventDefault()),D))return;let t=ri(e.currentTarget);function n(e){let t=h.state.triggerElement;if(!t)return;let n=ca(e),r=h.state.positionerElement,i=h.state.listElement;q(t,n)||q(r,n)||q(i,n)||ox(e,t)||h.context.setOpen(!1,Y(ha,e))}w&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(ti(e),h.context.setOpen(!0,Y(Na,e.nativeEvent)),h.context.inputRef.current?.focus())}},p.getValidationProps(F,c),se],stateAttributesMapping:rx})}),mx=X.createContext(void 0);function hx(){return X.useContext(mx)}var gx=X.createContext(void 0);function _x(e){let t=X.useContext(gx);if(t===void 0&&!e)throw Error(ji(21));return t}var vx=X.forwardRef(function(e,t){let n=tb(),{buttonRef:r,getButtonProps:i}=Oo({native:!1}),a=Zr(t,r);function o(e){n.context.setOpen(!1,Y(ho,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Z.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:qr})}),yx=X.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,id:a,style:o,...s}=e,{state:c,disabled:l,setTouched:u,validationMode:d,validation:f}=Mb(),{labelId:p}=Rb(),m=hx(),h=!!_x(!0),g=tb(),_=ib(),v=cu(),y=g.useState(`required`),b=g.useState(`disabled`),x=g.useState(`readOnly`),S=g.useState(`name`),C=g.useState(`form`),w=g.useState(`selectionMode`),T=g.useState(`autoHighlight`),E=g.useState(`inputProps`),D=g.useState(`triggerProps`),O=g.useState(`open`),k=g.useState(`mounted`),A=g.useState(`selectedValue`),j=g.useState(`id`),M=g.useState(`inline`),N=g.useState(`modal`),P=!!T,F=lx(g),I=l||b||i,L=ux(),R=ix(I,g.context.inputRef),ee=h||M,te=!ee||N,ne=Ib(a??(ee?void 0:j)),z=h?Db:c,[re,ie]=X.useState(null),B=X.useRef(!1),ae=X.useRef(null);K(()=>{O||(ae.current=null)},[O]);let oe=w===`none`&&!h,se=J(e=>{let t=h||g.state.inline;t&&!g.state.hasInputValue&&g.context.setInputValue(``,Y(fa)),g.update({inputElement:e,inputInsidePopup:t,inputOwnsFormValue:oe})}),ce=h?s:f.getValidationProps(I,s);function le(e){g.context.setIndices({activeIndex:null,selectedIndex:null,type:Yy(e),event:e})}let ue={...z,open:O,disabled:I,readOnly:x,popupSide:F,listEmpty:L};function de(e){if(!m)return;let t,n=m.chipsRef.current.length,[r]=dx(v);return e.key===r&&(e.currentTarget.selectionStart??0)===0&&A.length>0&&(e.preventDefault(),t=n>0?n-1:void 0),t}let fe=Eo(`input`,e,{state:ue,ref:[t,g.context.inputRef,se],props:[E,D,{value:re??_,"aria-readonly":x||void 0,"aria-required":y||void 0,"aria-labelledby":p,disabled:I,readOnly:x,required:w===`none`?y:void 0,form:C,...oe&&S&&{name:S},id:ne,onFocus(){if(R(!0),!M)return;let e=ae.current;ae.current=null,e!=null&&Object.hasOwn(g.context.valuesRef.current,e)&&g.context.setIndices({activeIndex:e})},onBlur(){u(!0),R(!1);let e=g.state.activeIndex;if(M&&e!==null&&T!==`always`&&(ae.current=e,g.context.setIndices({activeIndex:null})),d===`onBlur`){let e=w===`none`?_:A;f.commit(e)}},onCompositionStart(e){Wr||(B.current=!0,ie(e.currentTarget.value))},onCompositionEnd(e){B.current=!1;let t=e.currentTarget.value;ie(null),g.context.setInputValue(t,Y(wa,e.nativeEvent))},onChange(e){let t=e.nativeEvent,n=t.inputType,r=!n||n===`insertReplacementText`,i=B.current||!r;function a(e){!x&&!I&&e&&i&&(g.context.setOpen(!0,Y(wa,t)),P||le(t))}if(B.current){let n=e.currentTarget.value;ie(n),n===``&&!g.state.openOnInputClick&&!g.state.inputInsidePopup&&g.context.setOpen(!1,Y(Aa,t));let r=n.trim(),i=P&&r!==``;a(r),O&&g.state.activeIndex!==null&&!i&&le(t);return}let o=Y(wa,t);if(g.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Y(Aa,t);s&&!g.state.inputInsidePopup&&(w===`single`&&g.context.setSelectedValue(null,c),g.state.openOnInputClick||g.context.setOpen(!1,c)),a(e.currentTarget.value.trim()),O&&g.state.activeIndex!==null&&!P&&le(t)},onKeyDown(e){if(e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)return;if(I||x){x&&e.key===`Enter`&&O&&g.state.activeIndex!==null&&ti(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=v===`rtl`;if(e.key===`Home`){ti(e);let n=da&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){ti(e);let i=da&&r?0:t.value.length;t.setSelectionRange(i,i),t.scrollLeft=r?-n:n;return}if(!k&&e.key===`Escape`){let t=w===`multiple`&&Array.isArray(A)?A.length===0:A===null,n=Y(xa,e.nativeEvent),r=w===`multiple`?[]:null;g.context.setInputValue(``,n),g.context.setSelectedValue(r,n),t||g.state.inline||n.isPropagationAllowed||e.stopPropagation();return}if(m&&e.key===`Backspace`&&t.value===``&&Array.isArray(A)&&A.length>0){let t=m.chipsRef.current.length,n=t>0?t-1:A.length-1,r=A.filter((e,t)=>t!==n);le(e.nativeEvent),g.context.setSelectedValue(r,Y(fa,e.nativeEvent));return}let i=de(e);if(i!==void 0&&m?.chipsRef.current[i]?.focus(),e.which!==229&&e.key===`Enter`&&O){let t=g.state.activeIndex,n=e.nativeEvent;if(t===null){if(M)return;g.context.setOpen(!1,Y(fa,n));return}ti(e),fx(g,t,n)}}},ce],stateAttributesMapping:rx}),pe=h?(0,Z.jsx)(jb.Provider,{value:Ab,children:fe}):fe;return(0,Z.jsxs)(X.Fragment,{children:[O&&te&&(0,Z.jsx)(vx,{ref:g.context.startDismissRef}),pe]})}),bx={...Vi,...os},xx=X.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,nativeButton:a=!0,keepMounted:o=!1,style:s,...c}=e,{disabled:l}=Mb(),u=tb(),d=u.useState(`selectionMode`),f=u.useState(`disabled`),p=u.useState(`readOnly`),m=u.useState(`open`),h=u.useState(`selectedValue`),g=u.useState(`hasSelectionChips`),_=ib(),v=!1;v=d===`none`?_!==``:d===`single`?h!=null:g;let y=l||f||i,{buttonRef:b,getButtonProps:x}=Oo({native:a,disabled:y}),{mounted:S,transitionStatus:C,setMounted:w}=Zs(v),T={disabled:y,visible:v,open:m,transitionStatus:C};Ti({open:v,ref:u.context.clearRef,onComplete(){v||w(!1)}});let E=Eo(`button`,e,{state:T,ref:[t,b,u.context.clearRef],props:[{tabIndex:-1,children:`x`,onMouseDown(e){e.preventDefault()},onClick(e){if(y||p)return;let t=Yy(e);u.context.setInputValue(``,Y(no,e.nativeEvent)),d===`none`?u.context.setIndices({activeIndex:null,type:t,event:e.nativeEvent}):(u.context.setSelectedValue(Array.isArray(h)?[]:null,Y(no,e.nativeEvent)),u.context.setIndices({activeIndex:null,selectedIndex:null,type:t,event:e.nativeEvent})),u.context.inputRef.current?.focus()}},c,x],stateAttributesMapping:bx});return o||S?E:null}),Sx=X.createContext(null);function Cx(){return X.useContext(Sx)}function wx(e){let{children:t}=e,{filteredItems:n}=rb(),r=Cx(),i=r?r.items:n;return(0,Z.jsx)(X.Fragment,{children:i.map(t)})}var Tx=X.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Ex(){return X.useContext(Tx)}function Dx(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=J(i),[,o]=X.useState(0),s=Ei(kx).current,c=Ei(Ox).current,l=X.useRef(0),u=X.useRef(!0),d=X.useRef(null),f=X.useRef(null),p=J(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=J((e,t)=>{c.set(e,t),p()}),h=J(e=>{c.delete(e),p()}),g=J(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Mx(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Nx(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=jx(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=J(()=>{let[e,t]=Ax(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});K(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),K(()=>{u.current&&v()}),K(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=J(e=>(s.add(e),()=>{s.delete(e)})),b=X.useMemo(()=>({register:m,unregister:h,subscribeMapChange:y,nextIndexRef:l}),[m,h,y,l]);return(0,Z.jsx)(Tx.Provider,{value:b,children:t})}function Ox(){return new Map}function kx(){return new Set}function Ax(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>Nx(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function jx(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Mx(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function Nx(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Px=X.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=tb(),l=nb(),u=!!_x(!0),{filteredItems:d,hasItems:f}=rb(),p=c.useState(`selectionMode`),m=c.useState(`grid`),h=c.useState(`readOnly`),g=c.useState(`listProps`),_=c.useState(`virtualized`),v=c.useState(`forceMounted`),y=p===`multiple`,b=d.length===0,x=J(e=>{c.set(`positionerElement`,e)}),S=J(e=>{c.set(`listElement`,e)}),C=X.useMemo(()=>typeof o==`function`?n||=(0,Z.jsx)(wx,{children:o}):o,[o]),w={empty:b},T=l.useState(`floatingId`),E=Eo(`div`,e,{state:w,ref:[t,S,u?null:x],props:[g,{children:C,tabIndex:-1,id:T,role:m?`grid`:`listbox`,"aria-multiselectable":y?`true`:void 0,"aria-readonly":!m&&h?!0:void 0,onKeyDown(e){if(!(c.state.disabled||c.state.readOnly)&&e.key===`Enter`){let t=c.state.activeIndex;if(t==null)return;ti(e),fx(c,t,e.nativeEvent)}}},s]});if(_)return E;let D=f&&!v?void 0:c.context.labelsRef;return(0,Z.jsx)(Dx,{elementsRef:c.context.listRef,labelsRef:D,children:E})}),Fx=X.createContext(void 0);function Ix(){let e=X.useContext(Fx);if(e===void 0)throw Error(ji(20));return e}var Lx=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=tb(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Z.jsx)(Fx.Provider,{value:n,children:(0,Z.jsx)($a,{ref:t,...r})}):null}),Rx=X.forwardRef(function(e,t){let{cutout:n,...r}=e,i;if(n){let e=n.getBoundingClientRect();i=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${e.left}px ${e.top}px,${e.left}px ${e.bottom}px,${e.right}px ${e.bottom}px,${e.right}px ${e.top}px,${e.left}px ${e.top}px)`}return(0,Z.jsx)(`div`,{ref:t,role:`presentation`,"data-base-ui-inert":``,...r,style:{position:`fixed`,inset:0,userSelect:`none`,WebkitUserSelect:`none`,clipPath:i}})}),zx={},Bx={},Vx=``;function Hx(e,t){return bi(e)?e:t}function Ux(e,t,n){return/hidden|clip/.test(e.getComputedStyle(Hx(t,n)).overflowY)}function Wx(e){if(typeof document>`u`)return!1;let t=ri(e);return Qi(t).innerWidth-t.documentElement.clientWidth>0}function Gx(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=ri(e),n=t.documentElement,r=t.body,i=Hx(n,r),a=i.style.overflowY,o=n.style.scrollbarGutter;n.style.scrollbarGutter=`stable`,i.style.overflowY=`scroll`;let s=i.offsetWidth;i.style.overflowY=`hidden`;let c=i.offsetWidth;return i.style.overflowY=a,n.style.scrollbarGutter=o,s===c}function Kx(e){let t=ri(e),n=t.documentElement,r=t.body,i=Hx(n,r),a={overflowY:i.style.overflowY,overflowX:i.style.overflowX};return Object.assign(i.style,{overflowY:`hidden`,overflowX:`hidden`}),()=>{Object.assign(i.style,a)}}function qx(e){let t=ri(e),n=t.documentElement,r=t.body,i=Qi(n),a=0,o=0,s=!1,c=ai.create();if(Ri&&(i.visualViewport?.scale??1)!==1)return()=>{};function l(){let t=i.getComputedStyle(n),c=i.getComputedStyle(r),l=(t.scrollbarGutter||``).includes(`both-edges`)?`stable both-edges`:`stable`;a=n.scrollTop,o=n.scrollLeft,zx={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Vx=n.style.scrollBehavior,Bx={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};let u=n.scrollHeight>n.clientHeight,d=n.scrollWidth>n.clientWidth,f=t.overflowY===`scroll`||c.overflowY===`scroll`,p=t.overflowX===`scroll`||c.overflowX===`scroll`,m=Math.max(0,i.innerWidth-r.clientWidth),h=Math.max(0,i.innerHeight-r.clientHeight),g=parseFloat(c.marginTop)+parseFloat(c.marginBottom),_=parseFloat(c.marginLeft)+parseFloat(c.marginRight),v=Hx(n,r);s=Gx(e),s?(n.style.scrollbarGutter=l,v.style.overflowY=`hidden`,v.style.overflowX=`hidden`):(Object.assign(n.style,{scrollbarGutter:l,overflowY:`hidden`,overflowX:`hidden`}),(u||f)&&(n.style.overflowY=`scroll`),(d||p)&&(n.style.overflowX=`scroll`),Object.assign(r.style,{position:`relative`,height:g||h?`calc(100dvh - ${g+h}px)`:`100dvh`,width:_||m?`calc(100vw - ${_+m}px)`:`100vw`,boxSizing:`border-box`,overflowY:`hidden`,overflowX:`hidden`,scrollBehavior:`unset`}),r.scrollTop=a,r.scrollLeft=o,n.setAttribute(`data-base-ui-scroll-locked`,``),n.style.scrollBehavior=`unset`)}function u(){Object.assign(n.style,zx),Object.assign(r.style,Bx),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=Vx)}function d(){u(),c.request(l)}l();let f=di(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var Jx=new class{lockCount=0;restore=null;timeoutLock=eo.create();timeoutUnlock=eo.create();acquire(e){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(e)),this.release}release=()=>{--this.lockCount,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(e){if(this.lockCount===0||this.restore!==null)return;let t=ri(e),n=t.documentElement,r=t.body,i=Qi(n);if(Ux(i,n,r)){let t=new i.MutationObserver(()=>{Ux(i,n,r)||(t.disconnect(),this.restore=null,this.lock(e))}),a={attributes:!0};t.observe(n,a),t.observe(r,a),this.restore=()=>t.disconnect();return}let a=Da||!Wx(e);this.restore=a?Kx(e):qx(e)}};function Yx(e=!0,t=null){K(()=>{if(e)return Jx.acquire(t)},[e,t])}var Xx=20;function Zx(e,t,n,r){let[i,a]=X.useState(!1);K(()=>{if(!e||!t||n==null){a(!1);return}let r=ri(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-Xx)},[e,t,n]),Yx(e&&(!t||i),r)}var Qx=X.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a,side:o,align:s,sideOffset:c,alignOffset:l,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d,arrowPadding:f,sticky:p,disableAnchorTracking:m=!1,collisionAvoidance:h=Gr,style:g,..._}=e,v=tb(),y=nb(),b=Ix(),x=v.useState(`modal`),S=v.useState(`open`),C=v.useState(`mounted`),w=v.useState(`openMethod`),T=v.useState(`positionerElement`),E=v.useState(`triggerElement`),D=v.useState(`inputElement`),O=v.useState(`inputGroupElement`),k=v.useState(`inputInsidePopup`),A=v.useState(`transitionStatus`),j=ux(),M=Su({anchor:i??(k?E:O??D),floatingRootContext:y,positionMethod:a,mounted:C,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m,keepMounted:b,collisionAvoidance:h,lazyFlip:!0});Zx(S&&x,w===`touch`,T,E);let N={open:S,side:M.side,align:M.align,anchorHidden:M.anchorHidden,empty:j};K(()=>{v.set(`popupSide`,M.side)},[v,M.side]);let P=J(e=>{v.set(`positionerElement`,e)}),F=Eu(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Z.jsxs)(gx.Provider,{value:M,children:[C&&x&&(0,Z.jsx)(Rx,{inert:Si(!S),cutout:O??D??E}),F]})}),$x={...cs,...Vi},eS=X.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=tb(),l=_x(),u=nb(),d=c.useState(`mounted`),f=c.useState(`open`),p=c.useState(`openMethod`),m=c.useState(`popupProps`),h=c.useState(`transitionStatus`),g=c.useState(`inputInsidePopup`),_=c.useState(`inputElement`),v=c.useState(`modal`),y=c.useState(`id`),b=ux(),x=s.id??(g?Bb(y):void 0);K(()=>(c.set(`popupId`,c.context.popupRef.current?.id||x),()=>{c.set(`popupId`,void 0)}),[c,x]),Ti({open:f,ref:c.context.popupRef,onComplete(){f&&c.context.onOpenChangeComplete(!0)}});let S={open:f,side:l.side,align:l.align,anchorHidden:l.anchorHidden,transitionStatus:h,empty:b},C=Eo(`div`,e,{state:S,ref:[t,c.context.popupRef],props:[m,{id:x,role:g?`dialog`:`presentation`,onFocus(e){let t=ca(e.nativeEvent);p!==`touch`&&(q(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},Tu(h),s],stateAttributesMapping:$x}),w=a===void 0?g?e=>e===`touch`?c.context.popupRef.current:_:!1:a,T;T=o??(g?void 0:!1);let E=!g||v;return(0,Z.jsx)(Gs,{context:u,disabled:!d,modal:E,openInteractionType:p,initialFocus:w,returnFocus:T,getInsideElements:()=>[c.context.startDismissRef.current,c.context.endDismissRef.current],children:(0,Z.jsxs)(X.Fragment,{children:[C,E&&(0,Z.jsx)(vx,{ref:c.context.endDismissRef})]})})});function tS(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Ex(),u=X.useRef(-1),[d,f]=X.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=X.useRef(null),h=X.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return K(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var nS=X.createContext(void 0);function rS(){let e=X.useContext(nS);if(!e)throw Error(ji(19));return e}var iS=X.createContext(!1);function aS(){return X.useContext(iS)}function oS(e){let{componentProps:t,forwardedRef:n,virtualized:r,indexFromFilter:i}=e,{render:a,className:o,style:s,value:c=null,index:l,disabled:u=!1,nativeButton:d=!1,...f}=t,p=X.useRef(null),m=tS({guess:!0,index:l,textRef:p}),h=tb(),g=aS(),_=ab(),{props:v,id:y,selectionMode:b,disabled:x,readOnly:S,isItemEqualToValue:C}=h.useState(`itemRoot`),w=x||u,T=b!==`none`,E=l??i??m.index,D=E!==-1,O=h.useState(`isActive`,E),k=h.useState(`isSelected`,c),A=X.useRef(null),j=y!=null&&D?`${y}-${E}`:void 0,M=k&&T;K(()=>{if(!D||!r&&l==null)return;let e=h.context.listRef.current;return e[E]=A.current,()=>{delete e[E]}},[D,r,E,l,h]),K(()=>{if(!D||_)return;let e=h.context.valuesRef.current;return e[E]=c,()=>{delete e[E]}},[D,_,E,c,h]),K(()=>{if(!D||_)return;let e=h.state.selectedValue,t=h.state.selectedIndex;h.state.selectionMode===`multiple`&&Array.isArray(e)?t=mb(E,c,h.context.valuesRef.current,e,C,t):cb(c,e,C)&&(t=E),h.set(`selectedIndex`,t)},[D,_,h,E,c,C]);let{getButtonProps:N,buttonRef:P}=Oo({disabled:w,focusableWhenDisabled:!0,native:d,composite:!0}),F={disabled:w,selected:M,highlighted:O};function I(e){function t(){h.context.handleSelection(e,c)}h.state.submitOnItemClick?($s.flushSync(t),h.context.requestSubmit()):t()}let L={id:j,role:g?`gridcell`:`option`,"aria-selected":T?M:void 0,tabIndex:void 0,onPointerDownCapture(e){e.isPrimary&&(h.context.pointerDownItemRef.current=e.currentTarget),e.preventDefault()},onMouseDown(e){e.preventDefault()},onClick(e){w||S||I(e.nativeEvent)},onMouseUp(e){let t=h.context.pointerDownItemRef.current===e.currentTarget;h.context.pointerDownItemRef.current=null,!(w||S||e.button!==0||t||!O)&&I(e.nativeEvent)}},R=Eo(`div`,t,{ref:[P,n,m.ref,A],state:F,props:[v,L,f,N]}),ee=X.useMemo(()=>({selected:M,textRef:p}),[M,p]);return(0,Z.jsx)(nS.Provider,{value:ee,children:R})}function sS(e){let{componentProps:t,forwardedRef:n}=e,r=tb().useState(`isItemEqualToValue`),{flatFilteredValues:i}=rb(),a=db(i,t.value??null,r);return(0,Z.jsx)(oS,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var cS=X.memo(X.forwardRef(function(e,t){let n=tb().useState(`virtualized`);return n&&e.index==null?(0,Z.jsx)(sS,{componentProps:e,forwardedRef:t}):(0,Z.jsx)(oS,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),lS=X.createContext(void 0);function uS(){let e=X.useContext(lS);if(e===void 0)throw Error(ji(13));return e}var dS={imageLoadingStatus:()=>null},fS=X.forwardRef(function(e,t){let{className:n,render:r,style:i,...a}=e,[o,s]=X.useState(`idle`),c={imageLoadingStatus:o},l=X.useMemo(()=>({imageLoadingStatus:o,setImageLoadingStatus:s}),[o,s]),u=Eo(`span`,e,{state:c,ref:t,props:a,stateAttributesMapping:dS});return(0,Z.jsx)(lS.Provider,{value:l,children:u})});function pS(e,{referrerPolicy:t,crossOrigin:n,sizes:r,srcSet:i},a){let o=X.useState(`idle`),s=o[1];return K(()=>{if(!a)return Ui;if(!e&&!i)return s(`error`),Ui;let o=!0,c=new window.Image,l=e=>()=>{o&&s(e)};return s(`loading`),c.onload=l(`loaded`),c.onerror=l(`error`),t&&(c.referrerPolicy=t),c.crossOrigin=n??null,r&&(c.sizes=r),i&&(c.srcset=i),e&&(c.src=e),c.complete&&s(c.naturalWidth>0?`loaded`:`error`),()=>{o=!1}},[a,e,i,r,n,t,s]),o}var mS={...dS,...Vi},hS=X.forwardRef(function(e,t){let{className:n,render:r,onLoadingStatusChange:i,keepMounted:a=!1,style:o,sizes:s,srcSet:c,src:l,...u}=e,{setImageLoadingStatus:d}=uS(),[f,p]=pS(l,e,!a),m=f===`loaded`,{mounted:h,transitionStatus:g,setMounted:_}=Zs(m),v=X.useRef(null),y=X.useRef(!0);K(()=>{if(!a)return;let e=y.current;y.current=!1;let t=v.current;if(!t)return;if(!t.complete){p(`loading`);return}let n=t.naturalWidth>0?`loaded`:`error`;p(n),n===`loaded`&&e&&_(!0)},[a,l,c,s,u.crossOrigin,u.referrerPolicy,r,p,_]);let b=a?{"data-loading":f===`loading`?``:void 0,"data-error":f===`error`?``:void 0,"aria-hidden":f!==`loaded`||void 0,onLoad(){p(`loaded`)},onError(){p(`error`)}}:void 0,x=J(e=>{i?.(e),d(e)});K(()=>{f!==`idle`&&x(f)},[f,x]),K(()=>()=>d(`idle`),[d]),Ti({enabled:!m,open:m,ref:v,onComplete(){m||_(!1)}});let S={imageLoadingStatus:f,transitionStatus:a&&g===`ending`?void 0:g},C=a||h,w={};s!==void 0&&(w.sizes=s),c!==void 0&&(w.srcSet=c),l!==void 0&&(w.src=l);let T=Eo(`img`,e,{state:S,ref:[t,v],props:[b,u,w],stateAttributesMapping:mS,enabled:C});return C?T:null}),gS=X.forwardRef(function(e,t){let{className:n,render:r,delay:i=0,style:a,...o}=e,{imageLoadingStatus:s}=uS(),[c,l]=X.useState(i===0),u=po();return X.useEffect(()=>(i>0?u.start(i,()=>l(!0)):l(!0),u.clear),[u,i]),Eo(`span`,e,{state:{imageLoadingStatus:s},ref:t,props:o,stateAttributesMapping:dS,enabled:s!==`loaded`&&(i===0||c)})}),$=r();function _S(e){let t=(0,$.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,size:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`default`:i,o;t[4]===n?o=t[5]:(o=ua(`group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten`,n),t[4]=n,t[5]=o);let s;return t[6]!==r||t[7]!==a||t[8]!==o?(s=(0,Z.jsx)(fS,{"data-slot":`avatar`,"data-size":a,className:o,...r}),t[6]=r,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function vS(e){let t=(0,$.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=ua(`aspect-square size-full rounded-full object-cover`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(hS,{"data-slot":`avatar-image`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function yS(e){let t=(0,$.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=ua(`flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(gS,{"data-slot":`avatar-fallback`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function bS(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Ky({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=Zs(a,!0,!0),u=Ib(),[d,f]=X.useState(),p=d===null?void 0:d??u,m=J(e=>{let t=!a,n=Y(Xr,e.nativeEvent);r(t,n),!n.isCanceled&&o(t)});return X.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:m,mounted:s,open:a,panelId:p,setMounted:c,setOpen:o,setPanelIdState:f,transitionStatus:l}),[u,i,m,s,a,p,c,o,f,l])}var xS=X.createContext(void 0);function SS(){let e=X.useContext(xS);if(e===void 0)throw Error(ji(15));return e}var CS=`data-open`,wS=`data-closed`,TS=Yr,ES=`data-panel-open`,DS={[CS]:``},OS={[wS]:``},kS={open(e){return e?{[ES]:``}:null}},AS={open(e){return e?DS:OS},...Vi},jS=X.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=J(o),d=bS({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=X.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=X.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=Eo(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:AS});return(0,Z.jsx)(xS.Provider,{value:p,children:m})}),MS={...kS,...Vi},NS=X.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=SS(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Oo({disabled:c,native:u});return Eo(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:MS})}),PS={height:void 0,width:void 0};function FS(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:u}=e,d=X.useRef(null),f=X.useRef(null),[p,m]=X.useState(PS),h=X.useRef(PS),g=X.useRef(!1),_=X.useRef(s),v=X.useRef(!1),[y,b]=X.useState(!1),x=X.useRef(null),S=Zr(t,d),C=ps(s),w=Oi(d),T=!s&&!a,E=y?`idle`:u,D=s&&(_.current||v.current),O=!s&&a&&f.current===`css-animation`&&p.height===void 0&&p.width===void 0?h.current:p,k=n&&T&&f.current!==`css-animation`,A=J((e,t=!0)=>{t&&(h.current=e),m(e)}),j=J(()=>{x.current?.(),x.current=null}),M=J(e=>{j(),x.current=()=>{x.current=null,e()}}),N=J(()=>{s&&a&&f.current===`css-animation`&&(v.current=!0)});K(()=>{y&&u!==`starting`&&b(!1)},[y,u]),X.useEffect(()=>()=>{N(),j()},[N,j]),K(()=>{s||(_.current=!1,v.current=!1);let e=d.current;if(!e)return;!s&&x.current&&j();let t=LS(e,D);if(f.current=t,s&&u===`idle`&&_.current&&t===`css-animation`){h.current=IS(e);return}if(s&&u===`starting`){let n=g.current;if(g.current=!1,t===`none`){A(IS(e)),b(!0);return}if(t===`css-transition`){let t=BS(e);if(A(IS(e)),!n)return t;let r=zS(e,`transition-duration`,`0s`);return M(r),b(!0),t}A(IS(e));let r=zS(e,`animation-name`,`none`);if(!n){r();return}let i=zS(e,`animation-duration`,`0s`);r(),M(i),b(!0);return}if(!s&&a&&(u===`idle`||u===`starting`)){if(t===`none`){A(PS,!1),c(!1);return}A(IS(e));return}if(u!==`ending`)return;if(t===`none`){c(!1);return}let n=IS(e);n.height>0||n.width>0?(A(n),t===`css-animation`&&zS(e,`animation-name`,`none`)()):c(!1)},[a,s,j,A,c,M,D,u]),Ti({enabled:s&&a&&E===`idle`,open:!0,ref:d,onComplete(){s&&A(PS,!1)}}),X.useEffect(()=>{if(s||!a||E!==`ending`)return;if(!d.current){c(!1),A(PS,!1);return}let e=new AbortController,t=-1;function n(){C.current||(c(!1),A(PS,!1))}return t=ai.request(()=>{w(n,e.signal)}),()=>{ai.cancel(t),e.abort()}},[C,a,s,E,w,A,c]),K(()=>{let e=d.current;e&&n&&T&&e.setAttribute(`hidden`,`until-found`)},[T,n]),X.useEffect(function(){let e=d.current;if(!e)return;let t=eo.create(),n=-1,r=(r,i)=>{t.start(0,()=>{C.current||(n=ai.request(()=>{C.current||(r&&(g.current=!1),i&&e.setAttribute(TS,``),e.setAttribute(`hidden`,`until-found`))}))})},i=di(e,`beforematch`,t=>{let n=Y(fa,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}g.current=!0;let i=e.hasAttribute(TS);e.removeAttribute(TS),l(!0),r(!0,i)});return()=>{t.clear(),ai.cancel(n),i()}},[C,o,l]);let P=i||n||a||s;return{height:O.height,props:{...k?{[TS]:``}:void 0,hidden:T,id:r},ref:S,shouldPreventOpenAnimation:D,shouldRender:P,transitionStatus:E,width:O.width}}function IS(e){return{height:e.scrollHeight,width:e.scrollWidth}}function LS(e,t){let n=Qi(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&RS(n.animationDuration),i=RS(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function RS(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function zS(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{r===``?e.style.removeProperty(t):e.style.setProperty(t,r,i)}}function BS(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{n===``?e.style.removeProperty(t):e.style.setProperty(t,n)})}let r=ai.request(n);return()=>{ai.cancel(r),n()}}var VS=`--collapsible-panel-height`,HS=`--collapsible-panel-width`,US=X.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=SS(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;K(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=FS({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=Po(s,k),j=Eo(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[VS]:S===void 0?`auto`:`${S}px`,[HS]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:AS});return E?j:null}),WS=X.memo(X.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a,selected:o,...s}=e,c=X.useRef(null),{transitionStatus:l,setMounted:u}=Zs(o),d=Eo(`span`,e,{ref:[t,c],state:{selected:o,transitionStatus:l},props:[{"aria-hidden":!0,children:`✔️`},s],stateAttributesMapping:Vi});return Ti({batch:!0,enabled:!o,open:o,ref:c,onComplete(){o||u(!1)}}),d})),GS=X.forwardRef(function(e,t){let{selected:n}=rS();return e.keepMounted||n?(0,Z.jsx)(WS,{...e,selected:n,ref:t}):null}),KS=X.createContext(void 0);function qS(e=!0){let t=X.useContext(KS);if(t===void 0&&!e)throw Error(ji(25));return t}var JS=X.createContext(void 0);function YS(e){let t=X.useContext(JS);if(t===void 0&&!e)throw Error(ji(33));return t}var XS=X.createContext(void 0);function ZS(e){let t=X.useContext(XS);if(t===void 0&&!e)throw Error(ji(36));return t}var QS=X.createContext(null);function $S(e=`root`){let t=X.useContext(QS),n=X.useContext(XS);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var eC={visible:!0,ref:null};function tC(){return eC}function nC(e,t,n=`root`){let r=$S(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??tC)({label:e.label,children:e.children,render:e.render}),a=Zr(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function rC(e){e.preventDefault()}function iC(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=ZS(),u=qS(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return X.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?rC:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:Xa})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!yo&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&Ki(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var aC={type:`regular-item`};function oC(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=X.useRef(null),{getButtonProps:d,buttonRef:f}=Oo({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=iC({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=X.useCallback(e=>Ga(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Zr(u,f);return X.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var sC=X.createContext(void 0);function cC(){let e=X.useContext(sC);if(e===void 0)throw Error(ji(31));return e}var lC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=X.useState(void 0),c=Eo(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,Z.jsx)(sC.Provider,{value:s,children:c})}),uC=X.forwardRef(function(e,t){let n=$S()?.Group??lC;return(0,Z.jsx)(n,{...e,ref:t})}),dC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Ib(a),c=cC();return K(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),Eo(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),fC=X.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=ZS(),f=tS({guess:!0,label:a}),p=Ib(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=oC({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:aC});return Eo(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),pC=X.forwardRef(function(e,t){let n=nC(e,t);return n.visible?(0,Z.jsx)(fC,{...e,ref:n.ref}):null}),mC=X.createContext(void 0);function hC(e){let t=X.useContext(mC);if(t===void 0&&!e)throw Error(ji(69));return t}var gC=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),_C=X.createContext(void 0);function vC(){return X.useContext(_C)}function yC(e,t){let n=pa(e.render);if(X.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function bC(e,t,n){let r=yC(e,t),i=r===t?void 0:r;return[r,X.useCallback(e=>n?.(e?i:void 0),[i,n])]}function xC(e,t,n){let r=pa(e.render),i=X.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var SC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=ZS(),m=vC(),{side:h,align:g}=YS(),_=hC(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),S=l.useState(`instantType`),C=l.useState(`activeTriggerElement`),w=l.useState(`parent`),T=l.useState(`lastOpenChangeReason`),E=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),k=l.useState(`closeDelay`),A=l.useState(`hoverEnabled`),j=l.useState(`disabled`),M=l.useState(`openMethod`),N=l.useState(`activeTriggerId`),P=l.useState(`listElement`),[F,I]=bC(e,u,d),L=xC(e,C,N),R=w.type===`menu`?m:void 0,ee=w.type===`context-menu`,te=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(te=()=>l.state.activeIndex===null&&P),Ti({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),X.useEffect(()=>{function e(e){l.setOpen(!1,Y(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),Rc(D,{enabled:A&&!j&&!ee&&w.type!==`menubar`,closeDelay:k});let ne=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:z,handleFocus:re}=(X.useContext(QS)?.useParentHandoff??wC)(l,w,v,f),ie={transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},B=Eo(`div`,e,{state:ie,ref:[t,l.context.popupRef,ne,I],stateAttributesMapping:ls,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&gC.has(e.key)&&e.stopPropagation()},onFocus:re},Tu(y),c,{"data-rootownerid":E}]}),ae=w.type===void 0||ee;(C||w.type===`menubar`&&T!==`outside-press`)&&(ae=!0);let oe=R?.getReturnElement??z;return(0,Z.jsx)(Gs,{context:D,openInteractionType:M,modal:ee,disabled:!x,returnFocus:a??oe??ae,explicitReturnFocus:a===void 0&&oe?!1:void 0,initialFocus:te,restoreFocus:!0,getInsideElements:w.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:w.type===`menubar`?void 0:O,previousFocusableElement:C,nextFocusableElement:w.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:B})}),CC={parentVirtualFocusRef:void 0,handleFocus:void 0};function wC(){return CC}var TC=X.forwardRef(function(e,t){let n=$S()?.Popup??SC;return(0,Z.jsx)(n,{...e,ref:t})}),EC=X.createContext(void 0);function DC(){let e=X.useContext(EC);if(e===void 0)throw Error(ji(32));return e}var OC=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=ZS();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Z.jsx)(EC.Provider,{value:n,children:(0,Z.jsx)($a,{ref:t,...r,portalOwnerRole:o})})});function kC(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=X.useRef(null),o=X.useRef(null),s=Oi(r);K(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),K(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}var AC=X.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=Gr,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=ZS(),x=DC(),S=qS(!0),C=v.useState(`parent`),w=v.useState(`floatingRootContext`),T=v.useState(`floatingTreeRoot`),E=v.useState(`mounted`),D=v.useState(`open`),O=v.useState(`modal`),k=v.useState(`openMethod`),A=v.useState(`activeTriggerElement`),j=v.useState(`transitionStatus`),M=v.useState(`positionerElement`),N=v.useState(`instantType`),P=v.useState(`adaptiveOrigin`),F=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),L=v.useState(`floatingParentNodeId`),R=w.useState(`domReferenceElement`),ee=n,te=c,ne=l,z=s,re=h;C.type===`context-menu`&&(ee=n??C.context?.anchor,z??=`start`,!o&&z!==`center`&&(ne=e.alignOffset??2,te=e.sideOffset??-5));let ie=o,B=z;C.type===`menu`?(ie??=`inline-end`,B??=`start`,re=e.collisionAvoidance??Ha):C.type===`menubar`&&(ie??=C.context.orientation===`vertical`?`inline-end`:`bottom`,B??=`start`);let ae=C.type===`context-menu`,oe=Su({anchor:ee,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ie,sideOffset:te,align:B,alignOffset:ne,arrowPadding:ae?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:re,shift:ae?{crossAxis:!(`side`in re&&re.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:P,lazyFlip:y?`placement`:!1});X.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,Y(va)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,I]),X.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,Y(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let se=po();X.useEffect(()=>{D||se.clear()},[D,se]),X.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?se.isStarted()||se.start(e,()=>{v.setOpen(!1,Y(va))}):v.setOpen(!1,Y(va))}else se.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,se]),X.useEffect(()=>{let e={open:D,nodeId:I,parentNodeId:L,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,I,L]),kC({store:v,domReference:R,positionerElement:M,open:D});let ce={open:D,side:oe.side,align:oe.align,anchorHidden:oe.anchorHidden,nested:C.type===`menu`,instant:N},le=C.type===`menubar`&&C.context.modal;Zx(D&&(le||O&&F!==`trigger-hover`),k===`touch`,M,A);let ue=Eu(e,ce,{styles:oe.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),de=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),fe=null;return C.type===`menubar`?fe=C.context.contentElement:C.type===void 0&&(fe=A),(0,Z.jsxs)(JS.Provider,{value:oe,children:[de&&(0,Z.jsx)(Rx,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:Si(!D),cutout:fe}),(0,Z.jsx)(Fs,{id:I,children:(0,Z.jsx)(Dx,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:ue})})]})}),jC=X.createContext(null);function MC(e){let t=X.useContext(jC);if(t===null&&!e)throw Error(ji(5));return t}var NC={...Sc,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=Sc.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>Ri&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!Sc.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},PC=class extends Ba{constructor(e,t,n=!1){let r=new pc,i=IC(r,t,n,e);super(i,FC(r),NC),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function FC(e){return{positionerRef:X.createRef(),popupRef:X.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:X.createRef(),beforeTriggerFocusGuardRef:X.createRef(),beforeContentFocusGuardRef:X.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function IC(e,t,n=!1,r){return{...gc(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:jo,inputProps:jo,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new ks,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:jo,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var LC=X.createContext(null);function RC(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function zC(e,t){return e===`list-navigation`||RC(e,t)}var BC=ga(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:l=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0,isSubmenu:_=!1,virtualFocus:v=!1,virtualFocusRef:y,allowEscape:b=!0,resetOnPointerLeave:x=!0}=e,S=qS(!0),C=ZS(!0),w=MC(!0),T=C?.store,E=C?.virtualFocus??!1,D=X.useMemo(()=>_&&T?{type:`menu`,store:T}:w?{type:`menubar`,context:w}:S&&!T?{type:`context-menu`,context:S}:{type:void 0},[S,T,w,_]),O=Ib(),k=Ib(),[A,j]=X.useState(void 0),M=(A??k)||void 0,N=Ms(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=Ei(()=>F?P?.state.instantType:void 0).current,L=Ei(()=>{let e=new PC({open:o,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:D,disabled:s,highlightItemOnHover:g,modal:D.type===void 0?c:void 0,rootId:O,instantType:I},M,N!=null);return e.context.virtualFocusRef=y,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,m),L.useContextCallback(`onOpenChangeComplete`,i);let R=L.useState(`floatingTreeRoot`),ee=Ps(R),te=L.useState(`open`),ne=L.useState(`activeTriggerElement`),z=L.useState(`positionerElement`),re=L.useState(`hoverEnabled`),ie=L.useState(`disabled`),B=L.useState(`lastOpenChangeReason`),ae=L.useState(`parent`),oe=L.useState(`activeIndex`),se=L.useState(`keyboardOpen`),ce=L.useState(`payload`),le=L.useState(`floatingParentNodeId`),ue=X.useRef(null),de=X.useRef(ae.type!==`context-menu`),fe=po(),pe=X.useRef(!0),me=po(),he=le!=null,{openMethod:ge,triggerProps:_e}=Yb(te);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:ae.type===void 0?c:void 0,openMethod:ge,rootId:O}),lc(L);let{forceUnmount:ve,transitionStatus:ye}=uc(te,L,()=>{L.set(`allowMouseEnter`,!1)},F),be=Oi(L.context.popupRef);X.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!te){e();return}if(ye!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return be(e,t.signal),()=>{t.abort()}},[I,te,ye,be,L]),K(()=>{S&&!C?L.update({parent:{type:`context-menu`,context:S},floatingNodeId:ee,floatingParentNodeId:N}):(C||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:ee,floatingParentNodeId:N})},[S,C,ee,N,ne,L]),X.useEffect(()=>{te||(ue.current=null),ae.type===`context-menu`&&(te?fe.start(500,()=>{de.current=!0}):(fe.clear(),de.current=!1))},[fe,te,ae.type]),K(()=>{!te&&!re&&L.set(`hoverEnabled`,!0)},[te,re,L]);let xe=J((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||te===e&&t.trigger===ne&&B===n)return;let i=sc(t);if(!e&&t.trigger==null&&(t.trigger=ne??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!pe.current)return;e&&n===`trigger-focus`?(pe.current=!1,me.start(300,()=>{pe.current=!0})):(pe.current=!0,me.clear());let o=!e&&(n===`escape-key`||n==null);ue.current=t.event;let s=oc(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&zC(n,a),s.instantType=ae.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:RC(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),Se=Xs({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:xe}),Ce=Se.context.events;K(()=>{let e=({open:e,eventDetails:t})=>xe(e,t);return Ce.on(`setOpen`,e),()=>{Ce?.off(`setOpen`,e)}},[Ce,xe]),K(()=>L.subscribeToParentMenu(),[L]);let we=X.useCallback(()=>{L.setOpen(!1,Y(So))},[L]);X.useImperativeHandle(d,()=>({unmount:ve,close:we}),[ve,we]);let Te;ae.type===`context-menu`&&(Te=ae.context),X.useImperativeHandle(Te?.positionerRef,()=>z,[z]),X.useImperativeHandle(Te?.actionsRef,()=>({setOpen:xe}),[xe]);let Ee=Ys(Se,{enabled:!ie,bubbles:{escapeKey:f&&ae.type===`menu`},outsidePress(){return ae.type!==`context-menu`||ue.current?.type===`contextmenu`||de.current},externalTree:he?R:void 0}),De=cu(),Oe=qc(Se,{enabled:!ie,listRef:L.context.itemDomElements,activeIndex:oe,virtual:v,nested:ae.type===`menubar`||!v&&ae.type!==void 0,parentOrientation:ae.type===`menubar`?ae.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?se:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:De===`rtl`,disabledIndices:ya,onNavigate(e,t){L.setActiveIndex(e,Yy(t),t?.nativeEvent)},openOnArrowKeyDown:ae.type!==`context-menu`&&!(v&&_),externalTree:!v&&he?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),ke=X.useCallback(e=>{L.context.typingRef.current=e},[L]),Ae=Jc(Se,{enabled:!ie&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:oe,resetMs:500,onMatch:(e,t)=>{te&&e!==oe&&L.setActiveIndex(e,Ia,t.nativeEvent)},onTyping:ke}),je=J(a),Me=X.useRef(-1),Ne=J(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Me.current===n&&L.context.reportedItem===t)return;Me.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=fa,L.context.highlightEvent=void 0,a&&je(t,Gi(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});K(()=>{Ne()},[oe,Ne]);let Pe=X.useMemo(()=>{if(!v)return Oe.reference;if(!Oe.trigger)return jo;let{onFocus:e,...t}=Oe.trigger;return t},[v,Oe.reference,Oe.trigger]);L.useSyncedValue(`inputProps`,v?Oe.reference??jo:jo);let Fe=X.useMemo(()=>{let e=Ga(Ae.reference,Pe,Ee.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},_e);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=te,e},[L,Ae.reference,Pe,Ee.reference,_e,te]),Ie=X.useMemo(()=>{let e=Ga(Oe.trigger,Ee.trigger,_e);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Oe.trigger,Ee.trigger,_e]);Ei(()=>(L.update({inactiveTriggerProps:Ie}),null)),dc(L,{floatingRootContext:Se,activeTriggerProps:Fe,inactiveTriggerProps:Ie,popupProps:X.useMemo(()=>Ga(ec,{onMouseMove(){L.set(`allowMouseEnter`,!0),ae.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ae.floating,Oe.floating,Ee.floating),[ae.type,L,Ae.floating,Oe.floating,Ee.floating]),itemProps:Oe.item??jo});let Le=X.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Ne}),[L,D,u,l,b,k,v,E,Ne]),Re=typeof t==`function`?t({payload:ce}):t,ze=(0,Z.jsxs)(XS.Provider,{value:Le,children:[p&&(0,Z.jsx)(rc,{handle:p,store:L}),Re]});return(ae.type===void 0||ae.type===`context-menu`)&&(ze=(0,Z.jsx)(Is,{externalTree:R,children:ze})),ze});function VC(e){let t=X.useContext(LC);if(t===null)return(0,Z.jsx)(BC,{...e});let n=t.Root;return(0,Z.jsx)(LC.Provider,{value:null,children:(0,Z.jsx)(n,{...t.options,...e})})}function HC(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=ei(),{ref:i,index:a}=tS(e),o=n===a,s=X.useRef(null),c=Zr(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function UC(e){let{render:t,className:n,style:r,state:i=jo,props:a=ya,refs:o=ya,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=HC({metadata:s});return Eo(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function WC(e){if(ta(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!li(e))return WC(Jr(e))}function GC(e,t){function n(n,r,i){let a=n.currentTarget;$s.flushSync(()=>{e.setOpen(!1,Y(qa,n.nativeEvent,a))}),yi(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&co(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function KC(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=X.useRef(!1);return X.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,ri(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:jo,[t,n,r])}var qC=ro(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,m=ZS(!0),h=wc(d)??m?.store;if(!h)throw Error(ji(85));let g=Ib(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=X.useRef(null),S=YC(),C=ei(!0),w=Ns(),T=X.useMemo(()=>w??new ks,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=cc(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:Ps(T),floatingParentNodeId:Ms(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=Oo({disabled:A,native:o});X.useEffect(()=>{!y&&S.type===void 0&&(h.context.allowMouseUpTriggerRef.current=!1)},[h,y,S.type]);let N=X.useRef(null),P=po(),F=J(e=>{if(!N.current)return;P.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;q(N.current,t)||q(h.select(`positionerElement`),t)||t===N.current||t!=null&&WC(t)===h.select(`rootId`)||ox(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:ha})});X.useEffect(()=>{let e=ri(N.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[y,F,h]);let I=O&&S.context.hasSubmenuOpen,L=Bc(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:nl({blockPointerEvents:!O}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),R=JC(y,h.select(`lastOpenChangeReason`)),ee=Ks(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),te=Dc(v,{enabled:!A&&I}),ne=KC({open:y,enabled:O,mouseDownAction:`open`}),z=X.useMemo(()=>Ga(te.reference,ee.reference),[te.reference,ee.reference]),re=h.useState(`triggerProps`,D),ie=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:B,handleFocusTargetFocus:ae}=GC(h,x),oe={disabled:A,open:y},se=[N,t,M,E,x],ce=[z,L??jo,re,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),ri(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ie,O?{role:`menuitem`}:{},ne,p,j],le=Eo(`button`,e,{enabled:!O,stateAttributesMapping:ss,state:oe,ref:se,props:ce});return O?(0,Z.jsx)(UC,{tag:`button`,render:n,className:r,style:i,state:oe,refs:se,props:ce,stateAttributesMapping:ss}):y?(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(zi,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:B},`${g}-pre-focus-guard`),(0,Z.jsx)(X.Fragment,{children:le},g),(0,Z.jsx)(zi,{ref:h.context.triggerFocusTargetRef,onFocus:ae},`${g}-post-focus-guard`)]}):(0,Z.jsx)(X.Fragment,{children:le},g)});function JC(e,t){let n=po(),[r,i]=X.useState(!1);return K(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function YC(){let e=MC(!0);return X.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var XC=X.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return Eo(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})});function ZC(e){let[t,n]=X.useState({getBoundingClientRect(){return DOMRect.fromRect({width:0,height:0,x:0,y:0})}}),r=X.useRef(null),i=X.useRef(null),a=X.useRef(null),o=X.useRef(null),s=X.useRef(!0),c=X.useRef(null),l=ni(),u=X.useMemo(()=>({anchor:t,setAnchor:n,actionsRef:a,backdropRef:r,internalBackdropRef:i,positionerRef:o,allowMouseUpTriggerRef:s,initialCursorPointRef:c,rootId:l}),[t,l]);return(0,Z.jsx)(KS.Provider,{value:u,children:(0,Z.jsx)(XS.Provider,{value:void 0,children:(0,Z.jsx)(VC,{...e})})})}var QC=500,$C=X.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{setAnchor:o,actionsRef:s,internalBackdropRef:c,backdropRef:l,positionerRef:u,allowMouseUpTriggerRef:d,initialCursorPointRef:f,rootId:p}=qS(!1),{store:m}=ZS(!1),h=m.useState(`open`),g=m.useState(`disabled`),_=X.useRef(null),v=X.useRef(null),y=po(),b=po(),x=X.useRef(!1),S=X.useRef(null);function C(e,t,n){let r=n.type.startsWith(`touch`);f.current={x:e,y:t},o({getBoundingClientRect(){return DOMRect.fromRect({width:r?10:0,height:r?10:0,x:e,y:t})}}),x.current=!1,s.current?.setOpen(!0,Y(Xr,n)),b.start(QC,()=>{x.current=!0})}function w(e){if(g)return;d.current=!0,ti(e),C(e.clientX,e.clientY,e.nativeEvent);let t=ri(_.current);S.current?.abort();let n=new AbortController;S.current=n,t.addEventListener(`mouseup`,e=>{if(d.current=!1,!x.current)return;b.clear(),x.current=!1;let t=ca(e);q(u.current,t)||p&&t&&WC(t)===p||s.current?.setOpen(!1,Y(ha,e))},{once:!0,signal:n.signal})}function T(){y.clear(),v.current=null}function E(e){if(g||(d.current=!1,e.touches.length!==1)){T();return}e.stopPropagation();let t=e.touches[0],n={x:t.clientX,y:t.clientY};v.current=n,y.start(QC,()=>{C(n.x,n.y,e.nativeEvent)})}function D(e){if(e.touches.length!==1)T();else if(y.isStarted()&&v.current){let t=e.touches[0],n=Math.abs(t.clientX-v.current.x),r=Math.abs(t.clientY-v.current.y);(n>10||r>10)&&T()}}return X.useEffect(()=>()=>{S.current?.abort()},[]),X.useEffect(()=>{function e(e){if(g)return;let t=ca(e);(q(_.current,t)||q(c.current,t)||q(l.current,t))&&e.preventDefault()}let t=ri(_.current);return di(t,`contextmenu`,e)},[l,g,c]),Eo(`div`,e,{state:{open:h},ref:[_,t],props:[{onContextMenu:w,onTouchStart:E,onTouchMove:D,onTouchEnd:T,onTouchCancel:T,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:ss})}),ew=AC,tw=X.createContext(void 0);function nw(e){let t=X.useContext(tw);if(!e&&t===void 0)throw Error(ji(27));return t}var rw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=nw(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`),d={open:c,transitionStatus:s.useState(`transitionStatus`)};return Eo(`div`,e,{state:d,ref:[s.context.backdropRef,t],stateAttributesMapping:ls,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),iw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=nw(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=Oo({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Y(ho,e.nativeEvent))}return Eo(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})}),aw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=nw(),c=Ib(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),Eo(`p`,e,{ref:t,props:[{id:c},o]})}),ow=X.createContext(void 0);function sw(){let e=X.useContext(ow);if(e===void 0)throw Error(ji(26));return e}var cw=`--nested-dialogs`,lw=`data-nested-dialog-open`,uw={...cs,...Vi,nestedDialogOpen(e){return e?{[lw]:``}:null}},dw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=nw(),l=c.useState(`descriptionElementId`),u=c.useState(`disablePointerDismissal`),d=c.useState(`floatingRootContext`),f=c.useState(`popupProps`),p=c.useState(`modal`),m=c.useState(`mounted`),h=c.useState(`nested`),g=c.useState(`nestedOpenDialogCount`),_=c.useState(`open`),v=c.useState(`openMethod`),y=c.useState(`titleElementId`),b=c.useState(`transitionStatus`),x=c.useState(`role`),S=d.useState(`floatingId`);sw(),Ti({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?tc(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=Eo(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...ec,hidden:!m,onKeyDown(e){gC.has(e.key)&&e.stopPropagation()},style:{[cw]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:uw});return(0,Z.jsx)(Gs,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})}),fw=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=nw(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Z.jsx)(ow.Provider,{value:n,children:(0,Z.jsxs)($a,{ref:t,...r,children:[a&&o===!0&&(0,Z.jsx)(Rx,{ref:i.context.internalBackdropRef,inert:Si(!s)}),e.children]})}):null});function pw({store:e,parentContext:t,isDrawer:n}){let r=e.useState(`open`),i=e.useState(`mounted`),a=e.useState(`disablePointerDismissal`),o=e.useState(`modal`),s=e.useState(`popupElement`),c=e.useState(`floatingRootContext`),[l,u]=X.useState(0),[d,f]=X.useState(0),p=l===0,m=Ys(c,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?`intentional`:{mouse:o===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}},outsidePress(t){if(!e.context.outsidePressEnabledRef.current||`button`in t&&t.button!==0)return!1;if(`touches`in t){if(t.type===`touchend`){if(t.changedTouches.length!==1||t.touches.length!==0)return!1}else if(t.touches.length!==1)return!1}let n=ca(t);if(p&&!a){if(o){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||q(n,s)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return Yx(r&&o===!0,s),e.useContextCallback(`onNestedDialogOpen`,(t,n)=>{(e.select(`open`)||e.select(`mounted`))&&(u(t),f(n))}),K(()=>{!r&&!i&&(u(0),f(0))},[r,i]),K(()=>(t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(l+1,d+ +!!n),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,l,d,t]),dc(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var mw={...Sc,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role},hw=class extends Ba{constructor(e,t,n){let r=new pc,i=gw(e,r,t,n);super(i,_w(r),mw)}setOpen=(e,t)=>{t.preventUnmountOnClose=()=>{this.set(`preventUnmountingOnClose`,!0)},!e&&t.trigger==null&&this.state.activeTriggerId!=null&&(t.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(e,t),!t.isCanceled&&(this.state.floatingRootContext.dispatchOpenChange(e,t),this.update(oc(this.state,e,t.trigger)))}};function gw(e,t,n,r=!1){return{...gc(t,n,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:`dialog`,...e}}function _w(e){return{popupRef:X.createRef(),backdropRef:X.createRef(),internalBackdropRef:X.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function vw(e,t){let{children:n,open:r,defaultOpen:i=!1,onOpenChange:a,onOpenChangeComplete:o,disablePointerDismissal:s=!1,modal:c=!0,actionsRef:l,handle:u,triggerId:d,defaultTriggerId:f=null}=t,p=e===`drawer`,m=e===`alert-dialog`,h=m?!0:c,g=m||s,_=m?`alertdialog`:`dialog`,v=nw(!0),y={modal:h,disablePointerDismissal:g,nested:v!=null,role:_},b=nc((e,t)=>new hw({open:i,openProp:r,activeTriggerId:f,triggerIdProp:d,...y},e,t),!0);b.useControlledProp(`openProp`,r),b.useControlledProp(`triggerIdProp`,d),b.useSyncedValues(y),b.useContextCallback(`onOpenChange`,a),b.useContextCallback(`onOpenChangeComplete`,o);let x=b.useState(`open`),S=b.useState(`mounted`),C=b.useState(`payload`);fc(b,x),lc(b);let{forceUnmount:w}=uc(x,b);X.useImperativeHandle(l,()=>({unmount:w,close:()=>b.setOpen(!1,Y(So))}),[w,b]);let T=x||S||u!=null;return(0,Z.jsxs)(tw.Provider,{value:b,children:[u&&(0,Z.jsx)(rc,{handle:u,store:b}),T&&(0,Z.jsx)(pw,{store:b,parentContext:v?.context,isDrawer:p}),typeof n==`function`?n({payload:C}):n]})}var yw=ga(function(e){return vw(`dialog`,e)}),bw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=nw(),c=Ib(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),Eo(`h2`,e,{ref:t,props:[{id:c},o]})}),xw=X.forwardRef(function(e,t){let{render:n,className:r,id:i,name:a,value:o,disabled:s=!1,onValueChange:c,defaultValue:l,autoFocus:u=!1,style:d,...f}=e,{state:p,name:m,disabled:h,setTouched:g,setDirty:_,validityData:v,setFilled:y,validationMode:b,validation:x}=Mb(),{clearErrors:S,elementRef:C,submitCountRef:w}=Fb(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=Rb(),k=zb({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=J(()=>x.inputRef.current?.value);Nb(x.inputRef,k,j,M,!T,a),K(()=>{let e=j??x.inputRef.current?.value;e!==void 0&&y(e!==``)},[j,l,x.inputRef,y]),qb(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=X.useRef(null),P=ix(T,N),F=po();return Eo(`input`,e,{ref:[t,N],state:D,props:[{id:k,disabled:T,name:E,ref:x.inputRef,"aria-labelledby":O,autoFocus:u,...A?{value:o}:{defaultValue:l},onChange(e){let t=e.currentTarget.value,n=Y(fa,e.nativeEvent);c?.(t,n),!A&&(_(t!==(v.initialValue??``)),y(t!==``),!e.nativeEvent.defaultPrevented&&!n.isCanceled&&(S(E),x.change(t)))},onFocus(){P(!0)},onBlur(e){if(g(!0),P(!1),b===`onBlur`){let t=e.currentTarget.value;x.commit(t),A&&queueMicrotask(()=>{let e=x.inputRef.current?.value;e!==void 0&&e!==t&&e!==(v.initialValue??``)&&x.commit(e)})}},onKeyDown(e){if(e.currentTarget.tagName===`INPUT`&&e.key===`Enter`){g(!0);let t=e.currentTarget.value,n=e.currentTarget.form;if(n&&n===C.current&&!e.defaultPrevented){let t=e.currentTarget,n=w.current;F.start(0,()=>{w.current===n&&x.commit(t.value)})}else x.commit(t)}}},f,e=>x.getValidationProps(T,e)],stateAttributesMapping:kb})}),Sw=X.forwardRef(function(e,t){return(0,Z.jsx)(xw,{ref:t,...e})});function Cw(e){let t=(0,$.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,type:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=ua(`h-7 w-full min-w-0 rounded-md border border-input bg-input/20 px-2 py-0.5 text-sm transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-xs/relaxed file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-xs/relaxed dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[4]=n,t[5]=a);let o;return t[6]!==r||t[7]!==a||t[8]!==i?(o=(0,Z.jsx)(Sw,{type:i,"data-slot":`input`,className:a,...r}),t[6]=r,t[7]=a,t[8]=i,t[9]=o):o=t[9],o}function ww(e){let t=(0,$.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=ua(`group/input-group relative flex h-7 w-full min-w-0 items-center rounded-md border border-input bg-input/20 transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-data-[align=block-end]:rounded-md has-data-[align=block-start]:rounded-md has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-2 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/30 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-2 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[textarea]:rounded-md has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`div`,{"data-slot":`input-group`,role:`group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Tw=Li(`flex h-auto cursor-text items-center justify-center gap-1 py-2 text-xs/relaxed font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 **:data-[slot=kbd]:rounded-[calc(var(--radius-sm)-2px)] **:data-[slot=kbd]:bg-muted-foreground/10 **:data-[slot=kbd]:px-1 **:data-[slot=kbd]:text-[0.625rem] [&>svg:not([class*='size-'])]:size-3.5`,{variants:{align:{"inline-start":`order-first pl-2 has-[>button]:ml-[-0.275rem] has-[>kbd]:ml-[-0.275rem]`,"inline-end":`order-last pr-2 has-[>button]:mr-[-0.275rem] has-[>kbd]:mr-[-0.275rem]`,"block-start":`order-first w-full justify-start px-2 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2`,"block-end":`order-last w-full justify-start px-2 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2`}},defaultVariants:{align:`inline-start`}});function Ew(e){let t=(0,$.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,align:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`inline-start`:i,o;t[4]!==a||t[5]!==n?(o=ua(Tw({align:a}),n),t[4]=a,t[5]=n,t[6]=o):o=t[6];let s;return t[7]!==a||t[8]!==r||t[9]!==o?(s=(0,Z.jsx)(`div`,{role:`group`,"data-slot":`input-group-addon`,"data-align":a,className:o,onClick:Dw,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function Dw(e){e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`input`)?.focus()}var Ow=Li(`flex items-center gap-2 rounded-md text-xs/relaxed shadow-none`,{variants:{size:{xs:`h-5 gap-1 rounded-[calc(var(--radius-sm)-2px)] px-1 [&>svg:not([class*='size-'])]:size-3`,sm:`gap-1`,"icon-xs":`size-6 p-0 has-[>svg]:p-0`,"icon-sm":`size-7 p-0 has-[>svg]:p-0`}},defaultVariants:{size:`xs`}});function kw(e){let t=(0,$.c)(15),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:n,type:i,variant:a,size:o,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s=i===void 0?`button`:i,c=a===void 0?`ghost`:a,l=o===void 0?`xs`:o,u;t[6]!==n||t[7]!==l?(u=ua(Ow({size:l}),n),t[6]=n,t[7]=l,t[8]=u):u=t[8];let d;return t[9]!==r||t[10]!==l||t[11]!==u||t[12]!==s||t[13]!==c?(d=(0,Z.jsx)(Pa,{type:s,"data-size":l,variant:c,className:u,...r}),t[9]=r,t[10]=l,t[11]=u,t[12]=s,t[13]=c,t[14]=d):d=t[14],d}function Aw(e){let t=(0,$.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=ua(`flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(Cw,{"data-slot":`input-group-control`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function jw(e){let t=(0,$.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=ua(`[&_svg:not([class*='size-'])]:size-3.5`,r),t[4]=r,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(Vo,{className:`pointer-events-none size-3.5 text-muted-foreground`}),t[6]=o):o=t[6];let s;return t[7]!==n||t[8]!==i||t[9]!==a?(s=(0,Z.jsxs)(px,{"data-slot":`combobox-trigger`,className:a,...i,children:[n,o]}),t[7]=n,t[8]=i,t[9]=a,t[10]=s):s=t[10],s}function Mw(e){let t=(0,$.c)(10),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]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Z.jsx)(kw,{variant:`ghost`,size:`icon-xs`}),t[3]=i):i=t[3];let a;t[4]===n?a=t[5]:(a=ua(n),t[4]=n,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(Ur,{className:`pointer-events-none`}),t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==a?(s=(0,Z.jsx)(xx,{"data-slot":`combobox-clear`,render:i,className:a,...r,children:o}),t[7]=r,t[8]=a,t[9]=s):s=t[9],s}function Nw(e){let t=(0,$.c)(28),n,r,i,a,o,s;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6]):({className:r,children:n,disabled:a,showTrigger:o,showClear:s,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s);let c=a!==void 0&&a,l=o===void 0||o,u=s!==void 0&&s,d;t[7]===r?d=t[8]:(d=ua(`w-auto`,r),t[7]=r,t[8]=d);let f;t[9]===c?f=t[10]:(f=(0,Z.jsx)(Aw,{disabled:c}),t[9]=c,t[10]=f);let p;t[11]!==i||t[12]!==f?(p=(0,Z.jsx)(yx,{render:f,...i}),t[11]=i,t[12]=f,t[13]=p):p=t[13];let m;t[14]!==c||t[15]!==l?(m=l&&(0,Z.jsx)(kw,{size:`icon-xs`,variant:`ghost`,render:(0,Z.jsx)(jw,{}),"data-slot":`input-group-button`,className:`group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent`,disabled:c}),t[14]=c,t[15]=l,t[16]=m):m=t[16];let h;t[17]!==c||t[18]!==u?(h=u&&(0,Z.jsx)(Mw,{disabled:c}),t[17]=c,t[18]=u,t[19]=h):h=t[19];let g;t[20]!==m||t[21]!==h?(g=(0,Z.jsxs)(Ew,{align:`inline-end`,children:[m,h]}),t[20]=m,t[21]=h,t[22]=g):g=t[22];let _;return t[23]!==n||t[24]!==d||t[25]!==p||t[26]!==g?(_=(0,Z.jsxs)(ww,{className:d,children:[p,g,n]}),t[23]=n,t[24]=d,t[25]=p,t[26]=g,t[27]=_):_=t[27],_}function Pw(e){let t=(0,$.c)(21),n,r,i,a,o,s,c;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7]):({className:r,side:a,sideOffset:o,align:s,alignOffset:c,anchor:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c);let l=a===void 0?`bottom`:a,u=o===void 0?6:o,d=s===void 0?`start`:s,f=c===void 0?0:c,p=!!n,m;t[8]===r?m=t[9]:(m=ua(`group/combobox-content relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-[calc(var(--anchor-width)+--spacing(7))] origin-(--transform-origin) overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[chips=true]:min-w-(--anchor-width) data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-7 *:data-[slot=input-group]:border-none *:data-[slot=input-group]:bg-input/20 *:data-[slot=input-group]:shadow-none dark:bg-popover data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,r),t[8]=r,t[9]=m);let h;t[10]!==i||t[11]!==p||t[12]!==m?(h=(0,Z.jsx)(eS,{"data-slot":`combobox-content`,"data-chips":p,className:m,...i}),t[10]=i,t[11]=p,t[12]=m,t[13]=h):h=t[13];let g;return t[14]!==d||t[15]!==f||t[16]!==n||t[17]!==l||t[18]!==u||t[19]!==h?(g=(0,Z.jsx)(Lx,{children:(0,Z.jsx)(Qx,{side:l,sideOffset:u,align:d,alignOffset:f,anchor:n,className:`isolate z-50`,children:h})}),t[14]=d,t[15]=f,t[16]=n,t[17]=l,t[18]=u,t[19]=h,t[20]=g):g=t[20],g}function Fw(e){let t=(0,$.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=ua(`no-scrollbar max-h-[min(calc(--spacing(72)---spacing(9)),calc(var(--available-height)---spacing(9)))] scroll-py-1 overflow-y-auto overscroll-contain p-1 data-empty:p-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(Px,{"data-slot":`combobox-list`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Iw(e){let t=(0,$.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=ua(`relative flex min-h-7 w-full cursor-default items-center gap-2 rounded-md px-2 py-1 text-xs/relaxed outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,r),t[4]=r,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(GS,{render:(0,Z.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex items-center justify-center`}),children:(0,Z.jsx)(zo,{className:`pointer-events-none`})}),t[6]=o):o=t[6];let s;return t[7]!==n||t[8]!==i||t[9]!==a?(s=(0,Z.jsxs)(cS,{"data-slot":`combobox-item`,className:a,...i,children:[n,o]}),t[7]=n,t[8]=i,t[9]=a,t[10]=s):s=t[10],s}function Lw(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(VC,{"data-slot":`dropdown-menu`,...n}),t[2]=n,t[3]=r),r}function Rw(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(qC,{"data-slot":`dropdown-menu-trigger`,...n}),t[2]=n,t[3]=r),r}function zw(e){let t=(0,$.c)(18),n,r,i,a,o,s;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6]):({align:i,alignOffset:a,side:o,sideOffset:s,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s);let c=i===void 0?`start`:i,l=a===void 0?0:a,u=o===void 0?`bottom`:o,d=s===void 0?4:s,f;t[7]===n?f=t[8]:(f=ua(`z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95`,n),t[7]=n,t[8]=f);let p;t[9]!==r||t[10]!==f?(p=(0,Z.jsx)(TC,{"data-slot":`dropdown-menu-content`,className:f,...r}),t[9]=r,t[10]=f,t[11]=p):p=t[11];let m;return t[12]!==c||t[13]!==l||t[14]!==u||t[15]!==d||t[16]!==p?(m=(0,Z.jsx)(OC,{children:(0,Z.jsx)(AC,{className:`isolate z-50 outline-none`,align:c,alignOffset:l,side:u,sideOffset:d,children:p})}),t[12]=c,t[13]=l,t[14]=u,t[15]=d,t[16]=p,t[17]=m):m=t[17],m}function Bw(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(uC,{"data-slot":`dropdown-menu-group`,...n}),t[2]=n,t[3]=r),r}function Vw(e){let t=(0,$.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,inset:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=ua(`px-2 py-1.5 text-xs text-muted-foreground data-inset:pl-7.5`,n),t[4]=n,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(dC,{"data-slot":`dropdown-menu-label`,"data-inset":r,className:a,...i}),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Hw(e){let t=(0,$.c)(12),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:n,inset:r,variant:a,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=a===void 0?`default`:a,s;t[5]===n?s=t[6]:(s=ua(`group/dropdown-menu-item relative flex min-h-7 cursor-default items-center gap-2 rounded-md px-2 py-1 text-xs/relaxed outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7.5 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 data-[variant=destructive]:*:[svg]:text-destructive`,n),t[5]=n,t[6]=s);let c;return t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o?(c=(0,Z.jsx)(pC,{"data-slot":`dropdown-menu-item`,"data-inset":r,"data-variant":o,className:s,...i}),t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=c):c=t[11],c}function Uw(e){let t=(0,$.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=ua(`-mx-1 my-1 h-px bg-border/50`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(XC,{"data-slot":`dropdown-menu-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ww(e){let t=(0,$.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=ua(`pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-xs bg-muted px-1 font-sans text-[0.625rem] font-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`kbd`,{"data-slot":`kbd`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Gw=wr({id:Nt,name:Nt,signOut:dr}),Kw=E(ce).atom(Ft(_t(`/auth/user`),_(Et),_(Ve(Gw)))),qw=Je(y(``));function Jw(){return Ae(P(Hy(qw)))}function Yw(){let e=(0,$.c)(27),t=Hy(Kw);if(!ne(t))return null;let n;e[0]===t.value.id?n=e[1]:(n=wn(`github:`,``)(t.value.id),e[0]=t.value.id,e[1]=n);let r=`https://avatars.githubusercontent.com/u/${n}?s=96`,i;e[2]!==t.value.name||e[3]!==r?(i=(0,Z.jsx)(vS,{src:r,alt:t.value.name}),e[2]=t.value.name,e[3]=r,e[4]=i):i=e[4];let a;e[5]===t.value.name?a=e[6]:(a=ze(Te(0,1)(t.value.name)),e[5]=t.value.name,e[6]=a);let o;e[7]===a?o=e[8]:(o=(0,Z.jsx)(yS,{children:a}),e[7]=a,e[8]=o);let s;e[9]!==i||e[10]!==o?(s=(0,Z.jsx)(Rw,{"aria-label":`Account`,children:(0,Z.jsxs)(_S,{size:`sm`,children:[i,o]})}),e[9]=i,e[10]=o,e[11]=s):s=e[11];let c;e[12]===t.value.name?c=e[13]:(c=(0,Z.jsx)(Bw,{children:(0,Z.jsxs)(Vw,{children:[`@`,t.value.name]})}),e[12]=t.value.name,e[13]=c);let l;e[14]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Z.jsx)(Uw,{}),e[14]=l):l=e[14];let u=!t.value.signOut,d;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(d=new URLSearchParams({next:location.href}),e[15]=d):d=e[15];let f=`/auth/sign-out?${d}`,p;e[16]===f?p=e[17]:(p=(0,Z.jsx)(`a`,{"aria-label":`Sign out`,href:f}),e[16]=f,e[17]=p);let m;e[18]!==p||e[19]!==u?(m=(0,Z.jsx)(Hw,{variant:`destructive`,disabled:u,render:p,children:`Sign out`}),e[18]=p,e[19]=u,e[20]=m):m=e[20];let h;e[21]!==m||e[22]!==c?(h=(0,Z.jsxs)(zw,{align:`end`,className:`w-auto min-w-48`,children:[c,l,m]}),e[21]=m,e[22]=c,e[23]=h):h=e[23];let g;return e[24]!==h||e[25]!==s?(g=(0,Z.jsxs)(Lw,{children:[s,h]}),e[24]=h,e[25]=s,e[26]=g):g=e[26],g}function Xw(e){let t=(0,$.c)(66),[n,r]=Gy(qw),[i,a]=(0,X.useState)(!1),o;t[0]===n?o=t[1]:(o=()=>n!==``,t[0]=n,t[1]=o);let[s,c]=(0,X.useState)(o),l=(0,X.useRef)(null),u=(0,X.useRef)(null),d,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{let e=function(e){e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),c(!0),l.current?.focus())};return addEventListener(`keydown`,e),()=>removeEventListener(`keydown`,e)},f=[],t[2]=d,t[3]=f):(d=t[2],f=t[3]),(0,X.useEffect)(d,f);let p,m,h,g,_,v,y,b,x,S,C;if(t[4]!==i||t[5]!==e.commands||t[6]!==e.label||t[7]!==n||t[8]!==s||t[9]!==r){let a;t[21]===n?a=t[22]:(a=e=>Fe(Ae(P(n)))(Ae(e.label)),t[21]=n,t[22]=a),m=D(e.commands,a);let o,d;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>{(0,$s.flushSync)(()=>c(!0)),l.current?.focus()},d=(0,Z.jsx)(Yo,{}),t[23]=o,t[24]=d):(o=t[23],d=t[24]),t[25]===e.label?g=t[26]:(g=(0,Z.jsx)(Pa,{variant:`ghost`,size:`icon-sm`,"aria-label":e.label,className:`ml-auto sm:hidden`,onClick:o,children:d}),t[25]=e.label,t[26]=g),C=u;let f=s&&`max-sm:bg-background max-sm:absolute max-sm:inset-0 max-sm:z-10 max-sm:flex max-sm:max-w-none max-sm:items-center max-sm:gap-2 max-sm:px-3`;t[27]===f?h=t[28]:(h=ua(`mx-auto hidden w-full max-w-sm sm:flex lg:absolute lg:left-1/2 lg:-translate-x-1/2`,f),t[27]=f,t[28]=h),p=ex,_=m,v=null,y=Zw,b=n,t[29]===r?x=t[30]:(x=(e,t)=>{t.reason!==`item-press`&&r(e)},t[29]=r,t[30]=x),S=i&&Ne(m),t[4]=i,t[5]=e.commands,t[6]=e.label,t[7]=n,t[8]=s,t[9]=r,t[10]=p,t[11]=m,t[12]=h,t[13]=g,t[14]=_,t[15]=v,t[16]=y,t[17]=b,t[18]=x,t[19]=S,t[20]=C}else p=t[10],m=t[11],h=t[12],g=t[13],_=t[14],v=t[15],y=t[16],b=t[17],x=t[18],S=t[19],C=t[20];let w=n!==``,T;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>a(!0),t[31]=T):T=t[31];let E;t[32]!==m||t[33]!==i||t[34]!==r?(E=e=>{e.key!==`Escape`||i&&Ne(m)||(r(``),c(!1),e.currentTarget.blur())},t[32]=m,t[33]=i,t[34]=r,t[35]=E):E=t[35];let O;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Z.jsx)(Ew,{children:(0,Z.jsx)(Yo,{})}),t[36]=O):O=t[36];let k;t[37]===n?k=t[38]:(k=n===``&&(0,Z.jsx)(Ew,{align:`inline-end`,className:`max-sm:hidden`,children:(0,Z.jsx)(Ww,{children:`⌘K`})}),t[37]=n,t[38]=k);let A;t[39]!==e.label||t[40]!==w||t[41]!==E||t[42]!==k?(A=(0,Z.jsxs)(Nw,{ref:l,"aria-label":e.label,placeholder:`Search or run a command`,showTrigger:!1,showClear:w,className:`w-full`,onFocus:T,onKeyDown:E,children:[O,k]}),t[39]=e.label,t[40]=w,t[41]=E,t[42]=k,t[43]=A):A=t[43];let j;t[44]===r?j=t[45]:(j=(0,Z.jsx)(Pw,{anchor:u,children:(0,Z.jsx)(Fw,{children:e=>(0,Z.jsxs)(Iw,{value:e,onClick:()=>{r(``),c(!1),e.run()},children:[e.icon,e.label]},e.label)})}),t[44]=r,t[45]=j);let M;t[46]!==p||t[47]!==A||t[48]!==j||t[49]!==_||t[50]!==v||t[51]!==y||t[52]!==b||t[53]!==x||t[54]!==S?(M=(0,Z.jsxs)(p,{items:_,filter:v,itemToStringValue:y,value:b,onValueChange:x,open:S,onOpenChange:a,autoHighlight:!0,children:[A,j]}),t[46]=p,t[47]=A,t[48]=j,t[49]=_,t[50]=v,t[51]=y,t[52]=b,t[53]=x,t[54]=S,t[55]=M):M=t[55];let N;t[56]===r?N=t[57]:(N=(0,Z.jsx)(Pa,{variant:`ghost`,size:`sm`,className:`sm:hidden`,onClick:()=>{r(``),c(!1)},children:`Cancel`}),t[56]=r,t[57]=N);let F;t[58]!==h||t[59]!==M||t[60]!==N||t[61]!==C?(F=(0,Z.jsxs)(`div`,{ref:C,className:h,children:[M,N]}),t[58]=h,t[59]=M,t[60]=N,t[61]=C,t[62]=F):F=t[62];let I;return t[63]!==g||t[64]!==F?(I=(0,Z.jsxs)(Z.Fragment,{children:[g,F]}),t[63]=g,t[64]=F,t[65]=I):I=t[65],I}function Zw(e){return e.label}function Qw(e){let t=(0,$.c)(9),n;t[0]===e.label?n=t[1]:(n=(0,Z.jsx)(`span`,{className:`max-sm:hidden`,children:e.label}),t[0]=e.label,t[1]=n);let r;return t[2]!==e.disabled||t[3]!==e.icon||t[4]!==e.label||t[5]!==e.onClick||t[6]!==e.variant||t[7]!==n?(r=(0,Z.jsxs)(Pa,{"aria-label":e.label,variant:e.variant,disabled:e.disabled,onClick:e.onClick,children:[e.icon,n]}),t[2]=e.disabled,t[3]=e.icon,t[4]=e.label,t[5]=e.onClick,t[6]=e.variant,t[7]=n,t[8]=r):r=t[8],r}function $w(e){let t=(0,$.c)(25),n;t[0]===e.icon?n=t[1]:(n=(0,Z.jsx)(`img`,{src:e.icon,alt:``,className:`pixelated size-8`}),t[0]=e.icon,t[1]=n);let r;t[2]===e.name?r=t[3]:(r=(0,Z.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e.name}),t[2]=e.name,t[3]=r);let i;t[4]!==n||t[5]!==r?(i=(0,Z.jsxs)(`a`,{href:`/`,className:`-ml-1 flex shrink-0 items-center gap-1.5`,children:[n,r]}),t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;t[7]===e.tabs?a=t[8]:(a=e.tabs!==void 0&&(0,Z.jsx)(`nav`,{"aria-label":`Sections`,className:`ml-2 flex items-center gap-1`,children:e.tabs}),t[7]=e.tabs,t[8]=a);let o;t[9]===e.commands?o=t[10]:(o=e.commands===void 0&&(0,Z.jsx)(`span`,{className:`flex-1`}),t[9]=e.commands,t[10]=o);let s;t[11]!==e.commands||t[12]!==e.name?(s=e.commands!==void 0&&(0,Z.jsx)(Xw,{commands:e.commands,label:`Search ${e.name}`}),t[11]=e.commands,t[12]=e.name,t[13]=s):s=t[13];let c;t[14]===e.account?c=t[15]:(c=e.account??(0,Z.jsx)(Yw,{}),t[14]=e.account,t[15]=c);let l;t[16]!==e.action||t[17]!==c?(l=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 lg:ml-auto`,children:[e.action,c]}),t[16]=e.action,t[17]=c,t[18]=l):l=t[18];let u;return t[19]!==i||t[20]!==a||t[21]!==o||t[22]!==s||t[23]!==l?(u=(0,Z.jsxs)(`header`,{className:`bg-background border-border sticky top-0 z-30 flex h-12 shrink-0 items-center gap-2 border-b px-4`,children:[i,a,o,s,l]}),t[19]=i,t[20]=a,t[21]=o,t[22]=s,t[23]=l,t[24]=u):u=t[24],u}function eT(e){let t=(0,$.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=ua(`animate-pulse rounded-md bg-muted`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`div`,{"data-slot":`skeleton`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function tT(e){let t=(0,$.c)(8),n=e.label,r;if(t[0]!==e.media||t[1]!==e.rows){let n;t[3]===e.media?n=t[4]:(n=t=>(0,Z.jsxs)(`div`,{"aria-hidden":!0,className:`flex h-10 items-center gap-3 border-b px-1`,children:[e.media===!0&&(0,Z.jsx)(eT,{className:`size-5`}),(0,Z.jsx)(eT,{className:`h-4 w-1/3`})]},t),t[3]=e.media,t[4]=n),r=Sn(Oe(1,e.rows),n),t[0]=e.media,t[1]=e.rows,t[2]=r}else r=t[2];let i;return t[5]!==e.label||t[6]!==r?(i=(0,Z.jsx)(`div`,{"aria-busy":`true`,"aria-label":n,role:`status`,children:r}),t[5]=e.label,t[6]=r,t[7]=i):i=t[7],i}function nT(e){let t=(0,$.c)(5),n;t[0]===e.className?n=t[1]:(n=ua(`flex w-full max-w-3xl flex-col gap-4 self-start`,e.className),t[0]=e.className,t[1]=n);let r;return t[2]!==e.children||t[3]!==n?(r=(0,Z.jsx)(`main`,{className:`pb-safe flex min-h-0 flex-1 justify-center overflow-y-auto px-4 pt-3`,children:(0,Z.jsx)(`div`,{className:n,children:e.children})}),t[2]=e.children,t[3]=n,t[4]=r):r=t[4],r}function rT(e){let t=(0,$.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=ua(`flex items-center gap-2 text-xs/relaxed leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`label`,{"data-slot":`label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var iT=Li(`group/field flex w-full gap-2 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:`flex-col *:w-full [&>.sr-only]:w-auto`,horizontal:`flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`,responsive:`flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`}},defaultVariants:{orientation:`vertical`}});function aT(e){let t=(0,$.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,orientation:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`vertical`:i,o;t[4]!==n||t[5]!==a?(o=ua(iT({orientation:a}),n),t[4]=n,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==a||t[8]!==r||t[9]!==o?(s=(0,Z.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":a,className:o,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function oT(e){let t=(0,$.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=ua(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border has-[>[data-slot=field]]:not-has-[:disabled,[data-disabled]]:hover:bg-input/40 has-[>[data-slot=field]]:has-[:focus-visible]:border-ring has-[>[data-slot=field]]:has-[:focus-visible]:ring-2 has-[>[data-slot=field]]:has-[:focus-visible]:ring-ring/30 *:data-[slot=field]:p-2 dark:has-data-checked:bg-primary/10`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(rT,{"data-slot":`field-label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function sT(e){let t=(0,$.c)(15),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:r,children:n,errors:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o;bb0:{if(n){o=n;break bb0}if(!i?.length){o=null;break bb0}let e;t[5]===i?e=t[6]:(e=[...new Map(i.map(lT)).values()],t[5]=i,t[6]=e);let r=e;if(r?.length==1){o=r[0]?.message;break bb0}let a;t[7]===r?a=t[8]:(a=(0,Z.jsx)(`ul`,{className:`ml-4 flex list-disc flex-col gap-1`,children:r.map(cT)}),t[7]=r,t[8]=a),o=a}let s=o;if(!s)return null;let c;t[9]===r?c=t[10]:(c=ua(`text-xs/relaxed font-normal text-destructive`,r),t[9]=r,t[10]=c);let l;return t[11]!==s||t[12]!==a||t[13]!==c?(l=(0,Z.jsx)(`div`,{role:`alert`,"data-slot":`field-error`,className:c,...a,children:s}),t[11]=s,t[12]=a,t[13]=c,t[14]=l):l=t[14],l}function cT(e,t){return e?.message&&(0,Z.jsx)(`li`,{children:e.message},t)}function lT(e){return[e?.message,e]}function uT(e){let t=(0,$.c)(5),n=e.className,r;t[0]===e.result?r=t[1]:(r=zr(z(j(e.result),dT)),t[0]=e.result,t[1]=r);let i;return t[2]!==e.className||t[3]!==r?(i=(0,Z.jsx)(sT,{className:n,children:r}),t[2]=e.className,t[3]=r,t[4]=i):i=t[4],i}function dT(e){return e.message}var fT=Li(`inline-block size-1.5 shrink-0 rounded-full`,{defaultVariants:{status:`live`},variants:{status:{error:`bg-destructive`,live:`bg-primary`,off:`border-muted-foreground border`,quiet:`bg-muted-foreground/50`,warning:`bg-warning`}}});function pT(e){let t=(0,$.c)(6),n;t[0]!==e.className||t[1]!==e.status||t[2]!==e.waiting?(n=ua(fT({status:e.status}),e.waiting===!0&&`motion-safe:animate-pulse`,e.className),t[0]=e.className,t[1]=e.status,t[2]=e.waiting,t[3]=n):n=t[3];let r;return t[4]===n?r=t[5]:(r=(0,Z.jsx)(`span`,{"data-slot":`status-dot`,"aria-hidden":`true`,className:n}),t[4]=n,t[5]=r),r}function mT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(jS,{"data-slot":`collapsible`,...n}),t[2]=n,t[3]=r),r}function hT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(NS,{"data-slot":`collapsible-trigger`,...n}),t[2]=n,t[3]=r),r}function gT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(US,{"data-slot":`collapsible-content`,...n}),t[2]=n,t[3]=r),r}function _T(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(ZC,{"data-slot":`context-menu`,...n}),t[2]=n,t[3]=r),r}function vT(e){let t=(0,$.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=ua(`select-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)($C,{"data-slot":`context-menu-trigger`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function yT(e){let t=(0,$.c)(18),n,r,i,a,o,s;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6]):({className:n,align:i,alignOffset:a,side:o,sideOffset:s,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s);let c=i===void 0?`start`:i,l=a===void 0?4:a,u=o===void 0?`right`:o,d=s===void 0?0:s,f;t[7]===n?f=t[8]:(f=ua(`z-50 max-h-(--available-height) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,n),t[7]=n,t[8]=f);let p;t[9]!==r||t[10]!==f?(p=(0,Z.jsx)(TC,{"data-slot":`context-menu-content`,className:f,...r}),t[9]=r,t[10]=f,t[11]=p):p=t[11];let m;return t[12]!==c||t[13]!==l||t[14]!==u||t[15]!==d||t[16]!==p?(m=(0,Z.jsx)(OC,{children:(0,Z.jsx)(ew,{className:`isolate z-50 outline-none`,align:c,alignOffset:l,side:u,sideOffset:d,children:p})}),t[12]=c,t[13]=l,t[14]=u,t[15]=d,t[16]=p,t[17]=m):m=t[17],m}function bT(e){let t=(0,$.c)(12),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:n,inset:r,variant:a,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=a===void 0?`default`:a,s;t[5]===n?s=t[6]:(s=ua(`group/context-menu-item relative flex min-h-7 cursor-default items-center gap-2 rounded-md px-2 py-1 text-xs/relaxed outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7.5 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 data-[variant=destructive]:*:[svg]:text-destructive`,n),t[5]=n,t[6]=s);let c;return t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o?(c=(0,Z.jsx)(pC,{"data-slot":`context-menu-item`,"data-inset":r,"data-variant":o,className:s,...i}),t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=c):c=t[11],c}function xT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(yw,{"data-slot":`dialog`,...n}),t[2]=n,t[3]=r),r}function ST(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(fw,{"data-slot":`dialog-portal`,...n}),t[2]=n,t[3]=r),r}function CT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(iw,{"data-slot":`dialog-close`,...n}),t[2]=n,t[3]=r),r}function wT(e){let t=(0,$.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=ua(`fixed inset-0 isolate z-50 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(rw,{"data-slot":`dialog-overlay`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function TT(e){let t=(0,$.c)(15),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:r,children:n,showCloseButton:a,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=a===void 0||a,s;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Z.jsx)(wT,{}),t[5]=s):s=t[5];let c;t[6]===r?c=t[7]:(c=ua(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-xs/relaxed text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,r),t[6]=r,t[7]=c);let l;t[8]===o?l=t[9]:(l=o&&(0,Z.jsxs)(iw,{"data-slot":`dialog-close`,render:(0,Z.jsx)(Pa,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,Z.jsx)(Ur,{}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[8]=o,t[9]=l);let u;return t[10]!==n||t[11]!==i||t[12]!==c||t[13]!==l?(u=(0,Z.jsxs)(ST,{children:[s,(0,Z.jsxs)(dw,{"data-slot":`dialog-content`,className:c,...i,children:[n,l]})]}),t[10]=n,t[11]=i,t[12]=c,t[13]=l,t[14]=u):u=t[14],u}function ET(e){let t=(0,$.c)(14),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:r,showCloseButton:a,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=a!==void 0&&a,s;t[5]===r?s=t[6]:(s=ua(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,r),t[5]=r,t[6]=s);let c;t[7]===o?c=t[8]:(c=o&&(0,Z.jsx)(iw,{render:(0,Z.jsx)(Pa,{variant:`outline`}),children:`Close`}),t[7]=o,t[8]=c);let l;return t[9]!==n||t[10]!==i||t[11]!==s||t[12]!==c?(l=(0,Z.jsxs)(`div`,{"data-slot":`dialog-footer`,className:s,...i,children:[n,c]}),t[9]=n,t[10]=i,t[11]=s,t[12]=c,t[13]=l):l=t[13],l}function DT(e){let t=(0,$.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=ua(`text-sm font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(bw,{"data-slot":`dialog-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function OT(e){let t=(0,$.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=ua(`text-xs/relaxed text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(aw,{"data-slot":`dialog-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}bn(zt(sr(`AUTH_URL`)),g);function kT(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function AT(e){return kn(Ja)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}Ar()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var jT=class e extends An()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:Ja}){static layerClient=t=>_r(e,e=>R(function*(){return yield*e.next({...e.request,headers:Qt(e.request.headers,`authorization`,`Bearer ${yield*t}`)})}))},MT=Ov,NT=Av,PT=Mv,FT=Nt.check(Ee(/^[a-z0-9][a-z0-9_-]{0,23}$/u)),IT=Rn.check(Tn(2048),F(e=>{if(!URL.canParse(e))return!1;let t=new URL(e);return t.protocol===`https:`&&t.username===``&&t.password===``&&t.hash===``},{expected:`a public HTTPS URL without credentials or a fragment`})),LT=wr({url:IT}),RT=wr({id:FT}),zT=wr({authorization_endpoint:Rn,authorization_response_iss_parameter_supported:xe(dr),client_id_metadata_document_supported:xe(dr),issuer:Rn,registration_endpoint:xe(Rn),token_endpoint:Rn});wr({client_id:Rn});var BT=wr({access_token:Rn,expires_in:xe(Pn.check(m(0))),refresh_token:xe(Rn),token_type:Nt.check(Ee(/^Bearer$/iu))}),VT=wr({client:Nr({Document:{},Registered:{clientId:Rn}}),metadata:zT,scope:Nt}),HT=Nr({Authorized:{expiresAt:Pn,token:BT},Connected:{},Disconnected:{}}),UT=wr({src:Nt,theme:xe(Zn([`light`,`dark`]))}),WT=wr({error:xe(Nt),generation:Rn,icons:xe(Jn(UT)),id:FT,instructions:xe(Nt),link:HT,mode:Zn([`oauth`,`public`]),name:Rn,oauth:xe(VT),tools:Jn(Nt),url:IT});mn(Nt,WT);var GT=wr({error:xe(Nt),icons:Jn(UT),id:FT,name:Rn,status:Zn([`Connected`,`Not connected`,`Expired`]),tools:Jn(Nt),url:IT});Nr({Discovered:{icons:Jn(UT),instructions:xe(Nt),tools:Jn(Nt)},Failed:{error:Nt}}),wr({code:xe(Rn),error:xe(Nt),iss:xe(Rn),state:Rn});var KT=class extends qt(un(`gateway.servers`,{error:Ja,stream:!0,success:Jn(GT)}),un(`gateway.calls`,{error:Ja,stream:!0,success:FT}),un(`gateway.add`,{error:Ja,payload:LT,success:GT}),un(`gateway.remove`,{error:Ja,payload:RT})).middleware(jT){},qT=`${window.location.origin}/mcp`,JT=class extends en()(`@deslop/gateway/lib/utils/RpcClient`,{group:KT,protocol:Sa(`@deslop/gateway`)}){};function YT(e){return`/oauth/connect?${new URLSearchParams({id:e})}`}function XT(e){return Yt(e,e=>Ft(e(nt(`1 second`)),k(e=>e.input._tag===`RpcClientError`)))}var ZT=Je(JT.runtime.atom(XT(In(ue(JT,e=>e(`gateway.servers`,void 0)))))),QT=Je(JT.runtime.atom(XT(fn(In(ue(JT,e=>e(`gateway.calls`,void 0))))))),$T=Pr(e=>y(t=>{let n=Ke(t.self(),()=>-1);return I(t(QT),{onFailure:()=>n,onInitial:()=>n,onSuccess:t=>b(t.value[0]===e,{onFalse:()=>n,onTrue:()=>t.value[1]})})})),eE=Pr(e=>JT.runtime.fn(()=>_(JT,t=>t(`gateway.remove`,{id:e})))),tE=Ey(JT.runtime).make(NT({effects:{add:ut(function*(e){yield*Ft(Or(IT)(e),Ct(e=>Ja.make({cause:e,message:`Enter a public HTTPS MCP URL without credentials or a fragment, outside the gateway itself.`})));let t=yield*(yield*JT)(`gateway.add`,{url:e});t.status!==`Connected`&&location.assign(YT(t.id))})},events:PT({Cancel:{},Open:{},Submit:{},Typed:{url:Nt}}),root:MT({states:{Adding:{fields:{url:Nt}},Closed:{},Editing:{fields:{error:Nt,url:Nt}}}})}).handle({initial:{target:`Closed`},states:{Adding:{invoke:{input:e=>e.state.url,onDone:{target:`Closed`},onFailure:{data:e=>({error:e.error.message,url:e.state.url}),target:`Editing`},src:`add`}},Closed:{on:{Open:{data:{error:``,url:``},target:`Editing`}}},Editing:{on:{Cancel:{target:`Closed`},Submit:{data:e=>({url:e.state.url}),target:`Adding`},Typed:{data:e=>({error:``,url:e.event.url}),update:`Editing`}}}}})),nE=Bt(()=>yt(Xn(()=>navigator.clipboard.writeText(qT)),{onFailure:()=>vo.add({description:qT,title:`Cannot copy the MCP URL`,type:`error`}),onSuccess:()=>vo.add({title:`MCP URL copied`})})),rE=`/assets/icon-61pmFc-p.svg`,iE=St(le,e=>Ft(gr(e.status),Un(`Expired`,()=>0),Un(()=>e.error!==void 0,()=>0),Un(`Not connected`,()=>1),s(()=>2)));function aE(e){let t=(0,$.c)(10),n;t[0]===e.server.id?n=t[1]:(n=$T(e.server.id),t[0]=e.server.id,t[1]=n);let r=zu(n),i;t[2]===r?i=t[3]:(i=b(r>=0,{onFalse:uE,onTrue:lE}),t[2]=r,t[3]=i);let a;t[4]===e.server.status?a=t[5]:(a=Ft(gr(e.server.status),Un(`Connected`,cE),Un(`Expired`,sE),s(oE)),t[4]=e.server.status,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(pT,{className:i,status:a},r),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function oE(){return`off`}function sE(){return`error`}function cE(){return`live`}function lE(){return`port-blink`}function uE(){}function dE(e){let t=(0,$.c)(29),n;t[0]===e.server.id?n=t[1]:(n=eE(e.server.id),t[0]=e.server.id,t[1]=n);let[r,i]=Wu(n),a=e.open,o=e.onOpenChange,s;t[2]===e.server.name?s=t[3]:(s=(0,Z.jsxs)(DT,{children:[`Remove `,e.server.name,`?`]}),t[2]=e.server.name,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(OT,{children:`Its tools will no longer be available through the gateway. This does not revoke the provider’s grant.`}),t[4]=c):c=t[4];let l;t[5]===r?l=t[6]:(l=(0,Z.jsx)(uT,{result:r}),t[5]=r,t[6]=l);let u;t[7]===r?u=t[8]:(u=it(r),t[7]=r,t[8]=u);let d;t[9]===u?d=t[10]:(d=(0,Z.jsx)(CT,{render:(0,Z.jsx)(Pa,{variant:`ghost`,disabled:u}),children:`Cancel`}),t[9]=u,t[10]=d);let f;t[11]===r?f=t[12]:(f=it(r),t[11]=r,t[12]=f);let p;t[13]===i?p=t[14]:(p=()=>i(),t[13]=i,t[14]=p);let m;t[15]!==f||t[16]!==p?(m=(0,Z.jsx)(Pa,{variant:`destructive`,disabled:f,onClick:p,children:`Remove server`}),t[15]=f,t[16]=p,t[17]=m):m=t[17];let h;t[18]!==m||t[19]!==d?(h=(0,Z.jsxs)(ET,{children:[d,m]}),t[18]=m,t[19]=d,t[20]=h):h=t[20];let g;t[21]!==h||t[22]!==s||t[23]!==l?(g=(0,Z.jsxs)(TT,{children:[s,c,l,h]}),t[21]=h,t[22]=s,t[23]=l,t[24]=g):g=t[24];let _;return t[25]!==e.onOpenChange||t[26]!==e.open||t[27]!==g?(_=(0,Z.jsx)(xT,{open:a,onOpenChange:o,children:g}),t[25]=e.onOpenChange,t[26]=e.open,t[27]=g,t[28]=_):_=t[28],_}function fE(e){let t=(0,$.c)(7),[n,r]=(0,X.useState)(0),i;if(t[0]!==n||t[1]!==e.sources){let a;t[3]===n?a=t[4]:(a=e=>(0,Z.jsx)(`img`,{src:e,alt:``,className:`size-5 object-contain`,onError:()=>r(n+1)}),t[3]=n,t[4]=a),i=at(w(e.sources,n),{onNone:pE,onSome:a}),t[0]=n,t[1]=e.sources,t[2]=i}else i=t[2];let a;return t[5]===i?a=t[6]:(a=(0,Z.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:i}),t[5]=i,t[6]=a),a}function pE(){return(0,Z.jsx)(Zo,{className:`text-muted-foreground size-4`})}function mE(e){let t=(0,$.c)(9),n,r,i;if(t[0]!==e.server.icons||t[1]!==e.server.url){let a=new URL(e.server.url).hostname;r=et([...Sn(Le(e.server.icons,St($n,gE)),hE),`https://${a}/favicon.ico`,`https://${wn(/^(?:api|app|mcp)\./u,``)(a)}/favicon.ico`]),n=fE,i=f(r,` `),t[0]=e.server.icons,t[1]=e.server.url,t[2]=n,t[3]=r,t[4]=i}else n=t[2],r=t[3],i=t[4];let a;return t[5]!==n||t[6]!==r||t[7]!==i?(a=(0,Z.jsx)(n,{sources:r},i),t[5]=n,t[6]=r,t[7]=i,t[8]=a):a=t[8],a}function hE(e){return e.src}function gE(e){return e.theme!==`dark`}function _E(e){return Ft(gr(e.server.status),Un(`Expired`,()=>(0,Z.jsx)(`span`,{className:`text-destructive truncate`,children:`Sign-in expired`})),Un(`Not connected`,()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate`,children:`Not connected`})),s(()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate font-mono text-xs`,children:new URL(e.server.url).hostname})))}function vE(e){let t=(0,$.c)(86),n;t[0]===e.server.id?n=t[1]:(n=eE(e.server.id),t[0]=e.server.id,t[1]=n);let[r]=Wu(n),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(!1),c,l,u,d,f,p,m,h,g,_;t[2]!==i||t[3]!==o||t[4]!==e.server?(_=Dn(e.server.tools),t[15]!==i||t[16]!==e.server?(g=(0,Z.jsx)(dE,{open:i,onOpenChange:a,server:e.server}),t[15]=i,t[16]=e.server,t[17]=g):g=t[17],u=mT,f=`listitem`,p=o&&_,m=s,h=`border-b`,l=_T,c=vT,d=b(_,{onFalse:CE,onTrue:SE}),t[2]=i,t[3]=o,t[4]=e.server,t[5]=c,t[6]=l,t[7]=u,t[8]=d,t[9]=f,t[10]=p,t[11]=m,t[12]=h,t[13]=g,t[14]=_):(c=t[5],l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12],g=t[13],_=t[14]);let v;t[18]===d?v=t[19]:(v=(0,Z.jsx)(`div`,{tabIndex:d,className:`hover:bg-muted/50 relative flex h-10 min-w-0 items-center gap-3 px-1 text-sm`}),t[18]=d,t[19]=v);let y;t[20]!==e.server.name||t[21]!==_?(y=_&&(0,Z.jsx)(hT,{"aria-label":`Tools of ${e.server.name}`,className:`absolute inset-0 cursor-pointer`}),t[20]=e.server.name,t[21]=_,t[22]=y):y=t[22];let x;t[23]===e.server?x=t[24]:(x=(0,Z.jsx)(mE,{server:e.server}),t[23]=e.server,t[24]=x);let S;t[25]===e.server.name?S=t[26]:(S=(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.server.name}),t[25]=e.server.name,t[26]=S);let C;t[27]===e.server?C=t[28]:(C=(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-1`,children:(0,Z.jsx)(_E,{server:e.server})}),t[27]=e.server,t[28]=C);let w;t[29]!==e.server.tools||t[30]!==_?(w=_&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground shrink-0 font-mono text-xs max-sm:hidden`,children:[e.server.tools.length,` tools`]}),t[29]=e.server.tools,t[30]=_,t[31]=w):w=t[31];let T;t[32]!==e.server.error||t[33]!==e.server.id||t[34]!==e.server.status||t[35]!==r?(T=(e.server.status!==`Connected`||e.server.error!==void 0)&&(0,Z.jsx)(Pa,{size:`sm`,variant:`outline`,className:`relative shrink-0`,disabled:it(r),onClick:()=>location.assign(YT(e.server.id)),children:b(e.server.status===`Not connected`,{onFalse:xE,onTrue:bE})}),t[32]=e.server.error,t[33]=e.server.id,t[34]=e.server.status,t[35]=r,t[36]=T):T=t[36];let E;t[37]===e.server?E=t[38]:(E=(0,Z.jsx)(aE,{server:e.server}),t[37]=e.server,t[38]=E);let D;t[39]!==e.server.status||t[40]!==E?(D=(0,Z.jsx)(`span`,{role:`img`,title:e.server.status,"aria-label":e.server.status,className:`flex size-3 shrink-0 items-center justify-center`,children:E}),t[39]=e.server.status,t[40]=E,t[41]=D):D=t[41];let O;t[42]!==o||t[43]!==_?(O=_&&(0,Z.jsx)(Uo,{className:ua(`size-3.5 transition-transform`,o&&`rotate-90`)}),t[42]=o,t[43]=_,t[44]=O):O=t[44];let k;t[45]===O?k=t[46]:(k=(0,Z.jsx)(`span`,{className:`text-muted-foreground flex size-3.5 shrink-0 items-center justify-center`,children:O}),t[45]=O,t[46]=k);let A;t[47]!==c||t[48]!==S||t[49]!==C||t[50]!==w||t[51]!==T||t[52]!==D||t[53]!==k||t[54]!==v||t[55]!==y||t[56]!==x?(A=(0,Z.jsxs)(c,{render:v,children:[y,x,S,C,w,T,D,k]}),t[47]=c,t[48]=S,t[49]=C,t[50]=w,t[51]=T,t[52]=D,t[53]=k,t[54]=v,t[55]=y,t[56]=x,t[57]=A):A=t[57];let j;t[58]===r?j=t[59]:(j=it(r),t[58]=r,t[59]=j);let M;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>a(!0),t[60]=M):M=t[60];let N;t[61]===j?N=t[62]:(N=(0,Z.jsx)(yT,{className:`w-auto min-w-36`,children:(0,Z.jsx)(bT,{variant:`destructive`,disabled:j,onClick:M,children:`Remove`})}),t[61]=j,t[62]=N);let P;t[63]!==l||t[64]!==A||t[65]!==N?(P=(0,Z.jsxs)(l,{children:[A,N]}),t[63]=l,t[64]=A,t[65]=N,t[66]=P):P=t[66];let F;t[67]===e.server.error?F=t[68]:(F=e.server.error!==void 0&&(0,Z.jsx)(`p`,{className:`text-destructive pr-1 pb-2 pl-9 text-xs wrap-anywhere`,children:e.server.error}),t[67]=e.server.error,t[68]=F);let I=`Tools of ${e.server.name}`,L;t[69]===e.server.tools?L=t[70]:(L=Sn(e.server.tools,yE),t[69]=e.server.tools,t[70]=L);let R;t[71]!==I||t[72]!==L?(R=(0,Z.jsx)(gT,{children:(0,Z.jsx)(`ul`,{"aria-label":I,className:`pb-1`,children:L})}),t[71]=I,t[72]=L,t[73]=R):R=t[73];let ee;t[74]!==u||t[75]!==f||t[76]!==P||t[77]!==F||t[78]!==R||t[79]!==p||t[80]!==m||t[81]!==h?(ee=(0,Z.jsxs)(u,{role:f,open:p,onOpenChange:m,className:h,children:[P,F,R]}),t[74]=u,t[75]=f,t[76]=P,t[77]=F,t[78]=R,t[79]=p,t[80]=m,t[81]=h,t[82]=ee):ee=t[82];let te;return t[83]!==ee||t[84]!==g?(te=(0,Z.jsxs)(Z.Fragment,{children:[g,ee]}),t[83]=ee,t[84]=g,t[85]=te):te=t[85],te}function yE(e){return(0,Z.jsx)(`li`,{className:`flex h-8 items-center pr-1 pl-9 font-mono text-xs select-text`,children:e},e)}function bE(){return`Connect`}function xE(){return`Reconnect`}function SE(){}function CE(){return 0}function wE(e){let t=(0,$.c)(31),n=Uu(tE.send),r;t[0]===n?r=t[1]:(r=e=>{e.preventDefault(),n({_tag:`Submit`})},t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Z.jsx)(DT,{children:`Add a server`}),t[2]=i):i=t[2];let a=e.error!==``,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(oT,{htmlFor:`mcp-url`,children:`MCP URL`}),t[3]=o):o=t[3];let s;t[4]===n?s=t[5]:(s=e=>n({_tag:`Typed`,url:e.target.value}),t[4]=n,t[5]=s);let c=e.error!==``,l;t[6]!==e.adding||t[7]!==e.url||t[8]!==s||t[9]!==c?(l=(0,Z.jsx)(Cw,{id:`mcp-url`,type:`url`,autoComplete:`url`,placeholder:`https://example.com/mcp`,required:!0,autoFocus:!0,value:e.url,disabled:e.adding,onChange:s,"aria-invalid":c,"aria-describedby":`mcp-add-error`}),t[6]=e.adding,t[7]=e.url,t[8]=s,t[9]=c,t[10]=l):l=t[10];let u;t[11]===e.error?u=t[12]:(u=(0,Z.jsx)(sT,{id:`mcp-add-error`,children:e.error}),t[11]=e.error,t[12]=u);let d;t[13]!==a||t[14]!==l||t[15]!==u?(d=(0,Z.jsxs)(aT,{"data-invalid":a,children:[o,l,u]}),t[13]=a,t[14]=l,t[15]=u,t[16]=d):d=t[16];let f;t[17]===e.adding?f=t[18]:(f=(0,Z.jsx)(CT,{render:(0,Z.jsx)(Pa,{variant:`ghost`,type:`button`,disabled:e.adding}),children:`Cancel`}),t[17]=e.adding,t[18]=f);let p=e.adding,m;t[19]===e.adding?m=t[20]:(m=b(e.adding,{onFalse:EE,onTrue:TE}),t[19]=e.adding,t[20]=m);let h;t[21]!==e.adding||t[22]!==m?(h=(0,Z.jsx)(Pa,{type:`submit`,disabled:p,children:m}),t[21]=e.adding,t[22]=m,t[23]=h):h=t[23];let g;t[24]!==h||t[25]!==f?(g=(0,Z.jsxs)(ET,{children:[f,h]}),t[24]=h,t[25]=f,t[26]=g):g=t[26];let _;return t[27]!==r||t[28]!==g||t[29]!==d?(_=(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:r,children:[i,d,g]}),t[27]=r,t[28]=g,t[29]=d,t[30]=_):_=t[30],_}function TE(){return`Adding…`}function EE(){return`Add server`}function DE(){let e=(0,$.c)(11),t=Uu(tE.send),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Ty(tE,`Editing`),e[0]=n):n=e[0];let r=Ge(ky(n),pt),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Ty(tE,`Adding`),e[1]=i):i=e[1];let a=Ge(ky(i),pt),o=L(z(r,jE),()=>z(a,AE)),s=xT,c=lt(o),l=e=>{!e&<(r)&&t({_tag:`Cancel`})},u=TT,d=g(a),f=at(o,{onNone:kE,onSome:OE}),p;e[2]!==u||e[3]!==d||e[4]!==f?(p=(0,Z.jsx)(u,{showCloseButton:d,children:f}),e[2]=u,e[3]=d,e[4]=f,e[5]=p):p=e[5];let m;return e[6]!==s||e[7]!==c||e[8]!==l||e[9]!==p?(m=(0,Z.jsx)(s,{open:c,onOpenChange:l,children:p}),e[6]=s,e[7]=c,e[8]=l,e[9]=p,e[10]=m):m=e[10],m}function OE(e){return(0,Z.jsx)(wE,{...e})}function kE(){return null}function AE(e){return{adding:!0,error:``,url:e.url}}function jE(e){return{adding:!1,error:e.error,url:e.url}}function ME(e){let t=(0,$.c)(7),n=Jw(),r;if(t[0]!==e.servers||t[1]!==n){let i;t[3]===n?i=t[4]:(i=e=>Fe(n)(Ae(`${e.name} ${e.url}`)),t[3]=n,t[4]=i);let a;t[5]===n?a=t[6]:(a=()=>(0,Z.jsx)(ja,{children:(0,Z.jsx)(Za,{children:(0,Z.jsx)(La,{children:b(n===``,{onFalse:IE,onTrue:FE})})})}),t[5]=n,t[6]=a),r=Ce(D(Le(e.servers,iE),i),{onEmpty:a,onNonEmpty:NE}),t[0]=e.servers,t[1]=n,t[2]=r}else r=t[2];return r}function NE(e){return(0,Z.jsx)(`div`,{role:`list`,"aria-label":`MCP servers`,children:Sn(e,PE)})}function PE(e){return(0,Z.jsx)(vE,{server:e},e.id)}function FE(){return`No servers yet`}function IE(){return`No server matches`}function LE(){let e=(0,$.c)(5),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={includeFailure:!0},e[0]=t):t=e[0];let n=Ju(ZT,t);if(ne(n)){let t;return e[1]===n.value?t=e[2]:(t=(0,Z.jsx)(ME,{servers:n.value}),e[1]=n.value,e[2]=t),t}let r;return e[3]===n.cause?r=e[4]:(r=at(Jt(n.cause),{onNone:()=>(0,Z.jsx)(Co,{error:Fr(n.cause),reset:VE}),onSome:RE}),e[3]=n.cause,e[4]=r),r}function RE(e){return e._tag===`AuthError`?e.error===`access_denied`?(0,Z.jsx)(ja,{children:(0,Z.jsxs)(Za,{children:[(0,Z.jsx)(La,{children:`Admins only`}),(0,Z.jsx)(oo,{children:e.message})]})}):AT(e)?(0,Z.jsx)(Ta,{href:kT(location.href)}):(0,Z.jsx)(Co,{error:e,reset:zE}):(0,Z.jsx)(Co,{error:e,reset:BE})}function zE(){return location.reload()}function BE(){return location.reload()}function VE(){return location.reload()}function HE(){let e=(0,$.c)(24),t=Uu(tE.send),n=Uu(nE),r=ne(zu(ZT)),i=$w,a=rE,o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(qo,{}),e[0]=o):o=e[0];let s;e[1]===t?s=e[2]:(s=()=>t({_tag:`Open`}),e[1]=t,e[2]=s);let c;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(Go,{}),e[3]=c):c=e[3];let l;e[4]===n?l=e[5]:(l=()=>n(),e[4]=n,e[5]=l);let u=D([{icon:o,label:`Add server`,run:s},{icon:c,label:`Copy MCP URL`,run:l}],e=>r||e.label===`Copy MCP URL`),d;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(Go,{}),e[6]=d):d=e[6];let f;e[7]===n?f=e[8]:(f=(0,Z.jsx)(Qw,{icon:d,label:`Copy MCP URL`,variant:`outline`,onClick:()=>n()}),e[7]=n,e[8]=f);let p;e[9]!==r||e[10]!==t?(p=r&&(0,Z.jsx)(Qw,{icon:(0,Z.jsx)(qo,{}),label:`Add server`,onClick:()=>t({_tag:`Open`})}),e[9]=r,e[10]=t,e[11]=p):p=e[11];let m;e[12]!==f||e[13]!==p?(m=(0,Z.jsxs)(Z.Fragment,{children:[f,p]}),e[12]=f,e[13]=p,e[14]=m):m=e[14];let h;e[15]!==i||e[16]!==a||e[17]!==m||e[18]!==u?(h=(0,Z.jsx)(i,{icon:a,name:`gateway`,commands:u,action:m}),e[15]=i,e[16]=a,e[17]=m,e[18]=u,e[19]=h):h=e[19];let g,_;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(nT,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(tT,{label:`MCP servers`,media:!0,rows:4}),children:(0,Z.jsx)(LE,{})})}),_=(0,Z.jsx)(DE,{}),e[20]=g,e[21]=_):(g=e[20],_=e[21]);let v;return e[22]===h?v=e[23]:(v=(0,Z.jsxs)(Z.Fragment,{children:[h,g,_]}),e[22]=h,e[23]=v),v}export{HE as component};
|