@deslop/gateway 0.1.1237 → 0.1.1241
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/assets/(home)-RhAkUc53.js +1 -0
- package/dist/client/assets/effect-y8-0v7UZ.js +17 -0
- package/dist/client/assets/index-BeNnxYGw.js +4 -0
- package/dist/client/assets/index-ToF0ONjz.css +2 -0
- package/dist/client/index.html +3 -3
- package/dist/server.js +40 -4
- package/package.json +2 -2
- package/dist/client/assets/(home)-B4AqQVYP.js +0 -1
- package/dist/client/assets/effect-DJFrJOhz.js +0 -17
- package/dist/client/assets/index-BfeepIKf.js +0 -4
- package/dist/client/assets/index-CMIaK29s.css +0 -2
|
@@ -1 +0,0 @@
|
|
|
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 V,Ii as ae,In as oe,J as se,Ji as ce,Jn as le,Jr as ue,Jt as de,K as fe,Ki as pe,Kn as me,Kr as he,Kt as ge,L as _e,Li as ve,Ln as ye,Lt as be,M as xe,Mi as Se,Mn as Ce,Mr as we,Mt as Te,N as Ee,Ni as De,Nn as Oe,Nr as ke,Nt as Ae,O as je,Oi as Me,On as Ne,Or as Pe,P as Fe,Pi as Ie,Pn as Le,Pr as Re,Pt as ze,Q as Be,Qi as H,Qn as Ve,Qr as He,Qt as Ue,R as We,Ri as Ge,Rn as U,Rt as Ke,S as qe,Si as Je,Sn as Ye,Sr as Xe,St as Ze,T as Qe,Ti as $e,Tn as et,Tr as tt,Tt as nt,U as rt,Ui as it,Un as at,Ur as ot,Ut as st,V as W,Vi as ct,Vn as lt,Vt as ut,W as dt,Wi as ft,Wn as pt,Wr as mt,Wt as ht,X as gt,Xi as _t,Xn as vt,Xr as yt,Xt as bt,Yi as xt,Yn as St,Yr as Ct,Yt as wt,Z as Tt,Zi as Et,Zn as Dt,Zr as Ot,Zt as kt,_i as At,_n as jt,_r as G,_t as Mt,a as Nt,aa as Pt,ai as Ft,an as It,ar as Lt,at as Rt,b as zt,bi as Bt,bn as Vt,br as Ht,bt as Ut,cn as Wt,cr as Gt,ct as Kt,d as qt,di as Jt,dn as Yt,dr as Xt,dt as Zt,ei as Qt,en as $t,er as en,f as tn,fi as nn,fn as rn,fr as an,ft as on,gi as sn,gn as cn,gr as ln,gt as un,h as dn,hi as fn,hn as pn,hr as mn,ht as hn,i as gn,ia as _n,ii as vn,in as yn,ir as bn,it as xn,j as Sn,ji as Cn,jn as wn,jr as Tn,jt as En,k as Dn,ki as On,kn,kt as An,l as jn,li as Mn,ln as Nn,lr as Pn,lt as Fn,mi as In,mn as Ln,mr as Rn,mt as zn,n as Bn,ni as Vn,nn as Hn,nr as Un,nt as Wn,oa as Gn,oi as Kn,on as qn,or as Jn,ot as Yn,pn as Xn,pr as Zn,pt as Qn,q as $n,qi as er,qn as tr,qr as nr,qt as rr,r as ir,ri as ar,rn as or,rr as sr,rt as cr,si as lr,sn as ur,sr as dr,st as fr,t as pr,ti as mr,tn as hr,tr as gr,tt as _r,u as vr,ui as yr,un as br,ur as xr,v as Sr,vn as Cr,vr as wr,vt as Tr,w as Er,wn as Dr,wr as Or,wt as kr,x as Ar,xi as jr,xn as Mr,xr as Nr,xt as Pr,y as Fr,yi as Ir,yn as Lr,yr as Rr,yt as zr,z as Br,zi as Vr,zn as Hr,zt as Ur}from"./effect-DJFrJOhz.js";import{$ as Wr,$n as Gr,$t as Kr,A as qr,An as K,At as Jr,B as Yr,Bn as Xr,Bt as Zr,C as Qr,Cn as $r,Ct as ei,D as ti,Dn as ni,Dt as ri,E as ii,En as ai,Et as oi,F as si,Fn as ci,Ft as li,G as ui,Gn as di,Gt as fi,H as pi,Hn as mi,Ht as hi,I as gi,In as _i,It as vi,J as yi,Jn as bi,Jt as q,K as xi,Kn as Si,Kt as Ci,L as wi,Ln as Ti,Lt as Ei,M as Di,Mn as Oi,Mt as ki,N as Ai,Nn as ji,Nt as Mi,On as Ni,Ot as Pi,P as Fi,Pn as Ii,Pt as Li,Q as Ri,Qn as zi,Qt as Bi,R as Vi,Rn as Hi,Rt as Ui,S as Wi,Sn as Gi,St as Ki,T as qi,Tn as Ji,Tt as Yi,U as Xi,Un as Zi,Ut as Qi,V as $i,Vn as ea,Vt as ta,W as na,Wn as ra,Wt as ia,X as aa,Xn as oa,Xt as sa,Y as ca,Yn as la,Yt as ua,Z as da,Zn as fa,Zt as pa,_ as ma,_n as ha,_t as ga,a as _a,an as va,at as ya,b as ba,bn as xa,bt as Sa,c as Ca,cn as wa,ct as Ta,d as Ea,dn as Da,dt as Oa,en as ka,er as Aa,et as ja,f as Ma,fn as Na,ft as Pa,g as Fa,gn as Ia,gt as La,h as Ra,hn as za,ht as Ba,i as Va,in as Ha,it as Ua,j as Wa,jn as J,jt as Ga,k as Ka,kn as qa,kt as Ja,l as Ya,ln as Xa,lt as Za,m as Qa,mn as $a,mt as eo,n as to,nn as no,nt as ro,o as io,on as ao,ot as oo,p as so,pn as co,pt as lo,q as uo,qn as fo,qt as po,r as mo,rn as ho,rt as go,s as _o,sn as vo,st as yo,t as bo,tn as xo,tr as So,tt as Co,u as wo,un as To,ut as Eo,v as Do,vn as Oo,vt as ko,w as Y,wn as Ao,wt as jo,x as Mo,xn as No,xt as Po,y as Fo,yn as Io,yt as Lo,z as Ro,zn as zo}from"./index-BfeepIKf.js";var Bo={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};Bo.node;var Vo=Aa(Bo),Ho={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};Ho.node;var Uo=Aa(Ho),Wo={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Wo.node;var Go=Aa(Wo),Ko={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`}]]};Ko.node;var qo=Aa(Ko),Jo={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Jo.node;var Yo=Aa(Jo),Xo={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Xo.node;var Zo=Aa(Xo),Qo={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`}]]};Qo.node;var $o=Aa(Qo),es=`data-open`,ts=`data-closed`,ns=`data-anchor-hidden`,rs={[vi]:``},is={[vi]:``,[Ei]:``},as={[es]:``},os={[ts]:``},ss={[ns]:``},cs={open(e){return e?rs:null}},ls={open(e){return e?is:null}},us={open(e){return e?as:os},anchorHidden(e){return e?ss:null}},ds={...us,...Ui};function fs(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...fs(e,t.id,n)])}function ps(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 ms(e,t=!1){let{overflowY:n}=ji(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}function hs(e){let t=Oi(gs,e).current;return t.next=e,K(t.effect),t}function gs(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var _s=0;function vs(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(_s);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Gi;let o=requestAnimationFrame(a);return _s=o,()=>{_s===o&&(cancelAnimationFrame(o),_s=0)}}var ys=`data-base-ui-inert`,bs=new WeakMap,xs=new WeakSet,Ss=new WeakMap,Cs=0;function ws(e){return e?fo(e)?e.host:ws(e.parentNode):null}var Ts=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=ws(t);return e.contains(n)?n:null}).filter(e=>e!=null),Es=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},Ds=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{Ti(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function Os(e,t,n,{mark:r=!0}){let i=Ts(t,e),a=r?Ds(t,Es(i),new Set(i)):[],o=[],s=[];if(n){let e=Ts(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);Ds(t,Es(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(bs.get(e)||0)+1;bs.set(e,r),o.push(e),r===1&&n&&xs.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(Ss.get(e)||0)+1;Ss.set(e,t),s.push(e),t===1&&e.setAttribute(ys,``)}),Cs+=1,()=>{o.forEach(e=>{let t=(bs.get(e)||0)-1;bs.set(e,t),t||(xs.has(e)||e.removeAttribute(`aria-hidden`),xs.delete(e))}),r&&s.forEach(e=>{let t=(Ss.get(e)||0)-1;Ss.set(e,t),t||e.removeAttribute(ys)}),--Cs,Cs||(bs=new WeakMap,xs=new WeakSet,Ss=new WeakMap)}}function ks(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=ai(e[0]).body;return Os(e,i,n,{mark:r})}function As(){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 js=class{nodesRef={current:[]};events=As();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(),Ms=X.createContext(null),Ns=X.createContext(null),Ps=()=>X.useContext(Ms)?.id||null,Fs=e=>{let t=X.useContext(Ns);return e??t};function Is(e){let t=ii(),n=Fs(e),r=Ps();return K(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function Ls(e){let{children:t,id:n}=e,r=Ps();return(0,Z.jsx)(Ms.Provider,{value:X.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Rs(e){let{children:t,externalTree:n}=e,r=Oi(()=>n??new js).current;return(0,Z.jsx)(Ns.Provider,{value:r,children:t})}function zs(e,t){let n=ea(ua(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(Yi(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Bs=20,Vs=[];function Hs(){Vs=Vs.filter(e=>e.deref()?.isConnected)}function Us(e){Hs(),e&&Ti(e)!==`body`&&(Vs.push(new WeakRef(e)),Vs.length>Bs&&(Vs=Vs.slice(-20)))}function Ws(){return Hs(),Vs[Vs.length-1]?.deref()}function Gs(e){return e?yi(e)?e:ca(e)[0]||e:null}function Ks(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Xi(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return yi(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 qs(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=Mi(_)&&S,w=hs(i),T=hs(a),E=hs(o),D=hs(u),O=hs(g),k=Fs(m),A=mo(),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=$r(L,p,A?.beforeInsideRef),te=$r(R,A?.afterInsideRef),ne=ho(),z=ho(),re=gi(),ie=A!=null,B=Pi(v),V=J((e=B)=>e?ca(e):[]),ae=J(()=>h?.().filter(e=>e!=null)??[]);X.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&q(B,Ci(ai(B)))&&V().length===0&&!C&&ri(e)}let t=ai(B);return pi(t,`keydown`,e)},[r,B,c,C,V]),X.useEffect(()=>{if(r||!g)return;let e=ai(B);function t(){N.current=!1}function n(e){let t=ua(e),n=ae(),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`,po(t,`[data-base-ui-click-trigger]`)&&(M.current=!0,z.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return $i(pi(e,`pointerdown`,n,!0),pi(e,`pointerup`,t,!0),pi(e,`pointercancel`,t,!0),pi(e,`keydown`,i,!0),t)},[r,v,_,B,g,A,z,ae]),X.useEffect(()=>{if(r||!l)return;let e=ai(B);function n(){M.current=!0,z.start(0,()=>{M.current=!1})}function i(e){let t=ua(e);yi(t)&&(P.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=ua(n);c&&r==null&&a!=null&&q(v,a)&&Us(a),queueMicrotask(()=>{let o=x(),l=t.context.triggerElements,u=ae(),p=r?.hasAttribute(Va(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Fi(f),Fi(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&&(fs(k.nodesRef.current,o).find(e=>q(e.context?.elements.floating,r)||q(e.context?.elements.domReference,r))||ps(k.nodesRef.current,o).find(e=>[e.context?.elements.floating,Pi(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===_&&B&&Ks(B),s&&i!==_&&!ja(a)&&Ci(e)===e.body){if(ra(B)&&(B.focus(),s===`popup`)){re.request(()=>{B.focus()});return}let e=V(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||B;ra(n)&&n.focus()}b.current.insideReactTree?b.current.insideReactTree=!1:(C||!c)&&r&&m&&!M.current&&(C||r!==Ws())&&(j.current=!0,t.setOpen(!1,Y(Ya,n)))})}function o(){N.current||(b.current.insideReactTree=!0,ne.start(0,()=>{b.current.insideReactTree=!1}))}let u=ra(_)?_:null;if(v||u)return $i(u&&pi(u,`focusout`,a),u&&pi(u,`pointerdown`,n),v&&pi(v,`focusin`,i),v&&pi(v,`focusout`,a),v&&A&&pi(v,`focusout`,o,!0))},[r,_,v,B,c,k,A,t,l,s,V,C,x,b,ne,z,re,d,f,ae]),X.useEffect(()=>{if(r||!v||!g)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${Va(`portal`)}]`)||[]),t=(k?ps(k.nodesRef.current,x()):[]).find(e=>Mi(e.context?.elements.domReference||null))?.context?.elements.domReference,n=ks([v,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...ae(),t,Fi(f),Fi(d),C?_:null].filter(e=>e!=null),{ariaHidden:c||C,mark:!1}),i=ks([v,...e].filter(e=>e!=null));return()=>{i(),n()}},[g,r,_,v,c,A,C,k,x,d,f,ae]),K(()=>{if(!g||r||!ra(B))return;F.current=``,I.current=``;let e=ai(B),t=Ci(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??=V(B),i[0]||B),o;o=r===!0||r===null?a():Fi(r),o||=a();let s=q(B,Ci(e)),c=b.current.openEvent,l=c?.type===`mousedown`&&Yi(c);vs(o,{sync:l,preventScroll:o===B,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=Ci(e);return!(t!==o&&q(B,t))}})})},[r,g,B,V,w,D,O,b]);let oe=X.useRef(null);K(()=>{if(r||!B){oe.current=null;return}oe.current&&=(oe.current.cancelled=!0,null);let e=ai(B),t=Ci(e),n=D.current==null;Us(t);function i(e){if(e.open||(F.current=zs(e.nativeEvent,I.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(Va(`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(Yi(e.nativeEvent)||oi(e.nativeEvent))j.current=!1;else{let e=!1;ai(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&&Ti(t)!==`body`?t:null,s=n?o||a:a||o;return s||=Ws()||null,typeof i==`boolean`?s:Fi(i)||s||null}return()=>{y.off(`openchange`,i);let t=Ci(e),n=ae(),r=q(v,t)||n.some(e=>e===t||q(e,t))||k&&fs(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};oe.current=l,queueMicrotask(()=>{oe.current===l&&(oe.current=null);let n=Gs(c),i=E.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!j.current&&ra(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,ae]),K(()=>{if(!Bi||g||!v)return;let e=Ci(ai(v));ra(e)&&Li(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 Ks(B),()=>{queueMicrotask(Hs)}},[r,B]);let se=!r&&(!c||!C)&&(ie||c);return(0,Z.jsxs)(X.Fragment,{children:[se&&(0,Z.jsx)(Vi,{"data-type":`inside`,ref:ee,onFocus:e=>{if(c){let e=V();vs(e[e.length-1])}else A?.portalNode&&(j.current=!1,uo(e,A.portalNode)?na(_)?.focus():Fi(f??A.beforeOutsideRef)?.focus())}}),n,se&&(0,Z.jsx)(Vi,{"data-type":`inside`,ref:te,onFocus:e=>{c?vs(V()[0]):A?.portalNode&&(l&&(j.current=!0),uo(e,A.portalNode)?ui(_)?.focus():Fi(d??A.afterOutsideRef)?.focus())}})]})}function Js(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=Qr}=t,l=e.context.dataRef,u=X.useRef(void 0),d=gi(),f=ho(),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=ei(e.pointerType,!0)&&oi(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||ei(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=ua(s),p=Li(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:ei(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}:No,[n,p])}function Ys(){return!1}function Xs(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function Zs(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=Ys,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:f}=e.context,p=Fs(c),m=J(typeof i==`function`?i:()=>!1),h=typeof i==`function`?m:i,g=h!==!1,_=J(()=>a),{escapeKey:v,outsidePress:y}=Xs(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=ho(),O=ho(),k=ho(),A=J(()=>{O.clear(),d.current.insideReactTree=!1}),j=J(e=>{let t=d.current.floatingContext?.nodeId;return(p?fs(p.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),M=J(t=>Ja(t,e.select(`floatingElement`))||Ja(t,e.select(`domReferenceElement`))),N=J(t=>{o()&&e.setOpen(!1,Y(Qr,t.nativeEvent))}),P=J(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=jo(t)?t.nativeEvent:t;if(w.current||i.isComposing||!v&&j(`__escapeKeyBubbles`))return;let a=Y(Ca,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=ua(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 no,i=ai(u);function a(){k.clear(),w.current=!0}function o(){w.current=!0,k.start(Bi?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&&fs(p.nodesRef.current,t).some(t=>Ja(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=ua(n),i=`[${Va(`inert`)}]`,a=Zi(r)?r.getRootNode():null,o=Array.from((fo(a)?a:ai(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>q(e,r))))return;let c=Zi(r)?r:null;for(;c&&!di(c);){let e=Xr(c);if(di(e)||!Zi(e))break;c=e}if(!(o.length&&Zi(r)&&!Ga(r)&&!q(r,e.select(`floatingElement`))&&o.every(e=>!q(c,e)))){if(ra(r)&&!(`touches`in n)){let e=di(r),t=ji(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&&!Yi(n)&&!C.current)return;if(S.current){t.clear(),S.current=!1;return}}typeof h==`function`&&!h(n)||j(`__outsidePressBubbles`)||(e.setOpen(!1,Y(Do,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=ua(e);if(!n)return;let r=pi(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=$i(r&&$i(pi(i,`keydown`,P),pi(i,`compositionstart`,a),pi(i,`compositionend`,o)),g&&$i(pi(i,`click`,ee,!0),pi(i,`pointerdown`,ee,!0),pi(i,`pointerup`,te,!0),pi(i,`pointercancel`,te,!0),pi(i,`mousedown`,ee,!0),pi(i,`mouseup`,te,!0),pi(i,`touchstart`,R,{capture:!0,passive:!0}),pi(i,`touchmove`,z,{capture:!0,passive:!0}),pi(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 Qs(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};Zi(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 $s(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=si.request(()=>{a(`ending`)});return()=>{si.cancel(e)}}},[e,o,i,n]),K(()=>{if(!e||t||i===void 0)return;let n=si.request(()=>{a(void 0)});return()=>{si.cancel(n)}},[t,e,i]),K(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=si.request(()=>{a(`idle`)});return()=>{si.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function ec(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=J(i),{mounted:c,setMounted:l,transitionStatus:u}=$s(t,!1,!1,o),d=!t&&r;K(()=>{t&&s(!1)},[t,s]);let f=X.useRef(c),p=X.useRef(!1),m=ti(),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 Di({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||g()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:g}}var tc=e(n(),1),nc={tabIndex:-1,[fi]:``};function rc(e){return t=>t!==`touch`||e.current}function ic(e,t=!1){let n=ii(),r=Ps()!=null,i=Oi(()=>e(n,r)).current;return Qs({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function ac({handle:e,store:t}){return K(()=>e.attachStore(t),[e,t]),null}function oc(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function sc(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),oc(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),oc(t))})}function cc(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 lc(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function uc(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=sc(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 dc(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(ma);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,a,o,s,n])}function fc(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=ec({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 Oi(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function pc(e,t){e.useSyncedValues(t),K(()=>()=>{e.update({activeTriggerProps:No,inactiveTriggerProps:No,popupProps:No})},[e])}function mc(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 hc=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}},gc={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},_c=class extends Ha{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:As(),nested:n,triggerElements:i},gc),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&Ki(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 vc(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new _c({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:No,inactiveTriggerProps:No,popupProps:No}}var yc=e=>e.triggerIdProp??e.activeTriggerId,bc=e=>e.openProp??e.open,xc=e=>(e.popupElement?.id??e.floatingId)||void 0;function Sc(e,t){return t!==void 0&&bc(e)&&yc(e)===t}function Cc(e,t){return Sc(e,t)?!0:t!==void 0&&bc(e)&&yc(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var wc={open:bc,mounted:e=>e.mounted,transitionStatus:e=>bc(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:yc,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:xc,isTriggerActive:(e,t)=>t!==void 0&&yc(e)===t,isOpenedByTrigger:(e,t)=>Sc(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&yc(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Cc(e,t)?xc(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement},Tc=So();function Ec(e){let t=X.useCallback(t=>e===void 0?Gi:e.subscribeStore(t),[e]),n=X.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Tc.useSyncExternalStore)(t,n,()=>e?.serverStore)}function Dc(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=ii(),a=Ps()!=null,o=Oi(()=>new _c({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new hc,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=Zi(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 Oc=xo&&Bi;function kc(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=ho();X.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=ea(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&ra(t)&&t===Ci(ai(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return $i(pi(r,`blur`,i),Oc&&pi(r,`keydown`,a,!0),Oc&&pi(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`);Zi(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=ua(n.nativeEvent);if(Zi(a)){if(Oc&&!n.relatedTarget){if(!c.current&&!Li(a))return}else if(!li(a))return}let u=ki(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,Y(Mo,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,Y(Mo,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=Zi(r)&&r.hasAttribute(Va(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=Ci(ai(t));!r&&n===t||q(a.current.floatingContext?.refs.floating.current,n)||q(t,n)||o||ki(r??n,e.context.triggerElements)||e.setOpen(!1,Y(Mo,i))})}}},[a,r,e,l]);return X.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var Ac=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new no;restTimeout=new no;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},jc=new WeakMap;function Mc(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&jc.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),jc.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Nc(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=jc.get(n);a&&a!==e&&Mc(a),Mc(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,jc.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Pc(e){let t=e.context.dataRef.current,n=Oi(()=>t.hoverInteractionState??Ac.create()).current;return t.hoverInteractionState||=n,vo(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Fc(e,t){return t!=null&&!ei(t)?0:typeof e==`function`?e():e}function Ic(e,t,n){let r=Fc(e,n);return typeof r==`number`?r:r?.[t]}function Lc(e){return typeof e==`function`?e():e}function Rc(e,t){return t||e===`click`||e===`mousedown`}function zc(e){return e?.includes(`mouse`)&&e!==`mousedown`}function Bc(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=Fs(),u=Ps(),d=Pc(e),f=ho(),p=J(()=>Rc(c.current.openEvent?.type,d.interactedInside)),m=J(()=>zc(c.current.openEvent?.type)),h=J(()=>{Mc(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()&&Zi(s)&&o){let e=s,t=o,n=ai(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??po(e,`[data-rootownerid]`)??n.body;return Nc(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&&fs(l.nodesRef.current,u).length>0)}function a(t){let n=Ic(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,Y(Wi,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=ua(e);Jr(t)?d.interactedInside=po(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(ki(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&Zi(o)&&fs(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(Wi,n)),l.events.emit(`floating.closed`,n)})}let y=o;return $i(y&&pi(y,`mouseenter`,g),y&&pi(y,`mouseleave`,_),y&&pi(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var Vc={current:null};function Hc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=Vc,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=Fs(l),v=Pc(e),y=X.useRef(!1),b=hs(i),x=hs(r),S=hs(o),C=hs(n),w=hs(p),T=hs(f),E=J(()=>Rc(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(!Zi(r))return!1;let a=r;return i.hasMatchingElement(e=>q(e,a))&&(!t||!q(t,a))}),k=J(()=>{v.handler&&=(ai(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=J(()=>{Mc(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===Wi,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=Ic(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,Y(Wi,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,Y(Wi,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!Zi(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!ei(v.pointerType))return;let n=Lc(S.current),r=Ic(x.current,`open`,v.pointerType),i=ua(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(Zi(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(q(t,i)){c=t;break}}Zi(o)&&Zi(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&&Zi(c)&&Zi(s)&&q(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,Y(Wi,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,Y(Wi,t,c))}):g&&D()&&e.setOpen(!0,Y(Wi,t,c)))}function o(n){if(E()){A();return}k();let r=e.select(`domReferenceElement`),i=ai(r);v.restTimeout.clear(),v.restTimeoutPending=!1;let a=h.current.floatingContext??d?.();if(!ki(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?pi(r,`mouseout`,l):void 0;return s?$i(pi(r,`mousemove`,i,{once:!0}),pi(r,`mouseenter`,i),pi(r,`mouseleave`,o),f):$i(pi(r,`mouseenter`,i),pi(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&&!ei(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;Nc(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=Lc(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(Wi,n,r))}v.pointerType===`touch`?tc.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}function Uc(e){return Bi&&e.movementX===0&&e.movementY===0}function Wc(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function Gc(e,t){return Wc(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Kc(e,t,n){return Wc(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function qc(e,t,n){return Wc(t,n?e===hi:e===Qi,e===ta)}function Jc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Wc(t,n?e===Qi:e===hi,e===ia)}function Yc(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=Pi(E),A=Mi(D),j=hs(k),M=Ps(),N=Fs(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=hs(h),B=hs(T),V=hs(o),ae=hs(b),oe=gi(),se=gi(),ce=J(()=>{oe.cancel();function e(e){d||(re.current=vs(e,{sync:ne.current,preventScroll:!0}))}let t=n.current[F.current],r=z.current;t&&e(t),(ne.current?e=>e():e=>oe.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),me&&(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,V.current!=null)return;if(ee.current&&(F.current=-1,ce()),(!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=>se.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||Kc(I.current,_,u)||l?Ri(n):da(n),I.current=null,R())};t()}}else Co(n.current,r)||(F.current=r,ce(),z.current=!1)}}},[a,T,E,r,V,l,n,_,u,R,ce,se]),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=Ci(ai(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 le=r!=null,ue=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))}),de=J(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),fe=J(()=>Ri(n,ie.current)),pe=J(t=>{if(L.current=!1,ne.current=!0,t.which===229||!B.current&&t.currentTarget===j.current)return;if(l&&Jc(t.key,g,u,w)){Gc(t.key,de())||ri(t),e.setOpen(!1,Y(Fa,t.nativeEvent));let n=S?.current??D;ra(n)&&n.focus();return}r!=null&&r!==F.current&&!Co(n.current,r)&&(F.current=r);let i=F.current,a=Ri(n,h),o=da(n,h);if(A||(t.key===`Home`&&(ri(t),F.current=a,R(t)),t.key===`End`&&(ri(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(Gc(t.key,g)){ri(t);let e=Ci(t.currentTarget.ownerDocument);if(T&&!d&&q(t.currentTarget,e)&&!n.current.some(t=>t!=null&&q(t,e))){F.current=Kc(t.key,g,u)?a:o,R(t),r===F.current&&ce();return}let{index:l,wrapped:f}=Wr(n.current,i,{decrement:!Kc(t.key,g,u),loopFocus:c,allowEscape:s,disabledIndices:h,minIndex:a,maxIndex:o});f&&(ne.current=!1),F.current=l,R(t)}}),me=X.useMemo(()=>({onFocus(e){ne.current=!0,ue(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){Uc(e)||(ne.current=!0,z.current=!1,p&&ue(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)&&ae.current&&(re.current?.(),re.current=null,F.current=-1,R(e),!d)){let e=j.current,t=Ci(ai(e));e&&q(e,t)&&e.focus({preventScroll:!0})}}}),[ue,B,j,p,n,R,ae,d]),he=X.useMemo(()=>d&&T&&le&&{"aria-activedescendant":`${y}-${r}`},[d,T,le,y,r]),ge=X.useMemo(()=>({...A?{}:he,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&T&&!d){let n=ua(t.nativeEvent);if(n&&!q(j.current,n))return;ri(t);let r=Y(Ya,t.nativeEvent);e.setOpen(!1,r);let i=S?.current??D;!r.isCanceled&&ra(i)&&i.focus()}else pe(t)},onPointerMove(e){Uc(e)||(L.current=!0)}}),[he,pe,j,A,e,T,d,D,S]),_e=X.useMemo(()=>{function t(t){e.setOpen(!0,Y(Fa,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&Yi(e.nativeEvent)&&(P.current=!d)}function r(e){P.current=f,f===`auto`&&oi(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(n){let r=e.select(`open`);L.current=!1;let i=n.key.startsWith(`Arrow`),a=qc(n.key,de(),u),o=Gc(n.key,r?g:_),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||Li(n.currentTarget)))return pe(n);if(r||m||!i){if(s){let e=Gc(n.key,de());I.current=l&&e?null:n.key}l?a&&(ri(n),r?(F.current=fe(),R(n),d&&j.current?.focus()):t(n)):o&&(V.current!=null&&(F.current=V.current),ri(n),!r&&m?t(n):pe(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}},[pe,f,fe,l,R,e,m,g,_,de,u,V,d,j]),ve=X.useMemo(()=>({...he,..._e}),[he,_e]);return X.useMemo(()=>a?{reference:ve,floating:ge,item:me,trigger:_e}:{},[a,ve,ge,_e,me])}function Xc(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=ho(),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&&!ja(n)||n?.matches(`:disabled`)?!1:o==null||!ro(xa,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===` `&&(ri(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!==` `&&(ri(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 Zc=.1,Qc=Zc*Zc,$c=.5;function el(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function tl(e,t,n,r,i,a,o,s,c,l){let u=!1;return el(e,t,n,r,i,a)&&(u=!u),el(e,t,i,a,o,s)&&(u=!u),el(e,t,o,s,c,l)&&(u=!u),el(e,t,c,l,n,r)&&(u=!u),u}function nl(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function rl(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 il(e={}){let{blockPointerEvents:t=!1}=e,n=new no,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*Qc;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=ua(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&&Zi(r.relatedTarget)&&q(u,r.relatedTarget))return;function y(){return!!(s&&fs(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=rl(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=rl(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=rl(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=rl(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!nl(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?$c/2:$c*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+$c+1,o=C||T?S.bottom-$c:S.top,s=C?T?S.bottom-$c:S.top:S.bottom-$c;M=tl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?$c/2:$c*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-$c,o=C||T?S.top+$c:S.bottom,s=C?T?S.top+$c:S.bottom:S.top+$c;M=tl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?$c/2:$c*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+$c+1,o=w||E?S.right-$c:S.left,s=w?E?S.right-$c:S.left:S.right-$c;M=tl(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?$c/2:$c*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-$c,o=w||E?S.left+$c:S.right,s=w?E?S.left+$c:S.right:S.left+$c;M=tl(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 al(e,t,n){let{reference:r,floating:i}=e,a=ga(t),o=Ta(t),s=Eo(o),c=La(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=yo(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function ol(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}=ya(t,e),p=Ba(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Sa(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=Sa(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 sl=50,cl=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:ol},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=al(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<sl&&(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}=al(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},ll=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}=ya(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=La(r),_=ga(o),v=La(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[eo(o)]:Oa(o)),x=p!==`none`;!d&&x&&b.push(...lo(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=Za(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`||_===ga(t)||T.every(e=>ga(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=ga(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{}}}},ul=new Set([`left`,`top`]);async function dl(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=La(n),s=yo(n),c=ga(n)===`y`,l=ul.has(o)?-1:1,u=a&&c?-1:1,d=ya(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 fl=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 dl(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}}}}},pl=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}=ya(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=ga(i),p=Pa(f),m=u[p],h=u[f],g=(e,t)=>go(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}}}}}},ml=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}=ya(e,t),u={x:n,y:r},d=ga(i),f=Pa(d),p=u[f],m=u[d],h=ya(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=ul.has(La(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}}}},hl=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}=ya(e,t),c=await i.detectOverflow(t,s),l=La(n),u=yo(n),d=ga(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=Lo(p-c[m],g),y=Lo(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*ko(c.left,c.right):S=p-2*ko(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 gl(e){let t=ji(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=ra(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Po(n)!==a||Po(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function _l(e){return Zi(e)?e:e.contextElement}function vl(e){let t=_l(e);if(!ra(t))return Ua(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=gl(t),o=(a?Po(n.width):n.width)/r,s=(a?Po(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var yl=Ua(0);function bl(e){let t=ea(e);return!oa()||!t.visualViewport?yl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function xl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===ea(e)}function Sl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=_l(e),o=Ua(1);t&&(r?Zi(r)&&(o=vl(r)):o=vl(e));let s=xl(a,n,r)?bl(a):Ua(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=ea(a),t=Zi(r)?ea(r):r,n=e,i=_i(n);for(;i&&t!==n;){let e=vl(i),t=i.getBoundingClientRect(),r=ji(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=ea(i),i=_i(n)}}return Sa({width:u,height:d,x:c,y:l})}function Cl(e,t){let n=Hi(e).scrollLeft;return t?t.left+n:Sl(ci(e)).left+n}function wl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Cl(e,n),y:n.top+t.scrollTop}}function Tl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=ci(r),s=t?la(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Ua(1),u=Ua(0),d=ra(r);if((d||!a)&&((Ti(r)!==`body`||Si(o))&&(c=Hi(r)),d)){let e=Sl(r);l=vl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?wl(o,c):Ua(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 El(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Dl(e){let t=Hi(e),n=e.ownerDocument.body,r=ko(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=ko(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+Cl(e),o=-t.scrollTop;return ji(n).direction===`rtl`&&(a+=ko(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var Ol=25;function kl(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=ea(e),a=ci(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!oa()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(Cl(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<=Ol&&(s-=o)}return{width:s,height:c,x:l,y:u}}function Al(e,t){let n=Sl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=vl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function jl(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=kl(e,n,t);else if(t===`document`)r=Dl(ci(e));else if(Zi(t))r=Al(t,n);else{let n=bl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Sa(r)}function Ml(e,t){let n=t.get(e);if(n)return n;let r=zo(e,[],!1).filter(e=>Zi(e)&&Ti(e)!==`body`),i=null,a=ji(e).position===`fixed`,o=a?Xr(e):e;for(;Zi(o)&&!di(o);){let e=ji(o),t=mi(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Xr(o)}return t.set(e,r),r}function Nl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?la(t)?[]:Ml(t,this._c):[].concat(n),r],o=jl(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=jl(t,a[e],i);s=ko(n.top,s),c=Lo(n.right,c),l=Lo(n.bottom,l),u=ko(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Pl(e){let{width:t,height:n}=gl(e);return{width:t,height:n}}function Fl(e,t,n){let r=ra(t),i=ci(t),a=n===`fixed`,o=Sl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Ua(0);if((r||!a)&&((Ti(t)!==`body`||Si(i))&&(s=Hi(t)),r)){let e=Sl(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=Cl(i));let l=i&&!r&&!a?wl(i,s):Ua(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 Il(e){return ji(e).position===`static`}function Ll(e,t){if(!ra(e)||ji(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return ci(e)===n&&(n=n.ownerDocument.body),n}function Rl(e,t){let n=ea(e);if(la(e))return n;if(!ra(e)){let t=Xr(e);for(;t&&!di(t);){if(Zi(t)&&!Il(t))return t;t=Xr(t)}return n}let r=Ll(e,t);for(;r&&bi(r)&&Il(r);)r=Ll(r,t);return r&&di(r)&&Il(r)&&!mi(r)?n:r||Ii(e)||n}var zl=async function(e){let t=this.getOffsetParent||Rl,n=this.getDimensions,r=await n(e.floating);return{reference:Fl(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Bl(e){return ji(e).direction===`rtl`}var Vl={convertOffsetParentRelativeRectToViewportRelativeRect:Tl,getDocumentElement:ci,getClippingRect:Nl,getOffsetParent:Rl,getElementRects:zl,getClientRects:El,getDimensions:Pl,getScale:vl,isElement:Zi,isRTL:Bl};function Hl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ul(e,t,n){let r=null,i,a=ci(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=oo(d),h=oo(a.clientWidth-(u+f)),g=oo(a.clientHeight-(d+p)),_=oo(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:ko(0,Lo(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Hl(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=ea(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Wl(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=_l(e),u=i||a?[...l?zo(l):[],...t?zo(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Ul(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?Sl(e):null;c&&g();function g(){let t=Sl(e);h&&!Hl(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 Gl=fl,Kl=pl,ql=ll,Jl=hl,Yl=ml,Xl=(e,t,n)=>{let r=new Map,i=n??{},a={...Vl,...i.platform,_c:r};return cl(e,t,{...i,platform:a})},Zl=typeof document<`u`?X.useLayoutEffect:function(){};function Ql(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(!Ql(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)&&!Ql(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function $l(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function eu(e,t){let n=$l(e);return Math.round(t*n)/n}function tu(e){let t=X.useRef(e);return Zl(()=>{t.current=e}),t}function nu(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);Ql(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=tu(c),D=tu(i),O=tu(l),k=X.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Xl(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Ql(w.current,t)&&(w.current=t,tc.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Zl(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=X.useRef(!1);Zl(()=>(A.current=!0,()=>{A.current=!1}),[]),Zl(()=>{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=eu(M.floating,u.x),r=eu(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...$l(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 ru=(e,t)=>{let n=Gl(e);return{name:n.name,fn:n.fn,options:[e,t]}},iu=(e,t)=>{let n=Kl(e);return{name:n.name,fn:n.fn,options:[e,t]}},au=(e,t)=>({fn:Yl(e).fn,options:[e,t]}),ou=(e,t)=>{let n=ql(e);return{name:n.name,fn:n.fn,options:[e,t]}},su=(e,t)=>{let n=Jl(e);return{name:n.name,fn:n.fn,options:[e,t]}};function cu(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=Fs(n),p=X.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),m=nu({...e,elements:{...p,...l&&{reference:l}}}),h=X.useCallback(e=>{let t=Zi(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 lu=X.createContext(void 0);function uu(){return X.useContext(lu)?.direction??`ltr`}var du=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}=ya(e,t)||{};if(l==null)return{};let d=Ba(u),f={x:n,y:r},p=Ta(i),m=Eo(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=go(D,k,O),j=!c.arrow&&yo(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}}}),fu=(e,t)=>{let{name:n,fn:r}=du(e);return{name:n,fn:r,options:[e,t]}},pu={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}}}},mu={sideX:`left`,sideY:`top`},hu=`--available-width`,gu=`--available-height`,_u=`--anchor-width`,vu=`--anchor-height`,yu=`--transform-origin`,bu=hu,xu=gu;function Su(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 Cu(e,t,n){let{rects:r,placement:i}=e;return{side:Su(t,La(i),n),align:yo(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function wu(e){return Tu(e,cu)}function Tu(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=hs(n),M=hs(g),N=uu()===`rtl`,[P,F]=X.useState(null);!g&&P!==null&&F(null);let I=x===`placement`,L=P?La(P):null,R=P&&I?yo(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`),V=+(i===`left`),ae={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:z},oe=X.useRef(null),se=hs(a),ce=hs(s),le=typeof a==`function`?0:a,ue=typeof s==`function`?0:s,de=[];p&&de.push(p),de.push(ru(e=>{let t=Cu(e,i,N),n=typeof se.current==`function`?se.current(t):se.current,r=typeof ce.current==`function`?ce.current(t):ce.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[le,ue,N,i]));let fe=w===`none`&&C!==`shift`,pe=!fe&&(u||E||C===`shift`),me=C===`none`?null:ou({...ae,padding:{top:z.top+1+re,right:z.right+1+V,bottom:z.bottom+1+ie,left:z.left+1+B},mainAxis:!E&&C===`flip`,crossAxis:w===`flip`&&`alignment`,fallbackAxisSideDirection:T}),he=fe?null:iu({...ae,rootBoundary:D,mainAxis:w!==`none`,crossAxis:pe,limiter:u||E?void 0:au(e=>{if(!oe.current)return{};let{width:t,height:n}=oe.current.getBoundingClientRect(),r=ga(La(e.placement)),i=r===`y`?t:n,a=r===`y`?z.left+z.right:z.top+z.bottom;return{offset:i/2+a/2}})},[ae,u,E,D,z,w]);C===`shift`||w===`shift`||te===`center`?de.push(he,me):de.push(me,he),de.push(su({...ae,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!M.current)return;let i=e.style;i.setProperty(bu,`${t}px`),i.setProperty(xu,`${n}px`);let a=ea(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(_u,`${u}px`),i.setProperty(vu,`${d}px`)}}),fu(e=>({element:oe.current||ai(e.elements.floating).createElement(`div`),padding:oe.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=La(r),u=yo(r),d=ga(l)===`y`,f=oe.current,p=typeof a==`function`?a(Cu(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 pe&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(yu,d?`${m} ${h}`:`${h} ${m}`),{}}},pu,b),K(()=>{!g&&h&&h.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[g,h]);let ge=X.useMemo(()=>({ancestorScroll:!f,elementResize:!f&&typeof ResizeObserver<`u`,layoutShift:!f&&typeof IntersectionObserver<`u`}),[f]),{refs:_e,elements:ve,x:ye,y:be,middlewareData:xe,update:Se,placement:Ce,context:we,isPositioned:Te,floatingStyles:Ee}=t({rootContext:h,open:m?g:void 0,placement:ne,middleware:de,strategy:r,whileElementsMounted:m?void 0:(...e)=>Wl(...e,ge),nodeId:y,externalTree:S}),{sideX:De,sideY:Oe}=xe.adaptiveOrigin||mu,ke=Te?r:`fixed`,Ae=X.useMemo(()=>{let e;return e=Te?b?{position:ke,[De]:ye,[Oe]:be}:{...Ee,position:ke}:{position:ke,top:0,left:0},e[bu]=`100vw`,e[xu]=`100vh`,Te||(e.opacity=0),e},[b,ke,De,ye,Oe,be,Ee,Te]),je=X.useRef(null);K(()=>{if(!g)return;let e=j.current,t=typeof e==`function`?e():e,n=(Eu(t)?t.current:t)||null;n!==je.current&&(_e.setPositionReference(n),je.current=n)},[g,_e,A,j]),X.useEffect(()=>{if(!g)return;let e=j.current;typeof e!=`function`&&Eu(e)&&e.current!==je.current&&(_e.setPositionReference(e.current),je.current=e.current)},[g,_e,A,j]),X.useEffect(()=>{if(m&&g&&ve.reference&&ve.floating)return Wl(ve.reference,ve.floating,Se,ge)},[m,g,ve,Se,ge]);let Me=La(Ce),Ne=Su(i,Me,N),Pe=yo(Ce)||`center`,Fe=!!xe.hide?.referenceHidden;K(()=>{x&&g&&Te&&(Me!==ee||I&&Pe!==te)&&F(Ce)},[x,I,g,Te,Ce,Me,Pe,ee,te]);let Ie=X.useMemo(()=>({position:`absolute`,top:xe.arrow?.y,left:xe.arrow?.x}),[xe.arrow]),Le=xe.arrow?.centerOffset!==0;return X.useMemo(()=>({positionerStyles:Ae,arrowStyles:Ie,arrowRef:oe,arrowUncentered:Le,side:Ne,align:Pe,physicalSide:Me,anchorHidden:Fe,refs:_e,context:we,isPositioned:Te,update:Se}),[Ae,Ie,oe,Le,Ne,Pe,Me,Fe,_e,we,Te,Se])}function Eu(e){return e!=null&&`current`in e}function Du(e){return e===`starting`?Ka:No}function Ou(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),Oo(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Du(r),i],stateAttributesMapping:us})}var ku=e(o(),1);function Au(e){let t=ku.unstable_scheduleCallback(4,e);return()=>ku.unstable_cancelCallback(t)}var ju=X.createContext(Fe({scheduleTask:Au,defaultIdleTTL:400})),Mu=new WeakMap,Nu=0,Pu=new Set;function Fu(e){Nu++;try{return e()}finally{Nu--}}function Iu(e){if(Nu===0)return e();Pu.size===0&&queueMicrotask(Lu),Pu.add(e)}function Lu(){for(let e of Pu)Pu.delete(e),e()}function Ru(e,t){let n=Mu.get(e);n===void 0&&(n=new WeakMap,Mu.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,()=>Iu(n));return()=>{i--,Pu.delete(n),r()}},snapshot(){return Fu(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Fu(()=>Ar(t,e))}),a.value}};return n.set(t,o),o}function zu(e,t){let n=Ru(e,t);return X.useEffect(Lu),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Bu(e,t,n){let r=Ru(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(Lu),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Vu=(e,t)=>{let n=X.useContext(ju);return t?Bu(n,e,t):zu(n,e)};function Hu(e,t){X.useEffect(()=>e.mount(t),[t,e])}function Uu(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=sr(Ee(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Wu):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Wu=e=>{if(Ft(e))return e.value;throw Ir(e.cause)},Gu=(e,t)=>{let n=X.useContext(ju);return Hu(n,e),Uu(n,e,t)},Ku=(e,t)=>{let n=X.useContext(ju);return[zu(n,e),Uu(n,e,t)]},qu={suspendOnWaiting:new WeakMap,default:new WeakMap};function Ju(e,t,n){let r=n?qu.suspendOnWaiting:qu.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 Yu(e,t,n){let r=zu(e,t);if(r._tag===`Initial`||n&&r.waiting)throw Ju(e,t,n);return r}var Xu=(e,t)=>{let n=Yu(X.useContext(ju),e,t?.suspendOnWaiting??!1);if(n._tag===`Failure`&&!t?.includeFailure)throw Ir(n.cause);return n};Bt(`MachineSchemaEncodeError`);var Zu=class extends Bt(`MachineSchemaDecodeError`){},Qu=class extends Bt(`InfiniteTransitionError`){},$u=class extends Bt(`StartupError`){},ed=class extends Bt(`ChildAlreadyExistsError`){};Bt(`ProcessLocalError`);var td=class extends Bt(`StoppedError`){},nd=e=>e instanceof Qu||e instanceof Zu,rd=e=>nd(e)?U(e):N(e),id=e=>nd(e)||e instanceof $u?e:new $u({cause:Mn(e)}),ad=e=>e,od=`~effect/Machine/Target`,sd=Symbol(`effect/Machine/TargetSnapshot`),cd=Symbol(`effect/Machine/StateInput`),ld=Symbol(`effect/Machine/HistoryTarget`),ud=Symbol(`effect/Machine/InitialTarget`),dd=Symbol(`effect/Machine/ChoiceTarget`),fd=Symbol(`effect/Machine/NoTarget`),pd=Symbol(`effect/Machine/Declined`),md=Symbol(`effect/Machine/TargetSelection`),hd=Symbol(`effect/Machine/StateUpdate`),gd=Symbol(`effect/Machine/CombinedTarget`),_d=Symbol(`effect/Machine/SelectedBranch`),vd=(e,t,n,r)=>Object.freeze({[md]:md,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),yd=vd(`none`,void 0,`local`),bd=e=>H(e,md),xd=(e,t)=>Object.freeze({[hd]:hd,path:e,value:t}),Sd=e=>H(e,hd),Cd=(e,t)=>Object.freeze({[gd]:gd,target:e,update:t}),wd=e=>H(e,gd),Td=(e,t,n,r)=>Object.freeze({[_d]:_d,owner:e,branchIndex:t,branchKey:n,result:r}),Ed=e=>H(e,_d),Dd=Object.freeze({[fd]:fd}),Od=()=>Dd,kd=e=>H(e,fd),Ad=Object.freeze({[pd]:pd}),jd=()=>Ad,Md=e=>H(e,pd),Nd=(e,t)=>({[ld]:ld,path:e,parent:t}),Pd=e=>H(e,ld),Fd=(e,t,n)=>({[ud]:ud,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),Id=e=>H(e,ud),Ld=(e,t,n)=>({[dd]:dd,path:e,parent:t,...n===void 0?{}:{values:n}}),Rd=e=>H(e,dd),zd=(e,t)=>{if(!Ae(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(!Ae(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(Ae(t))return{schema:t,output:void 0,annotations:Ke(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=H(t,`schema`)&&Ae(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:Ke(n);if(t.type===`parallel`&&!H(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(H(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:Ae(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=Ae(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}},Bd=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=zd(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)}},Vd=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],Hd=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,Ud=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=ad(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:Vd(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:H(i,`reenter`)&&i.reenter===!0,acceptance:Hd(i),branches:Vd(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:Hd(r.always),branches:Vd(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:Hd(r.onDone),branches:Vd(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:Hd(a),branches:Vd(a)})}}}return t},Wd=(e,t,n)=>({[od]:od,[sd]:n?.snapshot,path:e,value:t,values:n?.values}),Gd=e=>H(e,od),Kd=e=>({[cd]:cd,input:e}),qd=e=>H(e,cd),Jd=e=>H(e,`path`)&&H(e,`value`),Yd=(e,t,n)=>{if(e.path===t)return pe(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return ft();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),H(e,`state`)&&Jd(e.state))return Yd(e.state,t,n);if(H(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if(Jd(r)){let e=Yd(r,t,n);if(ct(e))return e}}return ft()},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},Xd=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},Zd=new WeakMap,Qd=Symbol(`effect/Machine/EventConstruction`),$d=new WeakMap,ef=new WeakMap,tf=new WeakMap,nf=e=>{let t=e,n=ef.get(t);if(n!==void 0)return n;let r=nt(v(e));return ef.set(t,r),r},rf=e=>{let t=e,n=tf.get(t);if(n!==void 0)return n;let r=A(v(e));return tf.set(t,r),r},af=Symbol.for(`effect/Machine/protocol`),of=e=>{let t=e[af];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},sf=(e,t)=>{Object.defineProperty(e,af,{value:t,enumerable:!1})},cf=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),H(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&H(t,`make`)&&n(t)};for(let t of e)n(t);return t},lf=(e,t)=>{let n=Zd.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},uf=e=>lf(e.events,`public`).schemas,df=e=>lf(e.internalEvents,`internal`).schemas,ff=e=>lf(e.emittedEvents,`emitted`).schemas,pf=e=>{let t=uf(e),n=df(e),r=ff(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];sf(e,{event:Ze(a),emit:Ze(r),eventConstructors:cf(a),emissionConstructors:cf(r)})},mf=(e,t)=>sf(t,of(e)),hf=e=>H(e,`_tag`)?String(e._tag):void 0,gf=(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={[Qd]:Qd,_tag:n};return $d.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},_f=e=>typeof e==`object`&&!!e&&$d.has(e),vf=(e,t)=>{let n=[],r=e=>{if(H(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(H(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=>st(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:Ue(e)?[e.symbol]:B(e)?e.enums.map(([,e])=>e):kt(e)?e.types.flatMap(a):de(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 Ze([e]).pipe(Ur(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(H(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>gf(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},yf=(e,t)=>{let n=Object.freeze(Array.from(t)),r=vf(e,n);return Zd.set(r,{kind:e,schemas:n}),Object.freeze(r)},bf=(e,t,n,r)=>nf(t)(n).pipe(St(t=>new Zu({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),xf=(e,t,n,r)=>{let i=rf(t)(n);if(M(i))throw new Zu({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},Sf=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new Zu({machineId:e.id,boundary:r.boundary,cause:ze(t)?t:H(n,`~effect/SchemaIssue/Issue`)?new un(n):Mn(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},Cf=(e,t,n)=>new Zu({machineId:e.id,boundary:n,event:String(t._tag),cause:Mn(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),wf=(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}},Tf=(e,t,n,r)=>new Zu({machineId:e.id,boundary:n,event:String(t._tag),cause:Mn(r)}),Ef=(e,t,n,r)=>{let i=$d.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)?U(Cf(e,n,r)):Rn({try:()=>wf(n,i),catch:t=>Tf(e,n,r,t)}).pipe(_(t=>i.schema.makeEffect(t).pipe(St(t=>new Zu({machineId:e.id,boundary:r,event:String(n._tag),cause:new un(t)})))))},Df=(e,t,n,r)=>{let i=$d.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 Cf(e,n,r);let o;try{o=wf(n,i)}catch(t){throw Tf(e,n,r,t)}return Sf(e,i.schema,o,{boundary:r,event:String(n._tag)})},Of=(e,t)=>{let n=of(e);if(_f(t))return Ef(e,n,t,`event`);let r=hf(t);return bf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},kf=(e,t)=>{let n=of(e);if(_f(t))return Df(e,n,t,`event`);let r=hf(t);return xf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Af=(e,t)=>{let n=of(e);if(_f(t))return Ef(e,n,t,`emission`);let r=hf(t);return bf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},jf=(e,t)=>{let n=of(e);if(_f(t))return Df(e,n,t,`emission`);let r=hf(t);return xf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Mf=(e,t,n)=>xf(e,t,n,{boundary:`input`}),Nf=(e,t,n)=>qd(n)?Xd(t).makeEffect(n.input).pipe(St(n=>new Zu({machineId:e.id,boundary:`state`,state:t.path,cause:new un(n)}))):bf(e,Xd(t),n,{boundary:`state`,state:t.path}),Pf=(e,t,n)=>qd(n)?Sf(e,Xd(t),n.input,{boundary:`state`,state:t.path}):xf(e,Xd(t),n,{boundary:`state`,state:t.path}),Ff=(e,t,n)=>t.output===void 0?Pn(n):bf(e,t.output,n,{boundary:`output`,state:t.path}),If=(e,t,n)=>t.output===void 0?n:xf(e,t.output,n,{boundary:`output`,state:t.path}),Lf=(e,t)=>{let n=new Set(qf(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)&&!Kf(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&Gf(r,t.parent)&&Q(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},Rf=(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`||!(Kf(n,t.parent)||qf(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,Pf(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}),Lf(e,n.get(r))}return n},zf=lt(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*U(new Zu({machineId:e.id,boundary:`history`,state:r,cause:Mn(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`||!(Kf(n,t.parent)||qf(e,t.parent).includes(n)))return yield*U(new Zu({machineId:e.id,boundary:`history`,state:n,cause:Mn(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*U(new Zu({machineId:e.id,boundary:`history`,state:n,cause:Mn(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!s)return yield*U(new Zu({machineId:e.id,boundary:`history`,state:n,cause:Mn(Error(`Machine snapshot omits remembered value for "${n}"`))}));o.set(n,yield*bf(e,Xd(r),i.values[n],{boundary:`history`,state:n}))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)return yield*U(new Zu({machineId:e.id,boundary:`history`,state:r,cause:Mn(Error(`Machine snapshot contains incomplete history record "${r}"`))}));n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o});try{Lf(e,n.get(r))}catch(t){return yield*U(new Zu({machineId:e.id,boundary:`history`,state:r,cause:Mn(t)}))}}return n}),Bf=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>Yf(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},Vf=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),Hf=e=>e.machineReferences,Uf=new WeakMap,Wf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Gf=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),Kf=(e,t)=>e===t||Gf(e,t),qf=(e,t)=>{let n=Uf.get(e.stateNodes);n===void 0&&(n=new Map,Uf.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},Jf=(e,t)=>qf(e,t).length,Yf=(e,t,n)=>Q(e,t).order-Q(e,n).order,Xf=(e,t,n)=>Q(e,n).children.some(e=>t.active.has(e)),Zf=(e,t)=>{let n=Array.from(t.active).filter(n=>!Xf(e,t,n)).sort((t,n)=>Yf(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},Qf=(e,t)=>Zf(e,t)[0],$f=(e,t,n)=>{let r=Zf(e,t).filter(e=>Kf(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},ep=(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`)},tp=(e,t,n)=>{let r={},i=qf(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},np=(e,t,n)=>{let r=Q(e,n).parent;return r===void 0?void 0:t.values.get(r)},rp=(e,t)=>{let n=r=>t.active.has(r)?[r,...Q(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},ip=(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=ip(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]=ip(e,t,i)}i.states=a}return i},ap=(e,t)=>{let n=ip(e,t,ep(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:Bf(e,t.history)}),n},op=(e,t,n)=>{let r=ip(e,t,n);return t.history.size>0&&Object.assign(r,{history:Bf(e,t.history)}),r},sp=(e,t,n)=>{if(!H(n,`state`)||!Jd(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},cp=(e,t)=>{if(!H(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},lp=(e,t,n,r)=>{let i=Q(e,n),a=r[i.key];if(!Wf(r,i.key)||!Jd(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},up=(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,Pf(e,i,t.value));if(i.type===`compound`&&a(sp(e,i,t)),i.type===`parallel`){let n=cp(i,t);for(let t of i.children)a(lp(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:Rf(e,t)}},dp=(e,t)=>up(e,t),fp=(e,t)=>{try{return up(e,t)}catch(t){throw t instanceof Zu?t:new Zu({machineId:e.id,boundary:`configuration`,cause:Mn(t)})}},pp=lt(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=lt(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*Nf(e,i,t.value));if(i.type===`compound`&&(yield*a(sp(e,i,t))),i.type===`parallel`){let n=cp(i,t);for(let t of i.children)yield*a(lp(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*zf(e,t)}}),mp=(e,t)=>pp(e,t).pipe(Ce(t=>{if(nn(t))return Hr(At(t,t=>t instanceof Zu?t:new Zu({machineId:e.id,boundary:`configuration`,cause:yr(t)})));let n=Jt(t);return ct(n)&&n.value instanceof Zu?U(n.value):U(new Zu({machineId:e.id,boundary:`configuration`,cause:t}))})),hp=(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 qf(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&Gf(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}},gp=(e,t)=>e.history.get(t),_p=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=qf(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)Kf(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}};lt(function*(e,t,n,r,i){let a=Q(e,n),o=new Set,s=new Map,c=new Map,l=qf(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&&Wf(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*Nf(e,c,r));else if(i!==void 0&&Wf(i,n))s.set(n,yield*Nf(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)Kf(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}}),lt(function*(e,t,n,r){let i=yield*pp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=qf(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&&Wf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Wf(r,i))o.set(i,yield*Nf(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)Kf(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&&Wf(r,n))for(let[t,i]of Object.entries(r)){if(!Kf(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*Nf(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var vp=(e,t,n,r,i,a=!1)=>{let o=Q(e,n),s=new Set,c=new Map,l=new Map,u=qf(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&&Wf(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,Pf(e,a,r));else if(i!==void 0&&Wf(i,n))c.set(n,Pf(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)Kf(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}},yp=(e,t,n)=>{let r=vp(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,Pf(e,n,r))}return{...r,active:i,values:a}},bp=(e,t,n,r)=>{let i=up(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=qf(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&&Wf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Wf(r,i))o.set(i,Pf(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)Kf(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&&Wf(r,n))for(let[t,i]of Object.entries(r)){if(!Kf(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,Pf(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},xp=(e,t,n)=>{if(Gd(n)){let r=n[sd];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return bp(e,t,r,n.values)}return vp(e,t,n.path,n.value,n.values)}if(Jd(n)){let r=fp(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`)},Sp=(e,t)=>ad(e).handlers[t],Cp=(e,t,n)=>Q(e,n).children.find(e=>t.active.has(e)),wp=(e,t)=>Q(e,t).type===`final`,Tp=(e,t)=>Sp(e,t)?.onDone!==void 0,Ep=(e,t,n)=>{if(!t.active.has(n))return!1;let r=Q(e,n);if(r.type===`compound`){let r=Cp(e,t,n);return r!==void 0&&(n===``?!Tp(e,r)&&Ep(e,t,r):wp(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!Ep(e,t,n))return!1;return!0}return wp(e,n)},Dp=(e,t)=>{let n=ep(e,t);return Ep(e,t,n)&&!Tp(e,n)},Op=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),kp=lt(function*(e,t,n,r,i){let a=Q(e,n),o=Sp(e,n)?.output?.({state:t.values.get(n),containingState:np(e,t,n),ancestors:tp(e,t,n),event:r,outputs:i});return yield*Ff(e,a,o)}),Ap=lt(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=Cp(e,t,n);if(o===void 0||(n===``?Tp(e,o):!wp(e,o)))return;let s=yield*Ap(e,t,o,r,i,a);if(s===void 0)return;let c=Op(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*Ap(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Op(i,n,yield*kp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!wp(e,n))return;let s=Op(i,n,yield*kp(e,t,n,r));return s.isNew&&a.push(s),s}),jp=lt(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=Jf(e,n)-Jf(e,t);return r===0?Yf(e,t,n):r}))yield*Ap(e,a,t,n,r,i);return{configuration:a,completions:i}}),Mp=(e,t,n,r,i)=>{let a=Q(e,n),o=Sp(e,n)?.output?.({state:t.values.get(n),containingState:np(e,t,n),ancestors:tp(e,t,n),event:r,outputs:i});return If(e,a,o)},Np=(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=Cp(e,t,n);if(o===void 0||(n===``?Tp(e,o):!wp(e,o)))return;let s=Np(e,t,o,r,i,a);if(s===void 0)return;let c=Op(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=Np(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Op(i,n,Mp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!wp(e,n))return;let s=Op(i,n,Mp(e,t,n,r));return s.isNew&&a.push(s),s},Pp=(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=Jf(e,n)-Jf(e,t);return r===0?Yf(e,t,n):r}))Np(e,a,t,n,r,i);return{configuration:a,completions:i}},Fp=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},Ip=(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 Kd(Object.hasOwn(t,`data`)?t.data:{})}},Lp=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=Fp(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return Wd(t,Ip(i,e))}let a=new Map,o=(t,n)=>{let i=Fp(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=Ip(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=Fp(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=Fp(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=Fp(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=Fp(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 Ld(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return Wd(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...Fd(l,f,p),...m.size===0?{}:{children:m}}},Rp=(e,t,n)=>{let r=Fp(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 xd(t,Ip(i,r))},zp=(e,t,n=``)=>{let r=Fp(t),i=e.byPath.get(n);Lp(e,n,r);let a=Ip(i,r);if(i.type===`choice`)return Ld(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=Fp(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,zp(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]}},Bp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},Vp=`root`,Hp=e=>{let t=new Map,n=(e,r)=>{let i=!Ae(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!Ae(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 "${Vp}" is reserved for the root`);return t},Up=(e,t)=>{let n=Hp(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(Bp(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(Bp(t.branches,`Machine branches must be a map`))){let t=Bp(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={...Bp(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 Gp({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}},Wp=(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}},Gp=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=Wp(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return vd(`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 yd}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return vd(`state`,``,`branch`)}let i=Wp(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:Wp(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return vd(i.kind,i.path,r===`history`?`full`:`branch`,a)},Kp=(e,t,n,r)=>{let i=Bp(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`&&tr(a.value))&&!(a.kind===`streams`&&ur(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}},qp=Symbol(`effect/Machine/InitialEvent`),Jp=Symbol(`effect/Machine/SnapshotBuilderState`),Yp=Symbol(`effect/Machine/ChildMachineLogic`),Xp=new WeakSet,Zp=e=>Xp.has(e),Qp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},$p=e=>typeof e==`function`?e:()=>e,em=e=>{if(typeof e==`object`&&e&&H(e,`decoded`)&&e.decoded===!0&&H(e,`data`)){let t=Qp(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return $p(t.data)}let t=$p(e);return n=>Kd(e===void 0?{}:t(n))},tm=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(!H(e,`data`))throw Error(`Machine decoded construction requires data`);return $p(e.data)}let t=$p(e.data);return n=>Kd(H(e,`data`)?t(n):{})},nm=(e,t)=>{let n=(e,t,r)=>{if(H(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&H(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(Ae(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?{}:Qp(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?{}:Qp(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!Ae(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!Ae(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=em(r)}}else{let t=Qp(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||Ae(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`&&(H(t,`data`)||H(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=tm(t),l=e.states[a];if(H(t,`data`)&&!Ae(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);H(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?{}:Qp(c[t],`state handler`),e);l[t]=a.node,(Ae(i)||i.type!==`history`)&&(c[t]!==void 0||!Ae(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{[Jp]:i}};return Xp.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},rm=(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)},im=e=>`child`in e?e.child.id:e.id,am=(e,t)=>{let n=new Set;for(let r of e){let e=im(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},om=e=>e===void 0?[]:Array.isArray(e)?e:[e],sm=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(kf(e,t))},emit:t=>{r.push(jf(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},cm=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},lm=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(Kd(t.length===0?{}:t[0])),enumerable:!1}),t},um=e=>{let t={};return Object.defineProperty(t,Jp,{value:e,enumerable:!1}),t},dm=(e,t,n)=>{let r=um(n);for(let i of t.children){let a=cm(e,i);a.schema===void 0||H(n,a.key)||(r[a.key]=lm(r=>{let i=Object.assign({},n);return i[a.key]=r,dm(e,t,i)}))}return r},fm=(e,t)=>{let n=cm(e,t);if(n.type===`parallel`)return dm(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=cm(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return lm(e=>um({[r.key]:e}))},pm=(e,t)=>{if(typeof t!=`object`||!t||!H(t,Jp))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[Jp]},mm=Symbol(`effect/Machine/InvocationEvent`),hm=(e,t,n)=>({[mm]:!0,path:e,id:t,type:`done`,output:n}),gm=(e,t,n)=>({[mm]:!0,path:e,id:t,type:`element`,element:n}),_m=(e,t,n)=>({[mm]:!0,path:e,id:t,type:`failure`,error:n}),vm=(e,t,n)=>({[mm]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),ym=e=>typeof e==`object`&&!!e&&mm in e,bm=new WeakMap,xm=new WeakMap,Sm=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},Cm=(e,t)=>{let n=Object.create(e);return xm.set(n,Sm(e,t)),n},wm=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return Sm(e,n);let r=xm.get(e);if(r!==void 0)return r;let i=bm.get(e);if(i!==void 0)return i;let a=Sm(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>U(new td)},parent:void 0});return bm.set(e,a),a},Tm=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}},Em=(e,t,n)=>{let r=sm(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Dm=(e,t,n,r)=>{let i=sm(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Md(a.result)?{declined:!0}:{declined:!1,state:kd(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},Om=(e,t,n)=>{let r=sm(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},km=(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)=>Yf(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=ah(e,m,Ld(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=Id(i)?jm(e,r,i,n):Pd(i)?Mm(e,r,i,n):void 0;r=xp(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=ad(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,Pf(e,p,Kd({}))),u=!0;continue}let i=Om(e,t,{...wm(e,m),state:m.values.get(d),containingState:np(e,m,d),ancestors:tp(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...Zp(t)?{}:{builder:fm(e,d)}}),l=pm(d,i.value);a.set(p.path,Pf(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:ad(e).handlers[d]?.initialize,h=m===void 0?void 0:Om(e,m,{...wm(e,p),state:p.values.get(d),containingState:np(e,p,d),ancestors:tp(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...Zp(m)?{}:{builder:fm(e,d)}}),g=h===void 0?void 0:pm(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,Pf(e,n,Kd({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&Zp(m)){a.set(n.path,Pf(e,n,Kd({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,Pf(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 Am(e,t,n,r){let i=yp(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>Q(e,t).type===`choice`))return km(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=ah(e,i,Ld(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=Id(t)?jm(e,i,t,r):Pd(t)?Mm(e,i,t,r):void 0;i=xp(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=km(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 jm(e,t,n,r){let i=Am(e,t,n,r),a=op(e,i.configuration,n.path);return{target:Wd(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Mm(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=gp(t,n.path);if(a!==void 0){let i=km(e,_p(e,t,a),r),o=op(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:Wd(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=ad(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=Dm(e,s,{event:r,target:t=>zp(e.stateNodes,t),owner:n.parent});if(c.state===void 0||Pd(c.state)||!Jd(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=rh(c.state)===void 0?void 0:ah(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?fp(e,c.state):xp(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=xp(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=op(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:Wd(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 Nm=(e,t)=>{if(!t.transition.declinable)return t;let n=Dm(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},Pm=(e,t)=>[...qf(e,t)].reverse(),Fm=(e,t,n)=>{let r=qf(e,t),i=qf(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},Im=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||Gf(e,t)?t:e},Lm=(e,t,n)=>Bm(e,Array.from(t.active).filter(e=>n===void 0||Gf(e,n))),Rm=(e,t,n)=>Vm(e,Array.from(t.active).filter(e=>n===void 0||Gf(e,n))),zm=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),Bm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=qf(e,n).length-qf(e,t).length;return r===0?Q(e,n).order-Q(e,t).order:r}),Vm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=qf(e,t).length-qf(e,n).length;return r===0?Yf(e,t,n):r}),Hm=(e,t,n,r)=>({...wm(e,t),state:t.values.get(n),containingState:np(e,t,n),ancestors:tp(e,t,n),event:r}),Um=(e,t,n,r,i)=>({...wm(e,t),state:t.values.get(n),containingState:np(e,t,n),ancestors:tp(e,t,n),event:r,snapshot:i}),Wm=(e,t,n,r,i,a)=>({...wm(e,t),state:t.values.get(n),containingState:np(e,t,n),ancestors:tp(e,t,n),event:r,output:i,snapshot:a}),Gm=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=Em(e,ad(e).handlers[c]?.[i],Hm(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},Km=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=ap(e,t);for(let o of Zf(e,t))for(let c of Pm(e,o)){let l=Tm(ad(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Nm(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...wm(e,t),state:t.values.get(c),containingState:np(e,t,c),ancestors:tp(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},qm=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=ap(e,t);for(let o of r){let r=Tm(ad(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=Nm(e,{sourcePath:o.path,leafPath:$f(e,t,o.path),trigger:{type:`done`},transition:r,context:Wm(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},Jm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=ap(e,t);for(let o of Zf(e,t))for(let c of Pm(e,o)){let l=Tm(ad(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Nm(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:Um(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},Ym=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=ad(e).handlers[n.path],i=om(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=Tm(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=ap(e,t),s={...wm(e,t),state:t.values.get(n.path),containingState:np(e,t,n.path),ancestors:tp(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=Nm(e,{sourcePath:n.path,leafPath:$f(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},Xm=e=>{if(Pd(e)||Rd(e)||Gd(e)||Jd(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},Zm=(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(`, `)}`)}},Qm=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},$m=(e,t)=>Array.from(t).sort((t,n)=>Yf(e,t.selection.sourcePath,n.selection.sourcePath)),eh=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&Gf(e.sourcePath,t.sourcePath))),th=(e,t)=>{let n=[];for(let r of $m(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(Qm(r.exitPaths,i.exitPaths)||n){if(Gf(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},nh=(e,t={})=>{let n={...t},r=[],i=e=>{if(Rd(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:Ld(e.path,e.parent,n),values:n}))},rh=(e,t={})=>nh(e,t)[0],ih=(e,t)=>{if(Rd(e))return Ld(e.path,e.parent,{...t,...e.values??{}});if(Id(e))return{...e,values:{...t,...e.values}};if(!Gd(e)||Object.keys(t).length===0)return e;let n=e[sd];return Wd(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function ah(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=nh(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 Qu({machineId:e.id,state:d.target.path,maxIterations:sh});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=ad(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,Pf(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=Dm(e,p.transition,{...wm(e,h),containingState:np(e,h,f.path),ancestors:tp(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`);Zm(f.path,{type:`choice`},p.targets,g.state);let _=Xm(g.state);n=ih(g.state,d.values);let v=rh(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(!Gd(n)&&!Jd(n)&&!Pd(n)&&!Id(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 oh=(e,t,n)=>{let r=n.leafPath,i=n.collected??Dm(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=wd(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||Sd(o)?void 0:o;Zm(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(Sd(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:Pf(e,n,c.value)}})(),u=l!==void 0&&(Id(s)||Rd(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:ah(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&Id(f)?jm(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=Pd(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&Pd(m)){let i=n.transition.reenter?Q(e,n.sourcePath).parent:Fm(e,r,m.parent),a=g===void 0?Lm(e,t,i):Bm(e,Array.from(t.active).filter(e=>Kf(e,m.parent)));h=Mm(e,a.includes(m.parent)?hp(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(Id(r)){let i=jm(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(!Pd(r)){S.push(r);continue}let i=Mm(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?Xm(_):Xm(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:xp(e,t,_);for(let t of S)w=xp(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||!zm(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:Fm(e,r,C),O=Q(e,n.sourcePath).parent,k=n.transition.reenter?Im(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?Lm(e,t,k):Bm(e,Array.from(t.active).filter(e=>Kf(e,g.parent))),entryPaths:g===void 0?Rm(e,w,k):Vm(e,Array.from(w.active).filter(e=>Kf(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},sh=1e3,ch={_tag:qp},lh=(e,t)=>Dp(e,dp(e,t)),uh=(e,t,n)=>mp(e,t).pipe(_(t=>jp(e,t,n)),_(t=>{let n=ep(e,t.configuration);return!Dp(e,t.configuration)||!t.configuration.outputs.has(n)?N(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):Pn(t.configuration.outputs.get(n))})),dh=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Mf(e,e.input,void 0),t):[Mf(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=jm(e,i,r,ch),o=xp(e,i,a.target),s=ap(e,o),c=rp(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=Gm(e,o,c,ch,`entry`),p=ph(e,o,ch,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:ch,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:ap(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:ap(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}},fh=(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=eh(r),a=[];for(let n of i)a.push(oh(e,t,n));let o=th(e,a),s=$m(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:Xm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Xm(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=xp(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=Bm(e,s.flatMap(e=>e.exitPaths)),_=Vm(e,s.flatMap(e=>e.entryPaths));l=hp(e,t,l,g);let v=Gm(e,t,g,n,`exit`),y=Gm(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}},ph=(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 Qu({machineId:e.id,state:String(Qf(e,s)),maxIterations:sh});let t=Pp(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>ad(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=qm(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=fh(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(Dp(e,s)){let t=ep(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?Km(e,s,c):[];if(h.length>0){let t=fh(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=Jm(e,s,_);if(v.length===0){l=!0;continue}let y=fh(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}},mh=(e,t,n)=>{let r=ym(n)?n:kf(e,n);if(Dp(e,t)){let n=Pp(e,t,r),i=ep(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=ym(r)?Ym(e,t,r):Jm(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=fh(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...ph(e,a.next,r,o,s,c,l),event:r}},hh=(e,...t)=>Rn({try:()=>dh(e,...t),catch:id}),gh=(e,t)=>({raise:n=>Of(e,n).pipe(_(e=>t.sendTo(t.self,e))),emit:n=>Af(e,n).pipe(_(e=>t.emit(e)))}),_h=(e,t)=>re(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),vh=(e,t)=>O(Array.from(e,e=>t.emit(e)),{discard:!0}),yh=new WeakMap,bh=e=>{let t=yh.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>U(new td)},parent:void 0};return yh.set(e,n),n},xh=(e,t)=>{let n=t===void 0?bh(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},Sh=new Set([`initialize`,`invoke`,`on`,`output`]),Ch=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!Sh.has(t))return!1;return!0},wh=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=ad(e).handlers[a.path];if(!Ch(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=Tm(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)=>Yf(e,t,n)),r.sort((t,n)=>Yf(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=>qf(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&&(ad(e).handlers[``]===void 0||Reflect.ownKeys(ad(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}},Th=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()}),Eh=(e,t)=>t?{...e,next:Th(e.next)}:e,Dh=(e,t,n)=>{e.values[t]=n},Oh=(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}},kh=(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}},Ah=(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=Ah(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]=Ah(e,t,i)}i.states=a}return i},jh=(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=Ah(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Mh=(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{...xh(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:jh(t,n)}},Nh=Object.freeze([]),Ph=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(kf(e,t))},emit:t=>{(o??=[]).push(jf(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:kd(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??Nh,raisedEvents:a??Nh,emittedEvents:o??Nh}},Fh=(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:Mh(e,t,n,c,r,i)})}}}return a},Ih=(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},Lh=(e,t,n,r,i)=>{if((Gd(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&Gd(r)&&r[sd]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=Pf(e,t.nodes[i],r.value),{...n,values:a}}return Oh(t,xp(e,kh(t,n),r))},Rh=(e,t,n,r)=>{let i=Ph(e,r.transition.transition,r.context,r.transition.evaluate),a=wd(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(Sd(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:Pf(e,i,s.value)}})(),l=o===void 0||Sd(o)?void 0:o;Zm(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&Id(l)?jm(e,(()=>{let e=kh(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&&!Gd(d)&&!Jd(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=Th(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():Lh(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||!Ih(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:Xm(d),g=h===void 0?t.nodes[r.sourceIndex].parent:Fm(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?Im(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:Lm(e,kh(t,n),v),entryPaths:Rm(e,kh(t,f),v),choiceTransitions:u?.transitions??[]}},zh=(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:Xm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Xm(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=Rh(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=$m(e,th(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&Gf(t.sourcePath,e.sourcePath))).map(r=>Rh(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=Lh(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?Bm(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?Vm(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},Bh=(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 Qu({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:sh});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=Pp(e,kh(t,o),s).configuration,i=ep(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:Oh(t,n),commands:c??Nh,emittedEvents:u??Nh,microsteps:d??Nh,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=Tm(ad(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=Ph(e,h.transition,{...xh(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:jh(t,o)},h.evaluate),f=Sd(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`);Dh(o,n,Pf(e,r,f.value))}if(Zm(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!Gd(p)&&!Jd(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=Gd(p)?p[sd]===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]?Dh(o,n,Pf(e,t.nodes[n],p.value)):g=Lh(e,t,o,p,n)}let _=h.reenter||!Ih(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:Xm(p),resolvedTarget:p===void 0?void 0:Xm(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:Nh,entryPaths:_?[t.nodes[v].path]:Nh,changed:_};o=g,(d??=[]).push(Eh(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??Nh,emittedEvents:u??Nh,microsteps:d??Nh,done:!1,output:void 0};f+=1,s=g}},Vh=(e,t,n,r,i,a)=>{if(ym(r)){let i=mh(e,a===void 0?kh(t,n):Vf(kh(t,n),a),r);return{event:i.event,next:Oh(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:Oh(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=kf(e,r);if(t.flat)return Bh(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=kh(t,n);if(Dp(e,r)){let n=Pp(e,r,o).configuration,i=ep(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:Oh(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=Fh(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=zh(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[Eh(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new Qu({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:sh});if(t.finalIndices.some(e=>l.active[e]===1)){let n=Pp(e,kh(t,l),u).configuration;if(l=Oh(t,n),Dp(e,n)){let t=ep(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=Fh(e,t,l,n,a);if(r.length===0)continue;let s=zh(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(Eh(s,i))}},Hh=new WeakMap,Uh=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>ap(e,t),plan:(t,n,r,i)=>mh(e,i===void 0?t:Vf(t,i),n)}),Wh=(e,t)=>({fromConfiguration:e=>Oh(t,e),toConfiguration:e=>kh(t,e),snapshot:e=>jh(t,e),plan:(n,r,i=!1,a)=>Vh(e,t,n,r,i,a),...Object.values(ad(e).handlers).some(e=>e.initialize!==void 0&&!Zp(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Mf(e,e.input,void 0),n):[Mf(e,e.input,n[0])],a=e.initial(...i),o=Id(a)?Am(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,ch).configuration:fp(e,a),s=Pp(e,r===void 0?o:Vf(o,r),ch).configuration,c=Oh(t,s),l=jh(t,c);if(!Dp(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:rp(e,s),done:!1,output:void 0};let u=ep(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:rp(e,s),done:!0,output:s.outputs.get(u)}}}}),Gh=e=>{let t=Hh.get(e);if(t!==void 0)return t;let n=wh(e),r=n===void 0?Uh(e):Wh(e,n);return Hh.set(e,r),r},Kh=`Machine.invocation:`,qh=e=>e.startsWith(Kh),Jh=(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,Ct(t,G)}},Yh=e=>xr(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,Pn(t)}let t=l();return e.waiter=t,nr(t).pipe(T(Yh(e)))}),Xh=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),Zh=(e,t,n)=>{if(e.closed)return ft();let r=e.children.get(t);return r!==void 0&&Xh(r,n)?pe(r.ref):ft()},Qh=e=>{if(e.observers!==void 0)for(let t of e.observers)Jh(t,Zh(e,t.id,t.child))},$h=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&Qh(e))},eg=(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`&&Qh(e),!0},tg=e=>R(function*(){let t=yield*x(),n=0,r=0,i=0,a=0;return{rootSessionId:e,stream:qn(t).pipe(br(Xt(()=>{n+=1})),or(Xt(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>a++,publishUnsafe:i=>{n!==0&&Lr(t,{...i,sequence:r++,rootSessionId:e})},close:Vt(t)}}),ng=e=>({id:e.id,sessionId:e.sessionId}),rg=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?ng(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?ng(t):{id:String(t.id)}}]:[]}return[]}),ig=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:rg(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),ag=Symbol.for(`effect/Machine/activeSnapshotObserver`),og=Symbol.for(`effect/Machine/snapshotObserver`),sg=e=>typeof e==`object`&&!!e&&og in e,cg=Symbol.for(`effect/Machine/sendParentOverride`),lg=Symbol.for(`effect/Machine/acknowledgedSend`),ug=Symbol(`effect/Machine/AcknowledgedMessage`),dg=e=>typeof e==`object`&&!!e&&ug in e,fg=e=>dg(e)?e.event:e,pg=(e,t)=>{e!==void 0&&dg(e)&&(e.deferred!==void 0&&Ct(e.deferred,Pn(t)),e.inspection?.complete(t))},mg=(e,t)=>{e!==void 0&&dg(e)&&e.deferred!==void 0&&Ct(e.deferred,Hr(t))},hg=e=>{e!==void 0&&dg(e)&&e.deferred!==void 0&&Ct(e.deferred,U(new td))},gg=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,_g=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),vg=e=>e?._tag===`Childless`||e?.childless===!0,yg=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},bg=e=>{if(e.items===void 0)return ft();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),pe(t)},xg=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)hg(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},Sg=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),Cg=(e,t,n)=>{if(e.closed)return!1;for(yg(e,t),n?.();e.items!==void 0&&e.receivers.size>0;){let t=e.receivers.values().next().value;e.receivers.delete(t),t(G)}return!0},wg=e=>xr(()=>{let t=bg(e);return ct(t)?Pn(t.value):e.closed?me:wn(t=>(e.receivers.add(t),Xt(()=>{e.receivers.delete(t)}))).pipe(T(wg(e)))}),Tg=e=>{xg(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(me)},Eg=class extends jr()(`effect/Machine/MachineRuntime`){},Dg=(e,t)=>en(e,Eg,t),Og=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(fn);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(In);return n===void 0?e.cause.reasons.find(sn)===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}}},kg=(e,t)=>xr(()=>e(t)).pipe(ye,kn),Ag=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=Xt(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return Xt(()=>new n)},jg=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Mg=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&dg(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,Ng=(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=ig(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{[ug]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},Pg=(e,t,n)=>{if(!dg(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:ng(t),event:r.event,causedBy:r.causedBy})},Fg=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:G}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 xr(()=>{if(this.registry.closed)return me;if(this.has(t.key)||this.registry.children.has(t.id))return U(new ed({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()?_g(this.self,e,t,n):G,...this.sendAcknowledged===void 0?void 0:{[lg]:e=>i()?this.sendAcknowledged(e):me}},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,eg(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>$h(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??=Je(this.services,ie,o),e)):this.runtime.start(a,c)).pipe(Ve(e=>Ft(e)?G:($h(this.registry,t.id,n),r===void 0?G:r.stop)));return(u?d:he(d,o)).pipe(kn)})}stopAll(){return xr(()=>{let e=[];for(let t of this.registry.children.values())t.ownerActive&&e.push(this.stopEntry(t));return e.length===0?G: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})}},Ig=Xn(ft()).pipe(hr(Nn)),Lg=e=>G,Rg=(e,t)=>{},zg=()=>void 0,Bg=Symbol(`effect/Machine/EmissionsClosed`),Vg=()=>{let e,t=xr(()=>{let t=e;return t===Bg?Pn(void 0):t===void 0?x().pipe(_(t=>Xt(()=>{let n=e;return n===Bg?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(_(([e,n])=>n?Vt(t).pipe(Ne(e)):Pn(e))))):Pn(t)});return{emit:t=>xr(()=>e===void 0||e===Bg?G:Cr(e,t).pipe(kn)),close:()=>{let t=e;return e=Bg,t===void 0||t===Bg?G:Vt(t)},stream:Ln(t.pipe(le(e=>e===void 0?Hn:qn(e))))}},Hg={close:()=>G,spawn:(()=>N(Error(`Childless machine logic cannot spawn a process`))),get:()=>Pn(ft()),changes:()=>Ig,sendTo:()=>G,stop:()=>G,owned:{spawn:()=>N(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>G,stopPaths:()=>void 0}},Ug=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>xr(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return G;let t=mt(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?G:Array.isArray(a)?O(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>Xt(()=>$h(i,e,t)),s=(e,t,n,r)=>Xt(()=>eg(i,e,t,n,r)),c=e=>{let t=typeof e==`string`?e:e.id;return Xt(()=>{if(i.closed)return ft();let n=i.children.get(t);return n!==void 0&&Xh(n,e)?pe(n.ref):ft()})},l=e=>{let t=typeof e==`string`?e:e.id;return It(jt((n,r)=>Xt(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(_(n=>{let a=Xt(()=>{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 ot(r,a).pipe(T(Xt(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),Jh(n,Zh(i,t,e))})),Ne(Yh(n)))}))))},u=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return xr(()=>{if(i.closed)return G;let o=i.children.get(a);return o!==void 0&&Xh(o,e)?_g(o.ref,t,n,r):G})},d=e=>{let t=typeof e==`string`?e:e.id;return xr(()=>{if(i.closed)return G;let n=i.children.get(t);return n!==void 0&&Xh(n,e)?n.ref.stop:G})};function f(n,r){let a=typeof n==`object`&&n&&Yp in n?n:void 0,c=a===void 0?n:a[Yp](r?.input),l=a===void 0?r:{id:a.id,descriptor:a},u=Symbol(),d=l?.id??u,f;return xr(()=>i.closed?me:typeof d==`string`&&(i.children.has(d)||qh(d))?U(new ed({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?.[ag]===void 0?void 0:{onSnapshot:l[ag]},...l?.[cg]===void 0?void 0:{sendParent:l[cg]},onReady:(e,t)=>Xt(()=>{f=e}).pipe(T(s(d,u,e,l?.descriptor)),_(e=>e?G:t)),onStop:o(d,u),parent:e,runtime:t,origin:{_tag:`Spawn`,address:l?.id}}).pipe(Ve(e=>vn(e)?o(d,u).pipe(T(f===void 0?G:f.stop)):G),he(i.scope))))}return{close:a,spawn:f,get:c,changes:l,sendTo:u,stop:d,owned:new Fg(i,e,t,n,r)}},Wg=(e,t,n,r)=>Xt(()=>Ug(e,t,n,r)),Gg=(e,t)=>`${e.length}:${e}${t}`,Kg=(e,t)=>`${Kh}${Gg(e,t)}`,qg=e=>({initial:()=>G,run:()=>e}),Jg=(e,t,n)=>({initial:()=>G,run:({parent:r})=>{let i=r?.[lg];return i===void 0?N(Error(`Stream invocation requires an acknowledged parent machine`)):rn(e,e=>i(gm(t,n,e)).pipe(kn,Ce(()=>me)))}}),Yg=(e,t)=>typeof e==`function`?e(t):e,Xg=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),Zg=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>qg(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:()=>qg(Gt(Yg(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>Jg(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:()=>Yg(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[Yp](`input`in e?Yg(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},Qg=e=>e.length===0?G:e.length===1?e[0]:O(e,{discard:!0}),$g=(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(Oe(`StoppedError`,()=>G)),e_=e=>e instanceof Qu||e instanceof Zu||e instanceof td,t_=(e,t,n,r,i,a,o,s,c,l,u,d)=>xr(()=>{let f=Gg(n,r),p=u===void 0?o:()=>{let t=o();return{...t,run:i=>Rr(xr(()=>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):G,onOutcome:(t,i,o)=>T(Ht,xr(()=>i._tag===`Stopped`||!t()?G:i._tag===`Done`?s===void 0?e.failCause(Mn(Error(`Invocation "${r}" completed without the required onDone handler`))):$g(e,hm(n,r,i.output),u===void 0?void 0:o):i._tag===`Failure`&&c!==void 0&&(a===void 0||!e_(i.error))?$g(e,_m(n,r,i.error),u===void 0?void 0:o):e.failCause(i.cause))),...l===void 0?void 0:{onSnapshot:(t,i)=>t()?$g(e,vm(n,r,i)):G}})}),n_=(e,t)=>qh(e)?U(new ed({id:t})):void 0,r_=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:n_(String(r.address),i);return a===void 0?t_(e,t,n,i,r.address===void 0?Kg(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},i_=(e,t,n,r)=>{let i=r.child,a=n_(i.id,i.id);return a===void 0?t_(e,t,n,i.id,i.id,i,i[Yp],r.onDone,r.onFailure,r.onSnapshot,void 0):a},a_=(e,t,n,r,i,a)=>{let o=Xg(t),s=Vm(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...Hf(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:np(e,r,i),ancestors:tp(e,r,i),event:a};return om(Sp(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?i_(t,n,i,e):r_(t,n,i,Zg(e,s,i)))});return s.length===0?void 0:Qg(s)},o_=Symbol(`effect/Machine/CompiledStoppedCompletion`),s_=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[lg](e){return this.sendAcknowledgedEffect(e)}[og](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=Hg;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=jg(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:xr(()=>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 Mg(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:ig({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:Vn(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=Ug(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?Lg:this.inspector===void 0?e.send:t=>_g(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)=>gg(e)?this.inspector===void 0?e.send(t):_g(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?Rg:(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(yr(e)),U(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 c_(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?Pn(this):(this.runState=`Draining`,c(this.drainRuntime(),this.services).pipe(Ne(this)))}initialize(){let e=this;return R(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*Wg(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?Lg:e.inspector===void 0?t.send:n=>_g(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)=>gg(t)?e.inspector===void 0?t.send(n):_g(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?Rg:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>vn(t)?e.childRuntime.close(t):G,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(le(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(Ve(t=>(vn(t)&&e.publishStartFailed(t.cause),r(t))),oe(Xt(()=>{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:Dt,poll:Xt(()=>z(bg(e.mailbox),fg)),receiveMessage:Dt,pollMessage:Xt(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:Xt(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new c_(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(kn))),e.options.onSnapshot!==void 0&&(yield*kg(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 Xt(()=>this.current.snapshot.state)}get snapshot(){return Xt(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return xr(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=l(),nr(this.waiter)))}get stop(){return mn(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return Xt(()=>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(kn);return this.runState===`Initializing`?e:e.pipe(T(me))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(_(e=>e?pt(this.settleRequestedTermination()).pipe(kn):G))}sendAcknowledgedEffect(e){return ln(t=>He().pipe(_(n=>this.offerEvent(e,void 0,void 0,n).pipe(T(t(nr(n)))))))}offerEvent(e,t,n,r){return xr(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?Ng(i,a,e,t,n,r):r===void 0?e:{[ug]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return mn(wr(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return U(new td);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&Pg(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&&yg(this.mailbox,e),this.runState!==`Idle`)return G;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),G)}return this.startWorker(void 0)}))}startWorker(e){let t=c(this.drainRuntime(e),this.services);return(this.options.detached===!0?pt(t,{startImmediately:!0}):at(t,{startImmediately:!0})).pipe(_(e=>Xt(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(_(t=>t?pt(this.interruptAndFinish(e)):G))),kn)}stopEffect(){return xr(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?G: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!==Bg||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=Bg;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,xg(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),hg(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=o_,this.lifecycle=`Completed`,this.waiter!==void 0&&(Ct(this.waiter,this.resolveCompletion(o_)),this.waiter=void 0),!0}settleRequestedTermination(){return xr(()=>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 Dr(e).pipe(T(xr(()=>this.lifecycle===`Completed`?G:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?G:this.join.pipe(ye,kn)}resolveCompletion(e){if(e!==o_)return e;let t=U(new td);return this.completion=t,t}drainRuntime(e){let t=this;return ln(n=>R(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(xr(()=>{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(ye);if(t.flushPendingChanges(),vn(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(ct(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 xr(()=>{if(this.lifecycle!==`TerminationRequested`)return G;let e=this.termination;if(e===void 0)return G;let t=this.terminationSnapshot??this.reserveTermination(e);if(t===void 0)return this.awaitCompletion();let n=e._tag===`Stopped`?lr:e._tag===`Done`?Kn(e.output):Vn(e.cause),r=e._tag===`Stopped`?o_:e._tag===`Done`?Pn(e.output):Hr(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?G:xr(()=>this.options.onOutcome(Og(t))).pipe(ye,kn),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(T(Xt(()=>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`?ar():n}))));return mn(Xt(()=>{xg(this.mailbox)}).pipe(T(this.childRuntime.close(n)),T(this.setAndPublishSnapshot(t)),T(s),T(Xt(()=>{e._tag===`Failure`?mg(this.inFlightMessage,e.cause):hg(this.inFlightMessage),this.inFlightMessage=void 0})),T(i),T(this.options.onStop??G),T(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:G),T(Xt(()=>{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&&(Ct(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?Pn(e):Cr(e.changes,[e]).pipe(Ne(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe(an(()=>kg(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?G:Cr(e.changes,Kn(void 0)).pipe(kn)}emitEvent(e){let t=this.externalEmissions===void 0?xr(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===Bg?G:Cr(this.emissionsPubSub,e).pipe(kn)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe(an(()=>Xt(()=>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=Bg,e===void 0||e===Bg?G:Vt(e)}getOrCreateEmissions(){return xr(()=>{let e=this.emissionsPubSub;return e===Bg?Pn(void 0):e===void 0?x().pipe(_(e=>Xt(()=>{let t=this.emissionsPubSub;return t===Bg?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(_(([t,n])=>n?Vt(e).pipe(Ne(t)):Pn(t))))):Pn(e)})}emissionsStream(){return Ln(this.getOrCreateEmissions().pipe(le(e=>e===void 0?Hn:qn(e))))}setAndPublishSnapshot(e){return xr(()=>{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)),kn)})}setActiveState(e){return xr(()=>this.commitActiveState(e)??G)}pollCompiledMessage(){let e=bg(this.mailbox);return ct(e)&&(this.inFlightMessage=dg(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=dg(e)?e:void 0}completeCompiledMessage(e){pg(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]:Lr(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:Lr(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:kg(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,Lr(e.changes,t))}updateState(e){return xr(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?G:e(t.snapshot.state).pipe(_(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?G:this.setActiveState(e)}))})}getOrCreateChanges(){return xr(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?x({replay:1}).pipe(_(e=>Xt(()=>{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?Vt(e).pipe(Ne(t)):Pn(t))))):Pn(e.changes):Pn(void 0)})}changesStream(){let e=this;return Ln(R(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return Xn(e.current.snapshot);let n=yield*Mr(t),r=e.current;return r.snapshot.status===`active`?Xn(r.snapshot).pipe(hr(It(cn(Ye(n))).pipe(yn(e=>e.revision>r.revision),Wt(e=>e.snapshot)))):Xn(r.snapshot)}))}},c_=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return z(this.process.pollCompiledMessage(),fg)}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}},l_=lt(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*Le(),i=e.execution,a=new s_(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(Ve(e=>vn(e)?a.shutdownEmissions().pipe(T(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:G)):G))}),u_=(e,t,n,r)=>new s_(e,t,n,r).initializeCompiledSync(),d_=lt(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:jg(e,m,p),y=h===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:p},b,S,C=Sg(),w=t.emissions??Vg(),E=yield*He(),D=yield*He(),O=nr(D).pipe(ye,kn),k=!0,A,j=mr(E,{_tag:`Stopped`}).pipe(kn),M=(e,t)=>xr(()=>Cg(C,e,t)?G:U(new td)),N=h===void 0?void 0:(e,t,n,r)=>xr(()=>{let i=h.isActive()?Ng(h,v,e,t,n,r):r===void 0?e:{[ug]:!0,event:e,deferred:r};return M(i,()=>Pg(h,v,i))}),P=e.execution?._tag===`Compiled`?e=>ln(t=>He().pipe(_(n=>(h===void 0?M({[ug]:!0,event:e,deferred:n}):N(e,void 0,void 0,n)).pipe(T(t(nr(n))))),le(e=>e))):void 0,F={id:m,sessionId:p,stop:xr(()=>k?j:j.pipe(T(Dt))),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}=Hg;vg(e.execution)||({changes:I,close:L,get:ee,owned:te,sendTo:ne,spawn:re,stop:ie}=yield*Wg(F,d,void 0,P===void 0?void 0:e=>P(e)));let B=e=>Ft(e)?G:(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:G))),V=l===void 0?c??G:Xt(()=>l(Re)),ae=h===void 0?zg:()=>Mg(A,k),se=f??(u===void 0?Lg:h===void 0?u.send:e=>_g(u,e,v,ae())),ce=h===void 0?w.emit:e=>w.emit(e).pipe(an(()=>Xt(()=>h.publishUnsafe({_tag:`Emitted`,subject:v,emission:e,causedBy:ae()})))),ue={self:F,parent:u,spawn:re,sendParent:se,emit:ce,sendTo:h===void 0?((e,t)=>gg(e)?e.send(t):ne(e,t)):((e,t)=>gg(e)?_g(e,t,v,ae()):ne(e,t,v,ae())),stopChild:ie,failCause:e=>mr(E,{_tag:`Failure`,cause:e}).pipe(kn),inspectInitial:h===void 0?Rg:(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 de=yield*e.initial(ue).pipe(Ve(B),oe(Xt(()=>{k=!1}))),fe=yield*Bn({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:de}});y===void 0&&h?.publishUnsafe({_tag:`Initialized`,subject:v,snapshot:{status:`active`,state:de},initialEntryPaths:b??[],microsteps:ig({microsteps:S??[]})});let pe=s===void 0?e=>e.changes===void 0?Pn(e):Cr(e.changes,[e]).pipe(Ne(e)):e=>{let t=e.changes===void 0?Pn(e):Cr(e.changes,[e]).pipe(Ne(e)),n=e.snapshot;return n.status===`active`?t.pipe(an(()=>kg(s,n))):t},me=e=>e.changes===void 0?G:Cr(e.changes,Kn(void 0)).pipe(kn),he=e=>e.snapshot.status===`active`?Pn(e):me(e).pipe(Ne(e)),ge=e=>pr(fe).pipe(_(t=>t.revision===e.revision?pe(e).pipe(_(he)):Pn(void 0))),_e=e=>gn(fe,t=>t.terminalizing?Pn([void 0,t]):le(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?Pn(void 0):ge(e)),le(e=>e?.snapshot)),ve=e=>ir(fe,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(le(e=>e?.snapshot)),be=e=>Nt(fe,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(_(pe),_(he),kn),xe=h===void 0?e=>_e(t=>Pn(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(kn):t=>pr(fe).pipe(_(n=>_e(e=>Pn(e.status===`active`?{status:`active`,state:t}:void 0)).pipe(an(r=>Xt(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&h.publishUnsafe({_tag:`StateChanged`,subject:v,before:n.snapshot.state,after:t,causedByDeliveryId:A!==void 0&&dg(A)?A.inspection?.deliveryId:void 0})})))),kn),Se=(e,n,r)=>{let a=i===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?G:xr(()=>i(Og(e))).pipe(ye,kn),o=h===void 0?w.close():w.close().pipe(T(Xt(()=>h.publishUnsafe(y===void 0?{_tag:`Terminated`,subject:v,snapshot:e}:{_tag:`ActivityStopped`,subject:y.owner,activity:y,exit:e.status===`stopped`?ar():n}))));return mn(Xt(()=>Tg(C)).pipe(T(L(n)),T(be(e)),T(o),T(Xt(()=>{vn(n)?mg(A,n.cause):hg(A),A=void 0})),T(a),T(V),T(t.inspectionRoot===!0&&h!==void 0?h.close:G),T(r)))},Ce=ve(e=>({status:`stopped`,state:e.state})),we=e=>ve(t=>({status:`error`,state:t.state,cause:e})),Te=e=>ve(t=>({status:`done`,state:t.state,output:e})),Ee=e=>Se(e,lr,yt(D,new td)),De=(e,t)=>{let n=Vn(t);return Se(e,n,Ot(D,t))},Oe=(e,t)=>{let n=Kn(t);return Se(e,n,mr(D,t))},ke=mn(j.pipe(T(O))),Ae=e.execution?._tag===`Compiled`?{receiveMessage:wg(C).pipe(an(e=>Xt(()=>{A=dg(e)?e:void 0}))),pollMessage:Xt(()=>bg(C)).pipe(an(e=>Xt(()=>{ct(e)&&(A=dg(e.value)?e.value:void 0)}))),completeMessage:e=>{pg(A,e),A=void 0}}:void 0,je=h===void 0||e.execution?._tag===`Compiled`?wg(C).pipe(le(fg)):wg(C).pipe(an(e=>Xt(()=>{A=e})),le(fg)),Me=h===void 0||e.execution?._tag===`Compiled`?Xt(()=>bg(C)).pipe(le(z(fg))):Xt(()=>bg(C)).pipe(an(e=>Xt(()=>{ct(e)&&(A=e.value)})),le(z(fg))),Pe=h===void 0?e=>_e(t=>t.status===`active`?e(t.state).pipe(le(e=>({status:`active`,state:e}))):Pn(void 0)).pipe(kn):t=>pr(fe).pipe(_(n=>_e(e=>e.status===`active`?t(e.state).pipe(le(e=>({status:`active`,state:e}))):Pn(void 0)).pipe(an(t=>Xt(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&h.publishUnsafe({_tag:`StateChanged`,subject:v,before:n.snapshot.state,after:t.state,causedByDeliveryId:A!==void 0&&dg(A)?A.inspection?.deliveryId:void 0})})))),kn),Fe={...ue,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:te}:void 0,...Ae,receive:je,poll:Me,state:pr(fe).pipe(le(e=>e.snapshot.state)),setState:xe,updateState:Pe},Ie=gn(fe,e=>e.snapshot.status===`active`?e.changes===void 0?x({replay:1}).pipe(le(t=>[t,{...e,changes:t}])):Pn([e.changes,e]):Pn([void 0,e])),Le=Ln(R(function*(){let e=yield*Ie;if(e===void 0)return Xn((yield*pr(fe)).snapshot);let t=yield*Mr(e),n=yield*pr(fe);return n.snapshot.status===`active`?Xn(n.snapshot).pipe(hr(It(cn(Ye(t))).pipe(yn(e=>e.revision>n.revision),Wt(e=>e.snapshot)))):Xn(n.snapshot)})),Re={id:m,sessionId:p,...h===void 0?void 0:{inspectionSubject:v,sendInspected:N},state:pr(fe).pipe(le(e=>e.snapshot.state)),snapshot:pr(fe).pipe(le(e=>e.snapshot)),changes:Le,emissions:w.stream,join:nr(D),stop:ke,send:F.send,...P===void 0?void 0:{[lg]:P},child:ee,childChanges:I};o!==void 0&&!o(Re)?yield*j:a!==void 0&&(yield*a(Re,j)),s!==void 0&&(yield*kg(s,{status:`active`,state:de}));let ze=e=>{switch(e._tag){case`Stopped`:return Ce;case`Done`:return Te(e.output);case`Failure`:return we(e.cause)}},Be=(e,t)=>{switch(e._tag){case`Stopped`:return Ee(t);case`Done`:return Oe(t,e.output);case`Failure`:return De(t,e.cause)}},H=e=>n===!0?pt(e,{startImmediately:!0}):at(e,{startImmediately:!0}),Ue=yield*Qt(E),We=g(Ue)?yield*ln(t=>t(xr(()=>e.run(Fe))).pipe(ye,_(e=>mr(E,vn(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(H):void 0;return yield*H(ln(e=>R(function*(){let t=ct(Ue)?yield*Ue.value:yield*e(nr(E)),n=yield*ze(t);return We!==void 0&&(yield*Dr(We)),n===void 0?yield*O:yield*Be(t,n)}))),Re}),f_=((e,t)=>e.execution?._tag===`Compiled`?l_(e,t):d_(e,t)),p_=Ag(f_,u_),m_=new WeakMap,h_=e=>xr(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),re(t,e=>e.stop,{discard:!0})}),g_=()=>{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},__=e=>_(Jn,t=>{let n=m_.get(t);if(n!==void 0)return e(n.hooks);let r=g_();return m_.set(t,r),T(ot(t,h_(r)),e(r.hooks))});lt(function*(e,t,n){let r=yield*p_,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*__(t=>d_(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*__(t=>l_(e,{...i,...t})):yield*N(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*__(t=>f_(e,{...i,...t}))});var v_=lt(function*(e,t){let n=yield*p_;return yield*__(r=>f_(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),y_=lt(function*(e,t,n){let r=yield*p_,i=yield*r.nextSessionId,a=yield*tg(i);r.inspection=a;let o=Vg(),s=yield*He(),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(__(n=>{let r={...c,...n};return t===`generic`?d_(e,r):t===`compiled`?e.execution?._tag===`Compiled`?l_(e,r):N(Error(`Machine cannot force the compiled runtime for generic process logic`)):f_(e,r)}).pipe(Ve(e=>ue(s,e))));return{id:n?.id??i,sessionId:i,changes:Ln(nr(s).pipe(le(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),b_=((e,t)=>y_(e,`auto`,t));Tr({_tag:on(`MachineSnapshot`),version:on(2),active:Yn(Tr({path:Mt,value:be(Zt)})),completed:be(Yn(Tr({path:Mt,output:be(Zt)}))),history:be(hn(Mt,Tr({mode:Qn([`shallow`,`deep`]),active:Yn(Mt),values:hn(Mt,Zt)})))});var x_=(e,t,n)=>{let r=Q(e,n);if(r.type===`compound`){let r=Cp(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return x_(e,t,r)}return r.output},S_=(e,t)=>R(function*(){let n=yield*mp(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)||!Ep(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=x_(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*bf(e,o,t.output,{boundary:`output`,state:a}))}return ap(e,{...n,outputs:r})}).pipe(Ce(t=>C_(e,t))),C_=(e,t)=>{if(nn(t))return Hr(At(t,t=>t instanceof Zu?t:new Zu({machineId:e.id,boundary:`configuration`,cause:yr(t)})));let n=Jt(t);return ct(n)&&n.value instanceof Zu?U(n.value):U(new Zu({machineId:e.id,boundary:`configuration`,cause:t}))},w_=e=>e.length===0?G:e.length===1?e[0]:O(e,{discard:!0}),T_=(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}),E_=new WeakMap,D_=e=>{let t=E_.get(e);if(t!==void 0)return t;let n=Object.values(ad(e).handlers).some(e=>e.invoke!==void 0);return E_.set(e,n),n},O_=Pn(ft()),k_=(e,t)=>{let n=Gh(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=gh(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return lh(e,r)?uh(e,r,ch).pipe(le(pe)):void 0},o=e=>xr(()=>c(e)??O_),s=(e,t,r,a,s)=>{let c=a.commands.length===0?void 0:_h(a.commands,e.scope),l=a.emittedEvents.length===0?void 0:vh(a.emittedEvents,i(e)),u=()=>{let i=xr(()=>(t&&e.completeMessage({before:r,plan:T_(a,n.snapshot),after:s}),a.done?Pn(pe(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(xr(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=dg(r),c=a?r.event:r,l=t.state(),u;try{u=n.plan(t.executionState??n.fromConfiguration(fp(e,l)),c,a,t.scope)}catch(e){return rd(e)}if(t.executionState=u.next,u.microsteps.length===0){a&&t.completeMessage({before:l,plan:T_(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(xr(()=>(a&&t.completeMessage({before:l,plan:T_(u,n.snapshot),after:d}),o(t))))));a&&t.completeMessage({before:l,plan:T_(u,n.snapshot),after:d})}};return{run:e=>Dg(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:Dg(r,e.scope)}}},A_=class{initialized=!1;initial;constructor(e){this.initial=e}},j_=(e,t)=>{let n=Gh(e);return r=>{let i=r.state();if(t&&lh(e,i))return uh(e,i,ch).pipe(le(pe));let a=r.scope,o=r.executionState,s=o instanceof A_?o:new A_;r.executionState=s;let c,l,u;return u=xr(()=>{let t=r.pollMessage();if(g(t))return l=void 0,Pn(ft());let o=t.value,s=dg(o),d=s?o.event:o,f=i,p;try{p=n.plan(l??n.fromConfiguration(fp(e,i)),d,s,a)}catch(e){return rd(e)}if(l=p.next,p.microsteps.length===0)return s&&r.completeMessage({before:f,plan:T_(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(_h(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(vh(p.emittedEvents,c??=gh(e,a))),p.done)x.push(r.ownedChildren.stopAll());else if(m)for(let[t,n]of _){let i=a_(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=xr(()=>(s&&r.completeMessage({before:f,plan:T_(p,n.snapshot),after:y}),p.done?Pn(pe(p.output)):u));return x.length===0?e:w_(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(w_(b).pipe(T(xr(w))))}),Dg(xr(()=>{if(s.initialized)return u;let t=s.initial,o=t?.activeConfiguration??fp(e,i);l=t?.configuration??n.fromConfiguration(o);let c=a_(e,a,r.ownedChildren,o,t?.entryPaths??rp(e,o),ch);return s.initial=void 0,s.initialized=!0,c===void 0?u:c.pipe(T(u))}),a)}},M_=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},N_=(e,t)=>{let n=D_(e),r=Gh(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=M_(t);return n?{...r,executionState:new A_({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw id(e)}},s=t=>a===void 0?Dg(hh(Cm(e,t),...i).pipe(_(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:_h(n.commands,t),i=n.emittedEvents.length===0?void 0:vh(n.emittedEvents,gh(e,t)),a=Pn(M_(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):Rn({try:()=>o(t),catch:id});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:j_(e,t._tag===`Resume`)}:{_tag:`Owned`,...k_(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?Dg(S_(e,t.snapshot),n):s(n).pipe(le(e=>e.state)),run:t=>Dg(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(lh(e,l))return yield*uh(e,l,ch);if(!n){let n,o=ft(),u;for(;c===void 0;){let d=ct(o)?o.value:yield*a;o=ft();let f=dg(d),p=f?d.event:d,m=l,h;try{h=mh(e,Vf(n??fp(e,l),t),p)}catch(e){return yield*rd(e)}if(n=h.next,h.microsteps.length>0){let n=ap(e,h.next);yield*_h(h.commands,t),yield*s(n),l=n,h.emittedEvents.length>0&&(yield*vh(h.emittedEvents,u??=gh(e,t))),h.done&&(c={output:h.output})}f&&r({before:m,plan:T_(h,t=>ap(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)=>a_(e,t,u,n,r,i)??G,f=e=>u.stopPaths(e)??G;return yield*R(function*(){let n=yield*mp(e,l);yield*d(n,rp(e,n),ch),n=void 0;let o=ft(),p;for(;c===void 0;){let m=ct(o)?o.value:yield*a;o=ft();let h=dg(m),_=h?m.event:m,v=l,y;try{y=mh(e,Vf(n??fp(e,l),t),_)}catch(e){return yield*rd(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=ap(e,y.next);if(yield*_h(y.commands,t),n&&(yield*f(r)),yield*s(a),l=a,y.emittedEvents.length>0&&(yield*vh(y.emittedEvents,p??=gh(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:T_(y,t=>ap(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(Ve(()=>u.stopAll()))}),t)}},P_=new WeakMap,F_=(e,...t)=>{if(t.length>0)return N_(e,{_tag:`Initial`,args:t});let n=P_.get(e);if(n!==void 0)return n;let r=N_(e,{_tag:`Initial`,args:t});return P_.set(e,r),r},I_=(e,t)=>N_(e,{_tag:`Resume`,snapshot:t}),L_=(e,...t)=>b_(F_(e,...t),e.id===void 0?void 0:{id:e.id}),R_=(e,t)=>v_(I_(e,t),e.id===void 0?void 0:{id:e.id}),z_={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`]},B_=[`title`,`description`,`documentation`],V_=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),H_=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},U_=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},W_=e=>Number.isFinite(Number(e)),G_=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,K_=(e,t)=>{if(t.has(e))return`opaque`;if(rr(e)||ht(e)||wt(e)||bt(e)||Ue(e)||B(e))return`tagged`;if(st(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return kt(e)?G_(e.types.map(e=>K_(e,n))):de(e)?K_(e.thunk(),n):ut(e)?`opaque`:`untagged`},q_=(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||ge(n)?`untagged`:K_(n,new Set(t).add(e))}let n=new Set(t).add(e);return kt(e)?G_(e.types.map(e=>q_(e,n))):de(e)?q_(e.thunk(),n):ut(e)?`opaque`:`untagged`},J_=e=>Ae(e)&&q_(u(e.ast))!==`untagged`,Y_=(e,t,n)=>{let r=H_(t,n);return typeof n==`symbol`?U_(e,r,`state keys must be strings, not symbols`):typeof n==`number`?U_(e,r,`state keys cannot use numeric forms`):n===``?U_(e,r,`state keys cannot be empty`):n===`__proto__`?U_(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?U_(e,r,`state keys cannot contain "."`):W_(n)?U_(e,r,`state keys cannot use numeric forms`):r},X_=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&U_(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&U_(e,H_(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},Z_=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!V_(n,r))return;let a=n[r];(typeof a!=`object`||!a||Ae(a)||a.type!==`history`)&&U_(e,`${t}.${r}`,i)},Q_=(e,t,n,r)=>{let i=z_[r];for(let a of Reflect.ownKeys(n))i.includes(a)||U_(e,t,`${r} states cannot declare property "${String(a)}"`)},$_=(e,t,n)=>{X_(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))B_.includes(r)||U_(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&U_(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},ev=(e,t,n,r,i=!1)=>{X_(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:Y_(e,n,a),s=t[a];if(Ae(s)){J_(s)||U_(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}X_(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:V_(s,`states`)?`compound`:`atomic`;if(Q_(e,o,s,l),l===`history`||l===`choice`){r||U_(e,o,`${l} states must be declared below an active parent state`),V_(s,`annotations`)&&$_(e,o,s.annotations),l===`history`&&V_(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&U_(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=V_(s,`schema`);u&&!J_(s.schema)&&U_(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&V_(s,`annotations`)&&U_(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&V_(s,`annotations`)&&$_(e,o,s.annotations),l===`atomic`&&V_(s,`type`)&&s.type!==`active`&&U_(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&U_(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&V_(s,`type`)&&s.type!==`active`&&U_(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&U_(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&V_(s,`output`)&&!Ae(s.output)&&U_(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?(Z_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&Z_(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),ev(e,s.states,o,!0)):l===`parallel`&&(V_(s,`states`)||U_(e,`${o}.states`,`parallel states must declare child regions`),Z_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),ev(e,s.states,o,!0))}},tv=e=>typeof e==`object`&&e?Object.freeze({...e}):e,nv=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(Ae(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=nv(i.states)),`annotations`in i&&(a.annotations=tv(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},rv=e=>nv(e),iv=(e,t=``)=>{if(Ae(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(V_(n,`fields`)&&(V_(n,`schema`)&&U_(`Machine.state`,t,`declare fields or schema, not both`),X_(`Machine.state`,t,n.fields,`state fields`),V_(n.fields,`_tag`)&&U_(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=Ut(t,n.fields),delete r.fields),V_(n,`states`)){X_(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))Y_(`Machine.state`,t,r),e[r]=iv(n.states[r],r);r.states=e}return t===``?(ev(`Machine.state`,{"":r},``,!1,!0),rv({"":r})[``]):r},av=`~effect/Machine`,ov=`~effect/Machine/ChildMachine`,sv={..._t,...Gn,[av]:av,toJSON(){return{_id:`Machine`}}},cv=(e,t)=>{let n=Object.create(sv);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,mf(e,n),n},lv=e=>e.kind===`none`?yd:vd(e.kind,e.path,e.scope,e.updatePath),uv=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),dv=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],fv=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!H(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(!bd(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`||!Gf(r,e.path)||!Gf(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}},pv=(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(!Sd(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(!wd(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(wd(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=wd(e)?e.target:e,i=typeof r==`object`&&r&&H(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&&Gf(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},mv=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:jd};delete a.target;let o=e.resolve(a,n);if(Md(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return pv(o,e.selection,r),o},hv=e=>e.kind===`update`?void 0:e.path,gv=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},_v=(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||gv(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||!H(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!bd(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:lv(a)})}))},vv=(e,t,n,r={},i)=>{let a=Fp(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 Cd(Ld(i.path,i.parent),Rp(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`?Nd(n.path,n.parent):Ld(n.path,n.parent)}if(e.kind===`update`)return Rp(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 Cd(Lp(t,e.path,r,i),Rp(t,e.updatePath,n))}return Lp(t,e.path,a,i)},yv=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>Td(t,a,e.key,e.selection.kind===`none`?Od():vv(e.selection,n,r,o,i))]))),bv=(e,t,n)=>{if(t.kind===`none`){if(!kd(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`);pv(e,t,n)}},xv=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),Sv=(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:fv({target:()=>Gp(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?jd():s(e,t)}}let p=Gp(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 jd();if(s!==void 0)return s(e,a);if(h)return vv(p,r,t,{input:g(e)});let l=u(e);return vv(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)}}},Cv=(e,t,n,r,i)=>{let a=Sv(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(H(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=_v(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:jd};delete s.target,s.select=yv(l,u,t,r,n);let d=a(s,o);if(Md(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(!Ed(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 bv(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=>hv(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:hv(e.selection),selection:uv(e.selection),updates:dv(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=fv(a,void 0,t,n,i),u=(e,r)=>({result:mv(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:hv(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:hv(l.selection),selection:uv(l.selection),updates:dv(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},wv=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=Cv(e[a],t,n,r,a);return i},Tv=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=Kp(r,e,n,e=>xv(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=Cv(i[e],t,n,r,e));return rm(i,n)});return am(i,n),Array.isArray(e)?Object.freeze(i):i[0]},Ev=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!H(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=wv(d,t,s,i)),u.always!==void 0&&(u.always=Cv(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=Cv(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=Cv(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=Tv(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!H(u.choice,`transition`)||typeof u.choice.transition!=`function`||!H(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=zd(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`);Ev(e,t,r.states,s,i,l)}}},Dv=e=>e===``?Vp:e,Ov=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=Ud(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(!Gf(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${Dv(e.source)}" updates "${Dv(n)}" before choice "${t}", whose ${r} targets "${Dv(o)}" outside that owner`)}}}}}}},kv=(e,t)=>(n=>{let r=nm(t.root,n),i=Object.assign(Object.create(sv),e);if(mf(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=Bd(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:em(n.root);i.initial=e=>({...Fd(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);Ev(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Mf(i,i.input,e))},{"":r.handlers});let s=cv(i,o);return Ov(s),s}),Av=e=>{let t=iv(e),n=jv();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},jv=()=>({path:(e=>e),get:((e,t)=>Yd(e,t).pipe(z(e=>e.value))),getWithParents:((e,t)=>{let n={};return Yd(e,t,n).pipe(z(e=>({value:e.value,parents:n})))}),getSnapshot:Yd,matches:((e,t)=>ct(Yd(e,t)))}),Mv=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(Gn);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??yf(`internal`,[]),n.emittedEvents=e.emittedEvents??yf(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=kv(n,Up(e.root,e)),pf(n),n},Nv=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?[]:[Pr(e)]},Pv=e=>yf(`public`,Nv(e)),Fv=(e,t)=>Iv(e,t,e=>t.input===void 0?F_(t):F_(t,e)),Iv=(e,t,n)=>({[ov]:ov,id:e,machine:t,[Yp]:n}),Lv=L_,Rv=R_,zv=(e,t)=>{try{let n=dh(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},Bv=(e,t)=>{try{let n=Lt(S_(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!lh(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=Lt(uh(e,r,ch));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},Vv={spawn:()=>N(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>U(new td),stop:()=>G},Hv=(e,t)=>{if(e.snapshot.status!==`active`)return ft();try{let n=e.machine,r=fp(n,e.snapshot.state);for(let e of rp(n,r)){let i=Sp(n,e);for(let a of om(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({...Hf(r)??wm(n,r),children:Vv,state:r.values.get(e),containingState:np(n,r,e),ancestors:tp(n,r,e),event:ch}):a.input);let s=zv(i,i.input===void 0?[]:[o]);return s===void 0?void 0:pe(s)}}return ft()}catch{return}},Uv=class extends Bt(`ChildNotActiveError`){},Wv=new WeakMap,Gv=new WeakMap,Kv=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return Fr(e);let t=Nr(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=Xe(t,n);ct(r)&&r.value===e&&S(t,n)});return r=>{let i=Xe(t,r);if(ct(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return Or(t,r,o),n.register(a,{key:r,entry:o}),a}},qv=(e,t)=>dr(et(t,e=>e.stop).pipe(an(t=>Xt(()=>e.setSelf(fe(t)))),_(()=>Dt))),Jv=(e,t)=>qv(e,e.result(t).pipe(_(e=>e.start))),Yv=(e,t,n)=>qv(e,Rv(t,n)),Xv=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[Sr](t):t(e),Zv=(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}},Qv=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},$v=e=>e.snapshot,ey=Qe(e=>e.registry).pipe(qe),ty=e=>xr(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,G):T(t,ty(e))}),ny=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},ry=(e,t,n)=>xe(n=>{let r=dt(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:Ge(z(n.self(),$n),()=>Br(!0))},(r,i)=>{let a=r.get(e),o=r.get(ey),s=ny(t,o);W(a)||s.draining?(r.setSelf(Br(!0)),s.pending.push(Ee(o,e).pipe(_(e=>n(e,i)),ye,le(e=>{let t=_e(e);r.setSelf(s.pending.length===0?t:$n(t))}))),s.draining||(s.draining=!0,Un(ty(s)))):h(a)?r.setSelf(dt(a,()=>void 0)):gr(n(a.value,i),{onExit:e=>r.setSelf(_e(e))})}).pipe(Sn),iy=e=>Qe(t=>{let n=t(e);return W(n)?Br(n.waiting):h(n)?V(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?V(n.value.cause,{previous:t.self(),waiting:n.waiting}):fe(n.value.state,{waiting:n.waiting})}).pipe(je(Et),d(Zv(t=>[Xv(e,t)],e=>dt(e,e=>e.state)))),ay=e=>Qe(t=>{let n=t(e);if(W(n))return Br(n.waiting);if(h(n))return V(n.cause,{previous:t.self(),waiting:n.waiting});if(g(n.value)){let e=t.self();return ct(e)&&h(e.value)?e.value:fe(ft(),{waiting:n.waiting})}return n.value.value.status===`error`?V(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):fe(pe(n.value.value.state),{waiting:n.waiting})}).pipe(je(Et),d(Zv(t=>[Xv(e,t)],e=>dt(e,z(e=>e.state))))),oy=(e,t)=>Qe(n=>{let r=n(e);if(W(r))return Br(r.waiting);if(h(r))return V(r.cause,{previous:n.self(),waiting:r.waiting});if(g(r.value))return fe(ft());let i=r.value.value,a=bn(i.child(t)),o=gr(Ht.pipe(T(i.childChanges(t).pipe(rn(e=>Xt(()=>n.setSelf(fe(e))))))));return n.addFinalizer(o),fe(a)}).pipe(Sn),sy=(e,t)=>sg(e)?e[og](()=>t(bn(e.snapshot))):gr(e.changes.pipe(rn(e=>Xt(()=>t(e))))),cy=(e,t,n)=>{let r=Qe(t=>{let n=t(e);if(W(n))return Br(n.waiting);if(h(n))return V(n.cause,{previous:t.self(),waiting:n.waiting});if(g(n.value))return fe(ft());let r=n.value.value;return t.addFinalizer(sy(r,e=>t.setSelf(fe(pe(e))))),fe(pe(bn(r.snapshot)))}).pipe(d(Zv(()=>[],()=>{let e=n();return e===void 0?Br(!0):fe(z(e,$v),{waiting:!0})}))),i=new WeakMap,a=e=>ct(e)?Pn(e.value):U(new Uv({id:t.id})),o=ry(e,i,(e,t)=>_(a(e),e=>e.send(t))),s=ry(e,i,(e,t)=>_(a(e),e=>e.stop)),c=ly(e,n);return{ref:e,snapshot:r,result:ay(r),send:o,stop:s,child:c}},ly=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=Fr(n=>{let r=Fv(n,a);return cy(oy(e,r),r,Qv(()=>{let e=t();return e===void 0||g(e)?e:Hv(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},uy=(e,t,n)=>{let r=Sn(e),i=Qe(e=>{let t=e(r);if(W(t))return Br(t.waiting);if(h(t))return V(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(sy(n,t=>e.setSelf(fe(t,{waiting:t.status===`active`}))));let i=bn(n.snapshot);return fe(i,{waiting:i.status===`active`})}).pipe(d(Zv(()=>[],()=>{let e=n();return e===void 0?Br(!0):fe($v(e),{waiting:!0})}))),a=new WeakMap,o=ry(r,a,(e,t)=>e.send(t)),s=ry(r,a,(e,t)=>e.stop),c=ly(Er(r,pe),()=>{let e=n();return e===void 0?void 0:pe(e)}),l={ref:r,snapshot:i,result:iy(i),send:o,stop:s,child:c};return Gv.set(l,t),l},dy=(e,t)=>Yd(e,t).pipe(z(e=>e.value)),fy=(e,t)=>Yd(e,t),py=(e,t)=>Er(e,t).pipe(je(Et),d(Zv(t=>[Xv(e,t)],e=>dt(e,t)))),my=new WeakMap,hy=(e,t,n,r)=>{let i=my.get(e);i===void 0&&(i=new Map,my.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},gy=(e,t)=>hy(e,`select`,t,()=>py(e.result,e=>dy(e,t))),_y=(e,t)=>hy(e,`selectSnapshot`,t,()=>py(e.result,e=>fy(e,t))),vy=(e,t)=>hy(e,`selectChild`,t,()=>py(e.result,ve(e=>dy(e,t)))),yy=(e,t)=>hy(e,`selectSnapshotChild`,t,()=>py(e.result,ve(e=>fy(e,t)))),by=(e,t)=>hy(e,`matches`,t,()=>py(e.result,e=>ct(Yd(e,t)))),xy=(e,t)=>hy(e,`matchesChild`,t,()=>py(e.result,ae(e=>ct(Yd(e,t))))),Sy=(e,t,n)=>{let r=e.atom(()=>Lv(t,...n)),i=uy(e.atom(e=>Jv(e,r)),t,Qv(()=>zv(t,n)));return Wv.set(i,r),i},Cy=(e,t,n)=>uy(e.atom(e=>Yv(e,t,n)),t,Qv(()=>Bv(t,n))),wy=(e,t,n)=>{let r={owner:e,source:t},i=C(t,e=>e(r.source),{initialValueTarget:t}).pipe(je((e,t)=>r.source.equals(e,t)),d(e=>Xv(r.source,e)));return n!==void 0&&(i=i.pipe(Dn(n))),i},Ty=(e,t)=>{let n=Kv(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=Kv(r=>{let a=n(r);return wy(a,i(a.bridge),t.label?.(r,e))})}return r},Ey=e=>{let t=((t,...n)=>Sy(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>Cy(e,t,n)),family:((t,n)=>Ty(n=>Sy(e,t,[n]),n))}},Dy=_n(2,gy);_n(2,_y),_n(2,vy),_n(2,yy),_n(2,by),_n(2,xy);var Oy=Ey,ky=e=>Ay(X.useContext(ju),e),Ay=(e,t)=>{let n=X.useMemo(()=>{let n,r,i=e=>ne(e)?(n=e,e):W(e)&&n!==void 0?n:e;return{subscribe:n=>e.subscribe(t,n),snapshot:()=>i(e.get(t)),serverSnapshot:()=>r??=i(Ar(t,e))}},[e,t]);return X.useSyncExternalStore(n.subscribe,n.snapshot,n.serverSnapshot)},jy=ky,My=e(t(),1);function Ny(e){let t=My.unstable_scheduleCallback(4,e);return()=>My.unstable_cancelCallback(t)}var Py=X.createContext(Fe({scheduleTask:Ny,defaultIdleTTL:400})),Fy=new WeakMap,Iy=0,Ly=new Set;function Ry(e){Iy++;try{return e()}finally{Iy--}}function zy(e){if(Iy===0)return e();Ly.size===0&&queueMicrotask(By),Ly.add(e)}function By(){for(let e of Ly)Ly.delete(e),e()}function Vy(e,t){let n=Fy.get(e);n===void 0&&(n=new WeakMap,Fy.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,()=>zy(n));return()=>{i--,Ly.delete(n),r()}},snapshot(){return Ry(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Ry(()=>Ar(t,e))}),a.value}};return n.set(t,o),o}function Hy(e,t){let n=Vy(e,t);return X.useEffect(By),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Uy(e,t,n){let r=Vy(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(By),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Wy=(e,t)=>{let n=X.useContext(Py);return t?Uy(n,e,t):Hy(n,e)};function Gy(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=sr(Ee(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Ky):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Ky=e=>{if(Ft(e))return e.value;throw Ir(e.cause)},qy=(e,t)=>{let n=X.useContext(Py);return[Hy(n,e),Gy(n,e,t)]};function Jy({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 Yy(e){let t=X.useRef(!0);t.current&&(t.current=!1,e())}function Xy(e,t,n,r,i,a,o,s,c,l=2){let u=aa(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 Co(n.current,u)?void 0:u}function Zy(e){return e==null?ma:e.type.startsWith(`key`)?Ra:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?Fo:ma}var Qy=X.createContext(void 0),$y=X.createContext(void 0),eb=X.createContext(void 0),tb=X.createContext(!1),nb=X.createContext(``);function rb(){let e=X.useContext(Qy);if(!e)throw Error(Ni(22));return e}function ib(){let e=X.useContext($y);if(!e)throw Error(Ni(23));return e}function ab(){let e=X.useContext(eb);if(!e)throw Error(Ni(24));return e}function ob(){return X.useContext(nb)}function sb(){return X.useContext(tb)}function cb(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 lb=(e,t)=>Object.is(e,t);function ub(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function db(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!cb(e,t,(e,t)=>ub(e,t,n)):e!==t}function fb(e,t,n){return e?e.some(e=>e!==void 0&&ub(t,e,n)):!1}function pb(e,t,n){return e?e.findIndex(e=>e!==void 0&&ub(e,t,n)):-1}function mb(e,t){if(t!==lb)return n=>fb(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 hb(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(mb(t,n)):pb(e,t,n);return i===-1?null:i}function gb(e,t,n,r,i,a){return fb(r,t,i)?a!=null&&e>a&&fb(r,n[a],i)?a:e:e===a?hb(n,r,i,!0):a}function _b(e,t,n){return e.filter(e=>!ub(t,e,n))}function vb(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function yb(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function bb(e){return yb(e?.[0])}function xb(e){return bb(e)?e.flatMap(e=>e.items):e}function Sb(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(bb(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 Cb(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 vb(e)}function wb(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?vb(e.value):vb(e)}var Tb={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?Sb(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=>ub(t,e,n)):ub(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},Eb=`data-valid`,Db=`data-invalid`,Ob={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},kb={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Ab={disabled:!1,...kb},jb={valid(e){return e===null?null:e?{[Eb]:``}:{[Db]:``}}},Mb={invalid:void 0,name:void 0,validityData:{state:Ob,errors:[],error:``,value:``,initialValue:null},setValidityData:Gi,disabled:void 0,setTouched:Gi,setDirty:Gi,setFilled:Gi,setFocused:Gi,focusOwnerRef:{current:void 0},validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Ab,registerFieldControl:Gi,validation:{getValidationProps:(e,t=No)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Gi,getInputControl:()=>null,commit:async()=>{},change:Gi}},Nb=X.createContext(Mb);function Pb(e=!0){let t=X.useContext(Nb);if(t.setValidityData===Gi&&!e)throw Error(Ni(28));return t}function Fb(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Pb(),s=Oi(()=>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 Ib=X.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Gi,validationMode:`onSubmit`,submitCountRef:{current:0}});function Lb(){return X.useContext(Ib)}function Rb(e){return ii(e,`base-ui`)}var zb=X.createContext({controlId:void 0,registerControlId:Gi,resetControlId:Gi,labelId:void 0,setLabelId:Gi,messageIds:[],setMessageIds:Gi,getDescriptionProps:e=>e});function Bb(){return X.useContext(zb)}function Vb(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=Bb(),o=Rb(),s=Oi(()=>Symbol()),c=X.useRef(!1),l=X.useRef(!1),u=J(()=>{c.current&&i!==Gi&&(c.current=!1,i(s.current,void 0))});return K(()=>{if(!n||i===Gi){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 Hb(e){return e==null?void 0:`${e}-popup`}function Ub(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function Wb(e){return Array.isArray(e)?e.map(e=>Wb(e)).join(`,`):e==null?``:String(e)}var Gb=new Map;function Kb(e={}){let{locale:t,...n}=e,r={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...n},i=`${Wb(t)}|${JSON.stringify(r)}`,a=Gb.get(i);if(a)return a;let o=new Intl.Collator(t,r),s={contains(e,t,n){if(!t)return!0;let r=Cb(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=Cb(e,n);return o.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=Cb(e,n),i=t.length;return r.length>=i&&o.compare(r.slice(r.length-i),t)===0}};return Gb.set(i,s),s}var qb=Kb;function Jb(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 Yb(e,t){let n=X.useRef(e),r=J(t);K(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Xb(e,t){let{onClick:n,onPointerDown:r}=Jb(J((n,r)=>{(typeof e==`function`?e():e)||t(r||(ka?`touch`:``))}));return X.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function Zb(e){let[t,n]=X.useState(null),r=Xb(e,n);return Yb(e,t=>{t&&!e&&n(null)}),X.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var Qb=Symbol(`none`),$b={value:Qb,index:-1};function ex(e,t,n){let r=e.get(t);if(r!==void 0||n===lb)return r;for(let[r,i]of e)if(ub(r,t,n))return i}function tx(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=lb,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}=Lb(),{setDirty:ne,validityData:z,setFilled:re,name:ie,disabled:B,setTouched:V,setFocused:ae,validationMode:oe,validation:se}=Pb(),ce=uu(),le=Vb({id:t}),ue=qb({locale:R}),de=Array.isArray(y)?null:y;if(de&&typeof de.label!=`function`)throw Error(Ni(100));let fe=de?de.data:y,pe=de?.value,me=pe?void 0:fe,he=X.useMemo(()=>{if(!b||!pe)return;let e=xb(b),t=e.map(pe),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 ex(n,r,i)}}},[b,pe]),ge=X.useMemo(()=>de?e=>de.label(e,A,e=>{let t=he?.findItem(e,A);return t==null?Cb(e,O):de.itemLabel(t)}):O,[de,O,he,A]),_e=X.useMemo(()=>de?Object.assign(e=>de.itemLabel(e),{selected:e=>Cb(e,ge)}):O,[de,ge,O]);function ve(e){return Cb(e,ge)}let[ye,be]=X.useState(!1),[xe,Se]=X.useState(null),Ce=X.useRef(xe),we=X.useRef([]),Te=X.useRef([]),Ee=X.useRef(null),De=X.useRef(null),Oe=X.useRef(null),ke=X.useRef(null),Ae=X.useRef(null),je=X.useRef(!1),Me=X.useRef(null),Ne=X.useRef(null),Pe=X.useRef(null),Fe=X.useRef($b),Ie=X.useRef(null),Le=X.useRef([]),Re=X.useRef(null),ze=B||m,Be=ie??f,H=u===`multiple`,Ve=u===`single`,He=s!==void 0||o!==void 0,Ue=fe!==void 0,We=b!==void 0,Ge;Ge=w===`always`?`always`:w?`input-change`:!1;let[U,Ke]=Jy({controlled:i,default:H?r??xa:r,name:`Combobox`,state:`selectedValue`}),qe=X.useMemo(()=>x===null?()=>!0:x===void 0?Ub(ue,_e):x,[x,ue,_e]),Je=Oi(()=>He?o??``:Ve?ve(U):``).current,[Ye,Xe]=Jy({controlled:s,default:Je,name:`Combobox`,state:`inputValue`}),[Ze,Qe]=Jy({controlled:c,default:l,name:`Combobox`,state:`open`}),$e=bb(fe),et=!Ze&&xe!==null?xe:String(Ye).trim(),tt=Ve?ve(U):``,nt=Ve&&!ye&&et!==``&&tt.length===et.length&&ue.contains(tt,et),rt=nt?``:S??et,it=Ue&&We&&nt&&(!de||de.hasValue(U,A)),at=X.useMemo(()=>fe?xb(fe):xa,[fe]),ot=X.useMemo(()=>{if(b&&!it)return b;if(!fe)return xa;if($e){let e=fe,t=[],n=0;for(let r of e){if(F>-1&&n>=F)break;let e=F>-1?F-n:1/0,i=rt===``?r.items.slice(0,e):[];if(rt!==``)for(let t of r.items){if(i.length>=e)break;qe(t,rt,_e)&&i.push(t)}if(i.length>0){let e={...r,items:i};t.push(e),n+=i.length}}return t}if(rt===``)return F>-1?at.slice(0,F):at;let e=[];for(let t of at){if(F>-1&&e.length>=F)break;qe(t,rt,_e)&&e.push(t)}return e},[b,it,fe,$e,rt,F,qe,_e,at]),st=X.useMemo(()=>{if(he&&ot===b)return he.values;let e=xb(ot);return pe?e.map(e=>pe(e)):e},[ot,b,he,pe]),W=Oi(()=>{let e=null;return M&&Ze&&Ue&&u!==`none`&&(e=hb(st,U,A,H)),new Ha({id:le,labelId:void 0,selectedValue:U,open:Ze,items:me,selectionMode:u,name:Be,form:p,disabled:ze,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:ge,isItemEqualToValue:A,modal:P,autoHighlight:Ge,submitOnItemClick:ee,hasInputValue:He,mounted:!1,forceMounted:!1,transitionStatus:`idle`,inline:M,activeIndex:null,selectedIndex:e,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemRoot:{props:No,id:le,selectionMode:u,disabled:ze,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:Gi,setOpen:Gi,setInputValue:Gi,setSelectedValue:Gi,setIndices:Gi,handleSelection:Gi,forceMount:Gi,requestSubmit:Gi,listRef:we,labelsRef:Te,popupRef:Ee,emptyRef:Ae,inputRef:De,startDismissRef:Oe,endDismissRef:ke,chipsContainerRef:Me,clearRef:Ne,valuesRef:Le,pointerDownItemRef:Re,selectionEventRef:Pe},Tb)}).current,ct=u===`none`?Ye:U,lt=X.useMemo(()=>u===`none`?ct:Array.isArray(U)?U.map(e=>wb(e,k)):wb(U,k),[ct,k,u,U]),ut=J(d),dt=J(n),ft=W.useState(`activeIndex`),pt=W.useState(`selectedIndex`),mt=W.useState(`positionerElement`),ht=W.useState(`listElement`),gt=W.useState(`triggerElement`),_t=W.useState(`inputElement`),vt=W.useState(`inputGroupElement`),yt=W.useState(`inline`),bt=W.useState(`inputInsidePopup`),xt=W.useState(`inputOwnsFormValue`),St=Ve&&!bt&&Ye===tt,Ct=hs(gt),{openMethod:wt,triggerProps:Tt}=Zb(Ze),Et=J(()=>lt);Fb(bt?Ct:De,le,ct,Et,!ze,f);let Dt=J(()=>{fe?Te.current=st.map(ve):W.set(`forceMounted`,!0)}),Ot=J((e,t,n,r)=>{if(t===-1){if(Fe.current===$b)return;Fe.current=$b}else Fe.current={value:e,index:t};ut(e,qi(n,r,{index:t}))}),kt=J(e=>{let t={};e.activeIndex!==void 0&&(t.activeIndex=e.activeIndex),e.selectedIndex!==void 0&&(t.selectedIndex=e.selectedIndex),W.update(t);let n=e.activeIndex;if(n===void 0)return;let r=e.type||`none`;n===null?Ot(void 0,-1,r,e.event):Ot(Le.current[n],n,r,e.event)}),At=J((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(je.current=n.reason===Ma,n.reason===`input-change`){Ze&&xe!==null&&Se(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&be(!0),Ie.current={hasQuery:e};let n=W.state.listElement;if(!W.state.virtualized&&n){let e=Ee.current;for(let t of zo(n.firstElementChild??n)){if(!ra(t)||(e?!q(e,t):t.getAttribute(`role`)===`dialog`))break;if(ms(t)){t.scrollTop=0;break}}}e&&Ge&&W.state.activeIndex==null&&(Ze||yt)&&W.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&W.state.inputInsidePopup&&(Ie.current={hasQuery:!1,selection:!0});Xe(t)}}),jt=J(e=>{let t=!e&&bt&&!yt&&Ye!==``&&(String(Ye).trim()===xe||Ye===tt);!e&&(t||Ye===``||St)&&be(!1),Se(null),t&&At(``,Y(Ma))}),[G,Mt]=X.useState(!1),Nt=J((t,n)=>{if(Ze===t)return;n.reason===`escape-key`&&Ue&&st.length===0&&!Ae.current&&n.allowPropagation();let r=n,i=lc(r);if(e.onOpenChange?.(t,r),Ie.current?.hasQuery&&n.reason===`input-change`===n.isCanceled&&(Ie.current=null),!n.isCanceled&&(t&&xe!==null&&jt(n.reason===Ea),!t&&ye&&(Ve?(yt||Se(et),et===``&&be(!1)):H&&(yt||Se(et),bt&&kt({activeIndex:null}),(!bt||yt)&&At(``,Y(Ma,n.event,void 0,{isItemPress:n.reason===Qa})))),t||Mt(i()),Qe(t),!t&&bt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(V(!0),ae(!1),oe===`onBlur`))){let e=u===`none`?Ye:U;se.commit(e)}}),Pt=J((e,t)=>{a?.(e,t),!t.isCanceled&&(Ke(e),(u===`none`&&Ee.current&&N||Ve&&!W.state.inputInsidePopup)&&At(ve(e),Y(t.reason,t.event)))}),Ft=J((e,t)=>{let n=ua(e),r=Pe.current??e;Pe.current=null;let i=Y(Qa,r),a=po(n,`a`)?.getAttribute(`href`);if(a)a.startsWith(`#`)&&Nt(!1,i);else if(H){let e=Array.isArray(U)?U:[],n=fb(e,t,A),r=n?_b(e,t,A):[...e,t];if(Pt(r,i),i.isCanceled||!(De.current&&De.current.value.trim()!==``))return;if(W.state.inputInsidePopup){At(``,Y(Ma,i.event,void 0,{isItemPress:!0}));let e=Ie.current;e&&!n&&(e.toggledValue=t)}else Nt(!1,i)}else{if(Pt(t,i),i.isCanceled)return;Nt(!1,i)}}),It=J(()=>{let e=se.inputRef.current?.form??W.state.inputElement?.form;e&&typeof e.requestSubmit==`function`&&e.requestSubmit()}),Lt=J(()=>{if(dt?.(!1),be(!1),Se(null),kt(u===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),H&&De.current&&De.current.value!==``&&!je.current&&At(``,Y(Ma)),Ve){if(W.state.inputInsidePopup)De.current&&De.current.value!==``&&At(``,Y(Ma));else{let e=ve(U);De.current&&De.current.value!==e&&At(e,Y(e===``?Ma:ma))}}}),Rt=X.useMemo(()=>yt&&mt?{current:po(mt,`[role="dialog"]`)}:Ee,[yt,mt]),{mounted:zt,transitionStatus:Bt,forceUnmount:Vt}=ec({open:Ze,ref:Rt,preventUnmountOnClose:G,setPreventUnmountOnClose:Mt,onUnmount:Lt});X.useImperativeHandle(e.actionsRef,()=>({unmount:Vt,close:()=>Nt(!1,Y(wo))}),[Vt,Nt]),K(function(){let e=Ce.current!==null&&xe===null;if(Ce.current=xe,Ze&&(!e||!Ue)||(Ze||(Re.current=null),u===`none`))return;let t=Ue?st:Le.current;kt({selectedIndex:hb(t,U,A,H)})},[Ze,xe,U,u,H,Ue,st,A,kt]),K(()=>{fe&&(Le.current=st,we.current.length=st.length)},[fe,st]),K(()=>{!Ze&&Ie.current?.hasQuery&&(Ie.current=null)},[Ze]),K(()=>{if(!Ze&&yt&&Rt.current){Ie.current=null;return}let e=Ue||We?st:Le.current,t=Ie.current;if(t){let n=Ze||yt||W.state.positionerElement?.hidden===!1;if(t.hasQuery){let t=De.current;!Ge||String(Ye).trim()===``||yt&&Ge!==`always`&&(!t||Ci(t.ownerDocument)!==t)?Ie.current=null:n&&(e[0]!==void 0||!Ue&&!We)&&(W.set(`activeIndex`,0),Ie.current=null)}else if(String(Ye).trim()===``&&(Ie.current=null,n)){let e=t.selection;Ge===`always`&&!e&&W.state.selectionMode===`none`&&W.set(`activeIndex`,0),queueMicrotask(()=>{if(!W.state.open&&(!W.state.inline||Rt.current)||De.current&&De.current.value.trim()!==``)return;let n=W.state.selectedValue,r=W.state.selectionMode===`multiple`;if(r&&Array.isArray(n)?n.length>0:W.state.selectionMode!==`none`&&n!=null){let e=Ue||We?st:Le.current,i=pb(e,t.toggledValue,W.state.isItemEqualToValue);W.set(`activeIndex`,i===-1?hb(e,n,W.state.isItemEqualToValue,r):i)}else e?W.set(`activeIndex`,null):Ge===`always`&&W.set(`activeIndex`,0)})}}if(!Ze&&!yt)return;let n=W.state.activeIndex;if(n==null){if(Ge===`always`&&e.length>0){W.set(`activeIndex`,0);return}Ot(void 0,-1,ma);return}if(n>=e.length){Ot(void 0,-1,ma),W.set(`activeIndex`,null);return}let r=e[n],i=Fe.current.value,a=i!==Qb&&ub(r,i,W.state.isItemEqualToValue);Fe.current.index===n&&a||Ot(r,n,ma)},[ft,Ge,Ot,We,Ue,st,yt,Ze,Rt,W,Ye]),K(()=>{re(u===`none`?String(Ye)!==``:H?Array.isArray(U)&&U.length>0:U!=null)},[re,u,Ye,U,H]),X.useEffect(()=>{Ue&&Ge&&st.length===0&&kt({activeIndex:null})},[Ue,Ge,st.length,kt]);function Ht(){Ze&&et!==``&&et!==String(Je)&&!St&&be(!0)}function Ut(){Ze&&xe!==null&&jt(!1)}let Wt=!1;function Gt(){!Wt&&Ye!==tt&&(Wt=!0,At(tt,Y(ma)))}function Kt(){u!==`none`&&(te(Be),ne(db(U,z.initialValue,A)),se.change(U),Ve&&!He&&!bt&&Gt())}function qt(){Ve&&!He&&!bt&&!ye&&Gt()}function Jt(){u===`none`&&(te(Be),ne(Ye!==z.initialValue),se.change(Ye))}Yb(et,Ht),Yb(Ze,Ut),Yb(U,Kt),Yb(tt,qt),Yb(fe,qt),Yb(Ye,Jt);let Yt=Dc({open:yt?!0:Ze,onOpenChange:Nt,elements:{reference:bt?gt:_t,floating:mt}}),Xt=v?`grid`:`listbox`,Zt=Ze||yt,Qt=Zt?`true`:`false`,$t=X.useMemo(()=>{let e=_t?.tagName===`INPUT`,t=_t==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?ht?.id:void 0,r[`aria-autocomplete`]=h?`none`:I),{reference:r,floating:{role:`presentation`}}},[_t,Zt,Qt,Xt,ht?.id,I,h]),en=Js(Yt,{enabled:!ze&&C,event:`mousedown-only`,toggle:!1,touchOpenDelay:bt?0:100,reason:so}),tn=Zs(Yt,{enabled:!ze&&!yt,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:yt?!0:void 0,outsidePress(e){let t=ua(e);return!q(gt,t)&&!q(Ne.current,t)&&!q(Me.current,t)&&!q(vt,t)}}),nn=Yc(Yt,{enabled:!ze,id:le,listRef:we,activeIndex:ft,selectedIndex:pt,virtual:!0,loopFocus:D,allowEscape:D&&!Ge,focusItemOnOpen:ye||u===`none`&&!Ge?!1:`auto`,focusItemOnHover:E,resetOnPointerLeave:!T,orientation:v?`horizontal`:void 0,rtl:ce===`rtl`,disabledIndices:xa,grid:v?Xy:void 0,onNavigate(e,t){(t||Ze||yt&&e===null)&&Bt!==`ending`&&kt({activeIndex:e,type:Zy(t),event:t?.nativeEvent})}}),rn=X.useMemo(()=>qa(nn.reference,{onKeyDown(e){v&&W.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,W]),an=X.useMemo(()=>qa(nc,tn.floating),[tn.floating]),on=X.useMemo(()=>qa(nn.floating,$t.floating),[nn.floating,$t.floating]),sn=X.useMemo(()=>{let e=nn.item;return{props:e?{...e,onFocus:void 0}:No,id:le,selectionMode:u,disabled:ze,readOnly:h,isItemEqualToValue:A}},[nn.item,le,u,ze,h,A]);W.useContextCallback(`setOpen`,Nt),W.useContextCallback(`setInputValue`,At),W.useContextCallback(`setSelectedValue`,Pt),W.useContextCallback(`setIndices`,kt),W.useContextCallback(`handleSelection`,Ft),W.useContextCallback(`forceMount`,Dt),W.useContextCallback(`requestSubmit`,It),W.useContextCallback(`onOpenChangeComplete`,n),Yy(()=>{W.update({inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Tt,itemRoot:sn})});let cn={id:le,selectedValue:U,open:Ze,mounted:zt,transitionStatus:Bt,items:me,inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Tt,itemRoot:sn,openMethod:wt,selectionMode:u,name:Be,form:p,disabled:ze,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:ge,modal:P,autoHighlight:Ge,isItemEqualToValue:A,submitOnItemClick:ee,hasInputValue:He};K(()=>{W.update({...cn,inputOwnsFormValue:u===`none`&&(M||!W.state.inputInsidePopup)})},[W,...Object.values(cn)]);let ln=$r(_,se.inputRef),un=X.useMemo(()=>({query:et,hasItems:Ue,filteredItems:ot,flatFilteredValues:st}),[et,Ue,ot,st]),dn=X.useMemo(()=>Array.isArray(ct)?``:wb(ct,k),[ct,k]),fn=H&&Array.isArray(U)&&U.length>0,pn=H||u===`none`&&xt?void 0:Be,mn=X.useMemo(()=>!H||!Array.isArray(U)||!Be?null:U.map(e=>{let t=wb(e,k);return(0,Z.jsx)(`input`,{type:`hidden`,form:p,name:Be,value:t,disabled:ze},t)}),[H,U,p,Be,k,ze]),hn=(0,Z.jsxs)(X.Fragment,{children:[e.children,(0,Z.jsx)(`input`,{...se.getValidationProps(ze,{onFocus(){bt?gt?.focus():(De.current||gt)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||ze||h)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Y(ma,e.nativeEvent),i=()=>Le.current.findIndex(e=>wb(e,k).toLowerCase()===n||ve(e).toLowerCase()===n);function a(){if(H)return;if(u===`none`){At(t,r);return}let e=i();e===-1&&(e=Le.current.findIndex((e,t)=>{let r=Te.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Le.current[e];a!=null&&Pt?.(a,r)}Ve&&(Dt(),fe&&i()===-1&&W.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:le&&pn==null?`${le}-hidden-input`:void 0,form:p,name:pn,autoComplete:L,disabled:ze,required:g&&!fn,readOnly:h,value:dn,ref:ln,style:pn?Yr:Ro,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),mn]});return(0,Z.jsx)(Qy.Provider,{value:W,children:(0,Z.jsx)($y.Provider,{value:Yt,children:(0,Z.jsx)(tb.Provider,{value:Ue,children:(0,Z.jsx)(eb.Provider,{value:un,children:(0,Z.jsx)(nb.Provider,{value:Ye,children:hn})})})})})}function nx(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=qb({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?Cb(t,o):``)}return(0,Z.jsx)(tx,{...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 rx=`data-popup-side`,ix=`data-list-empty`,ax={...ls,...jb,popupSide:e=>e?{[rx]:e}:null,listEmpty:e=>e?{[ix]:``}:null};function ox(e,t,n){let{setFocused:r,focusOwnerRef:i}=Pb(),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 sx=5;function cx(e,t){let n=lx(t);return e.clientX>=n.left-sx&&e.clientX<=n.right+sx&&e.clientY>=n.top-sx&&e.clientY<=n.bottom+sx}function lx(e){let t=e.getBoundingClientRect(),n=ea(e);if(sa)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 ux(e,t){return e??t}function dx(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function fx(){return ab().filteredItems.length===0}function px(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function mx(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var hx=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}=Pb(),{labelId:m}=Bb(),h=rb(),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=ib(),N=ob(),P=ho(),F=u||_||a,I=fx(),L=dx(h),R=X.useRef(null),ee=ox(F,R);Vb({id:w?o:void 0});let te=w?o??T:o,ne=ux(m,E),z;D&&w?z=S??Hb(T):D&&(z=x?.id);let re=X.useRef(``);function ie(e){re.current=e.pointerType}let{reference:B}=Xc(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(ma))}}),{reference:V}=Js(M,{enabled:!_,event:`mousedown`}),{buttonRef:ae,getButtonProps:oe}=Ao({native:i,disabled:F}),se={...l,readOnly:v,open:D,disabled:F,popupSide:L,listEmpty:I,placeholder:g!==`none`&&!j},ce=J(e=>{h.set(`triggerElement`,e)});return Oo(`button`,e,{ref:[t,ae,R,ce],state:se,props:[C,V,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=ai(e.currentTarget);function n(e){let t=h.state.triggerElement;if(!t)return;let n=ua(e),r=h.state.positionerElement,i=h.state.listElement;q(t,n)||q(r,n)||q(i,n)||cx(e,t)||h.context.setOpen(!1,Y(_a,e))}w&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(ri(e),h.context.setOpen(!0,Y(Fa,e.nativeEvent)),h.context.inputRef.current?.focus())}},p.getValidationProps(F,c),oe],stateAttributesMapping:ax})}),gx=X.createContext(void 0);function _x(){return X.useContext(gx)}var vx=X.createContext(void 0);function yx(e){let t=X.useContext(vx);if(t===void 0&&!e)throw Error(Ni(21));return t}var bx=X.forwardRef(function(e,t){let n=rb(),{buttonRef:r,getButtonProps:i}=Ao({native:!1}),a=$r(t,r);function o(e){n.context.setOpen(!1,Y(_o,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Z.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:Yr})}),xx=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}=Pb(),{labelId:p}=Bb(),m=_x(),h=!!yx(!0),g=rb(),_=ob(),v=uu(),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=dx(g),I=l||b||i,L=fx(),R=ox(I,g.context.inputRef),ee=h||M,te=!ee||N,ne=Rb(a??(ee?void 0:j)),z=h?kb:c,[re,ie]=X.useState(null),B=X.useRef(!1),V=X.useRef(null);K(()=>{O||(V.current=null)},[O]);let ae=w===`none`&&!h,oe=J(e=>{let t=h||g.state.inline;t&&!g.state.hasInputValue&&g.context.setInputValue(``,Y(ma)),g.update({inputElement:e,inputInsidePopup:t,inputOwnsFormValue:ae})}),se=h?s:f.getValidationProps(I,s);function ce(e){g.context.setIndices({activeIndex:null,selectedIndex:null,type:Zy(e),event:e})}let le={...z,open:O,disabled:I,readOnly:x,popupSide:F,listEmpty:L};function ue(e){if(!m)return;let t,n=m.chipsRef.current.length,[r]=px(v);return e.key===r&&(e.currentTarget.selectionStart??0)===0&&A.length>0&&(e.preventDefault(),t=n>0?n-1:void 0),t}let de=Oo(`input`,e,{state:le,ref:[t,g.context.inputRef,oe],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,...ae&&S&&{name:S},id:ne,onFocus(){if(R(!0),!M)return;let e=V.current;V.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`&&(V.current=e,g.context.setIndices({activeIndex:null})),d===`onBlur`){let e=w===`none`?_:A;f.commit(e)}},onCompositionStart(e){Kr||(B.current=!0,ie(e.currentTarget.value))},onCompositionEnd(e){B.current=!1;let t=e.currentTarget.value;ie(null),g.context.setInputValue(t,Y(Ea,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(Ea,t)),P||ce(t))}if(B.current){let n=e.currentTarget.value;ie(n),n===``&&!g.state.openOnInputClick&&!g.state.inputInsidePopup&&g.context.setOpen(!1,Y(Ma,t));let r=n.trim(),i=P&&r!==``;a(r),O&&g.state.activeIndex!==null&&!i&&ce(t);return}let o=Y(Ea,t);if(g.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Y(Ma,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&&ce(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&&ri(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=v===`rtl`;if(e.key===`Home`){ri(e);let n=pa&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){ri(e);let i=pa&&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(Ca,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);ce(e.nativeEvent),g.context.setSelectedValue(r,Y(ma,e.nativeEvent));return}let i=ue(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(ma,n));return}ri(e),mx(g,t,n)}}},se],stateAttributesMapping:ax}),fe=h?(0,Z.jsx)(Nb.Provider,{value:Mb,children:de}):de;return(0,Z.jsxs)(X.Fragment,{children:[O&&te&&(0,Z.jsx)(bx,{ref:g.context.startDismissRef}),fe]})}),Sx={...Ui,...cs},Cx=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}=Pb(),u=rb(),d=u.useState(`selectionMode`),f=u.useState(`disabled`),p=u.useState(`readOnly`),m=u.useState(`open`),h=u.useState(`selectedValue`),g=u.useState(`hasSelectionChips`),_=ob(),v=!1;v=d===`none`?_!==``:d===`single`?h!=null:g;let y=l||f||i,{buttonRef:b,getButtonProps:x}=Ao({native:a,disabled:y}),{mounted:S,transitionStatus:C,setMounted:w}=$s(v),T={disabled:y,visible:v,open:m,transitionStatus:C};Di({open:v,ref:u.context.clearRef,onComplete(){v||w(!1)}});let E=Oo(`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=Zy(e);u.context.setInputValue(``,Y(io,e.nativeEvent)),d===`none`?u.context.setIndices({activeIndex:null,type:t,event:e.nativeEvent}):(u.context.setSelectedValue(Array.isArray(h)?[]:null,Y(io,e.nativeEvent)),u.context.setIndices({activeIndex:null,selectedIndex:null,type:t,event:e.nativeEvent})),u.context.inputRef.current?.focus()}},c,x],stateAttributesMapping:Sx});return o||S?E:null}),wx=X.createContext(null);function Tx(){return X.useContext(wx)}function Ex(e){let{children:t}=e,{filteredItems:n}=ab(),r=Tx(),i=r?r.items:n;return(0,Z.jsx)(X.Fragment,{children:i.map(t)})}var Dx=X.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Ox(){return X.useContext(Dx)}function kx(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=J(i),[,o]=X.useState(0),s=Oi(jx).current,c=Oi(Ax).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(!Px(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Fx(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=Nx(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=J(()=>{let[e,t]=Mx(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)(Dx.Provider,{value:b,children:t})}function Ax(){return new Map}function jx(){return new Set}function Mx(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)=>Fx(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 Nx(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Px(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 Fx(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Ix=X.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=rb(),l=ib(),u=!!yx(!0),{filteredItems:d,hasItems:f}=ab(),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)(Ex,{children:o}):o,[o]),w={empty:b},T=l.useState(`floatingId`),E=Oo(`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;ri(e),mx(c,t,e.nativeEvent)}}},s]});if(_)return E;let D=f&&!v?void 0:c.context.labelsRef;return(0,Z.jsx)(kx,{elementsRef:c.context.listRef,labelsRef:D,children:E})}),Lx=X.createContext(void 0);function Rx(){let e=X.useContext(Lx);if(e===void 0)throw Error(Ni(20));return e}var zx=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=rb(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Z.jsx)(Lx.Provider,{value:n,children:(0,Z.jsx)(to,{ref:t,...r})}):null}),Bx=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}})}),Vx={},Hx={},Ux=``;function Wx(e,t){return Si(e)?e:t}function Gx(e,t,n){return/hidden|clip/.test(e.getComputedStyle(Wx(t,n)).overflowY)}function Kx(e){if(typeof document>`u`)return!1;let t=ai(e);return ea(t).innerWidth-t.documentElement.clientWidth>0}function qx(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=ai(e),n=t.documentElement,r=t.body,i=Wx(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 Jx(e){let t=ai(e),n=t.documentElement,r=t.body,i=Wx(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 Yx(e){let t=ai(e),n=t.documentElement,r=t.body,i=ea(n),a=0,o=0,s=!1,c=si.create();if(Bi&&(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,Vx={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Ux=n.style.scrollBehavior,Hx={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=Wx(n,r);s=qx(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,Vx),Object.assign(r.style,Hx),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=Ux)}function d(){u(),c.request(l)}l();let f=pi(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var Xx=new class{lockCount=0;restore=null;timeoutLock=no.create();timeoutUnlock=no.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=ai(e),n=t.documentElement,r=t.body,i=ea(n);if(Gx(i,n,r)){let t=new i.MutationObserver(()=>{Gx(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=ka||!Kx(e);this.restore=a?Jx(e):Yx(e)}};function Zx(e=!0,t=null){K(()=>{if(e)return Xx.acquire(t)},[e,t])}var Qx=20;function $x(e,t,n,r){let[i,a]=X.useState(!1);K(()=>{if(!e||!t||n==null){a(!1);return}let r=ai(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-Qx)},[e,t,n]),Zx(e&&(!t||i),r)}var eS=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=qr,style:g,..._}=e,v=rb(),y=ib(),b=Rx(),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=fx(),M=wu({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});$x(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=Ou(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Z.jsxs)(vx.Provider,{value:M,children:[C&&x&&(0,Z.jsx)(Bx,{inert:wi(!S),cutout:O??D??E}),F]})}),tS={...us,...Ui},nS=X.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=rb(),l=yx(),u=ib(),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=fx(),x=s.id??(g?Hb(y):void 0);K(()=>(c.set(`popupId`,c.context.popupRef.current?.id||x),()=>{c.set(`popupId`,void 0)}),[c,x]),Di({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=Oo(`div`,e,{state:S,ref:[t,c.context.popupRef],props:[m,{id:x,role:g?`dialog`:`presentation`,onFocus(e){let t=ua(e.nativeEvent);p!==`touch`&&(q(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},Du(h),s],stateAttributesMapping:tS}),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)(qs,{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)(bx,{ref:c.context.endDismissRef})]})})});function rS(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Ox(),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 iS=X.createContext(void 0);function aS(){let e=X.useContext(iS);if(!e)throw Error(Ni(19));return e}var oS=X.createContext(!1);function sS(){return X.useContext(oS)}function cS(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=rS({guess:!0,index:l,textRef:p}),h=rb(),g=sS(),_=sb(),{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=gb(E,c,h.context.valuesRef.current,e,C,t):ub(c,e,C)&&(t=E),h.set(`selectedIndex`,t)},[D,_,h,E,c,C]);let{getButtonProps:N,buttonRef:P}=Ao({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?(tc.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=Oo(`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)(iS.Provider,{value:ee,children:R})}function lS(e){let{componentProps:t,forwardedRef:n}=e,r=rb().useState(`isItemEqualToValue`),{flatFilteredValues:i}=ab(),a=pb(i,t.value??null,r);return(0,Z.jsx)(cS,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var uS=X.memo(X.forwardRef(function(e,t){let n=rb().useState(`virtualized`);return n&&e.index==null?(0,Z.jsx)(lS,{componentProps:e,forwardedRef:t}):(0,Z.jsx)(cS,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),dS=X.createContext(void 0);function fS(){let e=X.useContext(dS);if(e===void 0)throw Error(Ni(13));return e}var pS={imageLoadingStatus:()=>null},mS=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=Oo(`span`,e,{state:c,ref:t,props:a,stateAttributesMapping:pS});return(0,Z.jsx)(dS.Provider,{value:l,children:u})});function hS(e,{referrerPolicy:t,crossOrigin:n,sizes:r,srcSet:i},a){let o=X.useState(`idle`),s=o[1];return K(()=>{if(!a)return Gi;if(!e&&!i)return s(`error`),Gi;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 gS={...pS,...Ui},_S=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}=fS(),[f,p]=hS(l,e,!a),m=f===`loaded`,{mounted:h,transitionStatus:g,setMounted:_}=$s(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]),Di({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=Oo(`img`,e,{state:S,ref:[t,v],props:[b,u,w],stateAttributesMapping:gS,enabled:C});return C?T:null}),vS=X.forwardRef(function(e,t){let{className:n,render:r,delay:i=0,style:a,...o}=e,{imageLoadingStatus:s}=fS(),[c,l]=X.useState(i===0),u=ho();return X.useEffect(()=>(i>0?u.start(i,()=>l(!0)):l(!0),u.clear),[u,i]),Oo(`span`,e,{state:{imageLoadingStatus:s},ref:t,props:o,stateAttributesMapping:pS,enabled:s!==`loaded`&&(i===0||c)})}),$=r();function yS(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=fa(`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)(mS,{"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 bS(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=fa(`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)(_S,{"data-slot":`avatar-image`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function xS(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=fa(`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)(vS,{"data-slot":`avatar-fallback`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function SS(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Jy({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=$s(a,!0,!0),u=Rb(),[d,f]=X.useState(),p=d===null?void 0:d??u,m=J(e=>{let t=!a,n=Y(Qr,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 CS=X.createContext(void 0);function wS(){let e=X.useContext(CS);if(e===void 0)throw Error(Ni(15));return e}var TS=`data-open`,ES=`data-closed`,DS=Zr,OS=`data-panel-open`,kS={[TS]:``},AS={[ES]:``},jS={open(e){return e?{[OS]:``}:null}},MS={open(e){return e?kS:AS},...Ui},NS=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=SS({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=Oo(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:MS});return(0,Z.jsx)(CS.Provider,{value:p,children:m})}),PS={...jS,...Ui},FS=X.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=wS(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Ao({disabled:c,native:u});return Oo(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:PS})}),IS={height:void 0,width:void 0};function LS(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(IS),h=X.useRef(IS),g=X.useRef(!1),_=X.useRef(s),v=X.useRef(!1),[y,b]=X.useState(!1),x=X.useRef(null),S=$r(t,d),C=hs(s),w=Ai(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=zS(e,D);if(f.current=t,s&&u===`idle`&&_.current&&t===`css-animation`){h.current=RS(e);return}if(s&&u===`starting`){let n=g.current;if(g.current=!1,t===`none`){A(RS(e)),b(!0);return}if(t===`css-transition`){let t=HS(e);if(A(RS(e)),!n)return t;let r=VS(e,`transition-duration`,`0s`);return M(r),b(!0),t}A(RS(e));let r=VS(e,`animation-name`,`none`);if(!n){r();return}let i=VS(e,`animation-duration`,`0s`);r(),M(i),b(!0);return}if(!s&&a&&(u===`idle`||u===`starting`)){if(t===`none`){A(IS,!1),c(!1);return}A(RS(e));return}if(u!==`ending`)return;if(t===`none`){c(!1);return}let n=RS(e);n.height>0||n.width>0?(A(n),t===`css-animation`&&VS(e,`animation-name`,`none`)()):c(!1)},[a,s,j,A,c,M,D,u]),Di({enabled:s&&a&&E===`idle`,open:!0,ref:d,onComplete(){s&&A(IS,!1)}}),X.useEffect(()=>{if(s||!a||E!==`ending`)return;if(!d.current){c(!1),A(IS,!1);return}let e=new AbortController,t=-1;function n(){C.current||(c(!1),A(IS,!1))}return t=si.request(()=>{w(n,e.signal)}),()=>{si.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=no.create(),n=-1,r=(r,i)=>{t.start(0,()=>{C.current||(n=si.request(()=>{C.current||(r&&(g.current=!1),i&&e.setAttribute(DS,``),e.setAttribute(`hidden`,`until-found`))}))})},i=pi(e,`beforematch`,t=>{let n=Y(ma,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}g.current=!0;let i=e.hasAttribute(DS);e.removeAttribute(DS),l(!0),r(!0,i)});return()=>{t.clear(),si.cancel(n),i()}},[C,o,l]);let P=i||n||a||s;return{height:O.height,props:{...k?{[DS]:``}:void 0,hidden:T,id:r},ref:S,shouldPreventOpenAnimation:D,shouldRender:P,transitionStatus:E,width:O.width}}function RS(e){return{height:e.scrollHeight,width:e.scrollWidth}}function zS(e,t){let n=ea(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&BS(n.animationDuration),i=BS(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function BS(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function VS(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 HS(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=si.request(n);return()=>{si.cancel(r),n()}}var US=`--collapsible-panel-height`,WS=`--collapsible-panel-width`,GS=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:_}=wS(),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}=LS({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=Io(s,k),j=Oo(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[US]:S===void 0?`auto`:`${S}px`,[WS]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:MS});return E?j:null}),KS=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}=$s(o),d=Oo(`span`,e,{ref:[t,c],state:{selected:o,transitionStatus:l},props:[{"aria-hidden":!0,children:`✔️`},s],stateAttributesMapping:Ui});return Di({batch:!0,enabled:!o,open:o,ref:c,onComplete(){o||u(!1)}}),d})),qS=X.forwardRef(function(e,t){let{selected:n}=aS();return e.keepMounted||n?(0,Z.jsx)(KS,{...e,selected:n,ref:t}):null}),JS=X.createContext(void 0);function YS(e=!0){let t=X.useContext(JS);if(t===void 0&&!e)throw Error(Ni(25));return t}var XS=X.createContext(void 0);function ZS(e){let t=X.useContext(XS);if(t===void 0&&!e)throw Error(Ni(33));return t}var QS=X.createContext(void 0);function $S(e){let t=X.useContext(QS);if(t===void 0&&!e)throw Error(Ni(36));return t}var eC=X.createContext(null);function tC(e=`root`){let t=X.useContext(eC),n=X.useContext(QS);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var nC={visible:!0,ref:null};function rC(){return nC}function iC(e,t,n=`root`){let r=tC(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??rC)({label:e.label,children:e.children,render:e.render}),a=$r(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function aC(e){e.preventDefault()}function oC(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=$S(),u=YS(!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?aC: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:Qa})},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&&!xo&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&Ji(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var sC={type:`regular-item`};function cC(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}=Ao({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=oC({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=X.useCallback(e=>qa(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=$r(u,f);return X.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var lC=X.createContext(void 0);function uC(){let e=X.useContext(lC);if(e===void 0)throw Error(Ni(31));return e}var dC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=X.useState(void 0),c=Oo(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,Z.jsx)(lC.Provider,{value:s,children:c})}),fC=X.forwardRef(function(e,t){let n=tC()?.Group??dC;return(0,Z.jsx)(n,{...e,ref:t})}),pC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Rb(a),c=uC();return K(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),Oo(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),mC=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}=$S(),f=rS({guess:!0,label:a}),p=Rb(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}=cC({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:sC});return Oo(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),hC=X.forwardRef(function(e,t){let n=iC(e,t);return n.visible?(0,Z.jsx)(mC,{...e,ref:n.ref}):null}),gC=X.createContext(void 0);function _C(e){let t=X.useContext(gC);if(t===void 0&&!e)throw Error(Ni(69));return t}var vC=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),yC=X.createContext(void 0);function bC(){return X.useContext(yC)}function xC(e,t){let n=ha(e.render);if(X.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function SC(e,t,n){let r=xC(e,t),i=r===t?void 0:r;return[r,X.useCallback(e=>n?.(e?i:void 0),[i,n])]}function CC(e,t,n){let r=ha(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 wC=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}=$S(),m=bC(),{side:h,align:g}=ZS(),_=_C(!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]=SC(e,u,d),L=CC(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),Di({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]),Bc(D,{enabled:A&&!j&&!ee&&w.type!==`menubar`,closeDelay:k});let ne=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:z,handleFocus:re}=(X.useContext(eC)?.useParentHandoff??EC)(l,w,v,f),ie={transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},B=Oo(`div`,e,{state:ie,ref:[t,l.context.popupRef,ne,I],stateAttributesMapping:ds,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&vC.has(e.key)&&e.stopPropagation()},onFocus:re},Du(y),c,{"data-rootownerid":E}]}),V=w.type===void 0||ee;(C||w.type===`menubar`&&T!==`outside-press`)&&(V=!0);let ae=R?.getReturnElement??z;return(0,Z.jsx)(qs,{context:D,openInteractionType:M,modal:ee,disabled:!x,returnFocus:a??ae??V,explicitReturnFocus:a===void 0&&ae?!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})}),TC={parentVirtualFocusRef:void 0,handleFocus:void 0};function EC(){return TC}var DC=X.forwardRef(function(e,t){let n=tC()?.Popup??wC;return(0,Z.jsx)(n,{...e,ref:t})}),OC=X.createContext(void 0);function kC(){let e=X.useContext(OC);if(e===void 0)throw Error(Ni(32));return e}var AC=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=$S();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Z.jsx)(OC.Provider,{value:n,children:(0,Z.jsx)(to,{ref:t,...r,portalOwnerRole:o})})});function jC(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=X.useRef(null),o=X.useRef(null),s=Ai(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 MC=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=qr,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=$S(),x=kC(),S=YS(!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??Wa):C.type===`menubar`&&(ie??=C.context.orientation===`vertical`?`inline-end`:`bottom`,B??=`start`);let V=C.type===`context-menu`,ae=wu({anchor:ee,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ie,sideOffset:te,align:B,alignOffset:ne,arrowPadding:V?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:re,shift:V?{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(ba)))}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 oe=ho();X.useEffect(()=>{D||oe.clear()},[D,oe]),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?oe.isStarted()||oe.start(e,()=>{v.setOpen(!1,Y(ba))}):v.setOpen(!1,Y(ba))}else oe.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,oe]),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]),jC({store:v,domReference:R,positionerElement:M,open:D});let se={open:D,side:ae.side,align:ae.align,anchorHidden:ae.anchorHidden,nested:C.type===`menu`,instant:N},ce=C.type===`menubar`&&C.context.modal;$x(D&&(ce||O&&F!==`trigger-hover`),k===`touch`,M,A);let le=Ou(e,se,{styles:ae.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),ue=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),de=null;return C.type===`menubar`?de=C.context.contentElement:C.type===void 0&&(de=A),(0,Z.jsxs)(XS.Provider,{value:ae,children:[ue&&(0,Z.jsx)(Bx,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:wi(!D),cutout:de}),(0,Z.jsx)(Ls,{id:I,children:(0,Z.jsx)(kx,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:le})})]})}),NC=X.createContext(null);function PC(e){let t=X.useContext(NC);if(t===null&&!e)throw Error(Ni(5));return t}var FC={...wc,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=wc.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>Bi&&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`&&!wc.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`)}},IC=class extends Ha{constructor(e,t,n=!1){let r=new hc,i=RC(r,t,n,e);super(i,LC(r),FC),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 LC(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 RC(e,t,n=!1,r){return{...vc(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:No,inputProps:No,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new js,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:No,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var zC=X.createContext(null);function BC(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function VC(e,t){return e===`list-navigation`||BC(e,t)}var HC=va(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=YS(!0),C=$S(!0),w=PC(!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=Rb(),k=Rb(),[A,j]=X.useState(void 0),M=(A??k)||void 0,N=Ps(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=Oi(()=>F?P?.state.instantType:void 0).current,L=Oi(()=>{let e=new IC({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=Is(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`),V=L.useState(`parent`),ae=L.useState(`activeIndex`),oe=L.useState(`keyboardOpen`),se=L.useState(`payload`),ce=L.useState(`floatingParentNodeId`),le=X.useRef(null),ue=X.useRef(V.type!==`context-menu`),de=ho(),fe=X.useRef(!0),pe=ho(),me=ce!=null,{openMethod:he,triggerProps:ge}=Zb(te);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:V.type===void 0?c:void 0,openMethod:he,rootId:O}),dc(L);let{forceUnmount:_e,transitionStatus:ve}=fc(te,L,()=>{L.set(`allowMouseEnter`,!1)},F),ye=Ai(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(ve!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return ye(e,t.signal),()=>{t.abort()}},[I,te,ve,ye,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||(le.current=null),V.type===`context-menu`&&(te?de.start(500,()=>{ue.current=!0}):(de.clear(),ue.current=!1))},[de,te,V.type]),K(()=>{!te&&!re&&L.set(`hoverEnabled`,!0)},[te,re,L]);let be=J((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||te===e&&t.trigger===ne&&B===n)return;let i=lc(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`&&!fe.current)return;e&&n===`trigger-focus`?(fe.current=!1,pe.start(300,()=>{fe.current=!0})):(fe.current=!0,pe.clear());let o=!e&&(n===`escape-key`||n==null);le.current=t.event;let s=cc(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&VC(n,a),s.instantType=V.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:BC(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),xe=Qs({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:be}),Se=xe.context.events;K(()=>{let e=({open:e,eventDetails:t})=>be(e,t);return Se.on(`setOpen`,e),()=>{Se?.off(`setOpen`,e)}},[Se,be]),K(()=>L.subscribeToParentMenu(),[L]);let Ce=X.useCallback(()=>{L.setOpen(!1,Y(wo))},[L]);X.useImperativeHandle(d,()=>({unmount:_e,close:Ce}),[_e,Ce]);let we;V.type===`context-menu`&&(we=V.context),X.useImperativeHandle(we?.positionerRef,()=>z,[z]),X.useImperativeHandle(we?.actionsRef,()=>({setOpen:be}),[be]);let Te=Zs(xe,{enabled:!ie,bubbles:{escapeKey:f&&V.type===`menu`},outsidePress(){return V.type!==`context-menu`||le.current?.type===`contextmenu`||ue.current},externalTree:me?R:void 0}),Ee=uu(),De=Yc(xe,{enabled:!ie,listRef:L.context.itemDomElements,activeIndex:ae,virtual:v,nested:V.type===`menubar`||!v&&V.type!==void 0,parentOrientation:V.type===`menubar`?V.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?oe:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:Ee===`rtl`,disabledIndices:xa,onNavigate(e,t){L.setActiveIndex(e,Zy(t),t?.nativeEvent)},openOnArrowKeyDown:V.type!==`context-menu`&&!(v&&_),externalTree:!v&&me?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),Oe=X.useCallback(e=>{L.context.typingRef.current=e},[L]),ke=Xc(xe,{enabled:!ie&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:ae,resetMs:500,onMatch:(e,t)=>{te&&e!==ae&&L.setActiveIndex(e,Ra,t.nativeEvent)},onTyping:Oe}),Ae=J(a),je=X.useRef(-1),Me=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(je.current===n&&L.context.reportedItem===t)return;je.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=ma,L.context.highlightEvent=void 0,a&&Ae(t,qi(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});K(()=>{Me()},[ae,Me]);let Ne=X.useMemo(()=>{if(!v)return De.reference;if(!De.trigger)return No;let{onFocus:e,...t}=De.trigger;return t},[v,De.reference,De.trigger]);L.useSyncedValue(`inputProps`,v?De.reference??No:No);let Pe=X.useMemo(()=>{let e=qa(ke.reference,Ne,Te.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},ge);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=te,e},[L,ke.reference,Ne,Te.reference,ge,te]),Fe=X.useMemo(()=>{let e=qa(De.trigger,Te.trigger,ge);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[De.trigger,Te.trigger,ge]);Oi(()=>(L.update({inactiveTriggerProps:Fe}),null)),pc(L,{floatingRootContext:xe,activeTriggerProps:Pe,inactiveTriggerProps:Fe,popupProps:X.useMemo(()=>qa(nc,{onMouseMove(){L.set(`allowMouseEnter`,!0),V.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)}},ke.floating,De.floating,Te.floating),[V.type,L,ke.floating,De.floating,Te.floating]),itemProps:De.item??No});let Ie=X.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Me}),[L,D,u,l,b,k,v,E,Me]),Le=typeof t==`function`?t({payload:se}):t,Re=(0,Z.jsxs)(QS.Provider,{value:Ie,children:[p&&(0,Z.jsx)(ac,{handle:p,store:L}),Le]});return(V.type===void 0||V.type===`context-menu`)&&(Re=(0,Z.jsx)(Rs,{externalTree:R,children:Re})),Re});function UC(e){let t=X.useContext(zC);if(t===null)return(0,Z.jsx)(HC,{...e});let n=t.Root;return(0,Z.jsx)(zC.Provider,{value:null,children:(0,Z.jsx)(n,{...t.options,...e})})}function WC(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=ni(),{ref:i,index:a}=rS(e),o=n===a,s=X.useRef(null),c=$r(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 GC(e){let{render:t,className:n,style:r,state:i=No,props:a=xa,refs:o=xa,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=WC({metadata:s});return Oo(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function KC(e){if(ra(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!di(e))return KC(Xr(e))}function qC(e,t){function n(n,r,i){let a=n.currentTarget;tc.flushSync(()=>{e.setOpen(!1,Y(Ya,n.nativeEvent,a))}),xi(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&&uo(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function JC(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,ai(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:No,[t,n,r])}var YC=ao(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=$S(!0),h=Ec(d)??m?.store;if(!h)throw Error(Ni(85));let g=Rb(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=X.useRef(null),S=ZC(),C=ni(!0),w=Fs(),T=X.useMemo(()=>w??new js,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=uc(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:Is(T),floatingParentNodeId:Ps(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=Ao({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=ho(),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&&KC(t)===h.select(`rootId`)||cx(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:_a})});X.useEffect(()=>{let e=ai(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=Hc(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:il({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=XC(y,h.select(`lastOpenChangeReason`)),ee=Js(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),te=kc(v,{enabled:!A&&I}),ne=JC({open:y,enabled:O,mouseDownAction:`open`}),z=X.useMemo(()=>qa(te.reference,ee.reference),[te.reference,ee.reference]),re=h.useState(`triggerProps`,D),ie=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:B,handleFocusTargetFocus:V}=qC(h,x),ae={disabled:A,open:y},oe=[N,t,M,E,x],se=[z,L??No,re,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),ai(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ie,O?{role:`menuitem`}:{},ne,p,j],ce=Oo(`button`,e,{enabled:!O,stateAttributesMapping:ls,state:ae,ref:oe,props:se});return O?(0,Z.jsx)(GC,{tag:`button`,render:n,className:r,style:i,state:ae,refs:oe,props:se,stateAttributesMapping:ls}):y?(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(Vi,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:B},`${g}-pre-focus-guard`),(0,Z.jsx)(X.Fragment,{children:ce},g),(0,Z.jsx)(Vi,{ref:h.context.triggerFocusTargetRef,onFocus:V},`${g}-post-focus-guard`)]}):(0,Z.jsx)(X.Fragment,{children:ce},g)});function XC(e,t){let n=ho(),[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 ZC(){let e=PC(!0);return X.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var QC=X.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return Oo(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})});function $C(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=ii(),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)(JS.Provider,{value:u,children:(0,Z.jsx)(QS.Provider,{value:void 0,children:(0,Z.jsx)(UC,{...e})})})}var ew=500,tw=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}=YS(!1),{store:m}=$S(!1),h=m.useState(`open`),g=m.useState(`disabled`),_=X.useRef(null),v=X.useRef(null),y=ho(),b=ho(),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(Qr,n)),b.start(ew,()=>{x.current=!0})}function w(e){if(g)return;d.current=!0,ri(e),C(e.clientX,e.clientY,e.nativeEvent);let t=ai(_.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=ua(e);q(u.current,t)||p&&t&&KC(t)===p||s.current?.setOpen(!1,Y(_a,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(ew,()=>{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=ua(e);(q(_.current,t)||q(c.current,t)||q(l.current,t))&&e.preventDefault()}let t=ai(_.current);return pi(t,`contextmenu`,e)},[l,g,c]),Oo(`div`,e,{state:{open:h},ref:[_,t],props:[{onContextMenu:w,onTouchStart:E,onTouchMove:D,onTouchEnd:T,onTouchCancel:T,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:ls})}),nw=MC,rw=X.createContext(void 0);function iw(e){let t=X.useContext(rw);if(!e&&t===void 0)throw Error(Ni(27));return t}var aw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=iw(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`),d={open:c,transitionStatus:s.useState(`transitionStatus`)};return Oo(`div`,e,{state:d,ref:[s.context.backdropRef,t],stateAttributesMapping:ds,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),ow=X.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=iw(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=Ao({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Y(_o,e.nativeEvent))}return Oo(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})}),sw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=iw(),c=Rb(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),Oo(`p`,e,{ref:t,props:[{id:c},o]})}),cw=X.createContext(void 0);function lw(){let e=X.useContext(cw);if(e===void 0)throw Error(Ni(26));return e}var uw=`--nested-dialogs`,dw=`data-nested-dialog-open`,fw={...us,...Ui,nestedDialogOpen(e){return e?{[dw]:``}:null}},pw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=iw(),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`);lw(),Di({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?rc(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=Oo(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...nc,hidden:!m,onKeyDown(e){vC.has(e.key)&&e.stopPropagation()},style:{[uw]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:fw});return(0,Z.jsx)(qs,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})}),mw=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=iw(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Z.jsx)(cw.Provider,{value:n,children:(0,Z.jsxs)(to,{ref:t,...r,children:[a&&o===!0&&(0,Z.jsx)(Bx,{ref:i.context.internalBackdropRef,inert:wi(!s)}),e.children]})}):null});function hw({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=Zs(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=ua(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 Zx(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]),pc(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var gw={...wc,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},_w=class extends Ha{constructor(e,t,n){let r=new hc,i=vw(e,r,t,n);super(i,yw(r),gw)}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(cc(this.state,e,t.trigger)))}};function vw(e,t,n,r=!1){return{...vc(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 yw(e){return{popupRef:X.createRef(),backdropRef:X.createRef(),internalBackdropRef:X.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function bw(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=iw(!0),y={modal:h,disablePointerDismissal:g,nested:v!=null,role:_},b=ic((e,t)=>new _w({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`);mc(b,x),dc(b);let{forceUnmount:w}=fc(x,b);X.useImperativeHandle(l,()=>({unmount:w,close:()=>b.setOpen(!1,Y(wo))}),[w,b]);let T=x||S||u!=null;return(0,Z.jsxs)(rw.Provider,{value:b,children:[u&&(0,Z.jsx)(ac,{handle:u,store:b}),T&&(0,Z.jsx)(hw,{store:b,parentContext:v?.context,isDrawer:p}),typeof n==`function`?n({payload:C}):n]})}var xw=va(function(e){return bw(`dialog`,e)}),Sw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=iw(),c=Rb(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),Oo(`h2`,e,{ref:t,props:[{id:c},o]})}),Cw=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}=Pb(),{clearErrors:S,elementRef:C,submitCountRef:w}=Lb(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=Bb(),k=Vb({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=J(()=>x.inputRef.current?.value);Fb(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]),Yb(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=X.useRef(null),P=ox(T,N),F=ho();return Oo(`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(ma,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:jb})}),ww=X.forwardRef(function(e,t){return(0,Z.jsx)(Cw,{ref:t,...e})});function Tw(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=fa(`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)(ww,{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 Ew(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=fa(`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 Dw=zi(`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 Ow(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=fa(Dw({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:kw,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function kw(e){e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`input`)?.focus()}var Aw=zi(`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 jw(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=fa(Aw({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)(Ia,{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 Mw(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=fa(`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)(Tw,{"data-slot":`input-group-control`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Nw(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=fa(`[&_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)(Uo,{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)(hx,{"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 Pw(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)(jw,{variant:`ghost`,size:`icon-xs`}),t[3]=i):i=t[3];let a;t[4]===n?a=t[5]:(a=fa(n),t[4]=n,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(Gr,{className:`pointer-events-none`}),t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==a?(s=(0,Z.jsx)(Cx,{"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 Fw(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=fa(`w-auto`,r),t[7]=r,t[8]=d);let f;t[9]===c?f=t[10]:(f=(0,Z.jsx)(Mw,{disabled:c}),t[9]=c,t[10]=f);let p;t[11]!==i||t[12]!==f?(p=(0,Z.jsx)(xx,{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)(jw,{size:`icon-xs`,variant:`ghost`,render:(0,Z.jsx)(Nw,{}),"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)(Pw,{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)(Ow,{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)(Ew,{className:d,children:[p,g,n]}),t[23]=n,t[24]=d,t[25]=p,t[26]=g,t[27]=_):_=t[27],_}function Iw(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=fa(`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)(nS,{"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)(zx,{children:(0,Z.jsx)(eS,{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 Lw(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=fa(`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)(Ix,{"data-slot":`combobox-list`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Rw(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=fa(`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)(qS,{render:(0,Z.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex items-center justify-center`}),children:(0,Z.jsx)(Vo,{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)(uS,{"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 zw(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`,...n}),t[2]=n,t[3]=r),r}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)(YC,{"data-slot":`dropdown-menu-trigger`,...n}),t[2]=n,t[3]=r),r}function Vw(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=fa(`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)(DC,{"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)(AC,{children:(0,Z.jsx)(MC,{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 Hw(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)(fC,{"data-slot":`dropdown-menu-group`,...n}),t[2]=n,t[3]=r),r}function Uw(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=fa(`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)(pC,{"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 Ww(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=fa(`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)(hC,{"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 Gw(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=fa(`-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)(QC,{"data-slot":`dropdown-menu-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Kw(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=fa(`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 qw=Tr({id:Mt,name:Mt,signOut:fr}),Jw=E(se).atom(Pt(gt(`/auth/user`),_(Tt),_(Be(qw)))),Yw=qe(y(``));function Xw(){return ke(P(Wy(Yw)))}function Zw(){let e=(0,$.c)(27),t=Wy(Jw);if(!ne(t))return null;let n;e[0]===t.value.id?n=e[1]:(n=Tn(`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)(bS,{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=Re(we(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)(xS,{children:a}),e[7]=a,e[8]=o);let s;e[9]!==i||e[10]!==o?(s=(0,Z.jsx)(Bw,{"aria-label":`Account`,children:(0,Z.jsxs)(yS,{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)(Hw,{children:(0,Z.jsxs)(Uw,{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)(Gw,{}),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)(Ww,{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)(Vw,{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)(zw,{children:[s,h]}),e[24]=h,e[25]=s,e[26]=g):g=e[26],g}function Qw(e){let t=(0,$.c)(66),[n,r]=qy(Yw),[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=>Pe(ke(P(n)))(ke(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,tc.flushSync)(()=>c(!0)),l.current?.focus()},d=(0,Z.jsx)(Zo,{}),t[23]=o,t[24]=d):(o=t[23],d=t[24]),t[25]===e.label?g=t[26]:(g=(0,Z.jsx)(Ia,{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=fa(`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=nx,_=m,v=null,y=$w,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&&Me(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&&Me(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)(Ow,{children:(0,Z.jsx)(Zo,{})}),t[36]=O):O=t[36];let k;t[37]===n?k=t[38]:(k=n===``&&(0,Z.jsx)(Ow,{align:`inline-end`,className:`max-sm:hidden`,children:(0,Z.jsx)(Kw,{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)(Fw,{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)(Iw,{anchor:u,children:(0,Z.jsx)(Lw,{children:e=>(0,Z.jsxs)(Rw,{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)(Ia,{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 $w(e){return e.label}function eT(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)(Ia,{"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 tT(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)(Qw,{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)(Zw,{}),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 nT(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=fa(`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 rT(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)(nT,{className:`size-5`}),(0,Z.jsx)(nT,{className:`h-4 w-1/3`})]},t),t[3]=e.media,t[4]=n),r=Cn(De(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 iT(e){let t=(0,$.c)(5),n;t[0]===e.className?n=t[1]:(n=fa(`flex min-h-full 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 aT(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=fa(`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 oT=zi(`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 sT(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=fa(oT({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 cT(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=fa(`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)(aT,{"data-slot":`field-label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function lT(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(dT)).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(uT)}),t[7]=r,t[8]=a),o=a}let s=o;if(!s)return null;let c;t[9]===r?c=t[10]:(c=fa(`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 uT(e,t){return e?.message&&(0,Z.jsx)(`li`,{children:e.message},t)}function dT(e){return[e?.message,e]}function fT(e){let t=(0,$.c)(5),n=e.className,r;t[0]===e.result?r=t[1]:(r=Vr(z(j(e.result),pT)),t[0]=e.result,t[1]=r);let i;return t[2]!==e.className||t[3]!==r?(i=(0,Z.jsx)(lT,{className:n,children:r}),t[2]=e.className,t[3]=r,t[4]=i):i=t[4],i}function pT(e){return e.message}var mT=zi(`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 hT(e){let t=(0,$.c)(6),n;t[0]!==e.className||t[1]!==e.status||t[2]!==e.waiting?(n=fa(mT({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 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)(NS,{"data-slot":`collapsible`,...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)(FS,{"data-slot":`collapsible-trigger`,...n}),t[2]=n,t[3]=r),r}function vT(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)(GS,{"data-slot":`collapsible-content`,...n}),t[2]=n,t[3]=r),r}function yT(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)($C,{"data-slot":`context-menu`,...n}),t[2]=n,t[3]=r),r}function bT(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=fa(`select-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(tw,{"data-slot":`context-menu-trigger`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function xT(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=fa(`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)(DC,{"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)(AC,{children:(0,Z.jsx)(nw,{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 ST(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=fa(`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)(hC,{"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 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)(xw,{"data-slot":`dialog`,...n}),t[2]=n,t[3]=r),r}function wT(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)(mw,{"data-slot":`dialog-portal`,...n}),t[2]=n,t[3]=r),r}function TT(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)(ow,{"data-slot":`dialog-close`,...n}),t[2]=n,t[3]=r),r}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=fa(`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)(aw,{"data-slot":`dialog-overlay`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function DT(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)(ET,{}),t[5]=s):s=t[5];let c;t[6]===r?c=t[7]:(c=fa(`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)(ow,{"data-slot":`dialog-close`,render:(0,Z.jsx)(Ia,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,Z.jsx)(Gr,{}),(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)(wT,{children:[s,(0,Z.jsxs)(pw,{"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 OT(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=fa(`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)(ow,{render:(0,Z.jsx)(Ia,{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 kT(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=fa(`text-sm font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(Sw,{"data-slot":`dialog-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function AT(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=fa(`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)(sw,{"data-slot":`dialog-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}xn(Rt(cr(`AUTH_URL`)),g);function jT(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function MT(e){return An(Xa)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}jr()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var NT=class e extends jn()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:Xa}){static layerClient=t=>vr(e,e=>R(function*(){return yield*e.next({...e.request,headers:$t(e.request.headers,`authorization`,`Bearer ${yield*t}`)})}))},PT=Av,FT=Mv,IT=Pv,LT=class extends zr()(`UpstreamError`,{cause:Kt()}){},RT=Mt.check(Te(/^[a-z0-9][a-z0-9_-]{0,23}$/u)),zT=zn.check(En(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`})),BT=Tr({url:zT}),VT=Tr({id:RT}),HT=Tr({authorization_endpoint:zn,authorization_response_iss_parameter_supported:be(fr),client_id_metadata_document_supported:be(fr),issuer:zn,registration_endpoint:be(zn),token_endpoint:zn});Tr({client_id:zn});var UT=Tr({access_token:zn,expires_in:be(Fn.check(m(0))),refresh_token:be(zn),token_type:Mt.check(Te(/^Bearer$/iu))}),WT=Tr({client:Pr({Document:{},Registered:{clientId:zn}}),metadata:HT,scope:Mt}),GT=Pr({Authorized:{expiresAt:Fn,token:UT},Connected:{},Disconnected:{}}),KT=Tr({src:Mt,theme:be(Qn([`light`,`dark`]))}),qT=Tr({error:be(Mt),generation:zn,icons:be(Yn(KT)),id:RT,instructions:be(Mt),link:GT,mode:Qn([`oauth`,`public`]),name:zn,oauth:be(WT),tools:Yn(Mt),url:zT});hn(Mt,qT);var JT=Tr({error:be(Mt),icons:Yn(KT),id:RT,name:zn,status:Qn([`Connected`,`Not connected`,`Expired`]),tools:Yn(Mt),url:zT});Pr({Discovered:{icons:Yn(KT),instructions:be(Mt),tools:Yn(Mt)},Failed:{error:Mt}}),Tr({code:be(zn),error:be(Mt),iss:be(zn),state:zn});var YT=class extends qt(dn(`gateway.servers`,{error:Xa,stream:!0,success:Yn(JT)}),dn(`gateway.calls`,{error:Xa,stream:!0,success:RT}),dn(`gateway.add`,{error:Xa,payload:BT,success:JT}),dn(`gateway.remove`,{error:Xa,payload:VT})).middleware(NT){},XT=`${window.location.origin}/mcp`,ZT=class extends tn()(`@deslop/gateway/lib/utils/RpcClient`,{group:YT,protocol:wa(`@deslop/gateway`)}){};function QT(e){return`/oauth/connect?${new URLSearchParams({id:e})}`}function $T(e){return Yt(e,e=>Pt(e(tt(`1 second`)),k(e=>e.input._tag===`RpcClientError`)))}var eE=qe(ZT.runtime.atom($T(Ln(le(ZT,e=>e(`gateway.servers`,void 0)))))),tE=qe(ZT.runtime.atom($T(pn(Ln(le(ZT,e=>e(`gateway.calls`,void 0))))))),nE=Fr(e=>y(t=>{let n=Ge(t.self(),()=>-1);return I(t(tE),{onFailure:()=>n,onInitial:()=>n,onSuccess:t=>b(t.value[0]===e,{onFalse:()=>n,onTrue:()=>t.value[1]})})})),rE=Fr(e=>ZT.runtime.fn(()=>_(ZT,t=>t(`gateway.remove`,{id:e})))),iE=Oy(ZT.runtime).make(FT({effects:{add:lt(function*(e){yield*Pt(kr(zT)(e),St(e=>Xa.make({cause:e,message:`Enter a public HTTPS MCP URL without credentials or a fragment, outside the gateway itself.`})));let t=yield*(yield*ZT)(`gateway.add`,{url:e});t.status!==`Connected`&&location.assign(QT(t.id))})},events:IT({Cancel:{},Open:{},Submit:{},Typed:{url:Mt}}),root:PT({states:{Adding:{fields:{url:Mt}},Closed:{},Editing:{fields:{error:Mt,url:Mt}}}})}).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`}}}}})),aE=zt(()=>vt(Zn({catch:e=>LT.make({cause:e}),try:()=>navigator.clipboard.writeText(XT)}),{onFailure:()=>bo.add({description:XT,title:`Cannot copy the MCP URL`,type:`error`}),onSuccess:()=>bo.add({title:`MCP URL copied`})})),oE=`/assets/icon-61pmFc-p.svg`,sE=xt(ce,e=>Pt(_r(e.status),Wn(`Expired`,()=>0),Wn(()=>e.error!==void 0,()=>0),Wn(`Not connected`,()=>1),s(()=>2)));function cE(e){let t=(0,$.c)(10),n;t[0]===e.server.id?n=t[1]:(n=nE(e.server.id),t[0]=e.server.id,t[1]=n);let r=Vu(n),i;t[2]===r?i=t[3]:(i=b(r>=0,{onFalse:pE,onTrue:fE}),t[2]=r,t[3]=i);let a;t[4]===e.server.status?a=t[5]:(a=Pt(_r(e.server.status),Wn(`Connected`,dE),Wn(`Expired`,uE),s(lE)),t[4]=e.server.status,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(hT,{className:i,status:a},r),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function lE(){return`off`}function uE(){return`error`}function dE(){return`live`}function fE(){return`port-blink`}function pE(){}function mE(e){let t=(0,$.c)(29),n;t[0]===e.server.id?n=t[1]:(n=rE(e.server.id),t[0]=e.server.id,t[1]=n);let[r,i]=Ku(n),a=e.open,o=e.onOpenChange,s;t[2]===e.server.name?s=t[3]:(s=(0,Z.jsxs)(kT,{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)(AT,{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)(fT,{result:r}),t[5]=r,t[6]=l);let u;t[7]===r?u=t[8]:(u=rt(r),t[7]=r,t[8]=u);let d;t[9]===u?d=t[10]:(d=(0,Z.jsx)(TT,{render:(0,Z.jsx)(Ia,{variant:`ghost`,disabled:u}),children:`Cancel`}),t[9]=u,t[10]=d);let f;t[11]===r?f=t[12]:(f=rt(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)(Ia,{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)(OT,{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)(DT,{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)(CT,{open:a,onOpenChange:o,children:g}),t[25]=e.onOpenChange,t[26]=e.open,t[27]=g,t[28]=_):_=t[28],_}function hE(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=it(w(e.sources,n),{onNone:gE,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 gE(){return(0,Z.jsx)($o,{className:`text-muted-foreground size-4`})}function _E(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=$e([...Cn(Ie(e.server.icons,xt(er,yE)),vE),`https://${a}/favicon.ico`,`https://${Tn(/^(?:api|app|mcp)\./u,``)(a)}/favicon.ico`]),n=hE,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 vE(e){return e.src}function yE(e){return e.theme!==`dark`}function bE(e){return Pt(_r(e.server.status),Wn(`Expired`,()=>(0,Z.jsx)(`span`,{className:`text-destructive truncate`,children:`Sign-in expired`})),Wn(`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 xE(e){let t=(0,$.c)(86),n;t[0]===e.server.id?n=t[1]:(n=rE(e.server.id),t[0]=e.server.id,t[1]=n);let[r]=Ku(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?(_=On(e.server.tools),t[15]!==i||t[16]!==e.server?(g=(0,Z.jsx)(mE,{open:i,onOpenChange:a,server:e.server}),t[15]=i,t[16]=e.server,t[17]=g):g=t[17],u=gT,f=`listitem`,p=o&&_,m=s,h=`border-b`,l=yT,c=bT,d=b(_,{onFalse:EE,onTrue:TE}),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)(_T,{"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)(_E,{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)(bE,{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)(Ia,{size:`sm`,variant:`outline`,className:`relative shrink-0`,disabled:rt(r),onClick:()=>location.assign(QT(e.server.id)),children:b(e.server.status===`Not connected`,{onFalse:wE,onTrue:CE})}),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)(cE,{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)(Go,{className:fa(`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=rt(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)(xT,{className:`w-auto min-w-36`,children:(0,Z.jsx)(ST,{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)(lT,{className:`mr-1 mb-2 ml-9 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=Cn(e.server.tools,SE),t[69]=e.server.tools,t[70]=L);let R;t[71]!==I||t[72]!==L?(R=(0,Z.jsx)(vT,{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 SE(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 CE(){return`Connect`}function wE(){return`Reconnect`}function TE(){}function EE(){return 0}function DE(e){let t=(0,$.c)(31),n=Gu(iE.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)(kT,{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)(cT,{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)(Tw,{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)(lT,{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)(sT,{"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)(TT,{render:(0,Z.jsx)(Ia,{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:kE,onTrue:OE}),t[19]=e.adding,t[20]=m);let h;t[21]!==e.adding||t[22]!==m?(h=(0,Z.jsx)(Ia,{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)(OT,{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 OE(){return`Adding…`}function kE(){return`Add server`}function AE(){let e=(0,$.c)(11),t=Gu(iE.send),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Dy(iE,`Editing`),e[0]=n):n=e[0];let r=We(jy(n),ft),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Dy(iE,`Adding`),e[1]=i):i=e[1];let a=We(jy(i),ft),o=L(z(r,PE),()=>z(a,NE)),s=CT,c=ct(o),l=e=>{!e&&ct(r)&&t({_tag:`Cancel`})},u=DT,d=g(a),f=it(o,{onNone:ME,onSome:jE}),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 jE(e){return(0,Z.jsx)(DE,{...e})}function ME(){return null}function NE(e){return{adding:!0,error:``,url:e.url}}function PE(e){return{adding:!1,error:e.error,url:e.url}}function FE(e){let t=(0,$.c)(7),n=Xw(),r;if(t[0]!==e.servers||t[1]!==n){let i;t[3]===n?i=t[4]:(i=e=>Pe(n)(ke(`${e.name} ${e.url}`)),t[3]=n,t[4]=i);let a;t[5]===n?a=t[6]:(a=()=>(0,Z.jsx)(Na,{children:(0,Z.jsx)($a,{children:(0,Z.jsx)(za,{children:b(n===``,{onFalse:zE,onTrue:RE})})})}),t[5]=n,t[6]=a),r=Se(D(Ie(e.servers,sE),i),{onEmpty:a,onNonEmpty:IE}),t[0]=e.servers,t[1]=n,t[2]=r}else r=t[2];return r}function IE(e){return(0,Z.jsx)(`div`,{role:`list`,"aria-label":`MCP servers`,children:Cn(e,LE)})}function LE(e){return(0,Z.jsx)(xE,{server:e},e.id)}function RE(){return`No servers yet`}function zE(){return`No server matches`}function BE(){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=Xu(eE,t);if(ne(n)){let t;return e[1]===n.value?t=e[2]:(t=(0,Z.jsx)(FE,{servers:n.value}),e[1]=n.value,e[2]=t),t}let r;return e[3]===n.cause?r=e[4]:(r=it(Jt(n.cause),{onNone:()=>(0,Z.jsx)(To,{error:Ir(n.cause),reset:WE}),onSome:VE}),e[3]=n.cause,e[4]=r),r}function VE(e){return e._tag===`AuthError`?e.error===`access_denied`?(0,Z.jsx)(Na,{children:(0,Z.jsxs)($a,{children:[(0,Z.jsx)(za,{children:`Admins only`}),(0,Z.jsx)(co,{children:e.message})]})}):MT(e)?(0,Z.jsx)(Da,{href:jT(location.href)}):(0,Z.jsx)(To,{error:e,reset:HE}):(0,Z.jsx)(To,{error:e,reset:UE})}function HE(){return location.reload()}function UE(){return location.reload()}function WE(){return location.reload()}function GE(){let e=(0,$.c)(24),t=Gu(iE.send),n=Gu(aE),r=ne(Vu(eE)),i=tT,a=oE,o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(Yo,{}),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)(qo,{}),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)(qo,{}),e[6]=d):d=e[6];let f;e[7]===n?f=e[8]:(f=(0,Z.jsx)(eT,{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)(eT,{icon:(0,Z.jsx)(Yo,{}),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)(iT,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(rT,{label:`MCP servers`,media:!0,rows:4}),children:(0,Z.jsx)(BE,{})})}),_=(0,Z.jsx)(AE,{}),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{GE as component};
|