@deslop/gateway 0.1.1241 → 0.1.1244
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/README.md +1 -1
- package/dist/client/assets/(home)-DiXZ1PZx.js +1 -0
- package/dist/client/assets/effect-BQU0ei-O.js +17 -0
- package/dist/client/assets/index-C989eNoD.js +4 -0
- package/dist/client/index.html +2 -2
- package/dist/server.js +1025 -1452
- package/package.json +2 -2
- package/dist/client/assets/(home)-RhAkUc53.js +0 -1
- package/dist/client/assets/effect-y8-0v7UZ.js +0 -17
- package/dist/client/assets/index-BeNnxYGw.js +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{$ as t,$i as n,$n as r,$r as i,$t as a,A as o,Ai as s,An as c,B as l,Bi as u,Bn as d,Bt as f,C as p,Ci as m,Cn as h,Cr as g,Ct as _,D as v,Dn as y,Dr as b,Dt as x,E as S,Ei as C,En as w,Er as T,F as E,Fi as D,Fn as O,Fr as k,Ft as A,G as j,Gi as M,Gn as N,Gr as P,Gt as F,H as I,Hi as L,Hn as R,Ht as ee,I as z,Ii as te,In as B,Ir as ne,It as re,J as V,Ji as H,Jn as ie,Jr as ae,Jt as oe,K as se,Kn as ce,Kr as le,Kt as ue,L as de,Li as fe,Ln as pe,Lr as me,Lt as he,M as ge,Mi as _e,Mn as ve,Mt as ye,N as be,Ni as xe,Nn as Se,Nt as Ce,O as we,Oi as Te,On as Ee,Ot as De,P as Oe,Pi as ke,Pn as Ae,Pr as je,Pt as Me,Q as Ne,Qi as Pe,Qn as Fe,Qr as Ie,Qt as Le,R as Re,Ri as ze,Rn as Be,Rr as Ve,Rt as He,S as Ue,Si as We,Sn as Ge,Sr as Ke,St as qe,T as Je,Ti as Ye,Tn as Xe,Tr as Ze,Tt as Qe,U as $e,Ui as et,Un as U,Ut as tt,V as nt,Vi as rt,Vn as it,Vt as at,W as ot,Wi as st,Wn as W,Wt as ct,X as lt,Xi as ut,Xn as dt,Xr as ft,Xt as pt,Yi as mt,Yn as ht,Yr as gt,Yt as _t,Z as vt,Zi as yt,Zn as bt,Zr as xt,Zt as St,_i as Ct,_n as wt,_r as Tt,_t as Et,a as Dt,ai as Ot,an as kt,ar as At,at as jt,b as Mt,bi as Nt,bn as Pt,br as G,bt as Ft,ci as It,cn as Lt,cr as Rt,ct as zt,d as Bt,da as Vt,dn as Ht,dr as Ut,dt as Wt,ea as Gt,ei as Kt,en as qt,er as Jt,et as Yt,f as Xt,fi as Zt,fn as Qt,fr as $t,ft as en,gn as tn,gr as nn,gt as rn,h as an,hi as on,hn as sn,hr as cn,ht as ln,i as un,ii as dn,in as fn,ir as pn,it as mn,j as hn,ji as gn,jn as _n,jr as vn,k as yn,ki as bn,kn as xn,kt as Sn,l as Cn,la as wn,li as Tn,ln as En,lr as Dn,lt as On,mi as kn,mr as An,mt as jn,n as Mn,na as Nn,ni as Pn,nn as Fn,nr as In,nt as Ln,oi as Rn,on as zn,or as Bn,ot as Vn,pi as Hn,pn as Un,pr as Wn,q as Gn,qi as Kn,qn,qr as Jn,qt as Yn,r as Xn,ra as Zn,ri as Qn,rn as $n,rr as er,rt as tr,si as nr,sn as rr,sr as ir,st as ar,t as or,ta as sr,ti as cr,tn as lr,tr as ur,u as dr,ua as fr,ui as pr,un as mr,ur as hr,ut as gr,v as _r,vi as vr,vn as yr,vr as br,vt as xr,w as Sr,wi as Cr,wn as wr,wr as Tr,wt as Er,x as Dr,xn as Or,xr as kr,xt as Ar,y as jr,yi as Mr,yn as Nr,yr as Pr,yt as Fr,z as Ir,zi as Lr,zn as Rr}from"./effect-BQU0ei-O.js";import{a as zr,i as Br,n as Vr,o as Hr,s as Ur,t as Wr}from"./react-BUjtWCUj.js";import{$ as Gr,$n as Kr,$t as qr,A as Jr,An as Yr,At as Xr,B as Zr,Bn as Qr,Bt as $r,C as ei,Cn as ti,Ct as ni,D as ri,Dn as ii,Dt as ai,E as oi,En as si,Et as ci,F as li,Fn as ui,Ft as di,G as fi,Gn as pi,Gt as mi,H as hi,Hn as gi,Ht as _i,I as vi,In as yi,It as bi,J as xi,Jn as Si,Jt as K,K as Ci,Kn as wi,Kt as Ti,L as Ei,Ln as Di,Lt as Oi,M as ki,Mn as q,Mt as Ai,N as ji,Nn as Mi,Nt as Ni,On as Pi,Ot as Fi,P as Ii,Pn as Li,Pt as Ri,Q as zi,Qn as Bi,Qt as Vi,R as Hi,Rn as Ui,Rt as Wi,S as Gi,Sn as Ki,St as qi,T as Ji,Tn as Yi,Tt as Xi,U as Zi,Un as Qi,Ut as $i,V as ea,Vn as ta,Vt as na,W as ra,Wn as ia,Wt as aa,X as oa,Xn as sa,Xt as ca,Y as la,Yn as ua,Yt as da,Z as fa,Zn as pa,Zt as ma,_ as ha,_n as ga,_t as _a,a as va,an as ya,at as ba,b as xa,bn as Sa,bt as Ca,c as wa,cn as Ta,ct as Ea,d as Da,dn as Oa,dt as ka,en as Aa,er as ja,et as Ma,f as Na,fn as Pa,ft as Fa,g as Ia,gn as La,gt as Ra,h as za,hn as Ba,ht as Va,i as Ha,in as Ua,it as Wa,j as Ga,jn as J,jt as Ka,k as qa,kn as Ja,kt as Ya,l as Xa,ln as Za,lt as Qa,m as $a,mn as eo,mt as to,n as no,nn as ro,nr as io,nt as ao,o as oo,on as so,ot as co,p as lo,pn as uo,pt as fo,q as po,qn as mo,qt as ho,r as go,rn as _o,rt as vo,s as yo,sn as bo,st as xo,t as So,tn as Co,tr as wo,tt as To,u as Eo,un as Do,ut as Oo,v as ko,vn as Ao,vt as jo,w as Y,wn as Mo,wt as No,x as Po,xn as Fo,xt as Io,y as Lo,yn as Ro,yt as zo,z as Bo,zn as Vo}from"./index-C989eNoD.js";var Ho={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};Ho.node;var Uo=wo(Ho),Wo={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};Wo.node;var Go=wo(Wo),Ko={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};Ko.node;var qo=wo(Ko),Jo={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`}]]};Jo.node;var Yo=wo(Jo),Xo={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Xo.node;var Zo=wo(Xo),Qo={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};Qo.node;var $o=wo(Qo),es={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`}]]};es.node;var ts=wo(es),ns=`data-open`,rs=`data-closed`,is=`data-anchor-hidden`,as={[bi]:``},os={[bi]:``,[Oi]:``},ss={[ns]:``},cs={[rs]:``},ls={[is]:``},us={open(e){return e?as:null}},ds={open(e){return e?os:null}},fs={open(e){return e?ss:cs},anchorHidden(e){return e?ls:null}},ps={...fs,...Wi};function ms(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...ms(e,t.id,n)])}function hs(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 gs(e,t=!1){let{overflowY:n}=Li(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}function _s(e){let t=Mi(vs,e).current;return t.next=e,J(t.effect),t}function vs(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var ys=0;function bs(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(ys);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),ti;let o=requestAnimationFrame(a);return ys=o,()=>{ys===o&&(cancelAnimationFrame(o),ys=0)}}var xs=`data-base-ui-inert`,Ss=new WeakMap,Cs=new WeakSet,ws=new WeakMap,Ts=0;function Es(e){return e?Si(e)?e.host:Es(e.parentNode):null}var Ds=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=Es(t);return e.contains(n)?n:null}).filter(e=>e!=null),Os=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},ks=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{Ui(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function As(e,t,n,{mark:r=!0}){let i=Ds(t,e),a=r?ks(t,Os(i),new Set(i)):[],o=[],s=[];if(n){let e=Ds(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);ks(t,Os(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(Ss.get(e)||0)+1;Ss.set(e,r),o.push(e),r===1&&n&&Cs.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(ws.get(e)||0)+1;ws.set(e,t),s.push(e),t===1&&e.setAttribute(xs,``)}),Ts+=1,()=>{o.forEach(e=>{let t=(Ss.get(e)||0)-1;Ss.set(e,t),t||(Cs.has(e)||e.removeAttribute(`aria-hidden`),Cs.delete(e))}),r&&s.forEach(e=>{let t=(ws.get(e)||0)-1;ws.set(e,t),t||e.removeAttribute(xs)}),--Ts,Ts||(Ss=new WeakMap,Cs=new WeakSet,ws=new WeakMap)}}function js(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=ii(e[0]).body;return As(e,i,n,{mark:r})}function Ms(){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 Ns=class{nodesRef={current:[]};events=Ms();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(Ur(),1),Z=Hr(),Ps=X.createContext(null),Fs=X.createContext(null),Is=()=>X.useContext(Ps)?.id||null,Ls=e=>{let t=X.useContext(Fs);return e??t};function Rs(e){let t=oi(),n=Ls(e),r=Is();return J(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function zs(e){let{children:t,id:n}=e,r=Is();return(0,Z.jsx)(Ps.Provider,{value:X.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Bs(e){let{children:t,externalTree:n}=e,r=Mi(()=>n??new Ns).current;return(0,Z.jsx)(Fs.Provider,{value:r,children:t})}function Vs(e,t){let n=gi(da(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(Xi(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Hs=20,Us=[];function Ws(){Us=Us.filter(e=>e.deref()?.isConnected)}function Gs(e){Ws(),e&&Ui(e)!==`body`&&(Us.push(new WeakRef(e)),Us.length>Hs&&(Us=Us.slice(-20)))}function Ks(){return Ws(),Us[Us.length-1]?.deref()}function qs(e){return e?xi(e)?e:la(e)[0]||e:null}function Js(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Zi(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return xi(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 Ys(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=q(()=>b.current.floatingContext?.nodeId),S=i===!1,C=Ni(_)&&S,w=_s(i),T=_s(a),E=_s(o),D=_s(u),O=_s(g),k=Ls(m),A=go(),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=Mo(L,p,A?.beforeInsideRef),z=Mo(R,A?.afterInsideRef),te=_o(),B=_o(),ne=vi(),re=A!=null,V=Fi(v),H=q((e=V)=>e?la(e):[]),ie=q(()=>h?.().filter(e=>e!=null)??[]);X.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&K(V,Ti(ii(V)))&&H().length===0&&!C&&ai(e)}let t=ii(V);return hi(t,`keydown`,e)},[r,V,c,C,H]),X.useEffect(()=>{if(r||!g)return;let e=ii(V);function t(){N.current=!1}function n(e){let t=da(e),n=ie(),r=K(v,t)||K(_,t)||K(A?.portalNode,t)||n.some(e=>e===t||K(e,t));N.current=!r,I.current=e.pointerType||`keyboard`,ho(t,`[data-base-ui-click-trigger]`)&&(M.current=!0,B.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return ea(hi(e,`pointerdown`,n,!0),hi(e,`pointerup`,t,!0),hi(e,`pointercancel`,t,!0),hi(e,`keydown`,i,!0),t)},[r,v,_,V,g,A,B,ie]),X.useEffect(()=>{if(r||!l)return;let e=ii(V);function n(){M.current=!0,B.start(0,()=>{M.current=!1})}function i(e){let t=da(e);xi(t)&&(P.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=da(n);c&&r==null&&a!=null&&K(v,a)&&Gs(a),queueMicrotask(()=>{let o=x(),l=t.context.triggerElements,u=ie(),p=r?.hasAttribute(Ha(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Ii(f),Ii(d)].includes(r),m=!(K(_,r)||K(v,r)||K(r,v)||K(A?.portalNode,r)||u.some(e=>e===r||K(e,r))||l.hasMatchingElement(e=>K(e,r))||p||k&&(ms(k.nodesRef.current,o).find(e=>K(e.context?.elements.floating,r)||K(e.context?.elements.domReference,r))||hs(k.nodesRef.current,o).find(e=>[e.context?.elements.floating,Fi(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===_&&V&&Js(V),s&&i!==_&&!Ma(a)&&Ti(e)===e.body){if(pi(V)&&(V.focus(),s===`popup`)){ne.request(()=>{V.focus()});return}let e=H(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||V;pi(n)&&n.focus()}b.current.insideReactTree?b.current.insideReactTree=!1:(C||!c)&&r&&m&&!M.current&&(C||r!==Ks())&&(j.current=!0,t.setOpen(!1,Y(Xa,n)))})}function o(){N.current||(b.current.insideReactTree=!0,te.start(0,()=>{b.current.insideReactTree=!1}))}let u=pi(_)?_:null;if(v||u)return ea(u&&hi(u,`focusout`,a),u&&hi(u,`pointerdown`,n),v&&hi(v,`focusin`,i),v&&hi(v,`focusout`,a),v&&A&&hi(v,`focusout`,o,!0))},[r,_,v,V,c,k,A,t,l,s,H,C,x,b,te,B,ne,d,f,ie]),X.useEffect(()=>{if(r||!v||!g)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${Ha(`portal`)}]`)||[]),t=(k?hs(k.nodesRef.current,x()):[]).find(e=>Ni(e.context?.elements.domReference||null))?.context?.elements.domReference,n=js([v,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...ie(),t,Ii(f),Ii(d),C?_:null].filter(e=>e!=null),{ariaHidden:c||C,mark:!1}),i=js([v,...e].filter(e=>e!=null));return()=>{i(),n()}},[g,r,_,v,c,A,C,k,x,d,f,ie]),J(()=>{if(!g||r||!pi(V))return;F.current=``,I.current=``;let e=ii(V),t=Ti(e);queueMicrotask(()=>{let n=w.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||K(V,t))return;let i=null,a=()=>(i??=H(V),i[0]||V),o;o=r===!0||r===null?a():Ii(r),o||=a();let s=K(V,Ti(e)),c=b.current.openEvent,l=c?.type===`mousedown`&&Xi(c);bs(o,{sync:l,preventScroll:o===V,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=Ti(e);return!(t!==o&&K(V,t))}})})},[r,g,V,H,w,D,O,b]);let ae=X.useRef(null);J(()=>{if(r||!V){ae.current=null;return}ae.current&&=(ae.current.cancelled=!0,null);let e=ii(V),t=Ti(e),n=D.current==null;Gs(t);function i(e){if(e.open||(F.current=Vs(e.nativeEvent,I.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(Ha(`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(Xi(e.nativeEvent)||ci(e.nativeEvent))j.current=!1;else{let e=!1;ii(V).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&&Ui(t)!==`body`?t:null,s=n?o||a:a||o;return s||=Ks()||null,typeof i==`boolean`?s:Ii(i)||s||null}return()=>{y.off(`openchange`,i);let t=Ti(e),n=ie(),r=K(v,t)||n.some(e=>e===t||K(e,t))||k&&ms(k.nodesRef.current,x(),!1).some(e=>K(e.context?.elements.floating,t)),o=T.current,s=F.current,c=a(s),l={cancelled:!1};ae.current=l,queueMicrotask(()=>{ae.current===l&&(ae.current=null);let n=qs(c),i=E.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!j.current&&pi(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,V,T,E,D,y,k,_,x,ie]),J(()=>{if(!Vi||g||!v)return;let e=Ti(ii(v));pi(e)&&Ri(e)&&K(v,e)&&e.blur()},[g,v]),J(()=>{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,_]),J(()=>{if(!r&&V)return Js(V),()=>{queueMicrotask(Ws)}},[r,V]);let oe=!r&&(!c||!C)&&(re||c);return(0,Z.jsxs)(X.Fragment,{children:[oe&&(0,Z.jsx)(Hi,{"data-type":`inside`,ref:ee,onFocus:e=>{if(c){let e=H();bs(e[e.length-1])}else A?.portalNode&&(j.current=!1,po(e,A.portalNode)?ra(_)?.focus():Ii(f??A.beforeOutsideRef)?.focus())}}),n,oe&&(0,Z.jsx)(Hi,{"data-type":`inside`,ref:z,onFocus:e=>{c?bs(H()[0]):A?.portalNode&&(l&&(j.current=!0),po(e,A.portalNode)?fi(_)?.focus():Ii(d??A.afterOutsideRef)?.focus())}})]})}function Xs(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=ei}=t,l=e.context.dataRef,u=X.useRef(void 0),d=vi(),f=_o(),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=ni(e.pointerType,!0)&&ci(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||ni(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=da(s),p=Ri(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:ni(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}:Ki,[n,p])}function Zs(){return!1}function Qs(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function $s(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=Zs,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:f}=e.context,p=Ls(c),m=q(typeof i==`function`?i:()=>!1),h=typeof i==`function`?m:i,g=h!==!1,_=q(()=>a),{escapeKey:v,outsidePress:y}=Qs(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=_o(),O=_o(),k=_o(),A=q(()=>{O.clear(),d.current.insideReactTree=!1}),j=q(e=>{let t=d.current.floatingContext?.nodeId;return(p?ms(p.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),M=q(t=>Ya(t,e.select(`floatingElement`))||Ya(t,e.select(`domReferenceElement`))),N=q(t=>{o()&&e.setOpen(!1,Y(ei,t.nativeEvent))}),P=q(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=No(t)?t.nativeEvent:t;if(w.current||i.isComposing||!v&&j(`__escapeKeyBubbles`))return;let a=Y(wa,i);e.setOpen(!1,a),a.isCanceled||t.preventDefault(),!v&&!a.isPropagationAllowed&&t.stopPropagation()}),F=q(()=>{d.current.insideReactTree=!0,O.start(0,A)}),I=q(t=>{if(!l||!n||t.button!==0)return;let r=da(t.nativeEvent);K(e.select(`floatingElement`),r)&&(b.current||(b.current=!0,x.current=!1))}),L=q(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 ro,i=ii(u);function a(){k.clear(),w.current=!0}function o(){w.current=!0,k.start(Vi?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&&ms(p.nodesRef.current,t).some(t=>Ya(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=da(n),i=`[${Ha(`inert`)}]`,a=ia(r)?r.getRootNode():null,o=Array.from((Si(a)?a:ii(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>K(e,r))))return;let c=ia(r)?r:null;for(;c&&!wi(c);){let e=ta(c);if(wi(e)||!ia(e))break;c=e}if(!(o.length&&ia(r)&&!Ka(r)&&!K(r,e.select(`floatingElement`))&&o.every(e=>!K(c,e)))){if(pi(r)&&!(`touches`in n)){let e=wi(r),t=Li(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&&!Xi(n)&&!C.current)return;if(S.current){t.clear(),S.current=!1;return}}typeof h==`function`&&!h(n)||j(`__outsidePressBubbles`)||(e.setOpen(!1,Y(ko,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=da(e);if(!n)return;let r=hi(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 z(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 te(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 B(e){L(e,te)}function ne(e){f()===`sloppy`&&E.current&&!M(e)&&(E.current.dismissOnTouchEnd&&N(e),D.clear(),E.current=null)}function re(e){L(e,ne)}let V=ea(r&&ea(hi(i,`keydown`,P),hi(i,`compositionstart`,a),hi(i,`compositionend`,o)),g&&ea(hi(i,`click`,ee,!0),hi(i,`pointerdown`,ee,!0),hi(i,`pointerup`,z,!0),hi(i,`pointercancel`,z,!0),hi(i,`mousedown`,ee,!0),hi(i,`mouseup`,z,!0),hi(i,`touchstart`,R,{capture:!0,passive:!0}),hi(i,`touchmove`,B,{capture:!0,passive:!0}),hi(i,`touchend`,re,{capture:!0,passive:!0})));return()=>{V(),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 ec(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),J(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:l};ia(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 tc(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),J(()=>{if(!e&&o&&i!==`ending`&&n){let e=li.request(()=>{a(`ending`)});return()=>{li.cancel(e)}}},[e,o,i,n]),J(()=>{if(!e||t||i===void 0)return;let n=li.request(()=>{a(void 0)});return()=>{li.cancel(n)}},[t,e,i]),J(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=li.request(()=>{a(`idle`)});return()=>{li.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function nc(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=q(i),{mounted:c,setMounted:l,transitionStatus:u}=tc(t,!1,!1,o),d=!t&&r;J(()=>{t&&s(!1)},[t,s]);let f=X.useRef(c),p=X.useRef(!1),m=ri(),h=()=>{f.current=!1,l(!1),a()};J(()=>{f.current=c,p.current&&(p.current=!1,!t&&c&&h())});let g=q(()=>{f.current&&(t?(p.current=!0,m()):h())});return ki({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||g()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:g}}var rc=e(Br(),1),ic={tabIndex:-1,[mi]:``};function ac(e){return t=>t!==`touch`||e.current}function oc(e,t=!1){let n=oi(),r=Is()!=null,i=Mi(()=>e(n,r)).current;return ec({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function sc({handle:e,store:t}){return J(()=>e.attachStore(t),[e,t]),null}function cc(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function lc(e,t){let n=X.useRef(null);return q(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),cc(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),cc(t))})}function uc(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 dc(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function fc(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=lc(e,n),o=q(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=q(e=>{a(e),e&&o(e)});return J(()=>(s(t.current),()=>s(null)),[s,t,n,e]),J(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function pc(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`);J(()=>{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(ha);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,a,o,s,n])}function mc(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=nc({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 Mi(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function hc(e,t){e.useSyncedValues(t),J(()=>()=>{e.update({activeTriggerProps:Ki,inactiveTriggerProps:Ki,popupProps:Ki})},[e])}function gc(e,t){J(()=>{!t&&e.state.openMethod!==null&&e.set(`openMethod`,null)},[t,e]),J(()=>()=>{e.state.openMethod!==null&&e.set(`openMethod`,null)},[e])}var _c=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}},vc={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},yc=class extends Ua{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:Ms(),nested:n,triggerElements:i},vc),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&qi(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 bc(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new yc({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:Ki,inactiveTriggerProps:Ki,popupProps:Ki}}var xc=e=>e.triggerIdProp??e.activeTriggerId,Sc=e=>e.openProp??e.open,Cc=e=>(e.popupElement?.id??e.floatingId)||void 0;function wc(e,t){return t!==void 0&&Sc(e)&&xc(e)===t}function Tc(e,t){return wc(e,t)?!0:t!==void 0&&Sc(e)&&xc(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var Ec={open:Sc,mounted:e=>e.mounted,transitionStatus:e=>Sc(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:xc,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Cc,isTriggerActive:(e,t)=>t!==void 0&&xc(e)===t,isOpenedByTrigger:(e,t)=>wc(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&xc(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Tc(e,t)?Cc(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement},Dc=io();function Oc(e){let t=X.useCallback(t=>e===void 0?ti:e.subscribeStore(t),[e]),n=X.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Dc.useSyncExternalStore)(t,n,()=>e?.serverStore)}function kc(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=oi(),a=Is()!=null,o=Mi(()=>new yc({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new _c,floatingId:i,syncOnly:!1,nested:a})).current;return J(()=>{let e={open:t,floatingId:i};r.reference!==void 0&&(e.referenceElement=r.reference,e.domReferenceElement=ia(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 Ac=Co&&Vi;function jc(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=_o();X.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=gi(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&pi(t)&&t===Ti(ii(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return ea(hi(r,`blur`,i),Ac&&hi(r,`keydown`,a,!0),Ac&&hi(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`);ia(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=da(n.nativeEvent);if(ia(a)){if(Ac&&!n.relatedTarget){if(!c.current&&!Ri(a))return}else if(!di(a))return}let u=Ai(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,Y(Po,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,Y(Po,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=ia(r)&&r.hasAttribute(Ha(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=Ti(ii(t));!r&&n===t||K(a.current.floatingContext?.refs.floating.current,n)||K(t,n)||o||Ai(r??n,e.context.triggerElements)||e.setOpen(!1,Y(Po,i))})}}},[a,r,e,l]);return X.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var Mc=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new ro;restTimeout=new ro;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},Nc=new WeakMap;function Pc(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&Nc.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),Nc.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Fc(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=Nc.get(n);a&&a!==e&&Pc(a),Pc(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,Nc.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Ic(e){let t=e.context.dataRef.current,n=Mi(()=>t.hoverInteractionState??Mc.create()).current;return t.hoverInteractionState||=n,bo(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Lc(e,t){return t!=null&&!ni(t)?0:typeof e==`function`?e():e}function Rc(e,t,n){let r=Lc(e,n);return typeof r==`number`?r:r?.[t]}function zc(e){return typeof e==`function`?e():e}function Bc(e,t){return t||e===`click`||e===`mousedown`}function Vc(e){return e?.includes(`mouse`)&&e!==`mousedown`}function Hc(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=Ls(),u=Is(),d=Ic(e),f=_o(),p=q(()=>Bc(c.current.openEvent?.type,d.interactedInside)),m=q(()=>Vc(c.current.openEvent?.type)),h=q(()=>{Pc(d)});J(()=>{a||(d.pointerType=void 0,d.restTimeoutPending=!1,d.interactedInside=!1,h())},[a,d,h]),X.useEffect(()=>h,[h]),J(()=>{if(n&&a&&d.handleCloseOptions?.blockPointerEvents&&m()&&ia(s)&&o){let e=s,t=o,n=ii(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??ho(e,`[data-rootownerid]`)??n.body;return Fc(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&&ms(l.nodesRef.current,u).length>0)}function a(t){let n=Rc(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,Y(Gi,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=da(e);Xr(t)?d.interactedInside=ho(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(Ai(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&ia(o)&&ms(l.nodesRef.current,r,!1).some(e=>K(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(Gi,n)),l.events.emit(`floating.closed`,n)})}let y=o;return ea(y&&hi(y,`mouseenter`,g),y&&hi(y,`mouseleave`,_),y&&hi(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var Uc={current:null};function Wc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=Uc,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=Ls(l),v=Ic(e),y=X.useRef(!1),b=_s(i),x=_s(r),S=_s(o),C=_s(n),w=_s(p),T=_s(f),E=q(()=>Bc(h.current.openEvent?.type,v.interactedInside)),D=q(()=>w.current?.()!==!1),O=q((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!K(t,n);if(!ia(r))return!1;let a=r;return i.hasMatchingElement(e=>K(e,a))&&(!t||!K(t,a))}),k=q(()=>{v.handler&&=(ii(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=q(()=>{Pc(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===Gi,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=Rc(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,Y(Gi,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,Y(Gi,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!ia(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!ni(v.pointerType))return;let n=zc(S.current),r=Rc(x.current,`open`,v.pointerType),i=da(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(ia(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(K(t,i)){c=t;break}}ia(o)&&ia(s)&&!e.context.triggerElements.hasElement(o)&&K(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&&ia(c)&&ia(s)&&K(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,Y(Gi,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,Y(Gi,t,c))}):g&&D()&&e.setOpen(!0,Y(Gi,t,c)))}function o(n){if(E()){A();return}k();let r=e.select(`domReferenceElement`),i=ii(r);v.restTimeout.clear(),v.restTimeoutPending=!1;let a=h.current.floatingContext??d?.();if(!Ai(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`&&K(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){K(r,e.relatedTarget)||(v.openChangeTimeout.clear(),v.restTimeout.clear(),v.restTimeoutPending=!1)}let f=m?hi(r,`mouseout`,l):void 0;return s?ea(hi(r,`mousemove`,i,{once:!0}),hi(r,`mouseenter`,i),hi(r,`mouseleave`,o),f):ea(hi(r,`mouseenter`,i),hi(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&&!ni(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;Fc(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=zc(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(Gi,n,r))}v.pointerType===`touch`?rc.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}function Gc(e){return Vi&&e.movementX===0&&e.movementY===0}function Kc(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function qc(e,t){return Kc(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Jc(e,t,n){return Kc(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function Yc(e,t,n){return Kc(t,n?e===_i:e===$i,e===na)}function Xc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Kc(t,n?e===$i:e===_i,e===aa)}function Zc(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=Fi(E),A=Ni(D),j=_s(k),M=Is(),N=Ls(x),P=X.useRef(f),F=X.useRef(o??-1),I=X.useRef(null),L=X.useRef(!0),R=q(e=>{i(F.current===-1?null:F.current,e)}),ee=X.useRef(!!E),z=X.useRef(T),te=X.useRef(!1),B=X.useRef(!1),ne=X.useRef(null),re=_s(h),V=_s(T),H=_s(o),ie=_s(b),ae=vi(),oe=vi(),se=q(()=>{ae.cancel();function e(e){d||(ne.current=bs(e,{sync:te.current,preventScroll:!0}))}let t=n.current[F.current],r=B.current;t&&e(t),(te.current?e=>e():e=>ae.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),pe&&(r||!L.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});J(()=>{O.current.orientation=g},[O,g]),J(()=>{T||(I.current=null),T&&f===`auto`||(P.current=f)},[T,f]),J(()=>{a&&(T&&E?(F.current=o??-1,P.current&&o!=null&&(B.current=!0,R())):ee.current&&(F.current=-1,R()))},[a,T,E,o,R]),J(()=>{if(a){if(!T)te.current=!1;else if(E){if(r==null){if(te.current=!1,H.current!=null)return;if(ee.current&&(F.current=-1,se()),(!z.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=>oe.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||Jc(I.current,_,u)||l?zi(n):fa(n),I.current=null,R())};t()}}else To(n.current,r)||(F.current=r,se(),B.current=!1)}}},[a,T,E,r,H,l,n,_,u,R,se,oe]),J(()=>{if(!a||E||!N||d||!ee.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=Ti(ii(D??t??null)),r=e.some(e=>e.context&&K(e.context.elements.floating,n));t&&!r&&L.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,d]),J(()=>{z.current=T,ee.current=!!E});let ce=r!=null,le=q(e=>{if(!V.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(F.current!==t||r!==t)&&(F.current=t,R(e))}),ue=q(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),de=q(()=>zi(n,re.current)),fe=q(t=>{if(L.current=!1,te.current=!0,t.which===229||!V.current&&t.currentTarget===j.current)return;if(l&&Xc(t.key,g,u,w)){qc(t.key,ue())||ai(t),e.setOpen(!1,Y(Ia,t.nativeEvent));let n=S?.current??D;pi(n)&&n.focus();return}r!=null&&r!==F.current&&!To(n.current,r)&&(F.current=r);let i=F.current,a=zi(n,h),o=fa(n,h);if(A||(t.key===`Home`&&(ai(t),F.current=a,R(t)),t.key===`End`&&(ai(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(qc(t.key,g)){ai(t);let e=Ti(t.currentTarget.ownerDocument);if(T&&!d&&K(t.currentTarget,e)&&!n.current.some(t=>t!=null&&K(t,e))){F.current=Jc(t.key,g,u)?a:o,R(t),r===F.current&&se();return}let{index:l,wrapped:f}=Gr(n.current,i,{decrement:!Jc(t.key,g,u),loopFocus:c,allowEscape:s,disabledIndices:h,minIndex:a,maxIndex:o});f&&(te.current=!1),F.current=l,R(t)}}),pe=X.useMemo(()=>({onFocus(e){te.current=!0,le(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){Gc(e)||(te.current=!0,B.current=!1,p&&le(e))},onPointerLeave(e){if(!V.current||!L.current||e.pointerType===`touch`)return;te.current=!0;let t=e.relatedTarget;if(p&&!n.current.includes(t)&&ie.current&&(ne.current?.(),ne.current=null,F.current=-1,R(e),!d)){let e=j.current,t=Ti(ii(e));e&&K(e,t)&&e.focus({preventScroll:!0})}}}),[le,V,j,p,n,R,ie,d]),me=X.useMemo(()=>d&&T&&ce&&{"aria-activedescendant":`${y}-${r}`},[d,T,ce,y,r]),he=X.useMemo(()=>({...A?{}:me,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&T&&!d){let n=da(t.nativeEvent);if(n&&!K(j.current,n))return;ai(t);let r=Y(Xa,t.nativeEvent);e.setOpen(!1,r);let i=S?.current??D;!r.isCanceled&&pi(i)&&i.focus()}else fe(t)},onPointerMove(e){Gc(e)||(L.current=!0)}}),[me,fe,j,A,e,T,d,D,S]),ge=X.useMemo(()=>{function t(t){e.setOpen(!0,Y(Ia,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&Xi(e.nativeEvent)&&(P.current=!d)}function r(e){P.current=f,f===`auto`&&ci(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(n){let r=e.select(`open`);L.current=!1;let i=n.key.startsWith(`Arrow`),a=Yc(n.key,ue(),u),o=qc(n.key,r?g:_),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||Ri(n.currentTarget)))return fe(n);if(r||m||!i){if(s){let e=qc(n.key,ue());I.current=l&&e?null:n.key}l?a&&(ai(n),r?(F.current=de(),R(n),d&&j.current?.focus()):t(n)):o&&(H.current!=null&&(F.current=H.current),ai(n),!r&&m?t(n):fe(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}},[fe,f,de,l,R,e,m,g,_,ue,u,H,d,j]),_e=X.useMemo(()=>({...me,...ge}),[me,ge]);return X.useMemo(()=>a?{reference:_e,floating:he,item:pe,trigger:ge}:{},[a,_e,he,ge,pe])}function Qc(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=q(s),f=e.useState(`open`),p=_o(),m=X.useRef(``),h=X.useRef(u??i??-1),g=X.useRef(null),_=q(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!Ma(n)||n?.matches(`:disabled`)?!1:o==null||!ao(Fo,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===` `&&(ai(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!==` `&&(ai(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=q(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);K(r,n)||K(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});J(()=>{(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 $c=.1,el=$c*$c,tl=.5;function nl(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function rl(e,t,n,r,i,a,o,s,c,l){let u=!1;return nl(e,t,n,r,i,a)&&(u=!u),nl(e,t,i,a,o,s)&&(u=!u),nl(e,t,o,s,c,l)&&(u=!u),nl(e,t,c,l,n,r)&&(u=!u),u}function il(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function al(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 ol(e={}){let{blockPointerEvents:t=!1}=e,n=new ro,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*el;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=da(r),g=r.type===`mouseleave`,_=K(u,h),v=K(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&ia(r.relatedTarget)&&K(u,r.relatedTarget))return;function y(){return!!(s&&ms(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=al(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=al(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=al(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=al(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!il(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?tl/2:tl*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+tl+1,o=C||T?S.bottom-tl:S.top,s=C?T?S.bottom-tl:S.top:S.bottom-tl;M=rl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?tl/2:tl*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-tl,o=C||T?S.top+tl:S.bottom,s=C?T?S.top+tl:S.bottom:S.top+tl;M=rl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?tl/2:tl*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+tl+1,o=w||E?S.right-tl:S.left,s=w?E?S.right-tl:S.left:S.right-tl;M=rl(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?tl/2:tl*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-tl,o=w||E?S.left+tl:S.right,s=w?E?S.left+tl:S.right:S.left+tl;M=rl(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 sl(e,t,n){let{reference:r,floating:i}=e,a=_a(t),o=Ea(t),s=Oo(o),c=Ra(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=xo(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function cl(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}=ba(t,e),p=Va(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Ca(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=Ca(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 ll=50,ul=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:cl},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=sl(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<ll&&(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}=sl(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},dl=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}=ba(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Ra(r),_=_a(o),v=Ra(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[to(o)]:ka(o)),x=p!==`none`;!d&&x&&b.push(...fo(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=Qa(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`||_===_a(t)||T.every(e=>_a(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=_a(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{}}}},fl=new Set([`left`,`top`]);async function pl(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Ra(n),s=xo(n),c=_a(n)===`y`,l=fl.has(o)?-1:1,u=a&&c?-1:1,d=ba(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 ml=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 pl(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}}}}},hl=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}=ba(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=_a(i),p=Fa(f),m=u[p],h=u[f],g=(e,t)=>vo(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}}}}}},gl=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}=ba(e,t),u={x:n,y:r},d=_a(i),f=Fa(d),p=u[f],m=u[d],h=ba(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=fl.has(Ra(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}}}},_l=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}=ba(e,t),c=await i.detectOverflow(t,s),l=Ra(n),u=xo(n),d=_a(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=zo(p-c[m],g),y=zo(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*jo(c.left,c.right):S=p-2*jo(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 vl(e){let t=Li(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=pi(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Io(n)!==a||Io(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function yl(e){return ia(e)?e:e.contextElement}function bl(e){let t=yl(e);if(!pi(t))return Wa(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=vl(t),o=(a?Io(n.width):n.width)/r,s=(a?Io(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var xl=Wa(0);function Sl(e){let t=gi(e);return!pa()||!t.visualViewport?xl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Cl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===gi(e)}function wl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=yl(e),o=Wa(1);t&&(r?ia(r)&&(o=bl(r)):o=bl(e));let s=Cl(a,n,r)?Sl(a):Wa(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=gi(a),t=ia(r)?gi(r):r,n=e,i=Di(n);for(;i&&t!==n;){let e=bl(i),t=i.getBoundingClientRect(),r=Li(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=gi(i),i=Di(n)}}return Ca({width:u,height:d,x:c,y:l})}function Tl(e,t){let n=Vo(e).scrollLeft;return t?t.left+n:wl(yi(e)).left+n}function El(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Tl(e,n),y:n.top+t.scrollTop}}function Dl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=yi(r),s=t?sa(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Wa(1),u=Wa(0),d=pi(r);if((d||!a)&&((Ui(r)!==`body`||mo(o))&&(c=Vo(r)),d)){let e=wl(r);l=bl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?El(o,c):Wa(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 Ol(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function kl(e){let t=Vo(e),n=e.ownerDocument.body,r=jo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=jo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+Tl(e),o=-t.scrollTop;return Li(n).direction===`rtl`&&(a+=jo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var Al=25;function jl(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=gi(e),a=yi(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!pa()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(Tl(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<=Al&&(s-=o)}return{width:s,height:c,x:l,y:u}}function Ml(e,t){let n=wl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=bl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Nl(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=jl(e,n,t);else if(t===`document`)r=kl(yi(e));else if(ia(t))r=Ml(t,n);else{let n=Sl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Ca(r)}function Pl(e,t){let n=t.get(e);if(n)return n;let r=Qr(e,[],!1).filter(e=>ia(e)&&Ui(e)!==`body`),i=null,a=Li(e).position===`fixed`,o=a?ta(e):e;for(;ia(o)&&!wi(o);){let e=Li(o),t=Qi(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=ta(o)}return t.set(e,r),r}function Fl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?sa(t)?[]:Pl(t,this._c):[].concat(n),r],o=Nl(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=Nl(t,a[e],i);s=jo(n.top,s),c=zo(n.right,c),l=zo(n.bottom,l),u=jo(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Il(e){let{width:t,height:n}=vl(e);return{width:t,height:n}}function Ll(e,t,n){let r=pi(t),i=yi(t),a=n===`fixed`,o=wl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Wa(0);if((r||!a)&&((Ui(t)!==`body`||mo(i))&&(s=Vo(t)),r)){let e=wl(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=Tl(i));let l=i&&!r&&!a?El(i,s):Wa(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 Rl(e){return Li(e).position===`static`}function zl(e,t){if(!pi(e)||Li(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return yi(e)===n&&(n=n.ownerDocument.body),n}function Bl(e,t){let n=gi(e);if(sa(e))return n;if(!pi(e)){let t=ta(e);for(;t&&!wi(t);){if(ia(t)&&!Rl(t))return t;t=ta(t)}return n}let r=zl(e,t);for(;r&&ua(r)&&Rl(r);)r=zl(r,t);return r&&wi(r)&&Rl(r)&&!Qi(r)?n:r||ui(e)||n}var Vl=async function(e){let t=this.getOffsetParent||Bl,n=this.getDimensions,r=await n(e.floating);return{reference:Ll(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Hl(e){return Li(e).direction===`rtl`}var Ul={convertOffsetParentRelativeRectToViewportRelativeRect:Dl,getDocumentElement:yi,getClippingRect:Fl,getOffsetParent:Bl,getElementRects:Vl,getClientRects:Ol,getDimensions:Il,getScale:bl,isElement:ia,isRTL:Hl};function Wl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Gl(e,t,n){let r=null,i,a=yi(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=co(d),h=co(a.clientWidth-(u+f)),g=co(a.clientHeight-(d+p)),_=co(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:jo(0,zo(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Wl(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=gi(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Kl(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=yl(e),u=i||a?[...l?Qr(l):[],...t?Qr(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Gl(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?wl(e):null;c&&g();function g(){let t=wl(e);h&&!Wl(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 ql=ml,Jl=hl,Yl=dl,Xl=_l,Zl=gl,Ql=(e,t,n)=>{let r=new Map,i=n??{},a={...Ul,...i.platform,_c:r};return ul(e,t,{...i,platform:a})},$l=typeof document<`u`?X.useLayoutEffect:function(){};function eu(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(!eu(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)&&!eu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function tu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function nu(e,t){let n=tu(e);return Math.round(t*n)/n}function ru(e){let t=X.useRef(e);return $l(()=>{t.current=e}),t}function iu(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);eu(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=ru(c),D=ru(i),O=ru(l),k=X.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Ql(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!eu(w.current,t)&&(w.current=t,rc.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);$l(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=X.useRef(!1);$l(()=>(A.current=!0,()=>{A.current=!1}),[]),$l(()=>{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=nu(M.floating,u.x),r=nu(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...tu(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 au=(e,t)=>{let n=ql(e);return{name:n.name,fn:n.fn,options:[e,t]}},ou=(e,t)=>{let n=Jl(e);return{name:n.name,fn:n.fn,options:[e,t]}},su=(e,t)=>({fn:Zl(e).fn,options:[e,t]}),cu=(e,t)=>{let n=Yl(e);return{name:n.name,fn:n.fn,options:[e,t]}},lu=(e,t)=>{let n=Xl(e);return{name:n.name,fn:n.fn,options:[e,t]}};function uu(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=Ls(n),p=X.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),m=iu({...e,elements:{...p,...l&&{reference:l}}}),h=X.useCallback(e=>{let t=ia(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 J(()=>{o&&(d.current=o)},[o]),J(()=>{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 du=X.createContext(void 0);function fu(){return X.useContext(du)?.direction??`ltr`}var pu=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}=ba(e,t)||{};if(l==null)return{};let d=Va(u),f={x:n,y:r},p=Ea(i),m=Oo(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=vo(D,k,O),j=!c.arrow&&xo(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}}}),mu=(e,t)=>{let{name:n,fn:r}=pu(e);return{name:n,fn:r,options:[e,t]}},hu={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}}}},gu={sideX:`left`,sideY:`top`},_u=`--available-width`,vu=`--available-height`,yu=`--anchor-width`,bu=`--anchor-height`,xu=`--transform-origin`,Su=_u,Cu=vu;function wu(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 Tu(e,t,n){let{rects:r,placement:i}=e;return{side:wu(t,Ra(i),n),align:xo(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Eu(e){return Du(e,uu)}function Du(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=q(O),A=O?k:n,j=_s(n),M=_s(g),N=fu()===`rtl`,[P,F]=X.useState(null);!g&&P!==null&&F(null);let I=x===`placement`,L=P?Ra(P):null,R=P&&I?xo(P)||`center`:null,ee=L||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":N?`left`:`right`,"inline-start":N?`right`:`left`}[i],z=R||o,te=z===`center`?ee:`${ee}-${z}`,B=l;typeof B==`number`?B={top:B,right:B,bottom:B,left:B}:B&&={top:B.top||0,right:B.right||0,bottom:B.bottom||0,left:B.left||0};let ne=+(i===`bottom`),re=+(i===`top`),V=+(i===`right`),H=+(i===`left`),ie={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:B},ae=X.useRef(null),oe=_s(a),se=_s(s),ce=typeof a==`function`?0:a,le=typeof s==`function`?0:s,ue=[];p&&ue.push(p),ue.push(au(e=>{let t=Tu(e,i,N),n=typeof oe.current==`function`?oe.current(t):oe.current,r=typeof se.current==`function`?se.current(t):se.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ce,le,N,i]));let de=w===`none`&&C!==`shift`,fe=!de&&(u||E||C===`shift`),pe=C===`none`?null:cu({...ie,padding:{top:B.top+1+ne,right:B.right+1+H,bottom:B.bottom+1+re,left:B.left+1+V},mainAxis:!E&&C===`flip`,crossAxis:w===`flip`&&`alignment`,fallbackAxisSideDirection:T}),me=de?null:ou({...ie,rootBoundary:D,mainAxis:w!==`none`,crossAxis:fe,limiter:u||E?void 0:su(e=>{if(!ae.current)return{};let{width:t,height:n}=ae.current.getBoundingClientRect(),r=_a(Ra(e.placement)),i=r===`y`?t:n,a=r===`y`?B.left+B.right:B.top+B.bottom;return{offset:i/2+a/2}})},[ie,u,E,D,B,w]);C===`shift`||w===`shift`||z===`center`?ue.push(me,pe):ue.push(pe,me),ue.push(lu({...ie,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!M.current)return;let i=e.style;i.setProperty(Su,`${t}px`),i.setProperty(Cu,`${n}px`);let a=gi(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(yu,`${u}px`),i.setProperty(bu,`${d}px`)}}),mu(e=>({element:ae.current||ii(e.elements.floating).createElement(`div`),padding:ae.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=Ra(r),u=xo(r),d=_a(l)===`y`,f=ae.current,p=typeof a==`function`?a(Tu(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 fe&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(xu,d?`${m} ${h}`:`${h} ${m}`),{}}},hu,b),J(()=>{!g&&h&&h.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[g,h]);let he=X.useMemo(()=>({ancestorScroll:!f,elementResize:!f&&typeof ResizeObserver<`u`,layoutShift:!f&&typeof IntersectionObserver<`u`}),[f]),{refs:ge,elements:_e,x:ve,y:ye,middlewareData:be,update:xe,placement:Se,context:Ce,isPositioned:we,floatingStyles:Te}=t({rootContext:h,open:m?g:void 0,placement:te,middleware:ue,strategy:r,whileElementsMounted:m?void 0:(...e)=>Kl(...e,he),nodeId:y,externalTree:S}),{sideX:Ee,sideY:De}=be.adaptiveOrigin||gu,Oe=we?r:`fixed`,ke=X.useMemo(()=>{let e;return e=we?b?{position:Oe,[Ee]:ve,[De]:ye}:{...Te,position:Oe}:{position:Oe,top:0,left:0},e[Su]=`100vw`,e[Cu]=`100vh`,we||(e.opacity=0),e},[b,Oe,Ee,ve,De,ye,Te,we]),Ae=X.useRef(null);J(()=>{if(!g)return;let e=j.current,t=typeof e==`function`?e():e,n=(Ou(t)?t.current:t)||null;n!==Ae.current&&(ge.setPositionReference(n),Ae.current=n)},[g,ge,A,j]),X.useEffect(()=>{if(!g)return;let e=j.current;typeof e!=`function`&&Ou(e)&&e.current!==Ae.current&&(ge.setPositionReference(e.current),Ae.current=e.current)},[g,ge,A,j]),X.useEffect(()=>{if(m&&g&&_e.reference&&_e.floating)return Kl(_e.reference,_e.floating,xe,he)},[m,g,_e,xe,he]);let je=Ra(Se),Me=wu(i,je,N),Ne=xo(Se)||`center`,Pe=!!be.hide?.referenceHidden;J(()=>{x&&g&&we&&(je!==ee||I&&Ne!==z)&&F(Se)},[x,I,g,we,Se,je,Ne,ee,z]);let Fe=X.useMemo(()=>({position:`absolute`,top:be.arrow?.y,left:be.arrow?.x}),[be.arrow]),Ie=be.arrow?.centerOffset!==0;return X.useMemo(()=>({positionerStyles:ke,arrowStyles:Fe,arrowRef:ae,arrowUncentered:Ie,side:Me,align:Ne,physicalSide:je,anchorHidden:Pe,refs:ge,context:Ce,isPositioned:we,update:xe}),[ke,Fe,ae,Ie,Me,Ne,je,Pe,ge,Ce,we,xe])}function Ou(e){return e!=null&&`current`in e}function ku(e){return e===`starting`?qa:Ki}function Au(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),Ro(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},ku(r),i],stateAttributesMapping:fs})}var ju=e(Wr(),1);function Mu(e){let t=ju.unstable_scheduleCallback(4,e);return()=>ju.unstable_cancelCallback(t)}var Nu=X.createContext(Oe({scheduleTask:Mu,defaultIdleTTL:400})),Pu=new WeakMap,Fu=0,Iu=new Set;function Lu(e){Fu++;try{return e()}finally{Fu--}}function Ru(e){if(Fu===0)return e();Iu.size===0&&queueMicrotask(zu),Iu.add(e)}function zu(){for(let e of Iu)Iu.delete(e),e()}function Bu(e,t){let n=Pu.get(e);n===void 0&&(n=new WeakMap,Pu.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,()=>Ru(n));return()=>{i--,Iu.delete(n),r()}},snapshot(){return Lu(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Lu(()=>Dr(t,e))}),a.value}};return n.set(t,o),o}function Vu(e,t){let n=Bu(e,t);return X.useEffect(zu),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Hu(e,t,n){let r=Bu(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(zu),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Uu=(e,t)=>{let n=X.useContext(Nu);return t?Hu(n,e,t):Vu(n,e)};function Wu(e,t){X.useEffect(()=>e.mount(t),[t,e])}function Gu(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=Bn(be(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Ku):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Ku=e=>{if(It(e))return e.value;throw We(e.cause)},qu=(e,t)=>{let n=X.useContext(Nu);return Wu(n,e),Gu(n,e,t)},Ju=(e,t)=>{let n=X.useContext(Nu);return[Vu(n,e),Gu(n,e,t)]},Yu={suspendOnWaiting:new WeakMap,default:new WeakMap};function Xu(e,t,n){let r=n?Yu.suspendOnWaiting:Yu.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 Zu(e,t,n){let r=Vu(e,t);if(r._tag===`Initial`||n&&r.waiting)throw Xu(e,t,n);return r}var Qu=(e,t)=>{let n=Zu(X.useContext(Nu),e,t?.suspendOnWaiting??!1);if(n._tag===`Failure`&&!t?.includeFailure)throw We(n.cause);return n};m(`MachineSchemaEncodeError`);var $u=class extends m(`MachineSchemaDecodeError`){},ed=class extends m(`InfiniteTransitionError`){},td=class extends m(`StartupError`){},nd=class extends m(`ChildAlreadyExistsError`){};m(`ProcessLocalError`);var rd=class extends m(`StoppedError`){},id=e=>e instanceof ed||e instanceof $u,ad=e=>id(e)?it(e):Be(e),od=e=>id(e)||e instanceof td?e:new td({cause:Zt(e)}),sd=e=>e,cd=`~effect/Machine/Target`,ld=Symbol(`effect/Machine/TargetSnapshot`),ud=Symbol(`effect/Machine/StateInput`),dd=Symbol(`effect/Machine/HistoryTarget`),fd=Symbol(`effect/Machine/InitialTarget`),pd=Symbol(`effect/Machine/ChoiceTarget`),md=Symbol(`effect/Machine/NoTarget`),hd=Symbol(`effect/Machine/Declined`),gd=Symbol(`effect/Machine/TargetSelection`),_d=Symbol(`effect/Machine/StateUpdate`),vd=Symbol(`effect/Machine/CombinedTarget`),yd=Symbol(`effect/Machine/SelectedBranch`),bd=(e,t,n,r)=>Object.freeze({[gd]:gd,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),xd=bd(`none`,void 0,`local`),Sd=e=>Zn(e,gd),Cd=(e,t)=>Object.freeze({[_d]:_d,path:e,value:t}),wd=e=>Zn(e,_d),Td=(e,t)=>Object.freeze({[vd]:vd,target:e,update:t}),Ed=e=>Zn(e,vd),Dd=(e,t,n,r)=>Object.freeze({[yd]:yd,owner:e,branchIndex:t,branchKey:n,result:r}),Od=e=>Zn(e,yd),kd=Object.freeze({[md]:md}),Ad=()=>kd,jd=e=>Zn(e,md),Md=Object.freeze({[hd]:hd}),Nd=()=>Md,Pd=e=>Zn(e,hd),Fd=(e,t)=>({[dd]:dd,path:e,parent:t}),Id=e=>Zn(e,dd),Ld=(e,t,n)=>({[fd]:fd,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),Rd=e=>Zn(e,fd),zd=(e,t,n)=>({[pd]:pd,path:e,parent:t,...n===void 0?{}:{values:n}}),Bd=e=>Zn(e,pd),Vd=(e,t)=>{if(!re(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(!re(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(re(t))return{schema:t,output:void 0,annotations:at(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=Zn(t,`schema`)&&re(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:at(n);if(t.type===`parallel`&&!Zn(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(Zn(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:re(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=re(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}},Hd=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=Vd(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)}},Ud=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],Wd=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,Gd=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=sd(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:Ud(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:Zn(i,`reenter`)&&i.reenter===!0,acceptance:Wd(i),branches:Ud(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:Wd(r.always),branches:Ud(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:Wd(r.onDone),branches:Ud(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:Wd(a),branches:Ud(a)})}}}return t},Kd=(e,t,n)=>({[cd]:cd,[ld]:n?.snapshot,path:e,value:t,values:n?.values}),qd=e=>Zn(e,cd),Jd=e=>({[ud]:ud,input:e}),Yd=e=>Zn(e,ud),Xd=e=>Zn(e,`path`)&&Zn(e,`value`),Zd=(e,t,n)=>{if(e.path===t)return yt(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return mt();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),Zn(e,`state`)&&Xd(e.state))return Zd(e.state,t,n);if(Zn(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if(Xd(r)){let e=Zd(r,t,n);if(M(e))return e}}return mt()},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},Qd=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},$d=new WeakMap,ef=Symbol(`effect/Machine/EventConstruction`),tf=new WeakMap,nf=new WeakMap,rf=new WeakMap,af=e=>{let t=e,n=nf.get(t);if(n!==void 0)return n;let r=De(tt(e));return nf.set(t,r),r},of=e=>{let t=e,n=rf.get(t);if(n!==void 0)return n;let r=Sn(tt(e));return rf.set(t,r),r},sf=Symbol.for(`effect/Machine/protocol`),cf=e=>{let t=e[sf];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},lf=(e,t)=>{Object.defineProperty(e,sf,{value:t,enumerable:!1})},uf=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),Zn(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&Zn(t,`make`)&&n(t)};for(let t of e)n(t);return t},df=(e,t)=>{let n=$d.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},ff=e=>df(e.events,`public`).schemas,pf=e=>df(e.internalEvents,`internal`).schemas,mf=e=>df(e.emittedEvents,`emitted`).schemas,hf=e=>{let t=ff(e),n=pf(e),r=mf(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];lf(e,{event:Qe(a),emit:Qe(r),eventConstructors:uf(a),emissionConstructors:uf(r)})},gf=(e,t)=>lf(t,cf(e)),_f=e=>Zn(e,`_tag`)?String(e._tag):void 0,vf=(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={[ef]:ef,_tag:n};return tf.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},yf=e=>typeof e==`object`&&!!e&&tf.has(e),bf=(e,t)=>{let n=[],r=e=>{if(Zn(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(Zn(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=>ue(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:lr(e)?[e.symbol]:F(e)?e.enums.map(([,e])=>e):qt(e)?e.types.flatMap(a):St(e)?a(e.thunk()):[],o=e=>{let t=Fn(e.ast);if(oe(t)){let e=t.propertySignatures.find(({name:e})=>e===`_tag`),n=e===void 0?[]:a(e.type);if(n.length>0)return n}try{return Qe([e]).pipe(ee(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(Zn(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>vf(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},xf=(e,t)=>{let n=Object.freeze(Array.from(t)),r=bf(e,n);return $d.set(r,{kind:e,schemas:n}),Object.freeze(r)},Sf=(e,t,n,r)=>af(t)(n).pipe(Fe(t=>new $u({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),Cf=(e,t,n,r)=>{let i=of(t)(n);if(Lr(i))throw new $u({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},wf=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new $u({machineId:e.id,boundary:r.boundary,cause:he(t)?t:Zn(n,`~effect/SchemaIssue/Issue`)?new Fr(n):Zt(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},Tf=(e,t,n)=>new $u({machineId:e.id,boundary:n,event:String(t._tag),cause:Zt(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),Ef=(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}},Df=(e,t,n,r)=>new $u({machineId:e.id,boundary:n,event:String(t._tag),cause:Zt(r)}),Of=(e,t,n,r)=>{let i=tf.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)?it(Tf(e,n,r)):Tt({try:()=>Ef(n,i),catch:t=>Df(e,n,r,t)}).pipe(U(t=>i.schema.makeEffect(t).pipe(Fe(t=>new $u({machineId:e.id,boundary:r,event:String(n._tag),cause:new Fr(t)})))))},kf=(e,t,n,r)=>{let i=tf.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 Tf(e,n,r);let o;try{o=Ef(n,i)}catch(t){throw Df(e,n,r,t)}return wf(e,i.schema,o,{boundary:r,event:String(n._tag)})},Af=(e,t)=>{let n=cf(e);if(yf(t))return Of(e,n,t,`event`);let r=_f(t);return Sf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},jf=(e,t)=>{let n=cf(e);if(yf(t))return kf(e,n,t,`event`);let r=_f(t);return Cf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Mf=(e,t)=>{let n=cf(e);if(yf(t))return Of(e,n,t,`emission`);let r=_f(t);return Sf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Nf=(e,t)=>{let n=cf(e);if(yf(t))return kf(e,n,t,`emission`);let r=_f(t);return Cf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Pf=(e,t,n)=>Cf(e,t,n,{boundary:`input`}),Ff=(e,t,n)=>Yd(n)?Qd(t).makeEffect(n.input).pipe(Fe(n=>new $u({machineId:e.id,boundary:`state`,state:t.path,cause:new Fr(n)}))):Sf(e,Qd(t),n,{boundary:`state`,state:t.path}),If=(e,t,n)=>Yd(n)?wf(e,Qd(t),n.input,{boundary:`state`,state:t.path}):Cf(e,Qd(t),n,{boundary:`state`,state:t.path}),Lf=(e,t,n)=>t.output===void 0?$t(n):Sf(e,t.output,n,{boundary:`output`,state:t.path}),Rf=(e,t,n)=>t.output===void 0?n:Cf(e,t.output,n,{boundary:`output`,state:t.path}),zf=(e,t)=>{let n=new Set(Yf(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)&&!Jf(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&qf(r,t.parent)&&Q(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},Bf=(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`||!(Jf(n,t.parent)||Yf(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,If(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}),zf(e,n.get(r))}return n},Vf=W(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*it(new $u({machineId:e.id,boundary:`history`,state:r,cause:Zt(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`||!(Jf(n,t.parent)||Yf(e,t.parent).includes(n)))return yield*it(new $u({machineId:e.id,boundary:`history`,state:n,cause:Zt(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*it(new $u({machineId:e.id,boundary:`history`,state:n,cause:Zt(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!s)return yield*it(new $u({machineId:e.id,boundary:`history`,state:n,cause:Zt(Error(`Machine snapshot omits remembered value for "${n}"`))}));o.set(n,yield*Sf(e,Qd(r),i.values[n],{boundary:`history`,state:n}))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)return yield*it(new $u({machineId:e.id,boundary:`history`,state:r,cause:Zt(Error(`Machine snapshot contains incomplete history record "${r}"`))}));n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o});try{zf(e,n.get(r))}catch(t){return yield*it(new $u({machineId:e.id,boundary:`history`,state:r,cause:Zt(t)}))}}return n}),Hf=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>Zf(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},Uf=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),Wf=e=>e.machineReferences,Gf=new WeakMap,Kf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),qf=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),Jf=(e,t)=>e===t||qf(e,t),Yf=(e,t)=>{let n=Gf.get(e.stateNodes);n===void 0&&(n=new Map,Gf.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},Xf=(e,t)=>Yf(e,t).length,Zf=(e,t,n)=>Q(e,t).order-Q(e,n).order,Qf=(e,t,n)=>Q(e,n).children.some(e=>t.active.has(e)),$f=(e,t)=>{let n=Array.from(t.active).filter(n=>!Qf(e,t,n)).sort((t,n)=>Zf(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},ep=(e,t)=>$f(e,t)[0],tp=(e,t,n)=>{let r=$f(e,t).filter(e=>Jf(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},np=(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`)},rp=(e,t,n)=>{let r={},i=Yf(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},ip=(e,t,n)=>{let r=Q(e,n).parent;return r===void 0?void 0:t.values.get(r)},ap=(e,t)=>{let n=r=>t.active.has(r)?[r,...Q(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},op=(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=op(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]=op(e,t,i)}i.states=a}return i},sp=(e,t)=>{let n=op(e,t,np(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:Hf(e,t.history)}),n},cp=(e,t,n)=>{let r=op(e,t,n);return t.history.size>0&&Object.assign(r,{history:Hf(e,t.history)}),r},lp=(e,t,n)=>{if(!Zn(n,`state`)||!Xd(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},up=(e,t)=>{if(!Zn(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},dp=(e,t,n,r)=>{let i=Q(e,n),a=r[i.key];if(!Kf(r,i.key)||!Xd(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},fp=(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,If(e,i,t.value));if(i.type===`compound`&&a(lp(e,i,t)),i.type===`parallel`){let n=up(i,t);for(let t of i.children)a(dp(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:Bf(e,t)}},pp=(e,t)=>fp(e,t),mp=(e,t)=>{try{return fp(e,t)}catch(t){throw t instanceof $u?t:new $u({machineId:e.id,boundary:`configuration`,cause:Zt(t)})}},hp=W(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=W(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*Ff(e,i,t.value));if(i.type===`compound`&&(yield*a(lp(e,i,t))),i.type===`parallel`){let n=up(i,t);for(let t of i.children)yield*a(dp(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*Vf(e,t)}}),gp=(e,t)=>hp(e,t).pipe(O(t=>{if(on(t))return R(Nt(t,t=>t instanceof $u?t:new $u({machineId:e.id,boundary:`configuration`,cause:Hn(t)})));let n=kn(t);return M(n)&&n.value instanceof $u?it(n.value):it(new $u({machineId:e.id,boundary:`configuration`,cause:t}))})),_p=(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 Yf(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&qf(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}},vp=(e,t)=>e.history.get(t),yp=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=Yf(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)Jf(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}};W(function*(e,t,n,r,i){let a=Q(e,n),o=new Set,s=new Map,c=new Map,l=Yf(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&&Kf(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*Ff(e,c,r));else if(i!==void 0&&Kf(i,n))s.set(n,yield*Ff(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)Jf(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}}),W(function*(e,t,n,r){let i=yield*hp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Yf(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&&Kf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Kf(r,i))o.set(i,yield*Ff(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)Jf(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&&Kf(r,n))for(let[t,i]of Object.entries(r)){if(!Jf(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*Ff(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var bp=(e,t,n,r,i,a=!1)=>{let o=Q(e,n),s=new Set,c=new Map,l=new Map,u=Yf(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&&Kf(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,If(e,a,r));else if(i!==void 0&&Kf(i,n))c.set(n,If(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)Jf(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}},xp=(e,t,n)=>{let r=bp(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,If(e,n,r))}return{...r,active:i,values:a}},Sp=(e,t,n,r)=>{let i=fp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Yf(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&&Kf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Kf(r,i))o.set(i,If(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)Jf(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&&Kf(r,n))for(let[t,i]of Object.entries(r)){if(!Jf(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,If(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},Cp=(e,t,n)=>{if(qd(n)){let r=n[ld];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return Sp(e,t,r,n.values)}return bp(e,t,n.path,n.value,n.values)}if(Xd(n)){let r=mp(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`)},wp=(e,t)=>sd(e).handlers[t],Tp=(e,t,n)=>Q(e,n).children.find(e=>t.active.has(e)),Ep=(e,t)=>Q(e,t).type===`final`,Dp=(e,t)=>wp(e,t)?.onDone!==void 0,Op=(e,t,n)=>{if(!t.active.has(n))return!1;let r=Q(e,n);if(r.type===`compound`){let r=Tp(e,t,n);return r!==void 0&&(n===``?!Dp(e,r)&&Op(e,t,r):Ep(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!Op(e,t,n))return!1;return!0}return Ep(e,n)},kp=(e,t)=>{let n=np(e,t);return Op(e,t,n)&&!Dp(e,n)},Ap=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),jp=W(function*(e,t,n,r,i){let a=Q(e,n),o=wp(e,n)?.output?.({state:t.values.get(n),containingState:ip(e,t,n),ancestors:rp(e,t,n),event:r,outputs:i});return yield*Lf(e,a,o)}),Mp=W(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=Tp(e,t,n);if(o===void 0||(n===``?Dp(e,o):!Ep(e,o)))return;let s=yield*Mp(e,t,o,r,i,a);if(s===void 0)return;let c=Ap(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*Mp(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Ap(i,n,yield*jp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Ep(e,n))return;let s=Ap(i,n,yield*jp(e,t,n,r));return s.isNew&&a.push(s),s}),Np=W(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=Xf(e,n)-Xf(e,t);return r===0?Zf(e,t,n):r}))yield*Mp(e,a,t,n,r,i);return{configuration:a,completions:i}}),Pp=(e,t,n,r,i)=>{let a=Q(e,n),o=wp(e,n)?.output?.({state:t.values.get(n),containingState:ip(e,t,n),ancestors:rp(e,t,n),event:r,outputs:i});return Rf(e,a,o)},Fp=(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=Tp(e,t,n);if(o===void 0||(n===``?Dp(e,o):!Ep(e,o)))return;let s=Fp(e,t,o,r,i,a);if(s===void 0)return;let c=Ap(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=Fp(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=Ap(i,n,Pp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Ep(e,n))return;let s=Ap(i,n,Pp(e,t,n,r));return s.isNew&&a.push(s),s},Ip=(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=Xf(e,n)-Xf(e,t);return r===0?Zf(e,t,n):r}))Fp(e,a,t,n,r,i);return{configuration:a,completions:i}},Lp=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},Rp=(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 Jd(Object.hasOwn(t,`data`)?t.data:{})}},zp=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=Lp(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return Kd(t,Rp(i,e))}let a=new Map,o=(t,n)=>{let i=Lp(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=Rp(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=Lp(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=Lp(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=Lp(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=Lp(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 zd(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return Kd(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...Ld(l,f,p),...m.size===0?{}:{children:m}}},Bp=(e,t,n)=>{let r=Lp(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 Cd(t,Rp(i,r))},Vp=(e,t,n=``)=>{let r=Lp(t),i=e.byPath.get(n);zp(e,n,r);let a=Rp(i,r);if(i.type===`choice`)return zd(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=Lp(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,Vp(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]}},Hp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},Up=`root`,Wp=e=>{let t=new Map,n=(e,r)=>{let i=!re(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!re(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 "${Up}" is reserved for the root`);return t},Gp=(e,t)=>{let n=Wp(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(Hp(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(Hp(t.branches,`Machine branches must be a map`))){let t=Hp(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={...Hp(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 qp({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}},Kp=(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}},qp=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=Kp(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return bd(`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 xd}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return bd(`state`,``,`branch`)}let i=Kp(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:Kp(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return bd(i.kind,i.path,r===`history`?`full`:`branch`,a)},Jp=(e,t,n,r)=>{let i=Hp(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`&&dt(a.value))&&!(a.kind===`streams`&&mr(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}},Yp=Symbol(`effect/Machine/InitialEvent`),Xp=Symbol(`effect/Machine/SnapshotBuilderState`),Zp=Symbol(`effect/Machine/ChildMachineLogic`),Qp=new WeakSet,$p=e=>Qp.has(e),em=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},tm=e=>typeof e==`function`?e:()=>e,nm=e=>{if(typeof e==`object`&&e&&Zn(e,`decoded`)&&e.decoded===!0&&Zn(e,`data`)){let t=em(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return tm(t.data)}let t=tm(e);return n=>Jd(e===void 0?{}:t(n))},rm=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(!Zn(e,`data`))throw Error(`Machine decoded construction requires data`);return tm(e.data)}let t=tm(e.data);return n=>Jd(Zn(e,`data`)?t(n):{})},im=(e,t)=>{let n=(e,t,r)=>{if(Zn(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&Zn(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(re(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?{}:em(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?{}:em(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!re(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!re(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=nm(r)}}else{let t=em(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||re(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`&&(Zn(t,`data`)||Zn(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=rm(t),l=e.states[a];if(Zn(t,`data`)&&!re(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);Zn(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?{}:em(c[t],`state handler`),e);l[t]=a.node,(re(i)||i.type!==`history`)&&(c[t]!==void 0||!re(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{[Xp]:i}};return Qp.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},am=(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)},om=e=>`child`in e?e.child.id:e.id,sm=(e,t)=>{let n=new Set;for(let r of e){let e=om(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},cm=e=>e===void 0?[]:Array.isArray(e)?e:[e],lm=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(jf(e,t))},emit:t=>{r.push(Nf(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},um=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},dm=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(Jd(t.length===0?{}:t[0])),enumerable:!1}),t},fm=e=>{let t={};return Object.defineProperty(t,Xp,{value:e,enumerable:!1}),t},pm=(e,t,n)=>{let r=fm(n);for(let i of t.children){let a=um(e,i);a.schema===void 0||Zn(n,a.key)||(r[a.key]=dm(r=>{let i=Object.assign({},n);return i[a.key]=r,pm(e,t,i)}))}return r},mm=(e,t)=>{let n=um(e,t);if(n.type===`parallel`)return pm(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=um(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return dm(e=>fm({[r.key]:e}))},hm=(e,t)=>{if(typeof t!=`object`||!t||!Zn(t,Xp))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[Xp]},gm=Symbol(`effect/Machine/InvocationEvent`),_m=(e,t,n)=>({[gm]:!0,path:e,id:t,type:`done`,output:n}),vm=(e,t,n)=>({[gm]:!0,path:e,id:t,type:`element`,element:n}),ym=(e,t,n)=>({[gm]:!0,path:e,id:t,type:`failure`,error:n}),bm=(e,t,n)=>({[gm]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),xm=e=>typeof e==`object`&&!!e&&gm in e,Sm=new WeakMap,Cm=new WeakMap,wm=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},Tm=(e,t)=>{let n=Object.create(e);return Cm.set(n,wm(e,t)),n},Em=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return wm(e,n);let r=Cm.get(e);if(r!==void 0)return r;let i=Sm.get(e);if(i!==void 0)return i;let a=wm(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>it(new rd)},parent:void 0});return Sm.set(e,a),a},Dm=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}},Om=(e,t,n)=>{let r=lm(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},km=(e,t,n,r)=>{let i=lm(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Pd(a.result)?{declined:!0}:{declined:!1,state:jd(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},Am=(e,t,n)=>{let r=lm(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},jm=(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)=>Zf(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=sh(e,m,zd(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=Rd(i)?Nm(e,r,i,n):Id(i)?Pm(e,r,i,n):void 0;r=Cp(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=sd(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,If(e,p,Jd({}))),u=!0;continue}let i=Am(e,t,{...Em(e,m),state:m.values.get(d),containingState:ip(e,m,d),ancestors:rp(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...$p(t)?{}:{builder:mm(e,d)}}),l=hm(d,i.value);a.set(p.path,If(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:sd(e).handlers[d]?.initialize,h=m===void 0?void 0:Am(e,m,{...Em(e,p),state:p.values.get(d),containingState:ip(e,p,d),ancestors:rp(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...$p(m)?{}:{builder:mm(e,d)}}),g=h===void 0?void 0:hm(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,If(e,n,Jd({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&$p(m)){a.set(n.path,If(e,n,Jd({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,If(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 Mm(e,t,n,r){let i=xp(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>Q(e,t).type===`choice`))return jm(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=sh(e,i,zd(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=Rd(t)?Nm(e,i,t,r):Id(t)?Pm(e,i,t,r):void 0;i=Cp(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=jm(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 Nm(e,t,n,r){let i=Mm(e,t,n,r),a=cp(e,i.configuration,n.path);return{target:Kd(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Pm(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=vp(t,n.path);if(a!==void 0){let i=jm(e,yp(e,t,a),r),o=cp(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:Kd(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=sd(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=km(e,s,{event:r,target:t=>Vp(e.stateNodes,t),owner:n.parent});if(c.state===void 0||Id(c.state)||!Xd(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=ah(c.state)===void 0?void 0:sh(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?mp(e,c.state):Cp(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=Cp(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=cp(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:Kd(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 Fm=(e,t)=>{if(!t.transition.declinable)return t;let n=km(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},Im=(e,t)=>[...Yf(e,t)].reverse(),Lm=(e,t,n)=>{let r=Yf(e,t),i=Yf(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},Rm=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||qf(e,t)?t:e},zm=(e,t,n)=>Hm(e,Array.from(t.active).filter(e=>n===void 0||qf(e,n))),Bm=(e,t,n)=>Um(e,Array.from(t.active).filter(e=>n===void 0||qf(e,n))),Vm=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),Hm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Yf(e,n).length-Yf(e,t).length;return r===0?Q(e,n).order-Q(e,t).order:r}),Um=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Yf(e,t).length-Yf(e,n).length;return r===0?Zf(e,t,n):r}),Wm=(e,t,n,r)=>({...Em(e,t),state:t.values.get(n),containingState:ip(e,t,n),ancestors:rp(e,t,n),event:r}),Gm=(e,t,n,r,i)=>({...Em(e,t),state:t.values.get(n),containingState:ip(e,t,n),ancestors:rp(e,t,n),event:r,snapshot:i}),Km=(e,t,n,r,i,a)=>({...Em(e,t),state:t.values.get(n),containingState:ip(e,t,n),ancestors:rp(e,t,n),event:r,output:i,snapshot:a}),qm=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=Om(e,sd(e).handlers[c]?.[i],Wm(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},Jm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=sp(e,t);for(let o of $f(e,t))for(let c of Im(e,o)){let l=Dm(sd(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Fm(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...Em(e,t),state:t.values.get(c),containingState:ip(e,t,c),ancestors:rp(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},Ym=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=sp(e,t);for(let o of r){let r=Dm(sd(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=Fm(e,{sourcePath:o.path,leafPath:tp(e,t,o.path),trigger:{type:`done`},transition:r,context:Km(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},Xm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=sp(e,t);for(let o of $f(e,t))for(let c of Im(e,o)){let l=Dm(sd(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Fm(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:Gm(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},Zm=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=sd(e).handlers[n.path],i=cm(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=Dm(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=sp(e,t),s={...Em(e,t),state:t.values.get(n.path),containingState:ip(e,t,n.path),ancestors:rp(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=Fm(e,{sourcePath:n.path,leafPath:tp(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},Qm=e=>{if(Id(e)||Bd(e)||qd(e)||Xd(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},$m=(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(`, `)}`)}},eh=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},th=(e,t)=>Array.from(t).sort((t,n)=>Zf(e,t.selection.sourcePath,n.selection.sourcePath)),nh=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&qf(e.sourcePath,t.sourcePath))),rh=(e,t)=>{let n=[];for(let r of th(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(eh(r.exitPaths,i.exitPaths)||n){if(qf(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},ih=(e,t={})=>{let n={...t},r=[],i=e=>{if(Bd(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:zd(e.path,e.parent,n),values:n}))},ah=(e,t={})=>ih(e,t)[0],oh=(e,t)=>{if(Bd(e))return zd(e.path,e.parent,{...t,...e.values??{}});if(Rd(e))return{...e,values:{...t,...e.values}};if(!qd(e)||Object.keys(t).length===0)return e;let n=e[ld];return Kd(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function sh(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=ih(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 ed({machineId:e.id,state:d.target.path,maxIterations:lh});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=sd(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,If(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=km(e,p.transition,{...Em(e,h),containingState:ip(e,h,f.path),ancestors:rp(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`);$m(f.path,{type:`choice`},p.targets,g.state);let _=Qm(g.state);n=oh(g.state,d.values);let v=ah(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(!qd(n)&&!Xd(n)&&!Id(n)&&!Rd(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 ch=(e,t,n)=>{let r=n.leafPath,i=n.collected??km(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=Ed(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||wd(o)?void 0:o;$m(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(wd(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:If(e,n,c.value)}})(),u=l!==void 0&&(Rd(s)||Bd(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:sh(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&Rd(f)?Nm(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=Id(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&Id(m)){let i=n.transition.reenter?Q(e,n.sourcePath).parent:Lm(e,r,m.parent),a=g===void 0?zm(e,t,i):Hm(e,Array.from(t.active).filter(e=>Jf(e,m.parent)));h=Pm(e,a.includes(m.parent)?_p(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(Rd(r)){let i=Nm(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(!Id(r)){S.push(r);continue}let i=Pm(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?Qm(_):Qm(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:Cp(e,t,_);for(let t of S)w=Cp(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||!Vm(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:Lm(e,r,C),O=Q(e,n.sourcePath).parent,k=n.transition.reenter?Rm(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?zm(e,t,k):Hm(e,Array.from(t.active).filter(e=>Jf(e,g.parent))),entryPaths:g===void 0?Bm(e,w,k):Um(e,Array.from(w.active).filter(e=>Jf(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},lh=1e3,uh={_tag:Yp},dh=(e,t)=>kp(e,pp(e,t)),fh=(e,t,n)=>gp(e,t).pipe(U(t=>Np(e,t,n)),U(t=>{let n=np(e,t.configuration);return!kp(e,t.configuration)||!t.configuration.outputs.has(n)?Be(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):$t(t.configuration.outputs.get(n))})),ph=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Pf(e,e.input,void 0),t):[Pf(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=Nm(e,i,r,uh),o=Cp(e,i,a.target),s=sp(e,o),c=ap(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=qm(e,o,c,uh,`entry`),p=hh(e,o,uh,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:uh,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:sp(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:sp(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}},mh=(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=nh(r),a=[];for(let n of i)a.push(ch(e,t,n));let o=rh(e,a),s=th(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:Qm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Qm(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=Cp(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=Hm(e,s.flatMap(e=>e.exitPaths)),_=Um(e,s.flatMap(e=>e.entryPaths));l=_p(e,t,l,g);let v=qm(e,t,g,n,`exit`),y=qm(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}},hh=(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 ed({machineId:e.id,state:String(ep(e,s)),maxIterations:lh});let t=Ip(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>sd(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=Ym(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=mh(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(kp(e,s)){let t=np(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?Jm(e,s,c):[];if(h.length>0){let t=mh(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=Xm(e,s,_);if(v.length===0){l=!0;continue}let y=mh(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}},gh=(e,t,n)=>{let r=xm(n)?n:jf(e,n);if(kp(e,t)){let n=Ip(e,t,r),i=np(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=xm(r)?Zm(e,t,r):Xm(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=mh(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...hh(e,a.next,r,o,s,c,l),event:r}},_h=(e,...t)=>Tt({try:()=>ph(e,...t),catch:od}),vh=(e,t)=>({raise:n=>Af(e,n).pipe(U(e=>t.sendTo(t.self,e))),emit:n=>Mf(e,n).pipe(U(e=>t.emit(e)))}),yh=(e,t)=>N(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),bh=(e,t)=>xn(Array.from(e,e=>t.emit(e)),{discard:!0}),xh=new WeakMap,Sh=e=>{let t=xh.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>it(new rd)},parent:void 0};return xh.set(e,n),n},Ch=(e,t)=>{let n=t===void 0?Sh(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},wh=new Set([`initialize`,`invoke`,`on`,`output`]),Th=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!wh.has(t))return!1;return!0},Eh=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=sd(e).handlers[a.path];if(!Th(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=Dm(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)=>Zf(e,t,n)),r.sort((t,n)=>Zf(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=>Yf(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&&(sd(e).handlers[``]===void 0||Reflect.ownKeys(sd(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}},Dh=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()}),Oh=(e,t)=>t?{...e,next:Dh(e.next)}:e,kh=(e,t,n)=>{e.values[t]=n},Ah=(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}},jh=(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}},Mh=(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=Mh(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]=Mh(e,t,i)}i.states=a}return i},Nh=(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=Mh(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Ph=(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{...Ch(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:Nh(t,n)}},Fh=Object.freeze([]),Ih=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(jf(e,t))},emit:t=>{(o??=[]).push(Nf(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:jd(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??Fh,raisedEvents:a??Fh,emittedEvents:o??Fh}},Lh=(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:Ph(e,t,n,c,r,i)})}}}return a},Rh=(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},zh=(e,t,n,r,i)=>{if((qd(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&qd(r)&&r[ld]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=If(e,t.nodes[i],r.value),{...n,values:a}}return Ah(t,Cp(e,jh(t,n),r))},Bh=(e,t,n,r)=>{let i=Ih(e,r.transition.transition,r.context,r.transition.evaluate),a=Ed(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(wd(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:If(e,i,s.value)}})(),l=o===void 0||wd(o)?void 0:o;$m(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&Rd(l)?Nm(e,(()=>{let e=jh(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&&!qd(d)&&!Xd(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=Dh(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():zh(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||!Rh(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:Qm(d),g=h===void 0?t.nodes[r.sourceIndex].parent:Lm(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?Rm(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:zm(e,jh(t,n),v),entryPaths:Bm(e,jh(t,f),v),choiceTransitions:u?.transitions??[]}},Vh=(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:Qm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Qm(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=Bh(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=th(e,rh(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&qf(t.sourcePath,e.sourcePath))).map(r=>Bh(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=zh(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?Hm(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?Um(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},Hh=(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 ed({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:lh});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=Ip(e,jh(t,o),s).configuration,i=np(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:Ah(t,n),commands:c??Fh,emittedEvents:u??Fh,microsteps:d??Fh,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=Dm(sd(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=Ih(e,h.transition,{...Ch(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:Nh(t,o)},h.evaluate),f=wd(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`);kh(o,n,If(e,r,f.value))}if($m(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!qd(p)&&!Xd(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=qd(p)?p[ld]===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]?kh(o,n,If(e,t.nodes[n],p.value)):g=zh(e,t,o,p,n)}let _=h.reenter||!Rh(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:Qm(p),resolvedTarget:p===void 0?void 0:Qm(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:Fh,entryPaths:_?[t.nodes[v].path]:Fh,changed:_};o=g,(d??=[]).push(Oh(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??Fh,emittedEvents:u??Fh,microsteps:d??Fh,done:!1,output:void 0};f+=1,s=g}},Uh=(e,t,n,r,i,a)=>{if(xm(r)){let i=gh(e,a===void 0?jh(t,n):Uf(jh(t,n),a),r);return{event:i.event,next:Ah(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:Ah(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=jf(e,r);if(t.flat)return Hh(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=jh(t,n);if(kp(e,r)){let n=Ip(e,r,o).configuration,i=np(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:Ah(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=Lh(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=Vh(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[Oh(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new ed({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:lh});if(t.finalIndices.some(e=>l.active[e]===1)){let n=Ip(e,jh(t,l),u).configuration;if(l=Ah(t,n),kp(e,n)){let t=np(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=Lh(e,t,l,n,a);if(r.length===0)continue;let s=Vh(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(Oh(s,i))}},Wh=new WeakMap,Gh=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>sp(e,t),plan:(t,n,r,i)=>gh(e,i===void 0?t:Uf(t,i),n)}),Kh=(e,t)=>({fromConfiguration:e=>Ah(t,e),toConfiguration:e=>jh(t,e),snapshot:e=>Nh(t,e),plan:(n,r,i=!1,a)=>Uh(e,t,n,r,i,a),...Object.values(sd(e).handlers).some(e=>e.initialize!==void 0&&!$p(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Pf(e,e.input,void 0),n):[Pf(e,e.input,n[0])],a=e.initial(...i),o=Rd(a)?Mm(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,uh).configuration:mp(e,a),s=Ip(e,r===void 0?o:Uf(o,r),uh).configuration,c=Ah(t,s),l=Nh(t,c);if(!kp(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:ap(e,s),done:!1,output:void 0};let u=np(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:ap(e,s),done:!0,output:s.outputs.get(u)}}}}),qh=e=>{let t=Wh.get(e);if(t!==void 0)return t;let n=Eh(e),r=n===void 0?Gh(e):Kh(e,n);return Wh.set(e,r),r},Jh=`Machine.invocation:`,Yh=e=>e.startsWith(Jh),Xh=(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,Ie(t,G)}},Zh=e=>Wn(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,$t(t)}let t=Pn();return e.waiter=t,ft(t).pipe(c(Zh(e)))}),Qh=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),$h=(e,t,n)=>{if(e.closed)return mt();let r=e.children.get(t);return r!==void 0&&Qh(r,n)?yt(r.ref):mt()},eg=e=>{if(e.observers!==void 0)for(let t of e.observers)Xh(t,$h(e,t.id,t.child))},tg=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&eg(e))},ng=(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`&&eg(e),!0},rg=e=>ie(function*(){let t=yield*w(),n=0,r=0,i=0,a=0;return{rootSessionId:e,stream:En(t).pipe(Un(An(()=>{n+=1})),zn(An(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>a++,publishUnsafe:i=>{n!==0&&Ge(t,{...i,sequence:r++,rootSessionId:e})},close:h(t)}}),ig=e=>({id:e.id,sessionId:e.sessionId}),ag=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?ig(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?ig(t):{id:String(t.id)}}]:[]}return[]}),og=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:ag(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),sg=Symbol.for(`effect/Machine/activeSnapshotObserver`),cg=Symbol.for(`effect/Machine/snapshotObserver`),lg=e=>typeof e==`object`&&!!e&&cg in e,ug=Symbol.for(`effect/Machine/sendParentOverride`),dg=Symbol.for(`effect/Machine/acknowledgedSend`),fg=Symbol(`effect/Machine/AcknowledgedMessage`),pg=e=>typeof e==`object`&&!!e&&fg in e,mg=e=>pg(e)?e.event:e,hg=(e,t)=>{e!==void 0&&pg(e)&&(e.deferred!==void 0&&Ie(e.deferred,$t(t)),e.inspection?.complete(t))},gg=(e,t)=>{e!==void 0&&pg(e)&&e.deferred!==void 0&&Ie(e.deferred,R(t))},_g=e=>{e!==void 0&&pg(e)&&e.deferred!==void 0&&Ie(e.deferred,it(new rd))},vg=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,yg=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),bg=e=>e?._tag===`Childless`||e?.childless===!0,xg=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},Sg=e=>{if(e.items===void 0)return mt();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),yt(t)},Cg=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)_g(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},wg=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),Tg=(e,t,n)=>{if(e.closed)return!1;for(xg(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},Eg=e=>Wn(()=>{let t=Sg(e);return M(t)?$t(t.value):e.closed?ht:Ae(t=>(e.receivers.add(t),An(()=>{e.receivers.delete(t)}))).pipe(c(Eg(e)))}),Dg=e=>{Cg(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(ht)},Og=class extends Cr()(`effect/Machine/MachineRuntime`){},kg=(e,t)=>er(e,Og,t),Ag=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(vr);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(Ct);return n===void 0?e.cause.reasons.find(Mr)===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}}},jg=(e,t)=>Wn(()=>e(t)).pipe(d,ve),Mg=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=An(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return An(()=>new n)},Ng=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Pg=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&pg(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,Fg=(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=og(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{[fg]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},Ig=(e,t,n)=>{if(!pg(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:ig(t),event:r.event,causedBy:r.causedBy})},Lg=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 Wn(()=>{if(this.registry.closed)return ht;if(this.has(t.key)||this.registry.children.has(t.id))return it(new nd({id:t.duplicateId}));let a=e(),o=this.registry.scope??=ae(`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()?yg(this.self,e,t,n):G,...this.sendAcknowledged===void 0?void 0:{[dg]:e=>i()?this.sendAcknowledged(e):ht}},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,ng(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>tg(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?U(this.runtime.nextSessionId,e=>this.runtime.startCompiledSync(a,c,this.scopedServices??=Ye(this.services,P,o),e)):this.runtime.start(a,c)).pipe(ur(e=>It(e)?G:(tg(this.registry,t.id,n),r===void 0?G:r.stop)));return(u?d:gt(d,o)).pipe(ve)})}stopAll(){return Wn(()=>{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]:xn(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]:xn(n,{concurrency:`unbounded`,discard:!0})}},Rg=tn(mt()).pipe(fn(Qt)),zg=e=>G,Bg=(e,t)=>{},Vg=()=>void 0,Hg=Symbol(`effect/Machine/EmissionsClosed`),Ug=()=>{let e,t=Wn(()=>{let t=e;return t===Hg?$t(void 0):t===void 0?w().pipe(U(t=>An(()=>{let n=e;return n===Hg?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(U(([e,n])=>n?h(t).pipe(_n(e)):$t(e))))):$t(t)});return{emit:t=>Wn(()=>e===void 0||e===Hg?G:Or(e,t).pipe(ve)),close:()=>{let t=e;return e=Hg,t===void 0||t===Hg?G:h(t)},stream:wt(t.pipe(bt(e=>e===void 0?kt:En(e))))}},Wg={close:()=>G,spawn:(()=>Be(Error(`Childless machine logic cannot spawn a process`))),get:()=>$t(mt()),changes:()=>Rg,sendTo:()=>G,stop:()=>G,owned:{spawn:()=>Be(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>G,stopPaths:()=>void 0}},Gg=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>Wn(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return G;let t=Jn(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)?xn(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>An(()=>tg(i,e,t)),s=(e,t,n,r)=>An(()=>ng(i,e,t,n,r)),l=e=>{let t=typeof e==`string`?e:e.id;return An(()=>{if(i.closed)return mt();let n=i.children.get(t);return n!==void 0&&Qh(n,e)?yt(n.ref):mt()})},u=e=>{let t=typeof e==`string`?e:e.id;return Lt(Pt((n,r)=>An(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(U(n=>{let a=An(()=>{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 le(r,a).pipe(c(An(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),Xh(n,$h(i,t,e))})),_n(Zh(n)))}))))},d=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return Wn(()=>{if(i.closed)return G;let o=i.children.get(a);return o!==void 0&&Qh(o,e)?yg(o.ref,t,n,r):G})},f=e=>{let t=typeof e==`string`?e:e.id;return Wn(()=>{if(i.closed)return G;let n=i.children.get(t);return n!==void 0&&Qh(n,e)?n.ref.stop:G})};function p(n,r){let a=typeof n==`object`&&n&&Zp in n?n:void 0,l=a===void 0?n:a[Zp](r?.input),u=a===void 0?r:{id:a.id,descriptor:a},d=Symbol(),f=u?.id??d,p;return Wn(()=>i.closed?ht:typeof f==`string`&&(i.children.has(f)||Yh(f))?it(new nd({id:f})):(i.scope??=ae(`parallel`),i.children.set(f,{_tag:`Starting`,token:d}),t.start(l,{detached:!0,...u?.id===void 0?void 0:{id:u.id},...u?.onOutcome===void 0?void 0:{onOutcome:u.onOutcome},...u?.[sg]===void 0?void 0:{onSnapshot:u[sg]},...u?.[ug]===void 0?void 0:{sendParent:u[ug]},onReady:(e,t)=>An(()=>{p=e}).pipe(c(s(f,d,e,u?.descriptor)),U(e=>e?G:t)),onStop:o(f,d),parent:e,runtime:t,origin:{_tag:`Spawn`,address:u?.id}}).pipe(ur(e=>nr(e)?o(f,d).pipe(c(p===void 0?G:p.stop)):G),gt(i.scope))))}return{close:a,spawn:p,get:l,changes:u,sendTo:d,stop:f,owned:new Lg(i,e,t,n,r)}},Kg=(e,t,n,r)=>An(()=>Gg(e,t,n,r)),qg=(e,t)=>`${e.length}:${e}${t}`,Jg=(e,t)=>`${Jh}${qg(e,t)}`,Yg=e=>({initial:()=>G,run:()=>e}),Xg=(e,t,n)=>({initial:()=>G,run:({parent:r})=>{let i=r?.[dg];return i===void 0?Be(Error(`Stream invocation requires an acknowledged parent machine`)):sn(e,e=>i(vm(t,n,e)).pipe(ve,O(()=>ht)))}}),Zg=(e,t)=>typeof e==`function`?e(t):e,Qg=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),$g=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Yg(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:()=>Yg(Ut(Zg(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>Xg(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:()=>Zg(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[Zp](`input`in e?Zg(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},e_=e=>e.length===0?G:e.length===1?e[0]:xn(e,{discard:!0}),t_=(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(B(`StoppedError`,()=>G)),n_=e=>e instanceof ed||e instanceof $u||e instanceof rd,r_=(e,t,n,r,i,a,o,s,l,u,d,f)=>Wn(()=>{let p=qg(n,r),m=d===void 0?o:()=>{let t=o();return{...t,run:i=>Ke(Wn(()=>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":f??r,"machine.invoke.kind":d,"machine.invoke.sessionId":i.self.sessionId},captureStackTrace:!1})}};return t.spawn(m,{key:p,path:n,id:i,duplicateId:r,...a===void 0?void 0:{descriptor:a},...d===void 0?void 0:{activityKind:d},sendParent:(t,n)=>t()?e.self.send(n):G,onOutcome:(t,i,o)=>c(g,Wn(()=>i._tag===`Stopped`||!t()?G:i._tag===`Done`?s===void 0?e.failCause(Zt(Error(`Invocation "${r}" completed without the required onDone handler`))):t_(e,_m(n,r,i.output),d===void 0?void 0:o):i._tag===`Failure`&&l!==void 0&&(a===void 0||!n_(i.error))?t_(e,ym(n,r,i.error),d===void 0?void 0:o):e.failCause(i.cause))),...u===void 0?void 0:{onSnapshot:(t,i)=>t()?t_(e,bm(n,r,i)):G}})}),i_=(e,t)=>Yh(e)?it(new nd({id:t})):void 0,a_=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:i_(String(r.address),i);return a===void 0?r_(e,t,n,i,r.address===void 0?Jg(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},o_=(e,t,n,r)=>{let i=r.child,a=i_(i.id,i.id);return a===void 0?r_(e,t,n,i.id,i.id,i,i[Zp],r.onDone,r.onFailure,r.onSnapshot,void 0):a},s_=(e,t,n,r,i,a)=>{let o=Qg(t),s=Um(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...Wf(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:ip(e,r,i),ancestors:rp(e,r,i),event:a};return cm(wp(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?o_(t,n,i,e):a_(t,n,i,$g(e,s,i)))});return s.length===0?void 0:e_(s)},c_=Symbol(`effect/Machine/CompiledStoppedCompletion`),l_=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[dg](e){return this.sendAcknowledgedEffect(e)}[cg](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=Wg;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=Ng(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:Wn(()=>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 Pg(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:og({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:Ot(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=Gg(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?zg:this.inspector===void 0?e.send:t=>yg(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)=>vg(e)?this.inspector===void 0?e.send(t):yg(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?Bg:(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(Hn(e)),it(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 u_(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?$t(this):(this.runState=`Draining`,In(this.drainRuntime(),this.services).pipe(_n(this)))}initialize(){let e=this;return ie(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*Kg(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?zg:e.inspector===void 0?t.send:n=>yg(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)=>vg(t)?e.inspector===void 0?t.send(n):yg(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?Bg:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>nr(t)?e.childRuntime.close(t):G,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(bt(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(ur(t=>(nr(t)&&e.publishStartFailed(t.cause),r(t))),Rr(An(()=>{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:Jt,poll:An(()=>Kn(Sg(e.mailbox),mg)),receiveMessage:Jt,pollMessage:An(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:An(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new u_(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(ve))),e.options.onSnapshot!==void 0&&(yield*jg(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 An(()=>this.current.snapshot.state)}get snapshot(){return An(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return Wn(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=Pn(),ft(this.waiter)))}get stop(){return br(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return An(()=>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(ve);return this.runState===`Initializing`?e:e.pipe(c(ht))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(U(e=>e?qn(this.settleRequestedTermination()).pipe(ve):G))}sendAcknowledgedEffect(e){return Pr(t=>cr().pipe(U(n=>this.offerEvent(e,void 0,void 0,n).pipe(c(t(ft(n)))))))}offerEvent(e,t,n,r){return Wn(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?Fg(i,a,e,t,n,r):r===void 0?e:{[fg]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return br(kr(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return it(new rd);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&Ig(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&&xg(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=Be(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=In(this.drainRuntime(e),this.services);return(this.options.detached===!0?qn(t,{startImmediately:!0}):ce(t,{startImmediately:!0})).pipe(U(e=>An(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(U(t=>t?qn(this.interruptAndFinish(e)):G))),ve)}stopEffect(){return Wn(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?G:this.requestTermination({_tag:`Stopped`}).pipe(U(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!==Hg||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=Hg;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,Cg(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),_g(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=c_,this.lifecycle=`Completed`,this.waiter!==void 0&&(Ie(this.waiter,this.resolveCompletion(c_)),this.waiter=void 0),!0}settleRequestedTermination(){return Wn(()=>this.runState===`Draining`?this.worker===void 0?(this.interruptRequested=!0,this.awaitCompletion()):this.interruptAndFinish(this.worker).pipe(c(this.awaitCompletion())):this.finishRequestedTermination())}interruptAndFinish(e){return y(e).pipe(c(Wn(()=>this.lifecycle===`Completed`?G:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?G:this.join.pipe(d,ve)}resolveCompletion(e){if(e!==c_)return e;let t=it(new rd);return this.completion=t,t}drainRuntime(e){let t=this;return Pr(n=>ie(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(Wn(()=>{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(d);if(t.flushPendingChanges(),nr(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(M(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 Wn(()=>{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`?pr:e._tag===`Done`?Tn(e.output):Ot(e.cause),r=e._tag===`Stopped`?c_:e._tag===`Done`?$t(e.output):R(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?G:Wn(()=>this.options.onOutcome(Ag(t))).pipe(d,ve),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(c(An(()=>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`?Rn():n}))));return br(An(()=>{Cg(this.mailbox)}).pipe(c(this.childRuntime.close(n)),c(this.setAndPublishSnapshot(t)),c(s),c(An(()=>{e._tag===`Failure`?gg(this.inFlightMessage,e.cause):_g(this.inFlightMessage),this.inFlightMessage=void 0})),c(i),c(this.options.onStop??G),c(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:G),c(An(()=>{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&&(Ie(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?$t(e):Or(e.changes,[e]).pipe(_n(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe(cn(()=>jg(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?G:Or(e.changes,Tn(void 0)).pipe(ve)}emitEvent(e){let t=this.externalEmissions===void 0?Wn(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===Hg?G:Or(this.emissionsPubSub,e).pipe(ve)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe(cn(()=>An(()=>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=Hg,e===void 0||e===Hg?G:h(e)}getOrCreateEmissions(){return Wn(()=>{let e=this.emissionsPubSub;return e===Hg?$t(void 0):e===void 0?w().pipe(U(e=>An(()=>{let t=this.emissionsPubSub;return t===Hg?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(U(([t,n])=>n?h(e).pipe(_n(t)):$t(t))))):$t(e)})}emissionsStream(){return wt(this.getOrCreateEmissions().pipe(bt(e=>e===void 0?kt:En(e))))}setAndPublishSnapshot(e){return Wn(()=>{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(U(e=>this.completeChanges(e)),ve)})}setActiveState(e){return Wn(()=>this.commitActiveState(e)??G)}pollCompiledMessage(){let e=Sg(this.mailbox);return M(e)&&(this.inFlightMessage=pg(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=pg(e)?e:void 0}completeCompiledMessage(e){hg(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]:Ge(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:Ge(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:jg(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,Ge(e.changes,t))}updateState(e){return Wn(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?G:e(t.snapshot.state).pipe(U(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?G:this.setActiveState(e)}))})}getOrCreateChanges(){return Wn(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?w({replay:1}).pipe(U(e=>An(()=>{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(U(([t,n])=>n?h(e).pipe(_n(t)):$t(t))))):$t(e.changes):$t(void 0)})}changesStream(){let e=this;return wt(ie(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return tn(e.current.snapshot);let n=yield*wr(t),r=e.current;return r.snapshot.status===`active`?tn(r.snapshot).pipe(fn(Lt(Nr(Xe(n))).pipe(rr(e=>e.revision>r.revision),Ht(e=>e.snapshot)))):tn(r.snapshot)}))}},u_=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return Kn(this.process.pollCompiledMessage(),mg)}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}},d_=W(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*pe(),i=e.execution,a=new l_(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(ur(e=>nr(e)?a.shutdownEmissions().pipe(c(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:G)):G))}),f_=(e,t,n,r)=>new l_(e,t,n,r).initializeCompiledSync(),p_=W(function*(e,t){let{detached:n,id:r,onOutcome:a,onReady:o,onReadySync:s,onSnapshot:l,onStop:u,onStopSync:f,parent:p,runtime:m,sendParent:h}=t,g=t.sessionId??(yield*m.nextSessionId),_=r??g,v=m.inspection,b=v===void 0?void 0:Ng(e,_,g),x=v===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:g},S,C,T=wg(),E=t.emissions??Ug(),D=yield*cr(),O=yield*cr(),k=ft(O).pipe(d,ve),A=!0,j,N=dn(D,{_tag:`Stopped`}).pipe(ve),P=(e,t)=>Wn(()=>Tg(T,e,t)?G:it(new rd)),F=v===void 0?void 0:(e,t,n,r)=>Wn(()=>{let i=v.isActive()?Fg(v,b,e,t,n,r):r===void 0?e:{[fg]:!0,event:e,deferred:r};return P(i,()=>Ig(v,b,i))}),I=e.execution?._tag===`Compiled`?e=>Pr(t=>cr().pipe(U(n=>(v===void 0?P({[fg]:!0,event:e,deferred:n}):F(e,void 0,void 0,n)).pipe(c(t(ft(n))))),bt(e=>e))):void 0,L={id:_,sessionId:g,stop:Wn(()=>A?N:N.pipe(c(Jt))),send:v===void 0?e=>P(e):e=>F(e,void 0,void 0),...v===void 0?void 0:{inspectionSubject:b,sendInspected:F}},{changes:R,close:ee,get:z,owned:te,sendTo:B,spawn:ne,stop:re}=Wg;bg(e.execution)||({changes:R,close:ee,get:z,owned:te,sendTo:B,spawn:ne,stop:re}=yield*Kg(L,m,void 0,I===void 0?void 0:e=>I(e)));let V=e=>It(e)?G:(v!==void 0&&v.publishUnsafe(x===void 0?{_tag:`StartFailed`,subject:b,cause:e.cause}:{_tag:`ActivityStopped`,subject:x.owner,activity:x,exit:e}),ee(e).pipe(c(E.close()),c(t.inspectionRoot===!0&&v!==void 0?v.close:G))),H=f===void 0?u??G:An(()=>f(Ie)),ae=v===void 0?Vg:()=>Pg(j,A),oe=h??(p===void 0?zg:v===void 0?p.send:e=>yg(p,e,b,ae())),se=v===void 0?E.emit:e=>E.emit(e).pipe(cn(()=>An(()=>v.publishUnsafe({_tag:`Emitted`,subject:b,emission:e,causedBy:ae()})))),le={self:L,parent:p,spawn:ne,sendParent:oe,emit:se,sendTo:v===void 0?((e,t)=>vg(e)?e.send(t):B(e,t)):((e,t)=>vg(e)?yg(e,t,b,ae()):B(e,t,b,ae())),stopChild:re,failCause:e=>dn(D,{_tag:`Failure`,cause:e}).pipe(ve),inspectInitial:v===void 0?Bg:(e,t=[])=>{S=e,C=t}};v!==void 0&&v.publishUnsafe(x===void 0?{_tag:`Created`,subject:b,parent:p?.inspectionSubject,origin:t.origin??{_tag:`Root`},definition:e.inspection?.definition}:{_tag:`ActivityStarted`,subject:x.owner,activity:x});let ue=yield*e.initial(le).pipe(ur(V),Rr(An(()=>{A=!1}))),de=yield*Mn({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:ue}});x===void 0&&v?.publishUnsafe({_tag:`Initialized`,subject:b,snapshot:{status:`active`,state:ue},initialEntryPaths:S??[],microsteps:og({microsteps:C??[]})});let fe=l===void 0?e=>e.changes===void 0?$t(e):Or(e.changes,[e]).pipe(_n(e)):e=>{let t=e.changes===void 0?$t(e):Or(e.changes,[e]).pipe(_n(e)),n=e.snapshot;return n.status===`active`?t.pipe(cn(()=>jg(l,n))):t},pe=e=>e.changes===void 0?G:Or(e.changes,Tn(void 0)).pipe(ve),me=e=>e.snapshot.status===`active`?$t(e):pe(e).pipe(_n(e)),he=e=>or(de).pipe(U(t=>t.revision===e.revision?fe(e).pipe(U(me)):$t(void 0))),ge=e=>un(de,t=>t.terminalizing?$t([void 0,t]):bt(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(U(e=>e===void 0?$t(void 0):he(e)),bt(e=>e?.snapshot)),_e=e=>Xn(de,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(bt(e=>e?.snapshot)),ye=e=>Dt(de,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(U(fe),U(me),ve),be=v===void 0?e=>ge(t=>$t(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(ve):t=>or(de).pipe(U(n=>ge(e=>$t(e.status===`active`?{status:`active`,state:t}:void 0)).pipe(cn(r=>An(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&v.publishUnsafe({_tag:`StateChanged`,subject:b,before:n.snapshot.state,after:t,causedByDeliveryId:j!==void 0&&pg(j)?j.inspection?.deliveryId:void 0})})))),ve),xe=(e,n,r)=>{let i=a===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?G:Wn(()=>a(Ag(e))).pipe(d,ve),o=v===void 0?E.close():E.close().pipe(c(An(()=>v.publishUnsafe(x===void 0?{_tag:`Terminated`,subject:b,snapshot:e}:{_tag:`ActivityStopped`,subject:x.owner,activity:x,exit:e.status===`stopped`?Rn():n}))));return br(An(()=>Dg(T)).pipe(c(ee(n)),c(ye(e)),c(o),c(An(()=>{nr(n)?gg(j,n.cause):_g(j),j=void 0})),c(i),c(H),c(t.inspectionRoot===!0&&v!==void 0?v.close:G),c(r)))},Se=_e(e=>({status:`stopped`,state:e.state})),Ce=e=>_e(t=>({status:`error`,state:t.state,cause:e})),we=e=>_e(t=>({status:`done`,state:t.state,output:e})),Te=e=>xe(e,pr,i(O,new rd)),Ee=(e,t)=>{let n=Ot(t);return xe(e,n,Kt(O,t))},De=(e,t)=>{let n=Tn(t);return xe(e,n,dn(O,t))},Oe=br(N.pipe(c(k))),ke=e.execution?._tag===`Compiled`?{receiveMessage:Eg(T).pipe(cn(e=>An(()=>{j=pg(e)?e:void 0}))),pollMessage:An(()=>Sg(T)).pipe(cn(e=>An(()=>{M(e)&&(j=pg(e.value)?e.value:void 0)}))),completeMessage:e=>{hg(j,e),j=void 0}}:void 0,Ae=v===void 0||e.execution?._tag===`Compiled`?Eg(T).pipe(bt(mg)):Eg(T).pipe(cn(e=>An(()=>{j=e})),bt(mg)),je=v===void 0||e.execution?._tag===`Compiled`?An(()=>Sg(T)).pipe(bt(Kn(mg))):An(()=>Sg(T)).pipe(cn(e=>An(()=>{M(e)&&(j=e.value)})),bt(Kn(mg))),Me=v===void 0?e=>ge(t=>t.status===`active`?e(t.state).pipe(bt(e=>({status:`active`,state:e}))):$t(void 0)).pipe(ve):t=>or(de).pipe(U(n=>ge(e=>e.status===`active`?t(e.state).pipe(bt(e=>({status:`active`,state:e}))):$t(void 0)).pipe(cn(t=>An(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&v.publishUnsafe({_tag:`StateChanged`,subject:b,before:n.snapshot.state,after:t.state,causedByDeliveryId:j!==void 0&&pg(j)?j.inspection?.deliveryId:void 0})})))),ve),Ne={...le,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:te}:void 0,...ke,receive:Ae,poll:je,state:or(de).pipe(bt(e=>e.snapshot.state)),setState:be,updateState:Me},Pe=un(de,e=>e.snapshot.status===`active`?e.changes===void 0?w({replay:1}).pipe(bt(t=>[t,{...e,changes:t}])):$t([e.changes,e]):$t([void 0,e])),Fe=wt(ie(function*(){let e=yield*Pe;if(e===void 0)return tn((yield*or(de)).snapshot);let t=yield*wr(e),n=yield*or(de);return n.snapshot.status===`active`?tn(n.snapshot).pipe(fn(Lt(Nr(Xe(t))).pipe(rr(e=>e.revision>n.revision),Ht(e=>e.snapshot)))):tn(n.snapshot)})),Ie={id:_,sessionId:g,...v===void 0?void 0:{inspectionSubject:b,sendInspected:F},state:or(de).pipe(bt(e=>e.snapshot.state)),snapshot:or(de).pipe(bt(e=>e.snapshot)),changes:Fe,emissions:E.stream,join:ft(O),stop:Oe,send:L.send,...I===void 0?void 0:{[dg]:I},child:z,childChanges:R};s!==void 0&&!s(Ie)?yield*N:o!==void 0&&(yield*o(Ie,N)),l!==void 0&&(yield*jg(l,{status:`active`,state:ue}));let Le=e=>{switch(e._tag){case`Stopped`:return Se;case`Done`:return we(e.output);case`Failure`:return Ce(e.cause)}},Re=(e,t)=>{switch(e._tag){case`Stopped`:return Te(t);case`Done`:return De(t,e.output);case`Failure`:return Ee(t,e.cause)}},ze=e=>n===!0?qn(e,{startImmediately:!0}):ce(e,{startImmediately:!0}),Be=yield*Qn(D),Ve=st(Be)?yield*Pr(t=>t(Wn(()=>e.run(Ne))).pipe(d,U(e=>dn(D,nr(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(ze):void 0;return yield*ze(Pr(e=>ie(function*(){let t=M(Be)?yield*Be.value:yield*e(ft(D)),n=yield*Le(t);return Ve!==void 0&&(yield*y(Ve)),n===void 0?yield*k:yield*Re(t,n)}))),Ie}),m_=((e,t)=>e.execution?._tag===`Compiled`?d_(e,t):p_(e,t)),h_=Mg(m_,f_),g_=new WeakMap,__=e=>Wn(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),N(t,e=>e.stop,{discard:!0})}),v_=()=>{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},y_=e=>U(Dn,t=>{let n=g_.get(t);if(n!==void 0)return e(n.hooks);let r=v_();return g_.set(t,r),c(le(t,__(r)),e(r.hooks))});W(function*(e,t,n){let r=yield*h_,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*y_(t=>p_(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*y_(t=>d_(e,{...i,...t})):yield*Be(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*y_(t=>m_(e,{...i,...t}))});var b_=W(function*(e,t){let n=yield*h_;return yield*y_(r=>m_(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),x_=W(function*(e,t,n){let r=yield*h_,i=yield*r.nextSessionId,a=yield*rg(i);r.inspection=a;let o=Ug(),s=yield*cr(),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*Se(y_(n=>{let r={...c,...n};return t===`generic`?p_(e,r):t===`compiled`?e.execution?._tag===`Compiled`?d_(e,r):Be(Error(`Machine cannot force the compiled runtime for generic process logic`)):m_(e,r)}).pipe(ur(e=>xt(s,e))));return{id:n?.id??i,sessionId:i,changes:wt(ft(s).pipe(bt(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),S_=((e,t)=>x_(e,`auto`,t));Ar({_tag:ln(`MachineSnapshot`),version:ln(2),active:On(Ar({path:Ft,value:f(jn)})),completed:f(On(Ar({path:Ft,output:f(jn)}))),history:f(xr(Ft,Ar({mode:rn([`shallow`,`deep`]),active:On(Ft),values:xr(Ft,jn)})))});var C_=(e,t,n)=>{let r=Q(e,n);if(r.type===`compound`){let r=Tp(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return C_(e,t,r)}return r.output},w_=(e,t)=>ie(function*(){let n=yield*gp(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)||!Op(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=C_(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*Sf(e,o,t.output,{boundary:`output`,state:a}))}return sp(e,{...n,outputs:r})}).pipe(O(t=>T_(e,t))),T_=(e,t)=>{if(on(t))return R(Nt(t,t=>t instanceof $u?t:new $u({machineId:e.id,boundary:`configuration`,cause:Hn(t)})));let n=kn(t);return M(n)&&n.value instanceof $u?it(n.value):it(new $u({machineId:e.id,boundary:`configuration`,cause:t}))},E_=e=>e.length===0?G:e.length===1?e[0]:xn(e,{discard:!0}),D_=(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}),O_=new WeakMap,k_=e=>{let t=O_.get(e);if(t!==void 0)return t;let n=Object.values(sd(e).handlers).some(e=>e.invoke!==void 0);return O_.set(e,n),n},A_=$t(mt()),j_=(e,t)=>{let n=qh(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=vh(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return dh(e,r)?fh(e,r,uh).pipe(bt(yt)):void 0},o=e=>Wn(()=>l(e)??A_),s=(e,t,r,a,s)=>{let l=a.commands.length===0?void 0:yh(a.commands,e.scope),u=a.emittedEvents.length===0?void 0:bh(a.emittedEvents,i(e)),d=()=>{let i=Wn(()=>(t&&e.completeMessage({before:r,plan:D_(a,n.snapshot),after:s}),a.done?$t(yt(a.output)):o(e)));return u===void 0?i:u.pipe(c(i))},f=()=>{let t=e.commit(s),n=d(),r=t===void 0?n:t.pipe(c(n));return t===void 0&&u===void 0?r:e.runAfterChanges(r)};return l===void 0?f():e.runAfterChanges(l.pipe(c(Wn(f))))},l=(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(st(e))return;r=e.value}let a=pg(r),l=a?r.event:r,u=t.state(),d;try{d=n.plan(t.executionState??n.fromConfiguration(mp(e,u)),l,a,t.scope)}catch(e){return ad(e)}if(t.executionState=d.next,d.microsteps.length===0){a&&t.completeMessage({before:u,plan:D_(d,n.snapshot),after:u});continue}let f=n.snapshot(d.next);if(d.commands.length>0||d.emittedEvents.length>0||d.done)return s(t,a,u,d,f);let p=t.commit(f);if(p!==void 0)return t.runAfterChanges(p.pipe(c(Wn(()=>(a&&t.completeMessage({before:u,plan:D_(d,n.snapshot),after:f}),o(t))))));a&&t.completeMessage({before:u,plan:D_(d,n.snapshot),after:f})}};return{run:e=>kg(a(e)??o(e),e.scope),runSync:(e,t)=>{let n=a(e);n!==void 0&&e.beginMessage(t);let r=n??l(e,t);return r===void 0?void 0:kg(r,e.scope)}}},M_=class{initialized=!1;initial;constructor(e){this.initial=e}},N_=(e,t)=>{let n=qh(e);return r=>{let i=r.state();if(t&&dh(e,i))return fh(e,i,uh).pipe(bt(yt));let a=r.scope,o=r.executionState,s=o instanceof M_?o:new M_;r.executionState=s;let l,u,d;return d=Wn(()=>{let t=r.pollMessage();if(st(t))return u=void 0,$t(mt());let o=t.value,s=pg(o),f=s?o.event:o,p=i,m;try{m=n.plan(u??n.fromConfiguration(mp(e,i)),f,s,a)}catch(e){return ad(e)}if(u=m.next,m.microsteps.length===0)return s&&r.completeMessage({before:p,plan:D_(m,n.snapshot),after:i}),d;let h=m.microsteps.some(e=>e.changed),g=h?m.microsteps.flatMap(e=>e.exitPaths):[],_=new Map;if(h){for(let e of m.microsteps)if(e.changed)for(let t of e.entryPaths)_.set(t,e.event)}let v=n.toConfiguration(m.next),y=n.snapshot(m.next),b=[];if(m.commands.length>0&&b.push(yh(m.commands,a)),h){let e=r.ownedChildren.stopPaths(g);e!==void 0&&b.push(e)}let x=[];if(m.emittedEvents.length>0&&x.push(bh(m.emittedEvents,l??=vh(e,a))),m.done)x.push(r.ownedChildren.stopAll());else if(h)for(let[t,n]of _){let i=s_(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=Wn(()=>(s&&r.completeMessage({before:p,plan:D_(m,n.snapshot),after:y}),m.done?$t(yt(m.output)):d));return x.length===0?e:E_(x).pipe(c(e))},w=()=>{let e=S(),t=C(),n=e===void 0?t:e.pipe(c(t));return e===void 0&&x.length===0?n:r.runAfterChanges(n)};return b.length===0?w():r.runAfterChanges(E_(b).pipe(c(Wn(w))))}),kg(Wn(()=>{if(s.initialized)return d;let t=s.initial,o=t?.activeConfiguration??mp(e,i);u=t?.configuration??n.fromConfiguration(o);let l=s_(e,a,r.ownedChildren,o,t?.entryPaths??ap(e,o),uh);return s.initial=void 0,s.initialized=!0,l===void 0?d:l.pipe(c(d))}),a)}},P_=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},F_=(e,t)=>{let n=k_(e),r=qh(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=P_(t);return n?{...r,executionState:new M_({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw od(e)}},s=t=>a===void 0?kg(_h(Tm(e,t),...i).pipe(U(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:yh(n.commands,t),i=n.emittedEvents.length===0?void 0:bh(n.emittedEvents,vh(e,t)),a=$t(P_(n));return r===void 0?i===void 0?a:i.pipe(c(a)):i===void 0?r.pipe(c(a)):r.pipe(c(i),c(a))})),t):Tt({try:()=>o(t),catch:od});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:N_(e,t._tag===`Resume`)}:{_tag:`Owned`,...j_(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?kg(w_(e,t.snapshot),n):s(n).pipe(bt(e=>e.state)),run:t=>kg(ie(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*Be(Error(`Machine statechart started without acknowledged mailbox access`));let c,l=yield*o;if(dh(e,l))return yield*fh(e,l,uh);if(!n){let n,o=mt(),u;for(;c===void 0;){let d=M(o)?o.value:yield*a;o=mt();let f=pg(d),p=f?d.event:d,m=l,h;try{h=gh(e,Uf(n??mp(e,l),t),p)}catch(e){return yield*ad(e)}if(n=h.next,h.microsteps.length>0){let n=sp(e,h.next);yield*yh(h.commands,t),yield*s(n),l=n,h.emittedEvents.length>0&&(yield*bh(h.emittedEvents,u??=vh(e,t))),h.done&&(c={output:h.output})}f&&r({before:m,plan:D_(h,t=>sp(e,t)),after:l}),c===void 0&&(o=yield*i,st(o)&&(n=void 0))}return c===void 0?yield*Be(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}let u=t.ownedChildren;if(u===void 0)return yield*Be(Error(`Invoking statechart started without an owned child runtime`));let d=(n,r,i)=>s_(e,t,u,n,r,i)??G,f=e=>u.stopPaths(e)??G;return yield*ie(function*(){let n=yield*gp(e,l);yield*d(n,ap(e,n),uh),n=void 0;let o=mt(),p;for(;c===void 0;){let m=M(o)?o.value:yield*a;o=mt();let h=pg(m),g=h?m.event:m,_=l,v;try{v=gh(e,Uf(n??mp(e,l),t),g)}catch(e){return yield*ad(e)}if(n=v.next,v.microsteps.length>0){let n=v.microsteps.some(e=>e.changed),r=v.microsteps.flatMap(e=>e.exitPaths),i=new Map;for(let e of v.microsteps)if(e.changed)for(let t of e.entryPaths)i.set(t,e.event);let a=sp(e,v.next);if(yield*yh(v.commands,t),n&&(yield*f(r)),yield*s(a),l=a,v.emittedEvents.length>0&&(yield*bh(v.emittedEvents,p??=vh(e,t))),v.done)c={output:v.output},yield*u.stopAll();else if(n)for(let[e,t]of i)yield*d(v.next,[e],t)}h&&r({before:_,plan:D_(v,t=>sp(e,t)),after:l}),c===void 0&&(o=yield*i,st(o)&&(n=void 0))}return c===void 0?yield*Be(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}).pipe(ur(()=>u.stopAll()))}),t)}},I_=new WeakMap,L_=(e,...t)=>{if(t.length>0)return F_(e,{_tag:`Initial`,args:t});let n=I_.get(e);if(n!==void 0)return n;let r=F_(e,{_tag:`Initial`,args:t});return I_.set(e,r),r},R_=(e,t)=>F_(e,{_tag:`Resume`,snapshot:t}),z_=(e,...t)=>S_(L_(e,...t),e.id===void 0?void 0:{id:e.id}),B_=(e,t)=>b_(R_(e,t),e.id===void 0?void 0:{id:e.id}),V_={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`]},H_=[`title`,`description`,`documentation`],U_=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),W_=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},G_=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},K_=e=>Number.isFinite(Number(e)),q_=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,J_=(e,t)=>{if(t.has(e))return`opaque`;if(pt(e)||Yn(e)||Le(e)||a(e)||lr(e)||F(e))return`tagged`;if(ue(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return qt(e)?q_(e.types.map(e=>J_(e,n))):St(e)?J_(e.thunk(),n):ct(e)?`opaque`:`untagged`},Y_=(e,t=new Set)=>{if(t.has(e))return`opaque`;if(oe(e)){let n=e.propertySignatures.find(({name:e})=>e===`_tag`)?.type;return n===void 0||_t(n)?`untagged`:J_(n,new Set(t).add(e))}let n=new Set(t).add(e);return qt(e)?q_(e.types.map(e=>Y_(e,n))):St(e)?Y_(e.thunk(),n):ct(e)?`opaque`:`untagged`},X_=e=>re(e)&&Y_(Fn(e.ast))!==`untagged`,Z_=(e,t,n)=>{let r=W_(t,n);return typeof n==`symbol`?G_(e,r,`state keys must be strings, not symbols`):typeof n==`number`?G_(e,r,`state keys cannot use numeric forms`):n===``?G_(e,r,`state keys cannot be empty`):n===`__proto__`?G_(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?G_(e,r,`state keys cannot contain "."`):K_(n)?G_(e,r,`state keys cannot use numeric forms`):r},Q_=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&G_(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&G_(e,W_(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},$_=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!U_(n,r))return;let a=n[r];(typeof a!=`object`||!a||re(a)||a.type!==`history`)&&G_(e,`${t}.${r}`,i)},ev=(e,t,n,r)=>{let i=V_[r];for(let a of Reflect.ownKeys(n))i.includes(a)||G_(e,t,`${r} states cannot declare property "${String(a)}"`)},tv=(e,t,n)=>{Q_(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))H_.includes(r)||G_(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&G_(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},nv=(e,t,n,r,i=!1)=>{Q_(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:Z_(e,n,a),s=t[a];if(re(s)){X_(s)||G_(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}Q_(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:U_(s,`states`)?`compound`:`atomic`;if(ev(e,o,s,l),l===`history`||l===`choice`){r||G_(e,o,`${l} states must be declared below an active parent state`),U_(s,`annotations`)&&tv(e,o,s.annotations),l===`history`&&U_(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&G_(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=U_(s,`schema`);u&&!X_(s.schema)&&G_(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&U_(s,`annotations`)&&G_(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&U_(s,`annotations`)&&tv(e,o,s.annotations),l===`atomic`&&U_(s,`type`)&&s.type!==`active`&&G_(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&G_(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&U_(s,`type`)&&s.type!==`active`&&G_(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&G_(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&U_(s,`output`)&&!re(s.output)&&G_(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?($_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&$_(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),nv(e,s.states,o,!0)):l===`parallel`&&(U_(s,`states`)||G_(e,`${o}.states`,`parallel states must declare child regions`),$_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),nv(e,s.states,o,!0))}},rv=e=>typeof e==`object`&&e?Object.freeze({...e}):e,iv=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(re(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=iv(i.states)),`annotations`in i&&(a.annotations=rv(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},av=e=>iv(e),ov=(e,t=``)=>{if(re(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(U_(n,`fields`)&&(U_(n,`schema`)&&G_(`Machine.state`,t,`declare fields or schema, not both`),Q_(`Machine.state`,t,n.fields,`state fields`),U_(n.fields,`_tag`)&&G_(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=_(t,n.fields),delete r.fields),U_(n,`states`)){Q_(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))Z_(`Machine.state`,t,r),e[r]=ov(n.states[r],r);r.states=e}return t===``?(nv(`Machine.state`,{"":r},``,!1,!0),av({"":r})[``]):r},sv=`~effect/Machine`,cv=`~effect/Machine/ChildMachine`,lv={...sr,...Vt,[sv]:sv,toJSON(){return{_id:`Machine`}}},uv=(e,t)=>{let n=Object.create(lv);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,gf(e,n),n},dv=e=>e.kind===`none`?xd:bd(e.kind,e.path,e.scope,e.updatePath),fv=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),pv=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],mv=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!Zn(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(!Sd(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`||!qf(r,e.path)||!qf(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}},hv=(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(!wd(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(!Ed(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(Ed(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=Ed(e)?e.target:e,i=typeof r==`object`&&r&&Zn(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&&qf(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},gv=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:Nd};delete a.target;let o=e.resolve(a,n);if(Pd(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return hv(o,e.selection,r),o},_v=e=>e.kind===`update`?void 0:e.path,vv=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},yv=(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||vv(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||!Zn(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!Sd(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:dv(a)})}))},bv=(e,t,n,r={},i)=>{let a=Lp(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 Td(zd(i.path,i.parent),Bp(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`?Fd(n.path,n.parent):zd(n.path,n.parent)}if(e.kind===`update`)return Bp(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 Td(zp(t,e.path,r,i),Bp(t,e.updatePath,n))}return zp(t,e.path,a,i)},xv=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>Dd(t,a,e.key,e.selection.kind===`none`?Ad():bv(e.selection,n,r,o,i))]))),Sv=(e,t,n)=>{if(t.kind===`none`){if(!jd(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`);hv(e,t,n)}},Cv=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),wv=(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:mv({target:()=>qp(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?Nd():s(e,t)}}let p=qp(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 Nd();if(s!==void 0)return s(e,a);if(h)return bv(p,r,t,{input:g(e)});let l=u(e);return bv(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)}}},Tv=(e,t,n,r,i)=>{let a=wv(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(Zn(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=yv(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:Nd};delete s.target,s.select=xv(l,u,t,r,n);let d=a(s,o);if(Pd(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(!Od(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 Sv(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=>_v(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:_v(e.selection),selection:fv(e.selection),updates:pv(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=mv(a,void 0,t,n,i),u=(e,r)=>({result:gv(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:_v(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:_v(l.selection),selection:fv(l.selection),updates:pv(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},Ev=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=Tv(e[a],t,n,r,a);return i},Dv=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=Jp(r,e,n,e=>Cv(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=Tv(i[e],t,n,r,e));return am(i,n)});return sm(i,n),Array.isArray(e)?Object.freeze(i):i[0]},Ov=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!Zn(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=Ev(d,t,s,i)),u.always!==void 0&&(u.always=Tv(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=Tv(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=Tv(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=Dv(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!Zn(u.choice,`transition`)||typeof u.choice.transition!=`function`||!Zn(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=Vd(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`);Ov(e,t,r.states,s,i,l)}}},kv=e=>e===``?Up:e,Av=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=Gd(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(!qf(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${kv(e.source)}" updates "${kv(n)}" before choice "${t}", whose ${r} targets "${kv(o)}" outside that owner`)}}}}}}},jv=(e,t)=>(n=>{let r=im(t.root,n),i=Object.assign(Object.create(lv),e);if(gf(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=Hd(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:nm(n.root);i.initial=e=>({...Ld(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);Ov(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Pf(i,i.input,e))},{"":r.handlers});let s=uv(i,o);return Av(s),s}),Mv=e=>{let t=ov(e),n=Nv();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},Nv=()=>({path:(e=>e),get:((e,t)=>Zd(e,t).pipe(Kn(e=>e.value))),getWithParents:((e,t)=>{let n={};return Zd(e,t,n).pipe(Kn(e=>({value:e.value,parents:n})))}),getSnapshot:Zd,matches:((e,t)=>M(Zd(e,t)))}),Pv=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(Vt);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??xf(`internal`,[]),n.emittedEvents=e.emittedEvents??xf(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=jv(n,Gp(e.root,e)),hf(n),n},Fv=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?[]:[Er(e)]},Iv=e=>xf(`public`,Fv(e)),Lv=(e,t)=>Rv(e,t,e=>t.input===void 0?L_(t):L_(t,e)),Rv=(e,t,n)=>({[cv]:cv,id:e,machine:t,[Zp]:n}),zv=z_,Bv=B_,Vv=(e,t)=>{try{let n=ph(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},Hv=(e,t)=>{try{let n=Rt(w_(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!dh(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=Rt(fh(e,r,uh));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},Uv={spawn:()=>Be(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>it(new rd),stop:()=>G},Wv=(e,t)=>{if(e.snapshot.status!==`active`)return mt();try{let n=e.machine,r=mp(n,e.snapshot.state);for(let e of ap(n,r)){let i=wp(n,e);for(let a of cm(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({...Wf(r)??Em(n,r),children:Uv,state:r.values.get(e),containingState:ip(n,r,e),ancestors:rp(n,r,e),event:uh}):a.input);let s=Vv(i,i.input===void 0?[]:[o]);return s===void 0?void 0:yt(s)}}return mt()}catch{return}},Gv=class extends m(`ChildNotActiveError`){},Kv=new WeakMap,qv=new WeakMap,Jv=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return jr(e);let t=Tr(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=Ze(t,n);M(r)&&r.value===e&&T(t,n)});return r=>{let i=Ze(t,r);if(M(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return b(t,r,o),n.register(a,{key:r,entry:o}),a}},Yv=(e,t)=>hr(Ee(t,e=>e.stop).pipe(cn(t=>An(()=>e.setSelf(se(t)))),U(()=>Jt))),Xv=(e,t)=>Yv(e,e.result(t).pipe(U(e=>e.start))),Zv=(e,t,n)=>Yv(e,Bv(t,n)),Qv=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[_r](t):t(e),$v=(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}},ey=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},ty=e=>e.snapshot,ny=Je(e=>e.registry).pipe(Ue),ry=e=>Wn(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,G):c(t,ry(e))}),iy=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},ay=(e,t,n)=>ge(n=>{let r=ot(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:L(Kn(n.self(),Gn),()=>Ir(!0))},(r,i)=>{let a=r.get(e),o=r.get(ny),s=iy(t,o);nt(a)||s.draining?(r.setSelf(Ir(!0)),s.pending.push(be(o,e).pipe(U(e=>n(e,i)),d,bt(e=>{let t=de(e);r.setSelf(s.pending.length===0?t:Gn(t))}))),s.draining||(s.draining=!0,At(ry(s)))):l(a)?r.setSelf(ot(a,()=>void 0)):pn(n(a.value,i),{onExit:e=>r.setSelf(de(e))})}).pipe(hn),oy=e=>Je(t=>{let n=t(e);return nt(n)?Ir(n.waiting):l(n)?z(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?z(n.value.cause,{previous:t.self(),waiting:n.waiting}):se(n.value.state,{waiting:n.waiting})}).pipe(we(Nn),o($v(t=>[Qv(e,t)],e=>ot(e,e=>e.state)))),sy=e=>Je(t=>{let n=t(e);if(nt(n))return Ir(n.waiting);if(l(n))return z(n.cause,{previous:t.self(),waiting:n.waiting});if(st(n.value)){let e=t.self();return M(e)&&l(e.value)?e.value:se(mt(),{waiting:n.waiting})}return n.value.value.status===`error`?z(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):se(yt(n.value.value.state),{waiting:n.waiting})}).pipe(we(Nn),o($v(t=>[Qv(e,t)],e=>ot(e,Kn(e=>e.state))))),cy=(e,t)=>Je(n=>{let r=n(e);if(nt(r))return Ir(r.waiting);if(l(r))return z(r.cause,{previous:n.self(),waiting:r.waiting});if(st(r.value))return se(mt());let i=r.value.value,a=ir(i.child(t)),o=pn(g.pipe(c(i.childChanges(t).pipe(sn(e=>An(()=>n.setSelf(se(e))))))));return n.addFinalizer(o),se(a)}).pipe(hn),ly=(e,t)=>lg(e)?e[cg](()=>t(ir(e.snapshot))):pn(e.changes.pipe(sn(e=>An(()=>t(e))))),uy=(e,t,n)=>{let r=Je(t=>{let n=t(e);if(nt(n))return Ir(n.waiting);if(l(n))return z(n.cause,{previous:t.self(),waiting:n.waiting});if(st(n.value))return se(mt());let r=n.value.value;return t.addFinalizer(ly(r,e=>t.setSelf(se(yt(e))))),se(yt(ir(r.snapshot)))}).pipe(o($v(()=>[],()=>{let e=n();return e===void 0?Ir(!0):se(Kn(e,ty),{waiting:!0})}))),i=new WeakMap,a=e=>M(e)?$t(e.value):it(new Gv({id:t.id})),s=ay(e,i,(e,t)=>U(a(e),e=>e.send(t))),c=ay(e,i,(e,t)=>U(a(e),e=>e.stop)),u=dy(e,n);return{ref:e,snapshot:r,result:sy(r),send:s,stop:c,child:u}},dy=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=jr(n=>{let r=Lv(n,a);return uy(cy(e,r),r,ey(()=>{let e=t();return e===void 0||st(e)?e:Wv(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},fy=(e,t,n)=>{let r=hn(e),i=Je(e=>{let t=e(r);if(nt(t))return Ir(t.waiting);if(l(t))return z(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(ly(n,t=>e.setSelf(se(t,{waiting:t.status===`active`}))));let i=ir(n.snapshot);return se(i,{waiting:i.status===`active`})}).pipe(o($v(()=>[],()=>{let e=n();return e===void 0?Ir(!0):se(ty(e),{waiting:!0})}))),a=new WeakMap,s=ay(r,a,(e,t)=>e.send(t)),c=ay(r,a,(e,t)=>e.stop),u=dy(Sr(r,yt),()=>{let e=n();return e===void 0?void 0:yt(e)}),d={ref:r,snapshot:i,result:oy(i),send:s,stop:c,child:u};return qv.set(d,t),d},py=(e,t)=>Zd(e,t).pipe(Kn(e=>e.value)),my=(e,t)=>Zd(e,t),hy=(e,t)=>Sr(e,t).pipe(we(Nn),o($v(t=>[Qv(e,t)],e=>ot(e,t)))),gy=new WeakMap,_y=(e,t,n,r)=>{let i=gy.get(e);i===void 0&&(i=new Map,gy.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},vy=(e,t)=>_y(e,`select`,t,()=>hy(e.result,e=>py(e,t))),yy=(e,t)=>_y(e,`selectSnapshot`,t,()=>hy(e.result,e=>my(e,t))),by=(e,t)=>_y(e,`selectChild`,t,()=>hy(e.result,rt(e=>py(e,t)))),xy=(e,t)=>_y(e,`selectSnapshotChild`,t,()=>hy(e.result,rt(e=>my(e,t)))),Sy=(e,t)=>_y(e,`matches`,t,()=>hy(e.result,e=>M(Zd(e,t)))),Cy=(e,t)=>_y(e,`matchesChild`,t,()=>hy(e.result,u(e=>M(Zd(e,t))))),wy=(e,t,n)=>{let r=e.atom(()=>zv(t,...n)),i=fy(e.atom(e=>Xv(e,r)),t,ey(()=>Vv(t,n)));return Kv.set(i,r),i},Ty=(e,t,n)=>fy(e.atom(e=>Zv(e,t,n)),t,ey(()=>Hv(t,n))),Ey=(e,t,n)=>{let r={owner:e,source:t},i=v(t,e=>e(r.source),{initialValueTarget:t}).pipe(we((e,t)=>r.source.equals(e,t)),o(e=>Qv(r.source,e)));return n!==void 0&&(i=i.pipe(yn(n))),i},Dy=(e,t)=>{let n=Jv(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=Jv(r=>{let a=n(r);return Ey(a,i(a.bridge),t.label?.(r,e))})}return r},Oy=e=>{let t=((t,...n)=>wy(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>Ty(e,t,n)),family:((t,n)=>Dy(n=>wy(e,t,[n]),n))}},ky=wn(2,vy);wn(2,yy),wn(2,by),wn(2,xy),wn(2,Sy),wn(2,Cy);var Ay=Oy,jy=e=>My(X.useContext(Nu),e),My=(e,t)=>{let n=X.useMemo(()=>{let n,r,i=e=>I(e)?(n=e,e):nt(e)&&n!==void 0?n:e;return{subscribe:n=>e.subscribe(t,n),snapshot:()=>i(e.get(t)),serverSnapshot:()=>r??=i(Dr(t,e))}},[e,t]);return X.useSyncExternalStore(n.subscribe,n.snapshot,n.serverSnapshot)},Ny=jy,Py=e(zr(),1);function Fy(e){let t=Py.unstable_scheduleCallback(4,e);return()=>Py.unstable_cancelCallback(t)}var Iy=X.createContext(Oe({scheduleTask:Fy,defaultIdleTTL:400})),Ly=new WeakMap,Ry=0,zy=new Set;function By(e){Ry++;try{return e()}finally{Ry--}}function Vy(e){if(Ry===0)return e();zy.size===0&&queueMicrotask(Hy),zy.add(e)}function Hy(){for(let e of zy)zy.delete(e),e()}function Uy(e,t){let n=Ly.get(e);n===void 0&&(n=new WeakMap,Ly.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,()=>Vy(n));return()=>{i--,zy.delete(n),r()}},snapshot(){return By(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:By(()=>Dr(t,e))}),a.value}};return n.set(t,o),o}function Wy(e,t){let n=Uy(e,t);return X.useEffect(Hy),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Gy(e,t,n){let r=Uy(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(Hy),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Ky=(e,t)=>{let n=X.useContext(Iy);return t?Gy(n,e,t):Wy(n,e)};function qy(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=Bn(be(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Jy):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Jy=e=>{if(It(e))return e.value;throw We(e.cause)},Yy=(e,t)=>{let n=X.useContext(Iy);return[Wy(n,e),qy(n,e,t)]};function Xy({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 Zy(e){let t=X.useRef(!0);t.current&&(t.current=!1,e())}function Qy(e,t,n,r,i,a,o,s,c,l=2){let u=oa(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 To(n.current,u)?void 0:u}function $y(e){return e==null?ha:e.type.startsWith(`key`)?za:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?Lo:ha}var eb=X.createContext(void 0),tb=X.createContext(void 0),nb=X.createContext(void 0),rb=X.createContext(!1),ib=X.createContext(``);function ab(){let e=X.useContext(eb);if(!e)throw Error(Ja(22));return e}function ob(){let e=X.useContext(tb);if(!e)throw Error(Ja(23));return e}function sb(){let e=X.useContext(nb);if(!e)throw Error(Ja(24));return e}function cb(){return X.useContext(ib)}function lb(){return X.useContext(rb)}function ub(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 db=(e,t)=>Object.is(e,t);function fb(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function pb(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!ub(e,t,(e,t)=>fb(e,t,n)):e!==t}function mb(e,t,n){return e?e.some(e=>e!==void 0&&fb(t,e,n)):!1}function hb(e,t,n){return e?e.findIndex(e=>e!==void 0&&fb(e,t,n)):-1}function gb(e,t){if(t!==db)return n=>mb(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 _b(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(gb(t,n)):hb(e,t,n);return i===-1?null:i}function vb(e,t,n,r,i,a){return mb(r,t,i)?a!=null&&e>a&&mb(r,n[a],i)?a:e:e===a?_b(n,r,i,!0):a}function yb(e,t,n){return e.filter(e=>!fb(t,e,n))}function bb(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function xb(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function Sb(e){return xb(e?.[0])}function Cb(e){return Sb(e)?e.flatMap(e=>e.items):e}function wb(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(Sb(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 Tb(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 bb(e)}function Eb(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?bb(e.value):bb(e)}var Db={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?wb(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=>fb(t,e,n)):fb(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},Ob=`data-valid`,kb=`data-invalid`,Ab={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},jb={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Mb={disabled:!1,...jb},Nb={valid(e){return e===null?null:e?{[Ob]:``}:{[kb]:``}}},Pb={invalid:void 0,name:void 0,validityData:{state:Ab,errors:[],error:``,value:``,initialValue:null},setValidityData:ti,disabled:void 0,setTouched:ti,setDirty:ti,setFilled:ti,setFocused:ti,focusOwnerRef:{current:void 0},validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Mb,registerFieldControl:ti,validation:{getValidationProps:(e,t=Ki)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:ti,getInputControl:()=>null,commit:async()=>{},change:ti}},Fb=X.createContext(Pb);function Ib(e=!0){let t=X.useContext(Fb);if(t.setValidityData===ti&&!e)throw Error(Ja(28));return t}function Lb(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Ib(),s=Mi(()=>Symbol());J(()=>{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]),J(()=>{let e=s.current;return()=>{o(e,void 0)}},[o,s])}var Rb=X.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:ti,validationMode:`onSubmit`,submitCountRef:{current:0}});function zb(){return X.useContext(Rb)}function Bb(e){return oi(e,`base-ui`)}var Vb=X.createContext({controlId:void 0,registerControlId:ti,resetControlId:ti,labelId:void 0,setLabelId:ti,messageIds:[],setMessageIds:ti,getDescriptionProps:e=>e});function Hb(){return X.useContext(Vb)}function Ub(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=Hb(),o=Bb(),s=Mi(()=>Symbol()),c=X.useRef(!1),l=X.useRef(!1),u=q(()=>{c.current&&i!==ti&&(c.current=!1,i(s.current,void 0))});return J(()=>{if(!n||i===ti){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]),J(()=>u,[u]),(n?r:void 0)??t??o}function Wb(e){return e==null?void 0:`${e}-popup`}function Gb(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function Kb(e){return Array.isArray(e)?e.map(e=>Kb(e)).join(`,`):e==null?``:String(e)}var qb=new Map;function Jb(e={}){let{locale:t,...n}=e,r={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...n},i=`${Kb(t)}|${JSON.stringify(r)}`,a=qb.get(i);if(a)return a;let o=new Intl.Collator(t,r),s={contains(e,t,n){if(!t)return!0;let r=Tb(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=Tb(e,n);return o.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=Tb(e,n),i=t.length;return r.length>=i&&o.compare(r.slice(r.length-i),t)===0}};return qb.set(i,s),s}var Yb=Jb;function Xb(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 Zb(e,t){let n=X.useRef(e),r=q(t);J(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Qb(e,t){let{onClick:n,onPointerDown:r}=Xb(q((n,r)=>{(typeof e==`function`?e():e)||t(r||(Aa?`touch`:``))}));return X.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function $b(e){let[t,n]=X.useState(null),r=Qb(e,n);return Zb(e,t=>{t&&!e&&n(null)}),X.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var ex=Symbol(`none`),tx={value:ex,index:-1};function nx(e,t,n){let r=e.get(t);if(r!==void 0||n===db)return r;for(let[r,i]of e)if(fb(r,t,n))return i}function rx(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=db,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:z}=zb(),{setDirty:te,validityData:B,setFilled:ne,name:re,disabled:V,setTouched:H,setFocused:ie,validationMode:ae,validation:oe}=Ib(),se=fu(),ce=Ub({id:t}),le=Yb({locale:R}),ue=Array.isArray(y)?null:y;if(ue&&typeof ue.label!=`function`)throw Error(Ja(100));let de=ue?ue.data:y,fe=ue?.value,pe=fe?void 0:de,me=X.useMemo(()=>{if(!b||!fe)return;let e=Cb(b),t=e.map(fe),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 nx(n,r,i)}}},[b,fe]),he=X.useMemo(()=>ue?e=>ue.label(e,A,e=>{let t=me?.findItem(e,A);return t==null?Tb(e,O):ue.itemLabel(t)}):O,[ue,O,me,A]),ge=X.useMemo(()=>ue?Object.assign(e=>ue.itemLabel(e),{selected:e=>Tb(e,he)}):O,[ue,he,O]);function _e(e){return Tb(e,he)}let[ve,ye]=X.useState(!1),[be,xe]=X.useState(null),Se=X.useRef(be),Ce=X.useRef([]),we=X.useRef([]),Te=X.useRef(null),Ee=X.useRef(null),De=X.useRef(null),Oe=X.useRef(null),ke=X.useRef(null),Ae=X.useRef(!1),je=X.useRef(null),Me=X.useRef(null),Ne=X.useRef(null),Pe=X.useRef(tx),Fe=X.useRef(null),Ie=X.useRef([]),Le=X.useRef(null),Re=V||m,ze=re??f,Be=u===`multiple`,Ve=u===`single`,He=s!==void 0||o!==void 0,Ue=de!==void 0,We=b!==void 0,Ge;Ge=w===`always`?`always`:w?`input-change`:!1;let[Ke,qe]=Xy({controlled:i,default:Be?r??Fo:r,name:`Combobox`,state:`selectedValue`}),Je=X.useMemo(()=>x===null?()=>!0:x===void 0?Gb(le,ge):x,[x,le,ge]),Ye=Mi(()=>He?o??``:Ve?_e(Ke):``).current,[Xe,Ze]=Xy({controlled:s,default:Ye,name:`Combobox`,state:`inputValue`}),[Qe,$e]=Xy({controlled:c,default:l,name:`Combobox`,state:`open`}),et=Sb(de),U=!Qe&&be!==null?be:String(Xe).trim(),tt=Ve?_e(Ke):``,nt=Ve&&!ve&&U!==``&&tt.length===U.length&&le.contains(tt,U),rt=nt?``:S??U,it=Ue&&We&&nt&&(!ue||ue.hasValue(Ke,A)),at=X.useMemo(()=>de?Cb(de):Fo,[de]),ot=X.useMemo(()=>{if(b&&!it)return b;if(!de)return Fo;if(et){let e=de,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;Je(t,rt,ge)&&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;Je(t,rt,ge)&&e.push(t)}return e},[b,it,de,et,rt,F,Je,ge,at]),st=X.useMemo(()=>{if(me&&ot===b)return me.values;let e=Cb(ot);return fe?e.map(e=>fe(e)):e},[ot,b,me,fe]),W=Mi(()=>{let e=null;return M&&Qe&&Ue&&u!==`none`&&(e=_b(st,Ke,A,Be)),new Ua({id:ce,labelId:void 0,selectedValue:Ke,open:Qe,items:pe,selectionMode:u,name:ze,form:p,disabled:Re,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:he,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:Ki,id:ce,selectionMode:u,disabled:Re,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:ti,setOpen:ti,setInputValue:ti,setSelectedValue:ti,setIndices:ti,handleSelection:ti,forceMount:ti,requestSubmit:ti,listRef:Ce,labelsRef:we,popupRef:Te,emptyRef:ke,inputRef:Ee,startDismissRef:De,endDismissRef:Oe,chipsContainerRef:je,clearRef:Me,valuesRef:Ie,pointerDownItemRef:Le,selectionEventRef:Ne},Db)}).current,ct=u===`none`?Xe:Ke,lt=X.useMemo(()=>u===`none`?ct:Array.isArray(Ke)?Ke.map(e=>Eb(e,k)):Eb(Ke,k),[ct,k,u,Ke]),ut=q(d),dt=q(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&&Xe===tt,Ct=_s(gt),{openMethod:wt,triggerProps:Tt}=$b(Qe),Et=q(()=>lt);Lb(bt?Ct:Ee,ce,ct,Et,!Re,f);let Dt=q(()=>{de?we.current=st.map(_e):W.set(`forceMounted`,!0)}),Ot=q((e,t,n,r)=>{if(t===-1){if(Pe.current===tx)return;Pe.current=tx}else Pe.current={value:e,index:t};ut(e,Ji(n,r,{index:t}))}),kt=q(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(Ie.current[n],n,r,e.event)}),At=q((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(Ae.current=n.reason===Na,n.reason===`input-change`){Qe&&be!==null&&xe(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&ye(!0),Fe.current={hasQuery:e};let n=W.state.listElement;if(!W.state.virtualized&&n){let e=Te.current;for(let t of Qr(n.firstElementChild??n)){if(!pi(t)||(e?!K(e,t):t.getAttribute(`role`)===`dialog`))break;if(gs(t)){t.scrollTop=0;break}}}e&&Ge&&W.state.activeIndex==null&&(Qe||yt)&&W.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&W.state.inputInsidePopup&&(Fe.current={hasQuery:!1,selection:!0});Ze(t)}}),jt=q(e=>{let t=!e&&bt&&!yt&&Xe!==``&&(String(Xe).trim()===be||Xe===tt);!e&&(t||Xe===``||St)&&ye(!1),xe(null),t&&At(``,Y(Na))}),[Mt,Nt]=X.useState(!1),Pt=q((t,n)=>{if(Qe===t)return;n.reason===`escape-key`&&Ue&&st.length===0&&!ke.current&&n.allowPropagation();let r=n,i=dc(r);if(e.onOpenChange?.(t,r),Fe.current?.hasQuery&&n.reason===`input-change`===n.isCanceled&&(Fe.current=null),!n.isCanceled&&(t&&be!==null&&jt(n.reason===Da),!t&&ve&&(Ve?(yt||xe(U),U===``&&ye(!1)):Be&&(yt||xe(U),bt&&kt({activeIndex:null}),(!bt||yt)&&At(``,Y(Na,n.event,void 0,{isItemPress:n.reason===$a})))),t||Nt(i()),$e(t),!t&&bt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(H(!0),ie(!1),ae===`onBlur`))){let e=u===`none`?Xe:Ke;oe.commit(e)}}),G=q((e,t)=>{a?.(e,t),!t.isCanceled&&(qe(e),(u===`none`&&Te.current&&N||Ve&&!W.state.inputInsidePopup)&&At(_e(e),Y(t.reason,t.event)))}),Ft=q((e,t)=>{let n=da(e),r=Ne.current??e;Ne.current=null;let i=Y($a,r),a=ho(n,`a`)?.getAttribute(`href`);if(a)a.startsWith(`#`)&&Pt(!1,i);else if(Be){let e=Array.isArray(Ke)?Ke:[],n=mb(e,t,A),r=n?yb(e,t,A):[...e,t];if(G(r,i),i.isCanceled||!(Ee.current&&Ee.current.value.trim()!==``))return;if(W.state.inputInsidePopup){At(``,Y(Na,i.event,void 0,{isItemPress:!0}));let e=Fe.current;e&&!n&&(e.toggledValue=t)}else Pt(!1,i)}else{if(G(t,i),i.isCanceled)return;Pt(!1,i)}}),It=q(()=>{let e=oe.inputRef.current?.form??W.state.inputElement?.form;e&&typeof e.requestSubmit==`function`&&e.requestSubmit()}),Lt=q(()=>{if(dt?.(!1),ye(!1),xe(null),kt(u===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),Be&&Ee.current&&Ee.current.value!==``&&!Ae.current&&At(``,Y(Na)),Ve){if(W.state.inputInsidePopup)Ee.current&&Ee.current.value!==``&&At(``,Y(Na));else{let e=_e(Ke);Ee.current&&Ee.current.value!==e&&At(e,Y(e===``?Na:ha))}}}),Rt=X.useMemo(()=>yt&&mt?{current:ho(mt,`[role="dialog"]`)}:Te,[yt,mt]),{mounted:zt,transitionStatus:Bt,forceUnmount:Vt}=nc({open:Qe,ref:Rt,preventUnmountOnClose:Mt,setPreventUnmountOnClose:Nt,onUnmount:Lt});X.useImperativeHandle(e.actionsRef,()=>({unmount:Vt,close:()=>Pt(!1,Y(Eo))}),[Vt,Pt]),J(function(){let e=Se.current!==null&&be===null;if(Se.current=be,Qe&&(!e||!Ue)||(Qe||(Le.current=null),u===`none`))return;let t=Ue?st:Ie.current;kt({selectedIndex:_b(t,Ke,A,Be)})},[Qe,be,Ke,u,Be,Ue,st,A,kt]),J(()=>{de&&(Ie.current=st,Ce.current.length=st.length)},[de,st]),J(()=>{!Qe&&Fe.current?.hasQuery&&(Fe.current=null)},[Qe]),J(()=>{if(!Qe&&yt&&Rt.current){Fe.current=null;return}let e=Ue||We?st:Ie.current,t=Fe.current;if(t){let n=Qe||yt||W.state.positionerElement?.hidden===!1;if(t.hasQuery){let t=Ee.current;!Ge||String(Xe).trim()===``||yt&&Ge!==`always`&&(!t||Ti(t.ownerDocument)!==t)?Fe.current=null:n&&(e[0]!==void 0||!Ue&&!We)&&(W.set(`activeIndex`,0),Fe.current=null)}else if(String(Xe).trim()===``&&(Fe.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)||Ee.current&&Ee.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:Ie.current,i=hb(e,t.toggledValue,W.state.isItemEqualToValue);W.set(`activeIndex`,i===-1?_b(e,n,W.state.isItemEqualToValue,r):i)}else e?W.set(`activeIndex`,null):Ge===`always`&&W.set(`activeIndex`,0)})}}if(!Qe&&!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,ha);return}if(n>=e.length){Ot(void 0,-1,ha),W.set(`activeIndex`,null);return}let r=e[n],i=Pe.current.value,a=i!==ex&&fb(r,i,W.state.isItemEqualToValue);Pe.current.index===n&&a||Ot(r,n,ha)},[ft,Ge,Ot,We,Ue,st,yt,Qe,Rt,W,Xe]),J(()=>{ne(u===`none`?String(Xe)!==``:Be?Array.isArray(Ke)&&Ke.length>0:Ke!=null)},[ne,u,Xe,Ke,Be]),X.useEffect(()=>{Ue&&Ge&&st.length===0&&kt({activeIndex:null})},[Ue,Ge,st.length,kt]);function Ht(){Qe&&U!==``&&U!==String(Ye)&&!St&&ye(!0)}function Ut(){Qe&&be!==null&&jt(!1)}let Wt=!1;function Gt(){!Wt&&Xe!==tt&&(Wt=!0,At(tt,Y(ha)))}function Kt(){u!==`none`&&(z(ze),te(pb(Ke,B.initialValue,A)),oe.change(Ke),Ve&&!He&&!bt&&Gt())}function qt(){Ve&&!He&&!bt&&!ve&&Gt()}function Jt(){u===`none`&&(z(ze),te(Xe!==B.initialValue),oe.change(Xe))}Zb(U,Ht),Zb(Qe,Ut),Zb(Ke,Kt),Zb(tt,qt),Zb(de,qt),Zb(Xe,Jt);let Yt=kc({open:yt?!0:Qe,onOpenChange:Pt,elements:{reference:bt?gt:_t,floating:mt}}),Xt=v?`grid`:`listbox`,Zt=Qe||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=Xs(Yt,{enabled:!Re&&C,event:`mousedown-only`,toggle:!1,touchOpenDelay:bt?0:100,reason:lo}),tn=$s(Yt,{enabled:!Re&&!yt,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:yt?!0:void 0,outsidePress(e){let t=da(e);return!K(gt,t)&&!K(Me.current,t)&&!K(je.current,t)&&!K(vt,t)}}),nn=Zc(Yt,{enabled:!Re,id:ce,listRef:Ce,activeIndex:ft,selectedIndex:pt,virtual:!0,loopFocus:D,allowEscape:D&&!Ge,focusItemOnOpen:ve||u===`none`&&!Ge?!1:`auto`,focusItemOnHover:E,resetOnPointerLeave:!T,orientation:v?`horizontal`:void 0,rtl:se===`rtl`,disabledIndices:Fo,grid:v?Qy:void 0,onNavigate(e,t){(t||Qe||yt&&e===null)&&Bt!==`ending`&&kt({activeIndex:e,type:$y(t),event:t?.nativeEvent})}}),rn=X.useMemo(()=>Yr(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(()=>Yr(ic,tn.floating),[tn.floating]),on=X.useMemo(()=>Yr(nn.floating,$t.floating),[nn.floating,$t.floating]),sn=X.useMemo(()=>{let e=nn.item;return{props:e?{...e,onFocus:void 0}:Ki,id:ce,selectionMode:u,disabled:Re,readOnly:h,isItemEqualToValue:A}},[nn.item,ce,u,Re,h,A]);W.useContextCallback(`setOpen`,Pt),W.useContextCallback(`setInputValue`,At),W.useContextCallback(`setSelectedValue`,G),W.useContextCallback(`setIndices`,kt),W.useContextCallback(`handleSelection`,Ft),W.useContextCallback(`forceMount`,Dt),W.useContextCallback(`requestSubmit`,It),W.useContextCallback(`onOpenChangeComplete`,n),Zy(()=>{W.update({inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Tt,itemRoot:sn})});let cn={id:ce,selectedValue:Ke,open:Qe,mounted:zt,transitionStatus:Bt,items:pe,inline:M,popupProps:an,listProps:on,inputProps:rn,triggerProps:Tt,itemRoot:sn,openMethod:wt,selectionMode:u,name:ze,form:p,disabled:Re,readOnly:h,required:g,grid:v,virtualized:j,openOnInputClick:C,itemToStringLabel:he,modal:P,autoHighlight:Ge,isItemEqualToValue:A,submitOnItemClick:ee,hasInputValue:He};J(()=>{W.update({...cn,inputOwnsFormValue:u===`none`&&(M||!W.state.inputInsidePopup)})},[W,...Object.values(cn)]);let ln=Mo(_,oe.inputRef),un=X.useMemo(()=>({query:U,hasItems:Ue,filteredItems:ot,flatFilteredValues:st}),[U,Ue,ot,st]),dn=X.useMemo(()=>Array.isArray(ct)?``:Eb(ct,k),[ct,k]),fn=Be&&Array.isArray(Ke)&&Ke.length>0,pn=Be||u===`none`&&xt?void 0:ze,mn=X.useMemo(()=>!Be||!Array.isArray(Ke)||!ze?null:Ke.map(e=>{let t=Eb(e,k);return(0,Z.jsx)(`input`,{type:`hidden`,form:p,name:ze,value:t,disabled:Re},t)}),[Be,Ke,p,ze,k,Re]),hn=(0,Z.jsxs)(X.Fragment,{children:[e.children,(0,Z.jsx)(`input`,{...oe.getValidationProps(Re,{onFocus(){bt?gt?.focus():(Ee.current||gt)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||Re||h)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Y(ha,e.nativeEvent),i=()=>Ie.current.findIndex(e=>Eb(e,k).toLowerCase()===n||_e(e).toLowerCase()===n);function a(){if(Be)return;if(u===`none`){At(t,r);return}let e=i();e===-1&&(e=Ie.current.findIndex((e,t)=>{let r=we.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Ie.current[e];a!=null&&G?.(a,r)}Ve&&(Dt(),de&&i()===-1&&W.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:ce&&pn==null?`${ce}-hidden-input`:void 0,form:p,name:pn,autoComplete:L,disabled:Re,required:g&&!fn,readOnly:h,value:dn,ref:ln,style:pn?Zr:Bo,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),mn]});return(0,Z.jsx)(eb.Provider,{value:W,children:(0,Z.jsx)(tb.Provider,{value:Yt,children:(0,Z.jsx)(rb.Provider,{value:Ue,children:(0,Z.jsx)(nb.Provider,{value:un,children:(0,Z.jsx)(ib.Provider,{value:Xe,children:hn})})})})})}function ix(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=Yb({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?Tb(t,o):``)}return(0,Z.jsx)(rx,{...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 ax=`data-popup-side`,ox=`data-list-empty`,sx={...ds,...Nb,popupSide:e=>e?{[ax]:e}:null,listEmpty:e=>e?{[ox]:``}:null};function cx(e,t,n){let{setFocused:r,focusOwnerRef:i}=Ib(),a=q(t=>{(t?!e:i.current===a)&&(i.current=t&&a,n?.(t),r(t))});return J(()=>{let e=t.current;return e?.getRootNode()?.activeElement===e&&a(!0),()=>a(!1)},[e,t,a]),a}var lx=5;function ux(e,t){let n=dx(t);return e.clientX>=n.left-lx&&e.clientX<=n.right+lx&&e.clientY>=n.top-lx&&e.clientY<=n.bottom+lx}function dx(e){let t=e.getBoundingClientRect(),n=gi(e);if(ca)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 fx(e,t){return e??t}function px(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function mx(){return sb().filteredItems.length===0}function hx(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function gx(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var _x=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}=Ib(),{labelId:m}=Hb(),h=ab(),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=ob(),N=cb(),P=_o(),F=u||_||a,I=mx(),L=px(h),R=X.useRef(null),ee=cx(F,R);Ub({id:w?o:void 0});let z=w?o??T:o,te=fx(m,E),B;D&&w?B=S??Wb(T):D&&(B=x?.id);let ne=X.useRef(``);function re(e){ne.current=e.pointerType}let{reference:V}=Qc(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(ha))}}),{reference:H}=Xs(M,{enabled:!_,event:`mousedown`}),{buttonRef:ie,getButtonProps:ae}=Yi({native:i,disabled:F}),oe={...l,readOnly:v,open:D,disabled:F,popupSide:L,listEmpty:I,placeholder:g!==`none`&&!j},se=q(e=>{h.set(`triggerElement`,e)});return Ro(`button`,e,{ref:[t,ie,R,se],state:oe,props:[C,H,V,{id:z,tabIndex:w?0:-1,role:w?`combobox`:void 0,"aria-expanded":D,"aria-haspopup":w?`dialog`:`listbox`,"aria-controls":B,"aria-required":w&&y||void 0,"aria-readonly":w&&v||void 0,"aria-labelledby":te,onPointerDown:re,onPointerEnter:re,onFocus(){ee(!0),!F&&P.start(0,h.context.forceMount)},onBlur(e){if(!K(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(),ne.current!==`touch`&&(h.context.inputRef.current?.focus(),w||e.preventDefault()),D))return;let t=ii(e.currentTarget);function n(e){let t=h.state.triggerElement;if(!t)return;let n=da(e),r=h.state.positionerElement,i=h.state.listElement;K(t,n)||K(r,n)||K(i,n)||ux(e,t)||h.context.setOpen(!1,Y(va,e))}w&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(ai(e),h.context.setOpen(!0,Y(Ia,e.nativeEvent)),h.context.inputRef.current?.focus())}},p.getValidationProps(F,c),ae],stateAttributesMapping:sx})}),vx=X.createContext(void 0);function yx(){return X.useContext(vx)}var bx=X.createContext(void 0);function xx(e){let t=X.useContext(bx);if(t===void 0&&!e)throw Error(Ja(21));return t}var Sx=X.forwardRef(function(e,t){let n=ab(),{buttonRef:r,getButtonProps:i}=Yi({native:!1}),a=Mo(t,r);function o(e){n.context.setOpen(!1,Y(yo,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Z.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:Zr})}),Cx=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}=Ib(),{labelId:p}=Hb(),m=yx(),h=!!xx(!0),g=ab(),_=cb(),v=fu(),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=px(g),I=l||b||i,L=mx(),R=cx(I,g.context.inputRef),ee=h||M,z=!ee||N,te=Bb(a??(ee?void 0:j)),B=h?jb:c,[ne,re]=X.useState(null),V=X.useRef(!1),H=X.useRef(null);J(()=>{O||(H.current=null)},[O]);let ie=w===`none`&&!h,ae=q(e=>{let t=h||g.state.inline;t&&!g.state.hasInputValue&&g.context.setInputValue(``,Y(ha)),g.update({inputElement:e,inputInsidePopup:t,inputOwnsFormValue:ie})}),oe=h?s:f.getValidationProps(I,s);function se(e){g.context.setIndices({activeIndex:null,selectedIndex:null,type:$y(e),event:e})}let ce={...B,open:O,disabled:I,readOnly:x,popupSide:F,listEmpty:L};function le(e){if(!m)return;let t,n=m.chipsRef.current.length,[r]=hx(v);return e.key===r&&(e.currentTarget.selectionStart??0)===0&&A.length>0&&(e.preventDefault(),t=n>0?n-1:void 0),t}let ue=Ro(`input`,e,{state:ce,ref:[t,g.context.inputRef,ae],props:[E,D,{value:ne??_,"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,...ie&&S&&{name:S},id:te,onFocus(){if(R(!0),!M)return;let e=H.current;H.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`&&(H.current=e,g.context.setIndices({activeIndex:null})),d===`onBlur`){let e=w===`none`?_:A;f.commit(e)}},onCompositionStart(e){qr||(V.current=!0,re(e.currentTarget.value))},onCompositionEnd(e){V.current=!1;let t=e.currentTarget.value;re(null),g.context.setInputValue(t,Y(Da,e.nativeEvent))},onChange(e){let t=e.nativeEvent,n=t.inputType,r=!n||n===`insertReplacementText`,i=V.current||!r;function a(e){!x&&!I&&e&&i&&(g.context.setOpen(!0,Y(Da,t)),P||se(t))}if(V.current){let n=e.currentTarget.value;re(n),n===``&&!g.state.openOnInputClick&&!g.state.inputInsidePopup&&g.context.setOpen(!1,Y(Na,t));let r=n.trim(),i=P&&r!==``;a(r),O&&g.state.activeIndex!==null&&!i&&se(t);return}let o=Y(Da,t);if(g.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Y(Na,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&&se(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&&ai(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=v===`rtl`;if(e.key===`Home`){ai(e);let n=ma&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){ai(e);let i=ma&&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(wa,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);se(e.nativeEvent),g.context.setSelectedValue(r,Y(ha,e.nativeEvent));return}let i=le(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(ha,n));return}ai(e),gx(g,t,n)}}},oe],stateAttributesMapping:sx}),de=h?(0,Z.jsx)(Fb.Provider,{value:Pb,children:ue}):ue;return(0,Z.jsxs)(X.Fragment,{children:[O&&z&&(0,Z.jsx)(Sx,{ref:g.context.startDismissRef}),de]})}),wx={...Wi,...us},Tx=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}=Ib(),u=ab(),d=u.useState(`selectionMode`),f=u.useState(`disabled`),p=u.useState(`readOnly`),m=u.useState(`open`),h=u.useState(`selectedValue`),g=u.useState(`hasSelectionChips`),_=cb(),v=!1;v=d===`none`?_!==``:d===`single`?h!=null:g;let y=l||f||i,{buttonRef:b,getButtonProps:x}=Yi({native:a,disabled:y}),{mounted:S,transitionStatus:C,setMounted:w}=tc(v),T={disabled:y,visible:v,open:m,transitionStatus:C};ki({open:v,ref:u.context.clearRef,onComplete(){v||w(!1)}});let E=Ro(`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=$y(e);u.context.setInputValue(``,Y(oo,e.nativeEvent)),d===`none`?u.context.setIndices({activeIndex:null,type:t,event:e.nativeEvent}):(u.context.setSelectedValue(Array.isArray(h)?[]:null,Y(oo,e.nativeEvent)),u.context.setIndices({activeIndex:null,selectedIndex:null,type:t,event:e.nativeEvent})),u.context.inputRef.current?.focus()}},c,x],stateAttributesMapping:wx});return o||S?E:null}),Ex=X.createContext(null);function Dx(){return X.useContext(Ex)}function Ox(e){let{children:t}=e,{filteredItems:n}=sb(),r=Dx(),i=r?r.items:n;return(0,Z.jsx)(X.Fragment,{children:i.map(t)})}var kx=X.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Ax(){return X.useContext(kx)}function jx(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=q(i),[,o]=X.useState(0),s=Mi(Nx).current,c=Mi(Mx).current,l=X.useRef(0),u=X.useRef(!0),d=X.useRef(null),f=X.useRef(null),p=q(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=q((e,t)=>{c.set(e,t),p()}),h=q(e=>{c.delete(e),p()}),g=q(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(!Ix(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Lx(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=Fx(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=q(()=>{let[e,t]=Px(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))});J(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),J(()=>{u.current&&v()}),J(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=q(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)(kx.Provider,{value:b,children:t})}function Mx(){return new Map}function Nx(){return new Set}function Px(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)=>Lx(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 Fx(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Ix(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 Lx(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Rx=X.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=ab(),l=ob(),u=!!xx(!0),{filteredItems:d,hasItems:f}=sb(),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=q(e=>{c.set(`positionerElement`,e)}),S=q(e=>{c.set(`listElement`,e)}),C=X.useMemo(()=>typeof o==`function`?n||=(0,Z.jsx)(Ox,{children:o}):o,[o]),w={empty:b},T=l.useState(`floatingId`),E=Ro(`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;ai(e),gx(c,t,e.nativeEvent)}}},s]});if(_)return E;let D=f&&!v?void 0:c.context.labelsRef;return(0,Z.jsx)(jx,{elementsRef:c.context.listRef,labelsRef:D,children:E})}),zx=X.createContext(void 0);function Bx(){let e=X.useContext(zx);if(e===void 0)throw Error(Ja(20));return e}var Vx=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=ab(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Z.jsx)(zx.Provider,{value:n,children:(0,Z.jsx)(no,{ref:t,...r})}):null}),Hx=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}})}),Ux={},Wx={},Gx=``;function Kx(e,t){return mo(e)?e:t}function qx(e,t,n){return/hidden|clip/.test(e.getComputedStyle(Kx(t,n)).overflowY)}function Jx(e){if(typeof document>`u`)return!1;let t=ii(e);return gi(t).innerWidth-t.documentElement.clientWidth>0}function Yx(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=ii(e),n=t.documentElement,r=t.body,i=Kx(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 Xx(e){let t=ii(e),n=t.documentElement,r=t.body,i=Kx(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 Zx(e){let t=ii(e),n=t.documentElement,r=t.body,i=gi(n),a=0,o=0,s=!1,c=li.create();if(Vi&&(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,Ux={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Gx=n.style.scrollBehavior,Wx={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=Kx(n,r);s=Yx(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,Ux),Object.assign(r.style,Wx),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=Gx)}function d(){u(),c.request(l)}l();let f=hi(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var Qx=new class{lockCount=0;restore=null;timeoutLock=ro.create();timeoutUnlock=ro.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=ii(e),n=t.documentElement,r=t.body,i=gi(n);if(qx(i,n,r)){let t=new i.MutationObserver(()=>{qx(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=Aa||!Jx(e);this.restore=a?Xx(e):Zx(e)}};function $x(e=!0,t=null){J(()=>{if(e)return Qx.acquire(t)},[e,t])}var eS=20;function tS(e,t,n,r){let[i,a]=X.useState(!1);J(()=>{if(!e||!t||n==null){a(!1);return}let r=ii(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-eS)},[e,t,n]),$x(e&&(!t||i),r)}var nS=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=Jr,style:g,..._}=e,v=ab(),y=ob(),b=Bx(),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=mx(),M=Eu({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});tS(S&&x,w===`touch`,T,E);let N={open:S,side:M.side,align:M.align,anchorHidden:M.anchorHidden,empty:j};J(()=>{v.set(`popupSide`,M.side)},[v,M.side]);let P=q(e=>{v.set(`positionerElement`,e)}),F=Au(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Z.jsxs)(bx.Provider,{value:M,children:[C&&x&&(0,Z.jsx)(Hx,{inert:Ei(!S),cutout:O??D??E}),F]})}),rS={...fs,...Wi},iS=X.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=ab(),l=xx(),u=ob(),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=mx(),x=s.id??(g?Wb(y):void 0);J(()=>(c.set(`popupId`,c.context.popupRef.current?.id||x),()=>{c.set(`popupId`,void 0)}),[c,x]),ki({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=Ro(`div`,e,{state:S,ref:[t,c.context.popupRef],props:[m,{id:x,role:g?`dialog`:`presentation`,onFocus(e){let t=da(e.nativeEvent);p!==`touch`&&(K(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},ku(h),s],stateAttributesMapping:rS}),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)(Ys,{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)(Sx,{ref:c.context.endDismissRef})]})})});function aS(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Ax(),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 J(()=>{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 oS=X.createContext(void 0);function sS(){let e=X.useContext(oS);if(!e)throw Error(Ja(19));return e}var cS=X.createContext(!1);function lS(){return X.useContext(cS)}function uS(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=aS({guess:!0,index:l,textRef:p}),h=ab(),g=lS(),_=lb(),{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;J(()=>{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]),J(()=>{if(!D||_)return;let e=h.context.valuesRef.current;return e[E]=c,()=>{delete e[E]}},[D,_,E,c,h]),J(()=>{if(!D||_)return;let e=h.state.selectedValue,t=h.state.selectedIndex;h.state.selectionMode===`multiple`&&Array.isArray(e)?t=vb(E,c,h.context.valuesRef.current,e,C,t):fb(c,e,C)&&(t=E),h.set(`selectedIndex`,t)},[D,_,h,E,c,C]);let{getButtonProps:N,buttonRef:P}=Yi({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?(rc.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=Ro(`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)(oS.Provider,{value:ee,children:R})}function dS(e){let{componentProps:t,forwardedRef:n}=e,r=ab().useState(`isItemEqualToValue`),{flatFilteredValues:i}=sb(),a=hb(i,t.value??null,r);return(0,Z.jsx)(uS,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var fS=X.memo(X.forwardRef(function(e,t){let n=ab().useState(`virtualized`);return n&&e.index==null?(0,Z.jsx)(dS,{componentProps:e,forwardedRef:t}):(0,Z.jsx)(uS,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),pS=X.createContext(void 0);function mS(){let e=X.useContext(pS);if(e===void 0)throw Error(Ja(13));return e}var hS={imageLoadingStatus:()=>null},gS=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=Ro(`span`,e,{state:c,ref:t,props:a,stateAttributesMapping:hS});return(0,Z.jsx)(pS.Provider,{value:l,children:u})});function _S(e,{referrerPolicy:t,crossOrigin:n,sizes:r,srcSet:i},a){let o=X.useState(`idle`),s=o[1];return J(()=>{if(!a)return ti;if(!e&&!i)return s(`error`),ti;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 vS={...hS,...Wi},yS=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}=mS(),[f,p]=_S(l,e,!a),m=f===`loaded`,{mounted:h,transitionStatus:g,setMounted:_}=tc(m),v=X.useRef(null),y=X.useRef(!0);J(()=>{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=q(e=>{i?.(e),d(e)});J(()=>{f!==`idle`&&x(f)},[f,x]),J(()=>()=>d(`idle`),[d]),ki({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=Ro(`img`,e,{state:S,ref:[t,v],props:[b,u,w],stateAttributesMapping:vS,enabled:C});return C?T:null}),bS=X.forwardRef(function(e,t){let{className:n,render:r,delay:i=0,style:a,...o}=e,{imageLoadingStatus:s}=mS(),[c,l]=X.useState(i===0),u=_o();return X.useEffect(()=>(i>0?u.start(i,()=>l(!0)):l(!0),u.clear),[u,i]),Ro(`span`,e,{state:{imageLoadingStatus:s},ref:t,props:o,stateAttributesMapping:hS,enabled:s!==`loaded`&&(i===0||c)})}),$=Vr();function xS(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=Bi(`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)(gS,{"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 SS(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=Bi(`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)(yS,{"data-slot":`avatar-image`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function CS(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=Bi(`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)(bS,{"data-slot":`avatar-fallback`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function wS(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Xy({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=tc(a,!0,!0),u=Bb(),[d,f]=X.useState(),p=d===null?void 0:d??u,m=q(e=>{let t=!a,n=Y(ei,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 TS=X.createContext(void 0);function ES(){let e=X.useContext(TS);if(e===void 0)throw Error(Ja(15));return e}var DS=`data-open`,OS=`data-closed`,kS=$r,AS=`data-panel-open`,jS={[DS]:``},MS={[OS]:``},NS={open(e){return e?{[AS]:``}:null}},PS={open(e){return e?jS:MS},...Wi},FS=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=q(o),d=wS({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=Ro(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:PS});return(0,Z.jsx)(TS.Provider,{value:p,children:m})}),IS={...NS,...Wi},LS=X.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=ES(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Yi({disabled:c,native:u});return Ro(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:IS})}),RS={height:void 0,width:void 0};function zS(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(RS),h=X.useRef(RS),g=X.useRef(!1),_=X.useRef(s),v=X.useRef(!1),[y,b]=X.useState(!1),x=X.useRef(null),S=Mo(t,d),C=_s(s),w=ji(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=q((e,t=!0)=>{t&&(h.current=e),m(e)}),j=q(()=>{x.current?.(),x.current=null}),M=q(e=>{j(),x.current=()=>{x.current=null,e()}}),N=q(()=>{s&&a&&f.current===`css-animation`&&(v.current=!0)});J(()=>{y&&u!==`starting`&&b(!1)},[y,u]),X.useEffect(()=>()=>{N(),j()},[N,j]),J(()=>{s||(_.current=!1,v.current=!1);let e=d.current;if(!e)return;!s&&x.current&&j();let t=VS(e,D);if(f.current=t,s&&u===`idle`&&_.current&&t===`css-animation`){h.current=BS(e);return}if(s&&u===`starting`){let n=g.current;if(g.current=!1,t===`none`){A(BS(e)),b(!0);return}if(t===`css-transition`){let t=WS(e);if(A(BS(e)),!n)return t;let r=US(e,`transition-duration`,`0s`);return M(r),b(!0),t}A(BS(e));let r=US(e,`animation-name`,`none`);if(!n){r();return}let i=US(e,`animation-duration`,`0s`);r(),M(i),b(!0);return}if(!s&&a&&(u===`idle`||u===`starting`)){if(t===`none`){A(RS,!1),c(!1);return}A(BS(e));return}if(u!==`ending`)return;if(t===`none`){c(!1);return}let n=BS(e);n.height>0||n.width>0?(A(n),t===`css-animation`&&US(e,`animation-name`,`none`)()):c(!1)},[a,s,j,A,c,M,D,u]),ki({enabled:s&&a&&E===`idle`,open:!0,ref:d,onComplete(){s&&A(RS,!1)}}),X.useEffect(()=>{if(s||!a||E!==`ending`)return;if(!d.current){c(!1),A(RS,!1);return}let e=new AbortController,t=-1;function n(){C.current||(c(!1),A(RS,!1))}return t=li.request(()=>{w(n,e.signal)}),()=>{li.cancel(t),e.abort()}},[C,a,s,E,w,A,c]),J(()=>{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=ro.create(),n=-1,r=(r,i)=>{t.start(0,()=>{C.current||(n=li.request(()=>{C.current||(r&&(g.current=!1),i&&e.setAttribute(kS,``),e.setAttribute(`hidden`,`until-found`))}))})},i=hi(e,`beforematch`,t=>{let n=Y(ha,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}g.current=!0;let i=e.hasAttribute(kS);e.removeAttribute(kS),l(!0),r(!0,i)});return()=>{t.clear(),li.cancel(n),i()}},[C,o,l]);let P=i||n||a||s;return{height:O.height,props:{...k?{[kS]:``}:void 0,hidden:T,id:r},ref:S,shouldPreventOpenAnimation:D,shouldRender:P,transitionStatus:E,width:O.width}}function BS(e){return{height:e.scrollHeight,width:e.scrollWidth}}function VS(e,t){let n=gi(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&HS(n.animationDuration),i=HS(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function HS(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function US(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 WS(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=li.request(n);return()=>{li.cancel(r),n()}}var GS=`--collapsible-panel-height`,KS=`--collapsible-panel-width`,qS=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:_}=ES(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;J(()=>(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}=zS({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=Sa(s,k),j=Ro(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[GS]:S===void 0?`auto`:`${S}px`,[KS]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:PS});return E?j:null}),JS=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}=tc(o),d=Ro(`span`,e,{ref:[t,c],state:{selected:o,transitionStatus:l},props:[{"aria-hidden":!0,children:`✔️`},s],stateAttributesMapping:Wi});return ki({batch:!0,enabled:!o,open:o,ref:c,onComplete(){o||u(!1)}}),d})),YS=X.forwardRef(function(e,t){let{selected:n}=sS();return e.keepMounted||n?(0,Z.jsx)(JS,{...e,selected:n,ref:t}):null}),XS=X.createContext(void 0);function ZS(e=!0){let t=X.useContext(XS);if(t===void 0&&!e)throw Error(Ja(25));return t}var QS=X.createContext(void 0);function $S(e){let t=X.useContext(QS);if(t===void 0&&!e)throw Error(Ja(33));return t}var eC=X.createContext(void 0);function tC(e){let t=X.useContext(eC);if(t===void 0&&!e)throw Error(Ja(36));return t}var nC=X.createContext(null);function rC(e=`root`){let t=X.useContext(nC),n=X.useContext(eC);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var iC={visible:!0,ref:null};function aC(){return iC}function oC(e,t,n=`root`){let r=rC(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??aC)({label:e.label,children:e.children,render:e.render}),a=Mo(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function sC(e){e.preventDefault()}function cC(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=tC(),u=ZS(!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?sC: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:$a})},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&&!Co&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&si(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var lC={type:`regular-item`};function uC(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}=Yi({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=cC({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=X.useCallback(e=>Yr(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Mo(u,f);return X.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var dC=X.createContext(void 0);function fC(){let e=X.useContext(dC);if(e===void 0)throw Error(Ja(31));return e}var pC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=X.useState(void 0),c=Ro(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,Z.jsx)(dC.Provider,{value:s,children:c})}),mC=X.forwardRef(function(e,t){let n=rC()?.Group??pC;return(0,Z.jsx)(n,{...e,ref:t})}),hC=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Bb(a),c=fC();return J(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),Ro(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),gC=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}=tC(),f=aS({guess:!0,label:a}),p=Bb(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}=uC({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:lC});return Ro(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),_C=X.forwardRef(function(e,t){let n=oC(e,t);return n.visible?(0,Z.jsx)(gC,{...e,ref:n.ref}):null}),vC=X.createContext(void 0);function yC(e){let t=X.useContext(vC);if(t===void 0&&!e)throw Error(Ja(69));return t}var bC=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),xC=X.createContext(void 0);function SC(){return X.useContext(xC)}function CC(e,t){let n=Ao(e.render);if(X.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function wC(e,t,n){let r=CC(e,t),i=r===t?void 0:r;return[r,X.useCallback(e=>n?.(e?i:void 0),[i,n])]}function TC(e,t,n){let r=Ao(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 EC=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}=tC(),m=SC(),{side:h,align:g}=$S(),_=yC(!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]=wC(e,u,d),L=TC(e,C,N),R=w.type===`menu`?m:void 0,ee=w.type===`context-menu`,z=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(z=()=>l.state.activeIndex===null&&P),ki({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]),Hc(D,{enabled:A&&!j&&!ee&&w.type!==`menubar`,closeDelay:k});let te=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:B,handleFocus:ne}=(X.useContext(nC)?.useParentHandoff??OC)(l,w,v,f),re={transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},V=Ro(`div`,e,{state:re,ref:[t,l.context.popupRef,te,I],stateAttributesMapping:ps,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&bC.has(e.key)&&e.stopPropagation()},onFocus:ne},ku(y),c,{"data-rootownerid":E}]}),H=w.type===void 0||ee;(C||w.type===`menubar`&&T!==`outside-press`)&&(H=!0);let ie=R?.getReturnElement??B;return(0,Z.jsx)(Ys,{context:D,openInteractionType:M,modal:ee,disabled:!x,returnFocus:a??ie??H,explicitReturnFocus:a===void 0&&ie?!1:void 0,initialFocus:z,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:V})}),DC={parentVirtualFocusRef:void 0,handleFocus:void 0};function OC(){return DC}var kC=X.forwardRef(function(e,t){let n=rC()?.Popup??EC;return(0,Z.jsx)(n,{...e,ref:t})}),AC=X.createContext(void 0);function jC(){let e=X.useContext(AC);if(e===void 0)throw Error(Ja(32));return e}var MC=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=tC();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Z.jsx)(AC.Provider,{value:n,children:(0,Z.jsx)(no,{ref:t,...r,portalOwnerRole:o})})});function NC(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=X.useRef(null),o=X.useRef(null),s=ji(r);J(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),J(()=>{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 PC=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=Jr,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=tC(),x=jC(),S=ZS(!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,z=c,te=l,B=s,ne=h;C.type===`context-menu`&&(ee=n??C.context?.anchor,B??=`start`,!o&&B!==`center`&&(te=e.alignOffset??2,z=e.sideOffset??-5));let re=o,V=B;C.type===`menu`?(re??=`inline-end`,V??=`start`,ne=e.collisionAvoidance??Ga):C.type===`menubar`&&(re??=C.context.orientation===`vertical`?`inline-end`:`bottom`,V??=`start`);let H=C.type===`context-menu`,ie=Eu({anchor:ee,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:re,sideOffset:z,align:V,alignOffset:te,arrowPadding:H?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:ne,shift:H?{crossAxis:!(`side`in ne&&ne.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(xa)))}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 ae=_o();X.useEffect(()=>{D||ae.clear()},[D,ae]),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?ae.isStarted()||ae.start(e,()=>{v.setOpen(!1,Y(xa))}):v.setOpen(!1,Y(xa))}else ae.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,ae]),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]),NC({store:v,domReference:R,positionerElement:M,open:D});let oe={open:D,side:ie.side,align:ie.align,anchorHidden:ie.anchorHidden,nested:C.type===`menu`,instant:N},se=C.type===`menubar`&&C.context.modal;tS(D&&(se||O&&F!==`trigger-hover`),k===`touch`,M,A);let ce=Au(e,oe,{styles:ie.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),le=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),ue=null;return C.type===`menubar`?ue=C.context.contentElement:C.type===void 0&&(ue=A),(0,Z.jsxs)(QS.Provider,{value:ie,children:[le&&(0,Z.jsx)(Hx,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:Ei(!D),cutout:ue}),(0,Z.jsx)(zs,{id:I,children:(0,Z.jsx)(jx,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:ce})})]})}),FC=X.createContext(null);function IC(e){let t=X.useContext(FC);if(t===null&&!e)throw Error(Ja(5));return t}var LC={...Ec,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=Ec.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>Vi&&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`&&!Ec.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`)}},RC=class extends Ua{constructor(e,t,n=!1){let r=new _c,i=BC(r,t,n,e);super(i,zC(r),LC),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 zC(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 BC(e,t,n=!1,r){return{...bc(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:Ki,inputProps:Ki,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new Ns,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:Ki,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var VC=X.createContext(null);function HC(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function UC(e,t){return e===`list-navigation`||HC(e,t)}var WC=ya(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=ZS(!0),C=tC(!0),w=IC(!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=Bb(),k=Bb(),[A,j]=X.useState(void 0),M=(A??k)||void 0,N=Is(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=Mi(()=>F?P?.state.instantType:void 0).current,L=Mi(()=>{let e=new RC({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=Rs(R),z=L.useState(`open`),te=L.useState(`activeTriggerElement`),B=L.useState(`positionerElement`),ne=L.useState(`hoverEnabled`),re=L.useState(`disabled`),V=L.useState(`lastOpenChangeReason`),H=L.useState(`parent`),ie=L.useState(`activeIndex`),ae=L.useState(`keyboardOpen`),oe=L.useState(`payload`),se=L.useState(`floatingParentNodeId`),ce=X.useRef(null),le=X.useRef(H.type!==`context-menu`),ue=_o(),de=X.useRef(!0),fe=_o(),pe=se!=null,{openMethod:me,triggerProps:he}=$b(z);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:H.type===void 0?c:void 0,openMethod:me,rootId:O}),pc(L);let{forceUnmount:ge,transitionStatus:_e}=mc(z,L,()=>{L.set(`allowMouseEnter`,!1)},F),ve=ji(L.context.popupRef);X.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!z){e();return}if(_e!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return ve(e,t.signal),()=>{t.abort()}},[I,z,_e,ve,L]),J(()=>{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,te,L]),X.useEffect(()=>{z||(ce.current=null),H.type===`context-menu`&&(z?ue.start(500,()=>{le.current=!0}):(ue.clear(),le.current=!1))},[ue,z,H.type]),J(()=>{!z&&!ne&&L.set(`hoverEnabled`,!0)},[z,ne,L]);let ye=q((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||z===e&&t.trigger===te&&V===n)return;let i=dc(t);if(!e&&t.trigger==null&&(t.trigger=te??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`&&!de.current)return;e&&n===`trigger-focus`?(de.current=!1,fe.start(300,()=>{de.current=!0})):(de.current=!0,fe.clear());let o=!e&&(n===`escape-key`||n==null);ce.current=t.event;let s=uc(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&UC(n,a),s.instantType=H.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:HC(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),be=ec({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:ye}),xe=be.context.events;J(()=>{let e=({open:e,eventDetails:t})=>ye(e,t);return xe.on(`setOpen`,e),()=>{xe?.off(`setOpen`,e)}},[xe,ye]),J(()=>L.subscribeToParentMenu(),[L]);let Se=X.useCallback(()=>{L.setOpen(!1,Y(Eo))},[L]);X.useImperativeHandle(d,()=>({unmount:ge,close:Se}),[ge,Se]);let Ce;H.type===`context-menu`&&(Ce=H.context),X.useImperativeHandle(Ce?.positionerRef,()=>B,[B]),X.useImperativeHandle(Ce?.actionsRef,()=>({setOpen:ye}),[ye]);let we=$s(be,{enabled:!re,bubbles:{escapeKey:f&&H.type===`menu`},outsidePress(){return H.type!==`context-menu`||ce.current?.type===`contextmenu`||le.current},externalTree:pe?R:void 0}),Te=fu(),Ee=Zc(be,{enabled:!re,listRef:L.context.itemDomElements,activeIndex:ie,virtual:v,nested:H.type===`menubar`||!v&&H.type!==void 0,parentOrientation:H.type===`menubar`?H.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?ae:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:Te===`rtl`,disabledIndices:Fo,onNavigate(e,t){L.setActiveIndex(e,$y(t),t?.nativeEvent)},openOnArrowKeyDown:H.type!==`context-menu`&&!(v&&_),externalTree:!v&&pe?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),De=X.useCallback(e=>{L.context.typingRef.current=e},[L]),Oe=Qc(be,{enabled:!re&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:ie,resetMs:500,onMatch:(e,t)=>{z&&e!==ie&&L.setActiveIndex(e,za,t.nativeEvent)},onTyping:De}),ke=q(a),Ae=X.useRef(-1),je=q(()=>{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(Ae.current===n&&L.context.reportedItem===t)return;Ae.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=ha,L.context.highlightEvent=void 0,a&&ke(t,Ji(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});J(()=>{je()},[ie,je]);let Me=X.useMemo(()=>{if(!v)return Ee.reference;if(!Ee.trigger)return Ki;let{onFocus:e,...t}=Ee.trigger;return t},[v,Ee.reference,Ee.trigger]);L.useSyncedValue(`inputProps`,v?Ee.reference??Ki:Ki);let Ne=X.useMemo(()=>{let e=Yr(Oe.reference,Me,we.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},he);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=z,e},[L,Oe.reference,Me,we.reference,he,z]),Pe=X.useMemo(()=>{let e=Yr(Ee.trigger,we.trigger,he);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Ee.trigger,we.trigger,he]);Mi(()=>(L.update({inactiveTriggerProps:Pe}),null)),hc(L,{floatingRootContext:be,activeTriggerProps:Ne,inactiveTriggerProps:Pe,popupProps:X.useMemo(()=>Yr(ic,{onMouseMove(){L.set(`allowMouseEnter`,!0),H.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)}},Oe.floating,Ee.floating,we.floating),[H.type,L,Oe.floating,Ee.floating,we.floating]),itemProps:Ee.item??Ki});let Fe=X.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:je}),[L,D,u,l,b,k,v,E,je]),Ie=typeof t==`function`?t({payload:oe}):t,Le=(0,Z.jsxs)(eC.Provider,{value:Fe,children:[p&&(0,Z.jsx)(sc,{handle:p,store:L}),Ie]});return(H.type===void 0||H.type===`context-menu`)&&(Le=(0,Z.jsx)(Bs,{externalTree:R,children:Le})),Le});function GC(e){let t=X.useContext(VC);if(t===null)return(0,Z.jsx)(WC,{...e});let n=t.Root;return(0,Z.jsx)(VC.Provider,{value:null,children:(0,Z.jsx)(n,{...t.options,...e})})}function KC(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Pi(),{ref:i,index:a}=aS(e),o=n===a,s=X.useRef(null),c=Mo(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 qC(e){let{render:t,className:n,style:r,state:i=Ki,props:a=Fo,refs:o=Fo,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=KC({metadata:s});return Ro(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function JC(e){if(pi(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!wi(e))return JC(ta(e))}function YC(e,t){function n(n,r,i){let a=n.currentTarget;rc.flushSync(()=>{e.setOpen(!1,Y(Xa,n.nativeEvent,a))}),Ci(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&&po(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function XC(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,ii(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:Ki,[t,n,r])}var ZC=so(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=tC(!0),h=Oc(d)??m?.store;if(!h)throw Error(Ja(85));let g=Bb(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=X.useRef(null),S=$C(),C=Pi(!0),w=Ls(),T=X.useMemo(()=>w??new Ns,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=fc(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:Rs(T),floatingParentNodeId:Is(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=Yi({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=_o(),F=q(e=>{if(!N.current)return;P.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;K(N.current,t)||K(h.select(`positionerElement`),t)||t===N.current||t!=null&&JC(t)===h.select(`rootId`)||ux(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:va})});X.useEffect(()=>{let e=ii(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=Wc(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:ol({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=QC(y,h.select(`lastOpenChangeReason`)),ee=Xs(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),z=jc(v,{enabled:!A&&I}),te=XC({open:y,enabled:O,mouseDownAction:`open`}),B=X.useMemo(()=>Yr(z.reference,ee.reference),[z.reference,ee.reference]),ne=h.useState(`triggerProps`,D),re=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:V,handleFocusTargetFocus:H}=YC(h,x),ie={disabled:A,open:y},ae=[N,t,M,E,x],oe=[B,L??Ki,ne,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),ii(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},re,O?{role:`menuitem`}:{},te,p,j],se=Ro(`button`,e,{enabled:!O,stateAttributesMapping:ds,state:ie,ref:ae,props:oe});return O?(0,Z.jsx)(qC,{tag:`button`,render:n,className:r,style:i,state:ie,refs:ae,props:oe,stateAttributesMapping:ds}):y?(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(Hi,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:V},`${g}-pre-focus-guard`),(0,Z.jsx)(X.Fragment,{children:se},g),(0,Z.jsx)(Hi,{ref:h.context.triggerFocusTargetRef,onFocus:H},`${g}-post-focus-guard`)]}):(0,Z.jsx)(X.Fragment,{children:se},g)});function QC(e,t){let n=_o(),[r,i]=X.useState(!1);return J(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function $C(){let e=IC(!0);return X.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var ew=X.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return Ro(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})});function tw(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=oi(),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)(XS.Provider,{value:u,children:(0,Z.jsx)(eC.Provider,{value:void 0,children:(0,Z.jsx)(GC,{...e})})})}var nw=500,rw=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}=ZS(!1),{store:m}=tC(!1),h=m.useState(`open`),g=m.useState(`disabled`),_=X.useRef(null),v=X.useRef(null),y=_o(),b=_o(),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(ei,n)),b.start(nw,()=>{x.current=!0})}function w(e){if(g)return;d.current=!0,ai(e),C(e.clientX,e.clientY,e.nativeEvent);let t=ii(_.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=da(e);K(u.current,t)||p&&t&&JC(t)===p||s.current?.setOpen(!1,Y(va,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(nw,()=>{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=da(e);(K(_.current,t)||K(c.current,t)||K(l.current,t))&&e.preventDefault()}let t=ii(_.current);return hi(t,`contextmenu`,e)},[l,g,c]),Ro(`div`,e,{state:{open:h},ref:[_,t],props:[{onContextMenu:w,onTouchStart:E,onTouchMove:D,onTouchEnd:T,onTouchCancel:T,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:ds})}),iw=PC,aw=X.createContext(void 0);function ow(e){let t=X.useContext(aw);if(!e&&t===void 0)throw Error(Ja(27));return t}var sw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=ow(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`),d={open:c,transitionStatus:s.useState(`transitionStatus`)};return Ro(`div`,e,{state:d,ref:[s.context.backdropRef,t],stateAttributesMapping:ps,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),cw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=ow(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=Yi({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Y(yo,e.nativeEvent))}return Ro(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})}),lw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=ow(),c=Bb(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),Ro(`p`,e,{ref:t,props:[{id:c},o]})}),uw=X.createContext(void 0);function dw(){let e=X.useContext(uw);if(e===void 0)throw Error(Ja(26));return e}var fw=`--nested-dialogs`,pw=`data-nested-dialog-open`,mw={...fs,...Wi,nestedDialogOpen(e){return e?{[pw]:``}:null}},hw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=ow(),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`);dw(),ki({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?ac(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=Ro(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...ic,hidden:!m,onKeyDown(e){bC.has(e.key)&&e.stopPropagation()},style:{[fw]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:mw});return(0,Z.jsx)(Ys,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})}),gw=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=ow(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Z.jsx)(uw.Provider,{value:n,children:(0,Z.jsxs)(no,{ref:t,...r,children:[a&&o===!0&&(0,Z.jsx)(Hx,{ref:i.context.internalBackdropRef,inert:Ei(!s)}),e.children]})}):null});function _w({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=$s(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=da(t);if(p&&!a){if(o){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||K(n,s)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return $x(r&&o===!0,s),e.useContextCallback(`onNestedDialogOpen`,(t,n)=>{(e.select(`open`)||e.select(`mounted`))&&(u(t),f(n))}),J(()=>{!r&&!i&&(u(0),f(0))},[r,i]),J(()=>(t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(l+1,d+ +!!n),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,l,d,t]),hc(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var vw={...Ec,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},yw=class extends Ua{constructor(e,t,n){let r=new _c,i=bw(e,r,t,n);super(i,xw(r),vw)}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(uc(this.state,e,t.trigger)))}};function bw(e,t,n,r=!1){return{...bc(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 xw(e){return{popupRef:X.createRef(),backdropRef:X.createRef(),internalBackdropRef:X.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function Sw(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=ow(!0),y={modal:h,disablePointerDismissal:g,nested:v!=null,role:_},b=oc((e,t)=>new yw({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`);gc(b,x),pc(b);let{forceUnmount:w}=mc(x,b);X.useImperativeHandle(l,()=>({unmount:w,close:()=>b.setOpen(!1,Y(Eo))}),[w,b]);let T=x||S||u!=null;return(0,Z.jsxs)(aw.Provider,{value:b,children:[u&&(0,Z.jsx)(sc,{handle:u,store:b}),T&&(0,Z.jsx)(_w,{store:b,parentContext:v?.context,isDrawer:p}),typeof n==`function`?n({payload:C}):n]})}var Cw=ya(function(e){return Sw(`dialog`,e)}),ww=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=ow(),c=Bb(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),Ro(`h2`,e,{ref:t,props:[{id:c},o]})}),Tw=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}=Ib(),{clearErrors:S,elementRef:C,submitCountRef:w}=zb(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=Hb(),k=Ub({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=q(()=>x.inputRef.current?.value);Lb(x.inputRef,k,j,M,!T,a),J(()=>{let e=j??x.inputRef.current?.value;e!==void 0&&y(e!==``)},[j,l,x.inputRef,y]),Zb(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=X.useRef(null),P=cx(T,N),F=_o();return Ro(`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(ha,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:Nb})}),Ew=X.forwardRef(function(e,t){return(0,Z.jsx)(Tw,{ref:t,...e})});function Dw(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=Bi(`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)(Ew,{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 Ow(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=Bi(`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 kw=Kr(`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 Aw(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=Bi(kw({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:jw,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function jw(e){e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`input`)?.focus()}var Mw=Kr(`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 Nw(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=Bi(Mw({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)(ga,{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 Pw(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=Bi(`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)(Dw,{"data-slot":`input-group-control`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Fw(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=Bi(`[&_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)(Go,{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)(_x,{"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 Iw(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)(Nw,{variant:`ghost`,size:`icon-xs`}),t[3]=i):i=t[3];let a;t[4]===n?a=t[5]:(a=Bi(n),t[4]=n,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(ja,{className:`pointer-events-none`}),t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==a?(s=(0,Z.jsx)(Tx,{"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 Lw(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=Bi(`w-auto`,r),t[7]=r,t[8]=d);let f;t[9]===c?f=t[10]:(f=(0,Z.jsx)(Pw,{disabled:c}),t[9]=c,t[10]=f);let p;t[11]!==i||t[12]!==f?(p=(0,Z.jsx)(Cx,{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)(Nw,{size:`icon-xs`,variant:`ghost`,render:(0,Z.jsx)(Fw,{}),"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)(Iw,{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)(Aw,{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)(Ow,{className:d,children:[p,g,n]}),t[23]=n,t[24]=d,t[25]=p,t[26]=g,t[27]=_):_=t[27],_}function Rw(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=Bi(`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)(iS,{"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)(Vx,{children:(0,Z.jsx)(nS,{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 zw(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=Bi(`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)(Rx,{"data-slot":`combobox-list`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Bw(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=Bi(`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)(YS,{render:(0,Z.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex items-center justify-center`}),children:(0,Z.jsx)(Uo,{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)(fS,{"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 Vw(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)(GC,{"data-slot":`dropdown-menu`,...n}),t[2]=n,t[3]=r),r}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)(ZC,{"data-slot":`dropdown-menu-trigger`,...n}),t[2]=n,t[3]=r),r}function Uw(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=Bi(`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)(kC,{"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)(MC,{children:(0,Z.jsx)(PC,{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 Ww(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)(mC,{"data-slot":`dropdown-menu-group`,...n}),t[2]=n,t[3]=r),r}function Gw(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=Bi(`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)(hC,{"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 Kw(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=Bi(`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)(_C,{"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 qw(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=Bi(`-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)(ew,{"data-slot":`dropdown-menu-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Jw(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=Bi(`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 Yw=Ar({id:Ft,name:Ft,signOut:gr}),Xw=S(V).atom(fr(lt(`/auth/user`),U(vt),U(Ne(Yw)))),Zw=Ue(p(``));function Qw(){return ne(Ve(Ky(Zw)))}function $w(){let e=(0,$.c)(27),t=Ky(Xw);if(!I(t))return null;let n;e[0]===t.value.id?n=e[1]:(n=je(`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)(SS,{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=me(k(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)(CS,{children:a}),e[7]=a,e[8]=o);let s;e[9]!==i||e[10]!==o?(s=(0,Z.jsx)(Hw,{"aria-label":`Account`,children:(0,Z.jsxs)(xS,{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)(Ww,{children:(0,Z.jsxs)(Gw,{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)(qw,{}),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)(Kw,{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)(Uw,{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)(Vw,{children:[s,h]}),e[24]=h,e[25]=s,e[26]=g):g=e[26],g}function eT(e){let t=(0,$.c)(66),[n,r]=Yy(Zw),[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=>vn(ne(Ve(n)))(ne(e.label)),t[21]=n,t[22]=a),m=bn(e.commands,a);let o,d;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>{(0,rc.flushSync)(()=>c(!0)),l.current?.focus()},d=(0,Z.jsx)($o,{}),t[23]=o,t[24]=d):(o=t[23],d=t[24]),t[25]===e.label?g=t[26]:(g=(0,Z.jsx)(ga,{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=Bi(`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=ix,_=m,v=null,y=tT,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&&gn(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&&gn(m)||(r(``),c(!1),e.currentTarget.blur())},t[32]=m,t[33]=i,t[34]=r,t[35]=E):E=t[35];let D;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Z.jsx)(Aw,{children:(0,Z.jsx)($o,{})}),t[36]=D):D=t[36];let O;t[37]===n?O=t[38]:(O=n===``&&(0,Z.jsx)(Aw,{align:`inline-end`,className:`max-sm:hidden`,children:(0,Z.jsx)(Jw,{children:`⌘K`})}),t[37]=n,t[38]=O);let k;t[39]!==e.label||t[40]!==w||t[41]!==E||t[42]!==O?(k=(0,Z.jsxs)(Lw,{ref:l,"aria-label":e.label,placeholder:`Search or run a command`,showTrigger:!1,showClear:w,className:`w-full`,onFocus:T,onKeyDown:E,children:[D,O]}),t[39]=e.label,t[40]=w,t[41]=E,t[42]=O,t[43]=k):k=t[43];let A;t[44]===r?A=t[45]:(A=(0,Z.jsx)(Rw,{anchor:u,children:(0,Z.jsx)(zw,{children:e=>(0,Z.jsxs)(Bw,{value:e,onClick:()=>{r(``),c(!1),e.run()},children:[e.icon,e.label]},e.label)})}),t[44]=r,t[45]=A);let j;t[46]!==p||t[47]!==k||t[48]!==A||t[49]!==_||t[50]!==v||t[51]!==y||t[52]!==b||t[53]!==x||t[54]!==S?(j=(0,Z.jsxs)(p,{items:_,filter:v,itemToStringValue:y,value:b,onValueChange:x,open:S,onOpenChange:a,autoHighlight:!0,children:[k,A]}),t[46]=p,t[47]=k,t[48]=A,t[49]=_,t[50]=v,t[51]=y,t[52]=b,t[53]=x,t[54]=S,t[55]=j):j=t[55];let M;t[56]===r?M=t[57]:(M=(0,Z.jsx)(ga,{variant:`ghost`,size:`sm`,className:`sm:hidden`,onClick:()=>{r(``),c(!1)},children:`Cancel`}),t[56]=r,t[57]=M);let N;t[58]!==h||t[59]!==j||t[60]!==M||t[61]!==C?(N=(0,Z.jsxs)(`div`,{ref:C,className:h,children:[j,M]}),t[58]=h,t[59]=j,t[60]=M,t[61]=C,t[62]=N):N=t[62];let P;return t[63]!==g||t[64]!==N?(P=(0,Z.jsxs)(Z.Fragment,{children:[g,N]}),t[63]=g,t[64]=N,t[65]=P):P=t[65],P}function tT(e){return e.label}function nT(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)(ga,{"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 rT(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)(eT,{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)($w,{}),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 iT(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=Bi(`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 aT(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)(iT,{className:`size-5`}),(0,Z.jsx)(iT,{className:`h-4 w-1/3`})]},t),t[3]=e.media,t[4]=n),r=ke(te(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 oT(e){let t=(0,$.c)(5),n;t[0]===e.className?n=t[1]:(n=Bi(`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 relative 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 sT(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=Bi(`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 cT=Kr(`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 lT(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=Bi(cT({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 uT(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=Bi(`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)(sT,{"data-slot":`field-label`,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,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(pT)).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(fT)}),t[7]=r,t[8]=a),o=a}let s=o;if(!s)return null;let c;t[9]===r?c=t[10]:(c=Bi(`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 fT(e,t){return e?.message&&(0,Z.jsx)(`li`,{children:e.message},t)}function pT(e){return[e?.message,e]}function mT(e){let t=(0,$.c)(5),n=e.className,r;t[0]===e.result?r=t[1]:(r=et(Kn(E(e.result),hT)),t[0]=e.result,t[1]=r);let i;return t[2]!==e.className||t[3]!==r?(i=(0,Z.jsx)(dT,{className:n,children:r}),t[2]=e.className,t[3]=r,t[4]=i):i=t[4],i}function hT(e){return e.message}var gT=Kr(`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 _T(e){let t=(0,$.c)(6),n;t[0]!==e.className||t[1]!==e.status||t[2]!==e.waiting?(n=Bi(gT({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 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)(FS,{"data-slot":`collapsible`,...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)(LS,{"data-slot":`collapsible-trigger`,...n}),t[2]=n,t[3]=r),r}function bT(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)(qS,{"data-slot":`collapsible-content`,...n}),t[2]=n,t[3]=r),r}function xT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(tw,{"data-slot":`context-menu`,...n}),t[2]=n,t[3]=r),r}function ST(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=Bi(`select-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(rw,{"data-slot":`context-menu-trigger`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function CT(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=Bi(`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)(kC,{"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)(MC,{children:(0,Z.jsx)(iw,{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 wT(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=Bi(`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)(_C,{"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 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)(Cw,{"data-slot":`dialog`,...n}),t[2]=n,t[3]=r),r}function ET(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)(gw,{"data-slot":`dialog-portal`,...n}),t[2]=n,t[3]=r),r}function DT(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)(cw,{"data-slot":`dialog-close`,...n}),t[2]=n,t[3]=r),r}function OT(e){let t=(0,$.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Bi(`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)(sw,{"data-slot":`dialog-overlay`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function kT(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)(OT,{}),t[5]=s):s=t[5];let c;t[6]===r?c=t[7]:(c=Bi(`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)(cw,{"data-slot":`dialog-close`,render:(0,Z.jsx)(ga,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,Z.jsx)(ja,{}),(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)(ET,{children:[s,(0,Z.jsxs)(hw,{"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 AT(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=Bi(`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)(cw,{render:(0,Z.jsx)(ga,{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 jT(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=Bi(`text-sm font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(ww,{"data-slot":`dialog-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function MT(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=Bi(`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)(lw,{"data-slot":`dialog-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var NT=Vn(ar(jt(`AUTH_URL`)),st);ie(function*(){let e=mn(Ft,`GITHUB_ADMINS`);return(yield*NT)?yield*zt(e,[`0`]):yield*e});function PT(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function FT(e){return ye(Do)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}Cr()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var IT=class e extends Cn()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:Do}){static layerClient=t=>dr(e,e=>ie(function*(){return yield*e.next({...e.request,headers:$n(e.request.headers,`authorization`,`Bearer ${yield*t}`)})}))},LT=Mv,RT=Pv,zT=Iv,BT=class extends qe()(`UpstreamError`,{cause:Wt()}){},VT=Ft.check(A(/^[a-z0-9][a-z0-9_-]{0,23}$/u)),HT=Et.check(Me(2048),He(e=>u(ze(t(e)),e=>e.protocol===`https:`&&e.username===``&&e.password===``&&e.hash===``),{expected:`a public HTTPS URL without credentials or a fragment`})),UT=Ar({url:HT}),WT=Ar({id:VT}),GT=Ar({authorization_endpoint:Et,authorization_response_iss_parameter_supported:f(gr),client_id_metadata_document_supported:f(gr),issuer:Et,registration_endpoint:f(Et),token_endpoint:Et});Ar({client_id:Et});var KT=Ar({access_token:Et,expires_in:f(en.check(Ce(0))),refresh_token:f(Et),token_type:Ft.check(A(/^Bearer$/iu))}),qT=Ar({client:Er({Document:{},Registered:{clientId:Et}}),metadata:GT,scope:Ft}),JT=Er({Authorized:{expiresAt:en,token:KT},Connected:{},Disconnected:{}}),YT=Ar({src:Ft,theme:f(rn([`light`,`dark`]))}),XT=Ar({error:f(Ft),generation:Et,icons:f(On(YT)),id:VT,instructions:f(Ft),link:JT,mode:rn([`oauth`,`public`]),name:Et,oauth:f(qT),tools:On(Ft),url:HT});xr(Ft,XT);var ZT=Ar({error:f(Ft),icons:On(YT),id:VT,name:Et,status:rn([`Connected`,`Not connected`,`Expired`]),tools:On(Ft),url:HT});Er({Discovered:{icons:On(YT),instructions:f(Ft),tools:On(Ft)},Failed:{error:Ft}}),Ar({code:f(Et),error:f(Ft),iss:f(Et),state:Et});var QT=class extends Bt(an(`gateway.servers`,{error:Do,stream:!0,success:On(ZT)}),an(`gateway.calls`,{error:Do,stream:!0,success:VT}),an(`gateway.add`,{error:Do,payload:UT,success:ZT}),an(`gateway.remove`,{error:Do,payload:WT})).middleware(IT){},$T=`${window.location.origin}/mcp`,eE=class extends Xt()(`@deslop/gateway/lib/utils/RpcClient`,{group:QT,protocol:Ta(`@deslop/gateway`)}){};function tE(e){return`/oauth/connect?${new URLSearchParams({id:e})}`}var nE=Ue(eE.runtime.atom(Za(wt(bt(eE,e=>e(`gateway.servers`,void 0)))))),rE=Ue(eE.runtime.atom(Za(yr(wt(bt(eE,e=>e(`gateway.calls`,void 0))))))),iE=jr(e=>p(t=>{let n=L(t.self(),()=>-1);return j(t(rE),{onFailure:()=>n,onInitial:()=>n,onSuccess:t=>C(t.value[0]===e,{onFalse:()=>n,onTrue:()=>t.value[1]})})})),aE=jr(e=>eE.runtime.fn(()=>U(eE,t=>t(`gateway.remove`,{id:e})))),oE=Ay(eE.runtime).make(RT({effects:{add:W(function*(e){yield*fr(x(HT)(e),Fe(e=>Do.make({cause:e,message:`Enter a public HTTPS MCP URL without credentials or a fragment, outside the gateway itself.`})));let t=yield*(yield*eE)(`gateway.add`,{url:e});t.status!==`Connected`&&location.assign(tE(t.id))})},events:zT({Cancel:{},Open:{},Submit:{},Typed:{url:Ft}}),root:LT({states:{Adding:{fields:{url:Ft}},Closed:{},Editing:{fields:{error:Ft,url:Ft}}}})}).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`}}}}})),sE=Mt(()=>r(nn({catch:e=>BT.make({cause:e}),try:()=>navigator.clipboard.writeText($T)}),{onFailure:()=>So.add({description:$T,title:`Cannot copy the MCP URL`,type:`error`}),onSuccess:()=>So.add({title:`MCP URL copied`})})),cE=`/assets/icon-61pmFc-p.svg`,lE=Gt(n,e=>fr(Ln(e.status),tr(`Expired`,()=>0),tr(()=>e.error!==void 0,()=>0),tr(`Not connected`,()=>1),Yt(()=>2)));function uE(e){let t=(0,$.c)(10),n;t[0]===e.server.id?n=t[1]:(n=iE(e.server.id),t[0]=e.server.id,t[1]=n);let r=Uu(n),i;t[2]===r?i=t[3]:(i=C(r>=0,{onFalse:hE,onTrue:mE}),t[2]=r,t[3]=i);let a;t[4]===e.server.status?a=t[5]:(a=fr(Ln(e.server.status),tr(`Connected`,pE),tr(`Expired`,fE),Yt(dE)),t[4]=e.server.status,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(_T,{className:i,status:a},r),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function dE(){return`off`}function fE(){return`error`}function pE(){return`live`}function mE(){return`port-blink`}function hE(){}function gE(e){let t=(0,$.c)(29),n;t[0]===e.server.id?n=t[1]:(n=aE(e.server.id),t[0]=e.server.id,t[1]=n);let[r,i]=Ju(n),a=e.open,o=e.onOpenChange,s;t[2]===e.server.name?s=t[3]:(s=(0,Z.jsxs)(jT,{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)(MT,{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)(mT,{result:r}),t[5]=r,t[6]=l);let u;t[7]===r?u=t[8]:(u=$e(r),t[7]=r,t[8]=u);let d;t[9]===u?d=t[10]:(d=(0,Z.jsx)(DT,{render:(0,Z.jsx)(ga,{variant:`ghost`,disabled:u}),children:`Cancel`}),t[9]=u,t[10]=d);let f;t[11]===r?f=t[12]:(f=$e(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)(ga,{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)(AT,{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)(kT,{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)(TT,{open:a,onOpenChange:o,children:g}),t[25]=e.onOpenChange,t[26]=e.open,t[27]=g,t[28]=_):_=t[28],_}function _E(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=H(s(e.sources,n),{onNone:vE,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 vE(){return(0,Z.jsx)(ts,{className:`text-muted-foreground size-4`})}function yE(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=Te([...ke(fe(e.server.icons,Gt(Pe,xE)),bE),`https://${a}/favicon.ico`,`https://${je(/^(?:api|app|mcp)\./u,``)(a)}/favicon.ico`]),n=_E,i=xe(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 bE(e){return e.src}function xE(e){return e.theme!==`dark`}function SE(e){return fr(Ln(e.server.status),tr(`Expired`,()=>(0,Z.jsx)(`span`,{className:`text-destructive truncate`,children:`Sign-in expired`})),tr(`Not connected`,()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate`,children:`Not connected`})),Yt(()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate font-mono text-xs`,children:new URL(e.server.url).hostname})))}function CE(e){let t=(0,$.c)(86),n;t[0]===e.server.id?n=t[1]:(n=aE(e.server.id),t[0]=e.server.id,t[1]=n);let[r]=Ju(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?(_=_e(e.server.tools),t[15]!==i||t[16]!==e.server?(g=(0,Z.jsx)(gE,{open:i,onOpenChange:a,server:e.server}),t[15]=i,t[16]=e.server,t[17]=g):g=t[17],u=vT,f=`listitem`,p=o&&_,m=s,h=`border-b`,l=xT,c=ST,d=C(_,{onFalse:OE,onTrue:DE}),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)(yT,{"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 b;t[23]===e.server?b=t[24]:(b=(0,Z.jsx)(yE,{server:e.server}),t[23]=e.server,t[24]=b);let x;t[25]===e.server.name?x=t[26]:(x=(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.server.name}),t[25]=e.server.name,t[26]=x);let S;t[27]===e.server?S=t[28]:(S=(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-1`,children:(0,Z.jsx)(SE,{server:e.server})}),t[27]=e.server,t[28]=S);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)(ga,{size:`sm`,variant:`outline`,className:`relative shrink-0`,disabled:$e(r),onClick:()=>location.assign(tE(e.server.id)),children:C(e.server.status===`Not connected`,{onFalse:EE,onTrue:TE})}),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)(uE,{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)(qo,{className:Bi(`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]!==x||t[49]!==S||t[50]!==w||t[51]!==T||t[52]!==D||t[53]!==k||t[54]!==v||t[55]!==y||t[56]!==b?(A=(0,Z.jsxs)(c,{render:v,children:[y,b,x,S,w,T,D,k]}),t[47]=c,t[48]=x,t[49]=S,t[50]=w,t[51]=T,t[52]=D,t[53]=k,t[54]=v,t[55]=y,t[56]=b,t[57]=A):A=t[57];let j;t[58]===r?j=t[59]:(j=$e(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)(CT,{className:`w-auto min-w-36`,children:(0,Z.jsx)(wT,{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)(dT,{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=ke(e.server.tools,wE),t[69]=e.server.tools,t[70]=L);let R;t[71]!==I||t[72]!==L?(R=(0,Z.jsx)(bT,{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 z;return t[83]!==ee||t[84]!==g?(z=(0,Z.jsxs)(Z.Fragment,{children:[g,ee]}),t[83]=ee,t[84]=g,t[85]=z):z=t[85],z}function wE(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 TE(){return`Connect`}function EE(){return`Reconnect`}function DE(){}function OE(){return 0}function kE(e){let t=(0,$.c)(31),n=qu(oE.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)(jT,{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)(uT,{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)(Dw,{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)(dT,{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)(lT,{"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)(DT,{render:(0,Z.jsx)(ga,{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=C(e.adding,{onFalse:jE,onTrue:AE}),t[19]=e.adding,t[20]=m);let h;t[21]!==e.adding||t[22]!==m?(h=(0,Z.jsx)(ga,{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)(AT,{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 AE(){return`Adding…`}function jE(){return`Add server`}function ME(){let e=(0,$.c)(11),t=qu(oE.send),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=ky(oE,`Editing`),e[0]=n):n=e[0];let r=Re(Ny(n),mt),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=ky(oE,`Adding`),e[1]=i):i=e[1];let a=Re(Ny(i),mt),o=ut(Kn(r,IE),()=>Kn(a,FE)),s=TT,c=M(o),l=e=>{!e&&M(r)&&t({_tag:`Cancel`})},u=kT,d=st(a),f=H(o,{onNone:PE,onSome:NE}),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 NE(e){return(0,Z.jsx)(kE,{...e})}function PE(){return null}function FE(e){return{adding:!0,error:``,url:e.url}}function IE(e){return{adding:!1,error:e.error,url:e.url}}function LE(e){let t=(0,$.c)(7),n=Qw(),r;if(t[0]!==e.servers||t[1]!==n){let i;t[3]===n?i=t[4]:(i=e=>vn(n)(ne(`${e.name} ${e.url}`)),t[3]=n,t[4]=i);let a;t[5]===n?a=t[6]:(a=()=>(0,Z.jsx)(uo,{children:(0,Z.jsx)(Ba,{children:(0,Z.jsx)(La,{children:C(n===``,{onFalse:VE,onTrue:BE})})})}),t[5]=n,t[6]=a),r=D(bn(fe(e.servers,lE),i),{onEmpty:a,onNonEmpty:RE}),t[0]=e.servers,t[1]=n,t[2]=r}else r=t[2];return r}function RE(e){return(0,Z.jsx)(`div`,{role:`list`,"aria-label":`MCP servers`,children:ke(e,zE)})}function zE(e){return(0,Z.jsx)(CE,{server:e},e.id)}function BE(){return`No servers yet`}function VE(){return`No server matches`}function HE(){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=Qu(nE,t);if(I(n)){let t;return e[1]===n.value?t=e[2]:(t=(0,Z.jsx)(LE,{servers:n.value}),e[1]=n.value,e[2]=t),t}let r;return e[3]===n.cause?r=e[4]:(r=H(kn(n.cause),{onNone:()=>(0,Z.jsx)(Oa,{error:We(n.cause),reset:KE}),onSome:UE}),e[3]=n.cause,e[4]=r),r}function UE(e){return e._tag===`AuthError`?e.error===`access_denied`?(0,Z.jsx)(uo,{children:(0,Z.jsxs)(Ba,{children:[(0,Z.jsx)(La,{children:`Admins only`}),(0,Z.jsx)(eo,{children:e.message})]})}):FT(e)?(0,Z.jsx)(Pa,{href:PT(location.href)}):(0,Z.jsx)(Oa,{error:e,reset:WE}):(0,Z.jsx)(Oa,{error:e,reset:GE})}function WE(){return location.reload()}function GE(){return location.reload()}function KE(){return location.reload()}function qE(){let e=(0,$.c)(24),t=qu(oE.send),n=qu(sE),r=I(Uu(nE)),i=rT,a=cE,o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(Zo,{}),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)(Yo,{}),e[3]=c):c=e[3];let l;e[4]===n?l=e[5]:(l=()=>n(),e[4]=n,e[5]=l);let u=bn([{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)(Yo,{}),e[6]=d):d=e[6];let f;e[7]===n?f=e[8]:(f=(0,Z.jsx)(nT,{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)(nT,{icon:(0,Z.jsx)(Zo,{}),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)(oT,{children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(aT,{label:`MCP servers`,media:!0,rows:4}),children:(0,Z.jsx)(HE,{})})}),_=(0,Z.jsx)(ME,{}),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{qE as component};
|