@deslop/gateway 0.1.1246 → 0.1.1248
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/(home)-sZExvmuj.js +41 -0
- package/dist/client/assets/{effect-C_dSYsHy.js → effect-ulqS1v1_.js} +1 -1
- package/dist/client/assets/{index-JOdkABge.js → index-CYQJJdPl.js} +3 -3
- package/dist/client/index.html +2 -2
- package/dist/server.js +528 -263
- package/package.json +2 -2
- package/dist/client/assets/(home)-BI8XKvh4.js +0 -41
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{a as t,i as n,n as r,o as i,s as a,t as o}from"./react-BUjtWCUj.js";import{$ as s,$i as c,$n as l,$r as u,$t as d,A as f,Ai as p,An as m,At as h,B as g,Bi as _,Bn as v,C as y,Ci as b,Cn as x,Cr as S,Ct as C,D as w,Di as T,Dn as E,Dr as D,E as O,En as k,Er as A,Et as j,F as M,Fi as N,Fn as ee,Fr as P,Ft as te,G as F,Gi as I,Gn as L,Gr as ne,Gt as re,H as R,Hi as ie,Hn as ae,Ht as z,I as B,Ii as oe,In as se,Ir as ce,It as le,J as ue,Ji as de,Jn as fe,Jr as pe,Jt as me,K as he,Ki as ge,Kn as _e,Kr as ve,Kt as ye,L as be,Li as xe,Ln as Se,Lr as Ce,Lt as we,M as Te,Mi as Ee,Mn as De,N as Oe,Ni as ke,Nn as Ae,Nt as je,O as Me,Oi as Ne,On as Pe,Or as Fe,Ot as Ie,P as Le,Pi as Re,Pn as ze,Pr as Be,Pt as Ve,Q as He,Qi as Ue,Qn as We,Qr as Ge,Qt as Ke,R as qe,Ri as Je,Rn as Ye,Rt as Xe,S as Ze,Si as Qe,Sn as $e,Sr as et,St as tt,T as nt,Ti as rt,Tn as it,Tr as at,Tt as ot,U as st,Ui as ct,Un as lt,Ut as ut,V as dt,Vi as ft,Vn as pt,Vt as mt,W as ht,Wi as gt,Wn as V,Wr as _t,Wt as vt,Xn as yt,Xr as bt,Xt as xt,Y as St,Yi as Ct,Yn as wt,Yr as Tt,Yt as Et,Z as Dt,Zi as Ot,Zn as kt,Zr as At,Zt as jt,_i as Mt,_n as Nt,_r as Pt,_t as Ft,a as It,aa as Lt,ai as Rt,an as zt,ar as Bt,at as Vt,b as Ht,bn as Ut,br as Wt,bt as Gt,ci as Kt,cn as qt,cr as Jt,ct as Yt,d as Xt,di as Zt,dn as Qt,dr as $t,dt as en,ea as tn,ei as nn,en as rn,er as an,et as on,f as sn,fi as cn,fn as ln,fr as un,ft as dn,gi as fn,gn as pn,gr as mn,gt as hn,h as gn,ha as _n,hr as vn,ht as yn,i as bn,ia as xn,ii as Sn,in as Cn,ir as wn,it as Tn,j as En,ji as Dn,jn as H,k as On,ki as kn,kn as An,kt as jn,l as Mn,li as Nn,ln as Pn,lr as Fn,lt as In,ma as Ln,mi as Rn,mn as zn,mr as U,n as Bn,na as Vn,ni as Hn,nn as Un,nr as Wn,oa as Gn,oi as Kn,on as qn,or as Jn,ot as Yn,pa as Xn,pi as Zn,pn as Qn,pr as W,pt as $n,q as er,qi as tr,qn as nr,qr as rr,qt as ir,r as ar,ra as or,ri as sr,rn as cr,rr as lr,rt as ur,sa as G,si as dr,sn as fr,sr as pr,st as mr,t as hr,ta as gr,ti as _r,tn as vr,tr as yr,tt as br,u as xr,un as Sr,ur as Cr,ut as wr,v as Tr,vi as Er,vn as Dr,vr as Or,vt as kr,w as Ar,wi as jr,wn as Mr,wr as Nr,wt as Pr,x as Fr,xi as Ir,xn as Lr,xr as K,xt as Rr,y as zr,yi as Br,yn as Vr,yr as Hr,yt as Ur,z as Wr,zi as Gr,zn as Kr,zt as qr}from"./effect-ulqS1v1_.js";import{$ as Jr,$t as Yr,A as Xr,At as Zr,B as Qr,Bt as $r,C as ei,Ct as ti,D as ni,Dt as ri,E as ii,Et as ai,F as oi,Ft as si,G as ci,Gt as li,H as ui,Ht as di,I as fi,It as pi,J as mi,Jt as hi,K as gi,Kt as _i,L as vi,Lt as yi,M as bi,Mt as xi,N as Si,Nt as Ci,O as wi,Ot as Ti,P as Ei,Pt as Di,Q as Oi,Qt as q,R as ki,Rt as Ai,S as ji,Sn as Mi,St as Ni,T as Pi,Tt as Fi,U as Ii,Ut as Li,V as Ri,Vt as zi,W as Bi,Wt as Vi,X as Hi,Xt as Ui,Y as Wi,Yt as Gi,Z as Ki,Zt as J,_ as qi,_n as Ji,_t as Yi,a as Xi,an as Zi,at as Qi,b as $i,bn as ea,bt as ta,c as na,cn as ra,d as ia,dn as aa,dt as oa,en as sa,et as ca,f as la,fn as ua,ft as da,g as fa,gn as pa,gt as Y,h as ma,hn as ha,ht as ga,i as _a,in as va,it as ya,j as ba,jt as xa,k as Sa,kt as Ca,l as wa,ln as Ta,lt as Ea,m as Da,mn as Oa,mt as ka,n as Aa,nn as ja,nt as Ma,o as Na,on as Pa,ot as Fa,p as Ia,pn as La,pt as Ra,q as za,qt as Ba,r as Va,rn as Ha,rt as Ua,s as Wa,sn as Ga,t as Ka,tn as qa,tt as Ja,u as Ya,un as Xa,ut as Za,v as Qa,vn as $a,vt as eo,wt as to,x as no,xn as ro,xt as io,y as ao,yn as oo,yt as so,z as co,zt as lo}from"./index-CYQJJdPl.js";var uo={name:`app-window`,size:24,node:[[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}],[`path`,{d:`M10 4v4`,key:`pp8u80`}],[`path`,{d:`M2 8h20`,key:`d11cs7`}],[`path`,{d:`M6 4v4`,key:`1svtjw`}]]};uo.node;var fo=ro(uo),po={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};po.node;var mo=ro(po),ho={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};ho.node;var go=ro(ho),_o={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`}]]};_o.node;var vo=ro(_o),yo={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};yo.node;var bo=ro(yo),xo={name:`search`,size:24,node:[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]};xo.node;var So=ro(xo),Co={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`}]]};Co.node;var wo=ro(Co),To=`data-open`,Eo=`data-closed`,Do=`data-anchor-hidden`,Oo={[ya]:``,[Qi]:``},ko={[To]:``},Ao={[Eo]:``},jo={[Do]:``},Mo={open(e){return e?Oo:null}},No={open(e){return e?ko:Ao},anchorHidden(e){return e?jo:null}},Po={...No,...Fa};function Fo(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...Fo(e,t.id,n)])}function Io(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 Lo(e){e.preventDefault(),e.stopPropagation()}function Ro(e){return`nativeEvent`in e}function zo(e){return e.pointerType===``&&e.isTrusted?!0:ta&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function Bo(e){return eo?!1:!ta&&e.width===0&&e.height===0||e.type===`pointerdown`&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`&&(ta||e.buttons===0)||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType===`touch`}function Vo(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function Ho(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}var Uo=Math.min,Wo=Math.max,Go=Math.round,Ko=Math.floor,qo=e=>({x:e,y:e}),Jo={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Yo(e,t,n){return Wo(e,Uo(t,n))}function Xo(e,t){return typeof e==`function`?e(t):e}function Zo(e){return e.split(`-`)[0]}function Qo(e){return e.split(`-`)[1]}function $o(e){return e===`x`?`y`:`x`}function es(e){return e===`y`?`height`:`width`}function ts(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function ns(e){return $o(ts(e))}function rs(e,t,n){n===void 0&&(n=!1);let r=Qo(e),i=ns(e),a=es(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=fs(o)),[o,fs(o)]}function is(e){let t=fs(e);return[as(e),t,as(t)]}function as(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var os=[`left`,`right`],ss=[`right`,`left`],cs=[`top`,`bottom`],ls=[`bottom`,`top`];function us(e,t,n){switch(e){case`top`:case`bottom`:return n?t?ss:os:t?os:ss;case`left`:case`right`:return t?cs:ls;default:return[]}}function ds(e,t,n,r){let i=Qo(e),a=us(Zo(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(as)))),a}function fs(e){let t=Zo(e);return Jo[t]+e.slice(t.length)}function ps(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function ms(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:ps(e)}function hs(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function gs(e){let t=Yr(_s,e).current;return t.next=e,J(t.effect),t}function _s(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var vs=0;function ys(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(vs);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Li;let o=requestAnimationFrame(a);return vs=o,()=>{vs===o&&(cancelAnimationFrame(o),vs=0)}}var bs=`data-base-ui-inert`,xs=new WeakMap,Ss=new WeakSet,Cs=new WeakMap,ws=0;function Ts(e){return e?Oa(e)?e.host:Ts(e.parentNode):null}var Es=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=Ts(t);return e.contains(n)?n:null}).filter(e=>e!=null),Ds=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},Os=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{va(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function ks(e,t,n,{mark:r=!0}){let i=Es(t,e),a=r?Os(t,Ds(i),new Set(i)):[],o=[],s=[];if(n){let e=Es(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);Os(t,Ds(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(xs.get(e)||0)+1;xs.set(e,r),o.push(e),r===1&&n&&Ss.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(Cs.get(e)||0)+1;Cs.set(e,t),s.push(e),t===1&&e.setAttribute(bs,``)}),ws+=1,()=>{o.forEach(e=>{let t=(xs.get(e)||0)-1;xs.set(e,t),t||(Ss.has(e)||e.removeAttribute(`aria-hidden`),Ss.delete(e))}),r&&s.forEach(e=>{let t=(Cs.get(e)||0)-1;Cs.set(e,t),t||e.removeAttribute(bs)}),--ws,ws||(xs=new WeakMap,Ss=new WeakSet,Cs=new WeakMap)}}function As(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=Ba(e[0]).body;return ks(e,i,n,{mark:r})}function js(){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 Ms=class{nodesRef={current:[]};events=js();addNode(e){this.nodesRef.current.push(e)}removeNode(e){let t=this.nodesRef.current.findIndex(t=>t===e);t!==-1&&this.nodesRef.current.splice(t,1)}},X=e(a(),1),Z=i(),Ns=X.createContext(null),Ps=X.createContext(null),Fs=()=>X.useContext(Ns)?.id||null,Is=e=>{let t=X.useContext(Ps);return e??t};function Ls(e){let t=ji(),n=Is(e),r=Fs();return J(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function Rs(e){let{children:t,id:n}=e,r=Fs();return(0,Z.jsx)(Ns.Provider,{value:X.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function zs(e){let{children:t,externalTree:n}=e,r=Yr(()=>n??new Ms).current;return(0,Z.jsx)(Ps.Provider,{value:r,children:t})}function Bs(e,t){let n=ra(Yi(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(zo(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Vs=20,Hs=[];function Us(){Hs=Hs.filter(e=>e.deref()?.isConnected)}function Ws(e){Us(),e&&va(e)!==`body`&&(Hs.push(new WeakRef(e)),Hs.length>Vs&&(Hs=Hs.slice(-20)))}function Gs(){return Us(),Hs[Hs.length-1]?.deref()}function Ks(e){return e?ui(e)?e:Ii(e)[0]||e:null}function qs(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=vi(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return ui(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 Js(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=Ja(_)&&S,w=gs(i),T=gs(a),E=gs(o),D=gs(u),O=gs(g),k=Is(m),A=Va(),j=X.useRef(!1),M=X.useRef(!1),N=X.useRef(!1),ee=X.useRef(null),P=X.useRef(``),te=X.useRef(``),F=X.useRef(null),I=X.useRef(null),L=Vi(F,p,A?.beforeInsideRef),ne=Vi(I,A?.afterInsideRef),re=to(),R=to(),ie=bi(),ae=A!=null,z=Hi(v),B=q((e=z)=>e?Ii(e):[]),oe=q(()=>h?.().filter(e=>e!=null)??[]);X.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&Y(z,ka(Ba(z)))&&B().length===0&&!C&&Lo(e)}let t=Ba(z);return fi(t,`keydown`,e)},[r,z,c,C,B]),X.useEffect(()=>{if(r||!g)return;let e=Ba(z);function t(){N.current=!1}function n(e){let t=Yi(e),n=oe(),r=Y(v,t)||Y(_,t)||Y(A?.portalNode,t)||n.some(e=>e===t||Y(e,t));N.current=!r,te.current=e.pointerType||`keyboard`,ga(t,`[data-base-ui-click-trigger]`)&&(M.current=!0,R.start(0,()=>{M.current=!1}))}function i(){te.current=`keyboard`}return oi(fi(e,`pointerdown`,n,!0),fi(e,`pointerup`,t,!0),fi(e,`pointercancel`,t,!0),fi(e,`keydown`,i,!0),t)},[r,v,_,z,g,A,R,oe]),X.useEffect(()=>{if(r||!l)return;let e=Ba(z);function n(){M.current=!0,R.start(0,()=>{M.current=!1})}function i(e){let t=Yi(e);ui(t)&&(ee.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=Yi(n);c&&r==null&&a!=null&&Y(v,a)&&Ws(a),queueMicrotask(()=>{let o=x(),l=t.context.triggerElements,u=oe(),p=r?.hasAttribute(_a(`focus-guard`))&&[F.current,I.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Xr(f),Xr(d)].includes(r),m=!(Y(_,r)||Y(v,r)||Y(r,v)||Y(A?.portalNode,r)||u.some(e=>e===r||Y(e,r))||l.hasMatchingElement(e=>Y(e,r))||p||k&&(Fo(k.nodesRef.current,o).find(e=>Y(e.context?.elements.floating,r)||Y(e.context?.elements.domReference,r))||Io(k.nodesRef.current,o).find(e=>[e.context?.elements.floating,Hi(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===_&&z&&qs(z),s&&i!==_&&!za(a)&&ka(e)===e.body){if(aa(z)&&(z.focus(),s===`popup`)){ie.request(()=>{z.focus()});return}let e=B(),t=ee.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||z;aa(n)&&n.focus()}b.current.insideReactTree?b.current.insideReactTree=!1:(C||!c)&&r&&m&&!M.current&&(C||r!==Gs())&&(j.current=!0,t.setOpen(!1,$i(na,n)))})}function o(){N.current||(b.current.insideReactTree=!0,re.start(0,()=>{b.current.insideReactTree=!1}))}let u=aa(_)?_:null;if(v||u)return oi(u&&fi(u,`focusout`,a),u&&fi(u,`pointerdown`,n),v&&fi(v,`focusin`,i),v&&fi(v,`focusout`,a),v&&A&&fi(v,`focusout`,o,!0))},[r,_,v,z,c,k,A,t,l,s,B,C,x,b,re,R,ie,d,f,oe]),X.useEffect(()=>{if(r||!v||!g)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${_a(`portal`)}]`)||[]),t=(k?Io(k.nodesRef.current,x()):[]).find(e=>Ja(e.context?.elements.domReference||null))?.context?.elements.domReference,n=As([v,...e,F.current,I.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...oe(),t,Xr(f),Xr(d),C?_:null].filter(e=>e!=null),{ariaHidden:c||C,mark:!1}),i=As([v,...e].filter(e=>e!=null));return()=>{i(),n()}},[g,r,_,v,c,A,C,k,x,d,f,oe]),J(()=>{if(!g||r||!aa(z))return;P.current=``,te.current=``;let e=Ba(z),t=ka(e);queueMicrotask(()=>{let n=w.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||Y(z,t))return;let i=null,a=()=>(i??=B(z),i[0]||z),o;o=r===!0||r===null?a():Xr(r),o||=a();let s=Y(z,ka(e)),c=b.current.openEvent,l=c?.type===`mousedown`&&zo(c);ys(o,{sync:l,preventScroll:o===z,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=ka(e);return!(t!==o&&Y(z,t))}})})},[r,g,z,B,w,D,O,b]);let se=X.useRef(null);J(()=>{if(r||!z){se.current=null;return}se.current&&=(se.current.cancelled=!0,null);let e=Ba(z),t=ka(e),n=D.current==null;Ws(t);function i(e){if(e.open||(P.current=Bs(e.nativeEvent,te.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(_a(`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(zo(e.nativeEvent)||Bo(e.nativeEvent))j.current=!1;else{let e=!1;Ba(z).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&&va(t)!==`body`?t:null,s=n?o||a:a||o;return s||=Gs()||null,typeof i==`boolean`?s:Xr(i)||s||null}return()=>{y.off(`openchange`,i);let t=ka(e),n=oe(),r=Y(v,t)||n.some(e=>e===t||Y(e,t))||k&&Fo(k.nodesRef.current,x(),!1).some(e=>Y(e.context?.elements.floating,t)),o=T.current,s=P.current,c=a(s),l={cancelled:!1};se.current=l,queueMicrotask(()=>{se.current===l&&(se.current=null);let n=Ks(c),i=E.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!j.current&&aa(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,z,T,E,D,y,k,_,x,oe]),J(()=>{if(!so||g||!v)return;let e=ka(Ba(v));aa(e)&&Ma(e)&&Y(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&&z)return qs(z),()=>{queueMicrotask(Us)}},[r,z]);let ce=!r&&(!c||!C)&&(ae||c);return(0,Z.jsxs)(X.Fragment,{children:[ce&&(0,Z.jsx)(Ei,{"data-type":`inside`,ref:L,onFocus:e=>{if(c){let e=B();ys(e[e.length-1])}else A?.portalNode&&(j.current=!1,Ri(e,A.portalNode)?ki(_)?.focus():Xr(f??A.beforeOutsideRef)?.focus())}}),n,ce&&(0,Z.jsx)(Ei,{"data-type":`inside`,ref:ne,onFocus:e=>{c?ys(B()[0]):A?.portalNode&&(l&&(j.current=!0),Ri(e,A.portalNode)?co(_)?.focus():Xr(d??A.afterOutsideRef)?.focus())}})]})}function Ys(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=ao}=t,l=e.context.dataRef,u=X.useRef(void 0),d=bi(),f=to(),p=X.useMemo(()=>{function t(t,n,r,i){let a=$i(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=Vo(e.pointerType,!0)&&Bo(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||Vo(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=Yi(s),p=Ma(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:Vo(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}:di,[n,p])}function Xs(){return!1}function Zs(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function Qs(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=Xs,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:f}=e.context,p=Is(c),m=q(typeof i==`function`?i:()=>!1),h=typeof i==`function`?m:i,g=h!==!1,_=q(()=>a),{escapeKey:v,outsidePress:y}=Zs(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=to(),O=to(),k=to(),A=q(()=>{O.clear(),d.current.insideReactTree=!1}),j=q(e=>{let t=d.current.floatingContext?.nodeId;return(p?Fo(p.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),M=q(t=>Ki(t,e.select(`floatingElement`))||Ki(t,e.select(`domReferenceElement`))),N=q(t=>{o()&&e.setOpen(!1,$i(ao,t.nativeEvent))}),ee=q(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=Ro(t)?t.nativeEvent:t;if(w.current||i.isComposing||!v&&j(`__escapeKeyBubbles`))return;let a=$i(Wa,i);e.setOpen(!1,a),a.isCanceled||t.preventDefault(),!v&&!a.isPropagationAllowed&&t.stopPropagation()}),P=q(()=>{d.current.insideReactTree=!0,O.start(0,A)}),te=q(t=>{if(!l||!n||t.button!==0)return;let r=Yi(t.nativeEvent);Y(e.select(`floatingElement`),r)&&(b.current||(b.current=!0,x.current=!1))}),F=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 ti,i=Ba(u);function a(){k.clear(),w.current=!0}function o(){w.current=!0,k.start(so?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&&Fo(p.nodesRef.current,t).some(t=>Ki(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=Yi(n),i=`[${_a(`inert`)}]`,a=Xa(r)?r.getRootNode():null,o=Array.from((Oa(a)?a:Ba(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>Y(e,r))))return;let c=Xa(r)?r:null;for(;c&&!ua(c);){let e=Ga(c);if(ua(e)||!Xa(e))break;c=e}if(!(o.length&&Xa(r)&&!Jr(r)&&!Y(r,e.select(`floatingElement`))&&o.every(e=>!Y(c,e)))){if(aa(r)&&!(`touches`in n)){let e=ua(r),t=sa(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&&!zo(n)&&!C.current)return;if(S.current){t.clear(),S.current=!1;return}}typeof h==`function`&&!h(n)||j(`__outsidePressBubbles`)||(e.setOpen(!1,$i(Da,n)),A())}}}function P(t){f()===`sloppy`&&t.pointerType!==`touch`&&e.select(`open`)&&n&&!M(t)&&N(t)}function te(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 F(e,t){let n=Yi(e);if(!n)return;let r=fi(n,e.type,()=>{t(e),r()})}function I(e){T.current=`touch`,F(e,te)}function L(e){D.clear(),e.type===`pointerdown`&&(e.button===0&&(C.current=!0),T.current=e.pointerType),(e.type!==`mousedown`||!E.current||E.current.dismissOnMouseDown)&&F(e,e=>{e.type===`pointerdown`?P(e):N(e)})}function ne(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 re(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 R(e){F(e,re)}function ie(e){f()===`sloppy`&&E.current&&!M(e)&&(E.current.dismissOnTouchEnd&&N(e),D.clear(),E.current=null)}function ae(e){F(e,ie)}let z=oi(r&&oi(fi(i,`keydown`,ee),fi(i,`compositionstart`,a),fi(i,`compositionend`,o)),g&&oi(fi(i,`click`,L,!0),fi(i,`pointerdown`,L,!0),fi(i,`pointerup`,ne,!0),fi(i,`pointercancel`,ne,!0),fi(i,`mousedown`,L,!0),fi(i,`mouseup`,ne,!0),fi(i,`touchstart`,I,{capture:!0,passive:!0}),fi(i,`touchmove`,R,{capture:!0,passive:!0}),fi(i,`touchend`,ae,{capture:!0,passive:!0})));return()=>{z(),t.clear(),c(),S.current=!1}},[d,u,r,g,h,l,n,v,y,ee,A,_,j,M,p,e,D,k]);let I=X.useMemo(()=>({onKeyDown:ee,onPointerDown:N,onClick:N}),[ee,N]),L=X.useMemo(()=>({onKeyDown:ee,onPointerDown:F,onMouseDown:F,onClickCapture:P,onMouseDownCapture(e){P(),te(e)},onPointerDownCapture(e){P(),te(e)},onMouseUpCapture:P,onTouchEndCapture:P,onTouchMoveCapture:P}),[ee,P,te,F]);return X.useMemo(()=>n?{reference:I,floating:L,trigger:I}:{},[n,I,L])}function $s(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};Xa(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 ec(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=ba.request(()=>{a(`ending`)});return()=>{ba.cancel(e)}}},[e,o,i,n]),J(()=>{if(!e||t||i===void 0)return;let n=ba.request(()=>{a(void 0)});return()=>{ba.cancel(n)}},[t,e,i]),J(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=ba.request(()=>{a(`idle`)});return()=>{ba.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function tc(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=q(i),{mounted:c,setMounted:l,transitionStatus:u}=ec(t,!1,!1,o),d=!t&&r;J(()=>{t&&s(!1)},[t,s]);let f=X.useRef(c),p=X.useRef(!1),m=ei(),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 wi({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||g()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:g}}var nc=e(n(),1),rc={tabIndex:-1,[Ra]:``};function ic(e){return t=>t!==`touch`||e.current}function ac(e,t=!1){let n=ji(),r=Fs()!=null,i=Yr(()=>e(n,r)).current;return $s({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function oc({handle:e,store:t}){return J(()=>e.attachStore(t),[e,t]),null}function sc(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function cc(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),sc(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),sc(t))})}function lc(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 uc(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function dc(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=cc(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 fc(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=$i(Ia);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,a,o,s,n])}function pc(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=tc({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 Yr(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function mc(e,t){e.useSyncedValues(t),J(()=>()=>{e.update({activeTriggerProps:di,inactiveTriggerProps:di,popupProps:di})},[e])}function hc(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 gc=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}},_c={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},vc=class extends Fi{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:js(),nested:n,triggerElements:i},_c),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&Ho(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 yc(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new vc({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:di,inactiveTriggerProps:di,popupProps:di}}var bc=e=>e.triggerIdProp??e.activeTriggerId,xc=e=>e.openProp??e.open,Sc=e=>(e.popupElement?.id??e.floatingId)||void 0;function Cc(e,t){return t!==void 0&&xc(e)&&bc(e)===t}function wc(e,t){return Cc(e,t)?!0:t!==void 0&&xc(e)&&bc(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var Tc={open:xc,mounted:e=>e.mounted,transitionStatus:e=>xc(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:bc,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Sc,isTriggerActive:(e,t)=>t!==void 0&&bc(e)===t,isOpenedByTrigger:(e,t)=>Cc(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&bc(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>wc(e,t)?Sc(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement},Ec=Mi();function Dc(e){let t=X.useCallback(t=>e===void 0?Li:e.subscribeStore(t),[e]),n=X.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Ec.useSyncExternalStore)(t,n,()=>e?.serverStore)}var Oc=Ni&&so;function kc(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=X.useRef(!1),s=X.useRef(null),c=X.useRef(!0),l=to();X.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=ra(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&aa(t)&&t===ka(Ba(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return oi(fi(r,`blur`,i),Oc&&fi(r,`keydown`,a,!0),Oc&&fi(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`);Xa(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=Yi(n.nativeEvent);if(Xa(a)){if(Oc&&!n.relatedTarget){if(!c.current&&!Ma(a))return}else if(!Ua(a))return}let u=ca(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,$i(qi,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,$i(qi,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=Xa(r)&&r.hasAttribute(_a(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=ka(Ba(t));!r&&n===t||Y(a.current.floatingContext?.refs.floating.current,n)||Y(t,n)||o||ca(r??n,e.context.triggerElements)||e.setOpen(!1,$i(qi,i))})}}},[a,r,e,l]);return X.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var Ac=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new ti;restTimeout=new ti;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},jc=new WeakMap;function Mc(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&jc.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),jc.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Nc(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=jc.get(n);a&&a!==e&&Mc(a),Mc(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,jc.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Pc(e){let t=e.context.dataRef.current,n=Yr(()=>t.hoverInteractionState??Ac.create()).current;return t.hoverInteractionState||=n,Ti(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Fc(e,t){return t!=null&&!Vo(t)?0:typeof e==`function`?e():e}function Ic(e,t,n){let r=Fc(e,n);return typeof r==`number`?r:r?.[t]}function Lc(e){return typeof e==`function`?e():e}function Rc(e,t){return t||e===`click`||e===`mousedown`}function zc(e){return e?.includes(`mouse`)&&e!==`mousedown`}function Bc(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=e.useState(`open`),o=e.useState(`floatingElement`),s=e.useState(`domReferenceElement`),{dataRef:c}=e.context,l=Is(),u=Fs(),d=Pc(e),f=to(),p=q(()=>Rc(c.current.openEvent?.type,d.interactedInside)),m=q(()=>zc(c.current.openEvent?.type)),h=q(()=>{Mc(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()&&Xa(s)&&o){let e=s,t=o,n=Ba(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??ga(e,`[data-rootownerid]`)??n.body;return Nc(d,{scopeElement:c,referenceElement:e,floatingElement:t}),()=>{h()}}},[n,a,s,o,d,m,l,u,h]),X.useEffect(()=>{if(!n)return;function t(){return!!(l&&u&&Fo(l.nodesRef.current,u).length>0)}function a(t){let n=Ic(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,$i(Qa,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=Yi(e);Oi(t)?d.interactedInside=ga(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(ca(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&Xa(o)&&Fo(l.nodesRef.current,r,!1).some(e=>Y(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,$i(Qa,n)),l.events.emit(`floating.closed`,n)})}let y=o;return oi(y&&fi(y,`mouseenter`,g),y&&fi(y,`mouseleave`,_),y&&fi(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var Vc={current:null};function Hc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=Vc,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=Is(l),v=Pc(e),y=X.useRef(!1),b=gs(i),x=gs(r),S=gs(o),C=gs(n),w=gs(p),T=gs(f),E=q(()=>Rc(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||!Y(t,n);if(!Xa(r))return!1;let a=r;return i.hasMatchingElement(e=>Y(e,a))&&(!t||!Y(t,a))}),k=q(()=>{v.handler&&=(Ba(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=q(()=>{Mc(v)});return u&&(v.handleCloseOptions=i?.__options),X.useEffect(()=>k,[k]),X.useEffect(()=>{if(!n)return;function e(e){e.open?y.current=!1:(y.current=e.reason===Qa,k(),v.openChangeTimeout.clear(),v.restTimeout.clear(),v.blockMouseMove=!0,v.restTimeoutPending=!1)}return g.on(`openchange`,e),()=>{g.off(`openchange`,e)}},[n,g,v,k]),X.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=Ic(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,$i(Qa,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,$i(Qa,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!Xa(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!Vo(v.pointerType))return;let n=Lc(S.current),r=Ic(x.current,`open`,v.pointerType),i=Yi(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(Xa(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(Y(t,i)){c=t;break}}Xa(o)&&Xa(s)&&!e.context.triggerElements.hasElement(o)&&Y(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&&Xa(c)&&Xa(s)&&Y(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,$i(Qa,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,$i(Qa,t,c))}):g&&D()&&e.setOpen(!0,$i(Qa,t,c)))}function o(n){if(E()){A();return}k();let r=e.select(`domReferenceElement`),i=Ba(r);v.restTimeout.clear(),v.restTimeoutPending=!1;let a=h.current.floatingContext??d?.();if(!ca(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`&&Y(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){Y(r,e.relatedTarget)||(v.openChangeTimeout.clear(),v.restTimeout.clear(),v.restTimeoutPending=!1)}let f=m?fi(r,`mouseout`,l):void 0;return s?oi(fi(r,`mousemove`,i,{once:!0}),fi(r,`mouseenter`,i),fi(r,`mouseleave`,o),f):oi(fi(r,`mouseenter`,i),fi(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&&!Vo(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;Nc(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=Lc(S.current);if(o&&!s||c===0||!s&&v.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;v.restTimeout.clear();function l(){if(v.restTimeoutPending=!1,E())return;let t=e.select(`open`);!v.blockMouseMove&&(!t||s)&&D()&&e.setOpen(!0,$i(Qa,n,r))}v.pointerType===`touch`?nc.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}function Uc(e){return so&&e.movementX===0&&e.movementY===0}function Wc(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function Gc(e,t){return Wc(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Kc(e,t,n){return Wc(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function qc(e,t,n){return Wc(t,n?e===Za:e===oa,e===Ea)}function Jc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Wc(t,n?e===oa:e===Za,e===da)}function Yc(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:l=!1,rtl:u=!1,virtual:d=!1,focusItemOnOpen:f=`auto`,focusItemOnHover:p=!0,openOnArrowKeyDown:m=!0,disabledIndices:h=void 0,orientation:g=`vertical`,triggerOrientation:_=g,parentOrientation:v,id:y,resetOnPointerLeave:b=!0,externalTree:x,nestedReturnFocusRef:S,grid:C}=t,w=C!=null,T=e.useState(`open`),E=e.useState(`floatingElement`),D=e.useState(`domReferenceElement`),O=e.context.dataRef,k=Hi(E),A=Ja(D),j=gs(k),M=Fs(),N=Is(x),ee=X.useRef(f),P=X.useRef(o??-1),te=X.useRef(null),F=X.useRef(!0),I=q(e=>{i(P.current===-1?null:P.current,e)}),L=X.useRef(!!E),ne=X.useRef(T),re=X.useRef(!1),R=X.useRef(!1),ie=X.useRef(null),ae=gs(h),z=gs(T),B=gs(o),oe=gs(b),se=bi(),ce=bi(),le=q(()=>{se.cancel();function e(e){d||(ie.current=ys(e,{sync:re.current,preventScroll:!0}))}let t=n.current[P.current],r=R.current;t&&e(t),(re.current?e=>e():e=>se.request(e))(()=>{let i=n.current[P.current]||t;i&&(t||e(i),he&&(r||!F.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});J(()=>{O.current.orientation=g},[O,g]),J(()=>{T||(te.current=null),T&&f===`auto`||(ee.current=f)},[T,f]),J(()=>{a&&(T&&E?(P.current=o??-1,ee.current&&o!=null&&(R.current=!0,I())):L.current&&(P.current=-1,I()))},[a,T,E,o,I]),J(()=>{if(a){if(!T)re.current=!1;else if(E){if(r==null){if(re.current=!1,B.current!=null)return;if(L.current&&(P.current=-1,le()),(!ne.current||!L.current)&&ee.current&&(te.current!=null||ee.current===!0&&te.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ce.request(e):queueMicrotask)(t),e+=1):(P.current=te.current==null||Kc(te.current,_,u)||l?ci(n):Bi(n),te.current=null,I())};t()}}else mi(n.current,r)||(P.current=r,le(),R.current=!1)}}},[a,T,E,r,B,l,n,_,u,I,le,ce]),J(()=>{if(!a||E||!N||d||!L.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=ka(Ba(D??t??null)),r=e.some(e=>e.context&&Y(e.context.elements.floating,n));t&&!r&&F.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,d]),J(()=>{ne.current=T,L.current=!!E});let ue=r!=null,de=q(e=>{if(!z.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(P.current!==t||r!==t)&&(P.current=t,I(e))}),fe=q(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),pe=q(()=>ci(n,ae.current)),me=q(t=>{if(F.current=!1,re.current=!0,t.which===229||!z.current&&t.currentTarget===j.current)return;if(l&&Jc(t.key,g,u,w)){Gc(t.key,fe())||Lo(t),e.setOpen(!1,$i(la,t.nativeEvent));let n=S?.current??D;aa(n)&&n.focus();return}r!=null&&r!==P.current&&!mi(n.current,r)&&(P.current=r);let i=P.current,a=ci(n,h),o=Bi(n,h);if(A||(t.key===`Home`&&(Lo(t),P.current=a,I(t)),t.key===`End`&&(Lo(t),P.current=o,I(t))),C!=null){let e=C(t,P.current,n,g,c,u,h,a,o);if(e!=null&&e!==P.current&&(P.current=e,I(t)),g===`both`)return}if(Gc(t.key,g)){Lo(t);let e=ka(t.currentTarget.ownerDocument);if(T&&!d&&Y(t.currentTarget,e)&&!n.current.some(t=>t!=null&&Y(t,e))){P.current=Kc(t.key,g,u)?a:o,I(t),r===P.current&&le();return}let{index:l,wrapped:f}=gi(n.current,i,{decrement:!Kc(t.key,g,u),loopFocus:c,allowEscape:s,disabledIndices:h,minIndex:a,maxIndex:o});f&&(re.current=!1),P.current=l,I(t)}}),he=X.useMemo(()=>({onFocus(e){re.current=!0,de(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){Uc(e)||(re.current=!0,R.current=!1,p&&de(e))},onPointerLeave(e){if(!z.current||!F.current||e.pointerType===`touch`)return;re.current=!0;let t=e.relatedTarget;if(p&&!n.current.includes(t)&&oe.current&&(ie.current?.(),ie.current=null,P.current=-1,I(e),!d)){let e=j.current,t=ka(Ba(e));e&&Y(e,t)&&e.focus({preventScroll:!0})}}}),[de,z,j,p,n,I,oe,d]),ge=X.useMemo(()=>d&&T&&ue&&{"aria-activedescendant":`${y}-${r}`},[d,T,ue,y,r]),_e=X.useMemo(()=>({...A?{}:ge,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&T&&!d){let n=Yi(t.nativeEvent);if(n&&!Y(j.current,n))return;Lo(t);let r=$i(na,t.nativeEvent);e.setOpen(!1,r);let i=S?.current??D;!r.isCanceled&&aa(i)&&i.focus()}else me(t)},onPointerMove(e){Uc(e)||(F.current=!0)}}),[ge,me,j,A,e,T,d,D,S]),ve=X.useMemo(()=>{function t(t){e.setOpen(!0,$i(la,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&zo(e.nativeEvent)&&(ee.current=!d)}function r(e){ee.current=f,f===`auto`&&Bo(e.nativeEvent)&&(ee.current=!0)}return{onKeyDown(n){let r=e.select(`open`);F.current=!1;let i=n.key.startsWith(`Arrow`),a=qc(n.key,fe(),u),o=Gc(n.key,r?g:_),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||Ma(n.currentTarget)))return me(n);if(r||m||!i){if(s){let e=Gc(n.key,fe());te.current=l&&e?null:n.key}l?a&&(Lo(n),r?(P.current=pe(),I(n),d&&j.current?.focus()):t(n)):o&&(B.current!=null&&(P.current=B.current),Lo(n),!r&&m?t(n):me(n),r&&I(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!d&&(P.current=-1,I(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[me,f,pe,l,I,e,m,g,_,fe,u,B,d,j]),ye=X.useMemo(()=>({...ge,...ve}),[ge,ve]);return X.useMemo(()=>a?{reference:ye,floating:_e,item:he,trigger:ve}:{},[a,ye,_e,ve,he])}function Xc(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=q(s),f=e.useState(`open`),p=to(),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&&!za(n)||n?.matches(`:disabled`)?!1:o==null||!Wi(zi,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===` `&&(Lo(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!==` `&&(Lo(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`);Y(r,n)||Y(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 Zc=.1,Qc=Zc*Zc,$c=.5;function el(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function tl(e,t,n,r,i,a,o,s,c,l){let u=!1;return el(e,t,n,r,i,a)&&(u=!u),el(e,t,i,a,o,s)&&(u=!u),el(e,t,o,s,c,l)&&(u=!u),el(e,t,c,l,n,r)&&(u=!u),u}function nl(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function rl(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function il(e={}){let{blockPointerEvents:t=!1}=e,n=new ti,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*Qc;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=Yi(r),g=r.type===`mouseleave`,_=Y(u,h),v=Y(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&Xa(r.relatedTarget)&&Y(u,r.relatedTarget))return;function y(){return!!(s&&Fo(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=rl(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=rl(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=rl(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=rl(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!nl(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?$c/2:$c*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+$c+1,o=C||T?S.bottom-$c:S.top,s=C?T?S.bottom-$c:S.top:S.bottom-$c;M=tl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?$c/2:$c*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-$c,o=C||T?S.top+$c:S.bottom,s=C?T?S.top+$c:S.bottom:S.top+$c;M=tl(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?$c/2:$c*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+$c+1,o=w||E?S.right-$c:S.left,s=w?E?S.right-$c:S.left:S.right-$c;M=tl(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?$c/2:$c*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-$c,o=w||E?S.left+$c:S.right,s=w?E?S.left+$c:S.right:S.left+$c;M=tl(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}function al(e,t,n){let{reference:r,floating:i}=e,a=ts(t),o=ns(t),s=es(o),c=Zo(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=Qo(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function ol(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Xo(t,e),p=ms(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=hs(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=hs(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var sl=50,cl=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:ol},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=al(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<sl&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=al(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},ll=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=Xo(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Zo(r),_=ts(o),v=Zo(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[fs(o)]:is(o)),x=p!==`none`;!d&&x&&b.push(...ds(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=rs(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`||_===ts(t)||T.every(e=>ts(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=ts(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},ul=new Set([`left`,`top`]);async function dl(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Zo(n),s=Qo(n),c=ts(n)===`y`,l=ul.has(o)?-1:1,u=a&&c?-1:1,d=Xo(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var fl=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await dl(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},pl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Xo(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=ts(i),p=$o(f),m=u[p],h=u[f],g=(e,t)=>Yo(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},ml=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Xo(e,t),u={x:n,y:r},d=ts(i),f=$o(d),p=u[f],m=u[d],h=Xo(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=ul.has(Zo(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},hl=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=Xo(e,t),c=await i.detectOverflow(t,s),l=Zo(n),u=Qo(n),d=ts(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=Uo(p-c[m],g),y=Uo(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*Wo(c.left,c.right):S=p-2*Wo(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function gl(e){let t=sa(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=aa(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Go(n)!==a||Go(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function _l(e){return Xa(e)?e:e.contextElement}function vl(e){let t=_l(e);if(!aa(t))return qo(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=gl(t),o=(a?Go(n.width):n.width)/r,s=(a?Go(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var yl=qo(0);function bl(e){let t=ra(e);return!Ji()||!t.visualViewport?yl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function xl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===ra(e)}function Sl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=_l(e),o=qo(1);t&&(r?Xa(r)&&(o=vl(r)):o=vl(e));let s=xl(a,n,r)?bl(a):qo(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=ra(a),t=Xa(r)?ra(r):r,n=e,i=Ha(n);for(;i&&t!==n;){let e=vl(i),t=i.getBoundingClientRect(),r=sa(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=ra(i),i=Ha(n)}}return hs({width:u,height:d,x:c,y:l})}function Cl(e,t){let n=Zi(e).scrollLeft;return t?t.left+n:Sl(ja(e)).left+n}function wl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Cl(e,n),y:n.top+t.scrollTop}}function Tl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=ja(r),s=t?pa(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=qo(1),u=qo(0),d=aa(r);if((d||!a)&&((va(r)!==`body`||La(o))&&(c=Zi(r)),d)){let e=Sl(r);l=vl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?wl(o,c):qo(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function El(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Dl(e){let t=Zi(e),n=e.ownerDocument.body,r=Wo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Wo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+Cl(e),o=-t.scrollTop;return sa(n).direction===`rtl`&&(a+=Wo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var Ol=25;function kl(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=ra(e),a=ja(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!Ji()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(Cl(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=Ol&&(s-=o)}return{width:s,height:c,x:l,y:u}}function Al(e,t){let n=Sl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=vl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function jl(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=kl(e,n,t);else if(t===`document`)r=Dl(ja(e));else if(Xa(t))r=Al(t,n);else{let n=bl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return hs(r)}function Ml(e,t){let n=t.get(e);if(n)return n;let r=Pa(e,[],!1).filter(e=>Xa(e)&&va(e)!==`body`),i=null,a=sa(e).position===`fixed`,o=a?Ga(e):e;for(;Xa(o)&&!ua(o);){let e=sa(o),t=Ta(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Ga(o)}return t.set(e,r),r}function Nl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?pa(t)?[]:Ml(t,this._c):[].concat(n),r],o=jl(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=jl(t,a[e],i);s=Wo(n.top,s),c=Uo(n.right,c),l=Uo(n.bottom,l),u=Wo(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Pl(e){let{width:t,height:n}=gl(e);return{width:t,height:n}}function Fl(e,t,n){let r=aa(t),i=ja(t),a=n===`fixed`,o=Sl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=qo(0);if((r||!a)&&((va(t)!==`body`||La(i))&&(s=Zi(t)),r)){let e=Sl(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=Cl(i));let l=i&&!r&&!a?wl(i,s):qo(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function Il(e){return sa(e).position===`static`}function Ll(e,t){if(!aa(e)||sa(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return ja(e)===n&&(n=n.ownerDocument.body),n}function Rl(e,t){let n=ra(e);if(pa(e))return n;if(!aa(e)){let t=Ga(e);for(;t&&!ua(t);){if(Xa(t)&&!Il(t))return t;t=Ga(t)}return n}let r=Ll(e,t);for(;r&&ha(r)&&Il(r);)r=Ll(r,t);return r&&ua(r)&&Il(r)&&!Ta(r)?n:r||qa(e)||n}var zl=async function(e){let t=this.getOffsetParent||Rl,n=this.getDimensions,r=await n(e.floating);return{reference:Fl(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Bl(e){return sa(e).direction===`rtl`}var Vl={convertOffsetParentRelativeRectToViewportRelativeRect:Tl,getDocumentElement:ja,getClippingRect:Nl,getOffsetParent:Rl,getElementRects:zl,getClientRects:El,getDimensions:Pl,getScale:vl,isElement:Xa,isRTL:Bl};function Hl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ul(e,t,n){let r=null,i,a=ja(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=Ko(d),h=Ko(a.clientWidth-(u+f)),g=Ko(a.clientHeight-(d+p)),_=Ko(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Wo(0,Uo(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Hl(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=ra(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Wl(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=_l(e),u=i||a?[...l?Pa(l):[],...t?Pa(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Ul(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Sl(e):null;c&&g();function g(){let t=Sl(e);h&&!Hl(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Gl=fl,Kl=pl,ql=ll,Jl=hl,Yl=ml,Xl=(e,t,n)=>{let r=new Map,i=n??{},a={...Vl,...i.platform,_c:r};return cl(e,t,{...i,platform:a})},Zl=typeof document<`u`?X.useLayoutEffect:function(){};function Ql(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Ql(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Ql(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function $l(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function eu(e,t){let n=$l(e);return Math.round(t*n)/n}function tu(e){let t=X.useRef(e);return Zl(()=>{t.current=e}),t}function nu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=X.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=X.useState(r);Ql(f,r)||p(r);let[m,h]=X.useState(null),[g,_]=X.useState(null),v=X.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=X.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=X.useRef(null),C=X.useRef(null),w=X.useRef(u),T=c!=null,E=tu(c),D=tu(i),O=tu(l),k=X.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Xl(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Ql(w.current,t)&&(w.current=t,nc.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Zl(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=X.useRef(!1);Zl(()=>(A.current=!0,()=>{A.current=!1}),[]),Zl(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=X.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=X.useMemo(()=>({reference:b,floating:x}),[b,x]),N=X.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=eu(M.floating,u.x),r=eu(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...$l(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return X.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:N}),[u,k,j,M,N])}var ru=(e,t)=>{let n=Gl(e);return{name:n.name,fn:n.fn,options:[e,t]}},iu=(e,t)=>{let n=Kl(e);return{name:n.name,fn:n.fn,options:[e,t]}},au=(e,t)=>({fn:Yl(e).fn,options:[e,t]}),ou=(e,t)=>{let n=ql(e);return{name:n.name,fn:n.fn,options:[e,t]}},su=(e,t)=>{let n=Jl(e);return{name:n.name,fn:n.fn,options:[e,t]}};function cu(e){let{nodeId:t,externalTree:n,rootContext:r}=e,i=r.useState(`referenceElement`),a=r.useState(`floatingElement`),o=r.useState(`domReferenceElement`),s=r.useState(`open`),c=r.useState(`floatingId`),[l,u]=X.useState(null),d=X.useRef(null),f=Is(n),p=X.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),m=nu({...e,elements:{...p,...l&&{reference:l}}}),h=X.useCallback(e=>{let t=Xa(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 lu=X.createContext(void 0);function uu(){return X.useContext(lu)?.direction??`ltr`}var du=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Xo(e,t)||{};if(l==null)return{};let d=ms(u),f={x:n,y:r},p=ns(i),m=es(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=Yo(D,k,O),j=!c.arrow&&Qo(i)!=null&&k!==A&&a.reference[m]/2-(k<D?T:E)-h[m]/2<0,M=j?k<D?k-D:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),fu=(e,t)=>{let{name:n,fn:r}=du(e);return{name:n,fn:r,options:[e,t]}},pu={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},mu={sideX:`left`,sideY:`top`},hu=`--available-width`,gu=`--available-height`,_u=`--anchor-width`,vu=`--anchor-height`,yu=`--transform-origin`,bu=hu,xu=gu;function Su(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function Cu(e,t,n){let{rects:r,placement:i}=e;return{side:Su(t,Zo(i),n),align:Qo(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function wu(e){return Tu(e,cu)}function Tu(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:l=5,sticky:u=!1,arrowPadding:d=5,disableAnchorTracking:f=!1,inline:p,keepMounted:m=!1,floatingRootContext:h,mounted:g,collisionAvoidance:_,shift:v,nodeId:y,adaptiveOrigin:b,lazyFlip:x=!1,externalTree:S}=e,C=_.side||`flip`,w=_.align||`flip`,T=_.fallbackAxisSide||`end`,E=v?.crossAxis??!1,D=v?.rootBoundary,O=typeof n==`function`?n:void 0,k=q(O),A=O?k:n,j=gs(n),M=gs(g),N=uu()===`rtl`,[ee,P]=X.useState(null);!g&&ee!==null&&P(null);let te=x===`placement`,F=ee?Zo(ee):null,I=ee&&te?Qo(ee)||`center`:null,L=F||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":N?`left`:`right`,"inline-start":N?`right`:`left`}[i],ne=I||o,re=ne===`center`?L:`${L}-${ne}`,R=l;typeof R==`number`?R={top:R,right:R,bottom:R,left:R}:R&&={top:R.top||0,right:R.right||0,bottom:R.bottom||0,left:R.left||0};let ie=+(i===`bottom`),ae=+(i===`top`),z=+(i===`right`),B=+(i===`left`),oe={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:R},se=X.useRef(null),ce=gs(a),le=gs(s),ue=typeof a==`function`?0:a,de=typeof s==`function`?0:s,fe=[];p&&fe.push(p),fe.push(ru(e=>{let t=Cu(e,i,N),n=typeof ce.current==`function`?ce.current(t):ce.current,r=typeof le.current==`function`?le.current(t):le.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ue,de,N,i]));let pe=w===`none`&&C!==`shift`,me=!pe&&(u||E||C===`shift`),he=C===`none`?null:ou({...oe,padding:{top:R.top+1+ie,right:R.right+1+B,bottom:R.bottom+1+ae,left:R.left+1+z},mainAxis:!E&&C===`flip`,crossAxis:w===`flip`&&`alignment`,fallbackAxisSideDirection:T}),ge=pe?null:iu({...oe,rootBoundary:D,mainAxis:w!==`none`,crossAxis:me,limiter:u||E?void 0:au(e=>{if(!se.current)return{};let{width:t,height:n}=se.current.getBoundingClientRect(),r=ts(Zo(e.placement)),i=r===`y`?t:n,a=r===`y`?R.left+R.right:R.top+R.bottom;return{offset:i/2+a/2}})},[oe,u,E,D,R,w]);C===`shift`||w===`shift`||ne===`center`?fe.push(ge,he):fe.push(he,ge),fe.push(su({...oe,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!M.current)return;let i=e.style;i.setProperty(bu,`${t}px`),i.setProperty(xu,`${n}px`);let a=ra(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(_u,`${u}px`),i.setProperty(vu,`${d}px`)}}),fu(e=>({element:se.current||Ba(e.elements.floating).createElement(`div`),padding:se.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=Zo(r),u=Qo(r),d=ts(l)===`y`,f=se.current,p=typeof a==`function`?a(Cu(e,i,N)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return me&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(yu,d?`${m} ${h}`:`${h} ${m}`),{}}},pu,b),J(()=>{!g&&h&&h.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[g,h]);let _e=X.useMemo(()=>({ancestorScroll:!f,elementResize:!f&&typeof ResizeObserver<`u`,layoutShift:!f&&typeof IntersectionObserver<`u`}),[f]),{refs:ve,elements:ye,x:be,y:xe,middlewareData:Se,update:Ce,placement:we,context:Te,isPositioned:Ee,floatingStyles:De}=t({rootContext:h,open:m?g:void 0,placement:re,middleware:fe,strategy:r,whileElementsMounted:m?void 0:(...e)=>Wl(...e,_e),nodeId:y,externalTree:S}),{sideX:Oe,sideY:ke}=Se.adaptiveOrigin||mu,Ae=Ee?r:`fixed`,je=X.useMemo(()=>{let e;return e=Ee?b?{position:Ae,[Oe]:be,[ke]:xe}:{...De,position:Ae}:{position:Ae,top:0,left:0},e[bu]=`100vw`,e[xu]=`100vh`,Ee||(e.opacity=0),e},[b,Ae,Oe,be,ke,xe,De,Ee]),Me=X.useRef(null);J(()=>{if(!g)return;let e=j.current,t=typeof e==`function`?e():e,n=(Eu(t)?t.current:t)||null;n!==Me.current&&(ve.setPositionReference(n),Me.current=n)},[g,ve,A,j]),X.useEffect(()=>{if(!g)return;let e=j.current;typeof e!=`function`&&Eu(e)&&e.current!==Me.current&&(ve.setPositionReference(e.current),Me.current=e.current)},[g,ve,A,j]),X.useEffect(()=>{if(m&&g&&ye.reference&&ye.floating)return Wl(ye.reference,ye.floating,Ce,_e)},[m,g,ye,Ce,_e]);let Ne=Zo(we),Pe=Su(i,Ne,N),Fe=Qo(we)||`center`,Ie=!!Se.hide?.referenceHidden;J(()=>{x&&g&&Ee&&(Ne!==L||te&&Fe!==ne)&&P(we)},[x,te,g,Ee,we,Ne,Fe,L,ne]);let Le=X.useMemo(()=>({position:`absolute`,top:Se.arrow?.y,left:Se.arrow?.x}),[Se.arrow]),Re=Se.arrow?.centerOffset!==0;return X.useMemo(()=>({positionerStyles:je,arrowStyles:Le,arrowRef:se,arrowUncentered:Re,side:Pe,align:Fe,physicalSide:Ne,anchorHidden:Ie,refs:ve,context:Te,isPositioned:Ee,update:Ce}),[je,Le,se,Re,Pe,Fe,Ne,Ie,ve,Te,Ee,Ce])}function Eu(e){return e!=null&&`current`in e}function Du(e){return e===`starting`?Pi:di}function Ou(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),$r(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Du(r),i],stateAttributesMapping:No})}var ku=e(o(),1);function Au(e){let t=ku.unstable_scheduleCallback(4,e);return()=>ku.unstable_cancelCallback(t)}var ju=X.createContext(Le({scheduleTask:Au,defaultIdleTTL:400})),Mu=new WeakMap,Nu=0,Pu=new Set;function Fu(e){Nu++;try{return e()}finally{Nu--}}function Iu(e){if(Nu===0)return e();Pu.size===0&&queueMicrotask(Lu),Pu.add(e)}function Lu(){for(let e of Pu)Pu.delete(e),e()}function Ru(e,t){let n=Mu.get(e);n===void 0&&(n=new WeakMap,Mu.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=0,a,o={subscribe(n){i++;let r=e.subscribe(t,()=>Iu(n));return()=>{i--,Pu.delete(n),r()}},snapshot(){return Fu(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Fu(()=>Fr(t,e))}),a.value}};return n.set(t,o),o}function zu(e,t){let n=Ru(e,t);return X.useEffect(Lu),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Bu(e,t,n){let r=Ru(e,t),i=X.useMemo(()=>{let e;return t=>(e!==void 0&&Object.is(e.source,t)||(e={source:t,value:n(t)}),e.value)},[n]);return X.useEffect(Lu),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var Vu=(e,t)=>{let n=X.useContext(ju);return t?Bu(n,e,t):zu(n,e)};function Hu(e,t){X.useEffect(()=>e.mount(t),[t,e])}function Uu(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?X.useCallback(r=>{e.set(t,r);let i=Jn(Oe(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Wu):i},[e,t,n.mode]):X.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Wu=e=>{if(dr(e))return e.value;throw Ir(e.cause)},Gu=(e,t)=>{let n=X.useContext(ju);return Hu(n,e),Uu(n,e,t)},Ku=(e,t)=>{let n=X.useContext(ju);return[zu(n,e),Uu(n,e,t)]};Qe(`MachineSchemaEncodeError`);var qu=class extends Qe(`MachineSchemaDecodeError`){},Ju=class extends Qe(`InfiniteTransitionError`){},Yu=class extends Qe(`StartupError`){},Xu=class extends Qe(`ChildAlreadyExistsError`){};Qe(`ProcessLocalError`);var Zu=class extends Qe(`StoppedError`){},Qu=e=>e instanceof Ju||e instanceof qu,$u=e=>Qu(e)?ae(e):Kr(e),ed=e=>Qu(e)||e instanceof Yu?e:new Yu({cause:Zt(e)}),td=e=>e,nd=`~effect/Machine/Target`,rd=Symbol(`effect/Machine/TargetSnapshot`),id=Symbol(`effect/Machine/StateInput`),ad=Symbol(`effect/Machine/HistoryTarget`),od=Symbol(`effect/Machine/InitialTarget`),sd=Symbol(`effect/Machine/ChoiceTarget`),cd=Symbol(`effect/Machine/NoTarget`),ld=Symbol(`effect/Machine/Declined`),ud=Symbol(`effect/Machine/TargetSelection`),dd=Symbol(`effect/Machine/StateUpdate`),fd=Symbol(`effect/Machine/CombinedTarget`),pd=Symbol(`effect/Machine/SelectedBranch`),md=(e,t,n,r)=>Object.freeze({[ud]:ud,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),hd=md(`none`,void 0,`local`),gd=e=>G(e,ud),_d=(e,t)=>Object.freeze({[dd]:dd,path:e,value:t}),vd=e=>G(e,dd),yd=(e,t)=>Object.freeze({[fd]:fd,target:e,update:t}),bd=e=>G(e,fd),xd=(e,t,n,r)=>Object.freeze({[pd]:pd,owner:e,branchIndex:t,branchKey:n,result:r}),Sd=e=>G(e,pd),Cd=Object.freeze({[cd]:cd}),wd=()=>Cd,Td=e=>G(e,cd),Ed=Object.freeze({[ld]:ld}),Dd=()=>Ed,Od=e=>G(e,ld),kd=(e,t)=>({[ad]:ad,path:e,parent:t}),Ad=e=>G(e,ad),jd=(e,t,n)=>({[od]:od,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),Md=e=>G(e,od),Nd=(e,t,n)=>({[sd]:sd,path:e,parent:t,...n===void 0?{}:{values:n}}),Pd=e=>G(e,sd),Fd=(e,t)=>{if(!we(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(!we(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(we(t))return{schema:t,output:void 0,annotations:z(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=G(t,`schema`)&&we(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:z(n);if(t.type===`parallel`&&!G(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(G(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:we(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=we(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}},Id=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=Fd(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)}},Ld=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],Rd=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,zd=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=td(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:Ld(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:G(i,`reenter`)&&i.reenter===!0,acceptance:Rd(i),branches:Ld(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:Rd(r.always),branches:Ld(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:Rd(r.onDone),branches:Ld(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:Rd(a),branches:Ld(a)})}}}return t},Bd=(e,t,n)=>({[nd]:nd,[rd]:n?.snapshot,path:e,value:t,values:n?.values}),Vd=e=>G(e,nd),Hd=e=>({[id]:id,input:e}),Ud=e=>G(e,id),Wd=e=>G(e,`path`)&&G(e,`value`),Gd=(e,t,n)=>{if(e.path===t)return gr(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return c();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),G(e,`state`)&&Wd(e.state))return Gd(e.state,t,n);if(G(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if(Wd(r)){let e=Gd(r,t,n);if(Ct(e))return e}}return c()},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},Kd=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},qd=new WeakMap,Jd=Symbol(`effect/Machine/EventConstruction`),Yd=new WeakMap,Xd=new WeakMap,Zd=new WeakMap,Qd=e=>{let t=e,n=Xd.get(t);if(n!==void 0)return n;let r=jn(vt(e));return Xd.set(t,r),r},$d=e=>{let t=e,n=Zd.get(t);if(n!==void 0)return n;let r=h(vt(e));return Zd.set(t,r),r},ef=Symbol.for(`effect/Machine/protocol`),tf=e=>{let t=e[ef];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},nf=(e,t)=>{Object.defineProperty(e,ef,{value:t,enumerable:!1})},rf=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),G(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&G(t,`make`)&&n(t)};for(let t of e)n(t);return t},af=(e,t)=>{let n=qd.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},of=e=>af(e.events,`public`).schemas,sf=e=>af(e.internalEvents,`internal`).schemas,cf=e=>af(e.emittedEvents,`emitted`).schemas,lf=e=>{let t=of(e),n=sf(e),r=cf(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];nf(e,{event:j(a),emit:j(r),eventConstructors:rf(a),emissionConstructors:rf(r)})},uf=(e,t)=>nf(t,tf(e)),df=e=>G(e,`_tag`)?String(e._tag):void 0,ff=(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={[Jd]:Jd,_tag:n};return Yd.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},pf=e=>typeof e==`object`&&!!e&&Yd.has(e),mf=(e,t)=>{let n=[],r=e=>{if(G(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(G(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=>ir(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:Un(e)?[e.symbol]:ye(e)?e.enums.map(([,e])=>e):vr(e)?e.types.flatMap(a):Ke(e)?a(e.thunk()):[],o=e=>{let t=cr(e.ast);if(Et(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 j([e]).pipe(ut(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(G(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>ff(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},hf=(e,t)=>{let n=Object.freeze(Array.from(t)),r=mf(e,n);return qd.set(r,{kind:e,schemas:n}),Object.freeze(r)},gf=(e,t,n,r)=>Qd(t)(n).pipe(l(t=>new qu({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),_f=(e,t,n,r)=>{let i=$d(t)(n);if(ft(i))throw new qu({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},vf=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new qu({machineId:e.id,boundary:r.boundary,cause:Xe(t)?t:G(n,`~effect/SchemaIssue/Issue`)?new Gt(n):Zt(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},yf=(e,t,n)=>new qu({machineId:e.id,boundary:n,event:String(t._tag),cause:Zt(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),bf=(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}},xf=(e,t,n,r)=>new qu({machineId:e.id,boundary:n,event:String(t._tag),cause:Zt(r)}),Sf=(e,t,n,r)=>{let i=Yd.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)?ae(yf(e,n,r)):Or({try:()=>bf(n,i),catch:t=>xf(e,n,r,t)}).pipe(V(t=>i.schema.makeEffect(t).pipe(l(t=>new qu({machineId:e.id,boundary:r,event:String(n._tag),cause:new Gt(t)})))))},Cf=(e,t,n,r)=>{let i=Yd.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 yf(e,n,r);let o;try{o=bf(n,i)}catch(t){throw xf(e,n,r,t)}return vf(e,i.schema,o,{boundary:r,event:String(n._tag)})},wf=(e,t)=>{let n=tf(e);if(pf(t))return Sf(e,n,t,`event`);let r=df(t);return gf(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Tf=(e,t)=>{let n=tf(e);if(pf(t))return Cf(e,n,t,`event`);let r=df(t);return _f(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Ef=(e,t)=>{let n=tf(e);if(pf(t))return Sf(e,n,t,`emission`);let r=df(t);return gf(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Df=(e,t)=>{let n=tf(e);if(pf(t))return Cf(e,n,t,`emission`);let r=df(t);return _f(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Of=(e,t,n)=>_f(e,t,n,{boundary:`input`}),kf=(e,t,n)=>Ud(n)?Kd(t).makeEffect(n.input).pipe(l(n=>new qu({machineId:e.id,boundary:`state`,state:t.path,cause:new Gt(n)}))):gf(e,Kd(t),n,{boundary:`state`,state:t.path}),Af=(e,t,n)=>Ud(n)?vf(e,Kd(t),n.input,{boundary:`state`,state:t.path}):_f(e,Kd(t),n,{boundary:`state`,state:t.path}),jf=(e,t,n)=>t.output===void 0?un(n):gf(e,t.output,n,{boundary:`output`,state:t.path}),Mf=(e,t,n)=>t.output===void 0?n:_f(e,t.output,n,{boundary:`output`,state:t.path}),Nf=(e,t)=>{let n=new Set(Uf(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)&&!Hf(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&Vf(r,t.parent)&&Q(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},Pf=(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`||!(Hf(n,t.parent)||Uf(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,Af(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}),Nf(e,n.get(r))}return n},Ff=L(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*ae(new qu({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`||!(Hf(n,t.parent)||Uf(e,t.parent).includes(n)))return yield*ae(new qu({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*ae(new qu({machineId:e.id,boundary:`history`,state:n,cause:Zt(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!s)return yield*ae(new qu({machineId:e.id,boundary:`history`,state:n,cause:Zt(Error(`Machine snapshot omits remembered value for "${n}"`))}));o.set(n,yield*gf(e,Kd(r),i.values[n],{boundary:`history`,state:n}))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)return yield*ae(new qu({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{Nf(e,n.get(r))}catch(t){return yield*ae(new qu({machineId:e.id,boundary:`history`,state:r,cause:Zt(t)}))}}return n}),If=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>Gf(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},Lf=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),Rf=e=>e.machineReferences,zf=new WeakMap,Bf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Vf=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),Hf=(e,t)=>e===t||Vf(e,t),Uf=(e,t)=>{let n=zf.get(e.stateNodes);n===void 0&&(n=new Map,zf.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},Wf=(e,t)=>Uf(e,t).length,Gf=(e,t,n)=>Q(e,t).order-Q(e,n).order,Kf=(e,t,n)=>Q(e,n).children.some(e=>t.active.has(e)),qf=(e,t)=>{let n=Array.from(t.active).filter(n=>!Kf(e,t,n)).sort((t,n)=>Gf(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},Jf=(e,t)=>qf(e,t)[0],Yf=(e,t,n)=>{let r=qf(e,t).filter(e=>Hf(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},Xf=(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`)},Zf=(e,t,n)=>{let r={},i=Uf(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},Qf=(e,t,n)=>{let r=Q(e,n).parent;return r===void 0?void 0:t.values.get(r)},$f=(e,t)=>{let n=r=>t.active.has(r)?[r,...Q(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},ep=(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=ep(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]=ep(e,t,i)}i.states=a}return i},tp=(e,t)=>{let n=ep(e,t,Xf(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:If(e,t.history)}),n},np=(e,t,n)=>{let r=ep(e,t,n);return t.history.size>0&&Object.assign(r,{history:If(e,t.history)}),r},rp=(e,t,n)=>{if(!G(n,`state`)||!Wd(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},ip=(e,t)=>{if(!G(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},ap=(e,t,n,r)=>{let i=Q(e,n),a=r[i.key];if(!Bf(r,i.key)||!Wd(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},op=(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,Af(e,i,t.value));if(i.type===`compound`&&a(rp(e,i,t)),i.type===`parallel`){let n=ip(i,t);for(let t of i.children)a(ap(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:Pf(e,t)}},sp=(e,t)=>op(e,t),cp=(e,t)=>{try{return op(e,t)}catch(t){throw t instanceof qu?t:new qu({machineId:e.id,boundary:`configuration`,cause:Zt(t)})}},lp=L(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=L(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*kf(e,i,t.value));if(i.type===`compound`&&(yield*a(rp(e,i,t))),i.type===`parallel`){let n=ip(i,t);for(let t of i.children)yield*a(ap(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*Ff(e,t)}}),up=(e,t)=>lp(e,t).pipe(se(t=>{if(Rn(t))return lt(Br(t,t=>t instanceof qu?t:new qu({machineId:e.id,boundary:`configuration`,cause:cn(t)})));let n=Zn(t);return Ct(n)&&n.value instanceof qu?ae(n.value):ae(new qu({machineId:e.id,boundary:`configuration`,cause:t}))})),dp=(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 Uf(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&Vf(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}},fp=(e,t)=>e.history.get(t),pp=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=Uf(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)Hf(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}};L(function*(e,t,n,r,i){let a=Q(e,n),o=new Set,s=new Map,c=new Map,l=Uf(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&&Bf(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*kf(e,c,r));else if(i!==void 0&&Bf(i,n))s.set(n,yield*kf(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)Hf(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}}),L(function*(e,t,n,r){let i=yield*lp(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Uf(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&&Bf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Bf(r,i))o.set(i,yield*kf(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)Hf(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&&Bf(r,n))for(let[t,i]of Object.entries(r)){if(!Hf(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*kf(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var mp=(e,t,n,r,i,a=!1)=>{let o=Q(e,n),s=new Set,c=new Map,l=new Map,u=Uf(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&&Bf(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,Af(e,a,r));else if(i!==void 0&&Bf(i,n))c.set(n,Af(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)Hf(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}},hp=(e,t,n)=>{let r=mp(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,Af(e,n,r))}return{...r,active:i,values:a}},gp=(e,t,n,r)=>{let i=op(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Uf(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&&Bf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&Bf(r,i))o.set(i,Af(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)Hf(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&&Bf(r,n))for(let[t,i]of Object.entries(r)){if(!Hf(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,Af(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},_p=(e,t,n)=>{if(Vd(n)){let r=n[rd];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return gp(e,t,r,n.values)}return mp(e,t,n.path,n.value,n.values)}if(Wd(n)){let r=cp(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`)},vp=(e,t)=>td(e).handlers[t],yp=(e,t,n)=>Q(e,n).children.find(e=>t.active.has(e)),bp=(e,t)=>Q(e,t).type===`final`,xp=(e,t)=>vp(e,t)?.onDone!==void 0,Sp=(e,t,n)=>{if(!t.active.has(n))return!1;let r=Q(e,n);if(r.type===`compound`){let r=yp(e,t,n);return r!==void 0&&(n===``?!xp(e,r)&&Sp(e,t,r):bp(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!Sp(e,t,n))return!1;return!0}return bp(e,n)},Cp=(e,t)=>{let n=Xf(e,t);return Sp(e,t,n)&&!xp(e,n)},wp=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),Tp=L(function*(e,t,n,r,i){let a=Q(e,n),o=vp(e,n)?.output?.({state:t.values.get(n),containingState:Qf(e,t,n),ancestors:Zf(e,t,n),event:r,outputs:i});return yield*jf(e,a,o)}),Ep=L(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=yp(e,t,n);if(o===void 0||(n===``?xp(e,o):!bp(e,o)))return;let s=yield*Ep(e,t,o,r,i,a);if(s===void 0)return;let c=wp(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*Ep(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=wp(i,n,yield*Tp(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!bp(e,n))return;let s=wp(i,n,yield*Tp(e,t,n,r));return s.isNew&&a.push(s),s}),Dp=L(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=Wf(e,n)-Wf(e,t);return r===0?Gf(e,t,n):r}))yield*Ep(e,a,t,n,r,i);return{configuration:a,completions:i}}),Op=(e,t,n,r,i)=>{let a=Q(e,n),o=vp(e,n)?.output?.({state:t.values.get(n),containingState:Qf(e,t,n),ancestors:Zf(e,t,n),event:r,outputs:i});return Mf(e,a,o)},kp=(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=yp(e,t,n);if(o===void 0||(n===``?xp(e,o):!bp(e,o)))return;let s=kp(e,t,o,r,i,a);if(s===void 0)return;let c=wp(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=kp(e,t,n,r,i,a);o===void 0?c=!1:s[Q(e,n).key]=o.output}if(!c)return;let l=wp(i,n,Op(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!bp(e,n))return;let s=wp(i,n,Op(e,t,n,r));return s.isNew&&a.push(s),s},Ap=(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=Wf(e,n)-Wf(e,t);return r===0?Gf(e,t,n):r}))kp(e,a,t,n,r,i);return{configuration:a,completions:i}},jp=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},Mp=(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 Hd(Object.hasOwn(t,`data`)?t.data:{})}},Np=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=jp(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return Bd(t,Mp(i,e))}let a=new Map,o=(t,n)=>{let i=jp(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=Mp(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=jp(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=jp(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=jp(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=jp(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 Nd(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return Bd(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...jd(l,f,p),...m.size===0?{}:{children:m}}},Pp=(e,t,n)=>{let r=jp(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 _d(t,Mp(i,r))},Fp=(e,t,n=``)=>{let r=jp(t),i=e.byPath.get(n);Np(e,n,r);let a=Mp(i,r);if(i.type===`choice`)return Nd(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=jp(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,Fp(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]}},Ip=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},Lp=`root`,Rp=e=>{let t=new Map,n=(e,r)=>{let i=!we(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!we(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 "${Lp}" is reserved for the root`);return t},zp=(e,t)=>{let n=Rp(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(Ip(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(Ip(t.branches,`Machine branches must be a map`))){let t=Ip(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={...Ip(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 Vp({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}},Bp=(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}},Vp=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=Bp(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return md(`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 hd}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return md(`state`,``,`branch`)}let i=Bp(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:Bp(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return md(i.kind,i.path,r===`history`?`full`:`branch`,a)},Hp=(e,t,n,r)=>{let i=Ip(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`&&kt(a.value))&&!(a.kind===`streams`&&Qt(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}},Up=Symbol(`effect/Machine/InitialEvent`),Wp=Symbol(`effect/Machine/SnapshotBuilderState`),Gp=Symbol(`effect/Machine/ChildMachineLogic`),Kp=new WeakSet,qp=e=>Kp.has(e),Jp=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},Yp=e=>typeof e==`function`?e:()=>e,Xp=e=>{if(typeof e==`object`&&e&&G(e,`decoded`)&&e.decoded===!0&&G(e,`data`)){let t=Jp(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return Yp(t.data)}let t=Yp(e);return n=>Hd(e===void 0?{}:t(n))},Zp=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(!G(e,`data`))throw Error(`Machine decoded construction requires data`);return Yp(e.data)}let t=Yp(e.data);return n=>Hd(G(e,`data`)?t(n):{})},Qp=(e,t)=>{let n=(e,t,r)=>{if(G(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&G(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(we(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?{}:Jp(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?{}:Jp(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!we(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!we(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=Xp(r)}}else{let t=Jp(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||we(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`&&(G(t,`data`)||G(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=Zp(t),l=e.states[a];if(G(t,`data`)&&!we(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);G(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?{}:Jp(c[t],`state handler`),e);l[t]=a.node,(we(i)||i.type!==`history`)&&(c[t]!==void 0||!we(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{[Wp]:i}};return Kp.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},$p=(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)},em=e=>`child`in e?e.child.id:e.id,tm=(e,t)=>{let n=new Set;for(let r of e){let e=em(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},nm=e=>e===void 0?[]:Array.isArray(e)?e:[e],rm=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(Tf(e,t))},emit:t=>{r.push(Df(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},im=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},am=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(Hd(t.length===0?{}:t[0])),enumerable:!1}),t},om=e=>{let t={};return Object.defineProperty(t,Wp,{value:e,enumerable:!1}),t},sm=(e,t,n)=>{let r=om(n);for(let i of t.children){let a=im(e,i);a.schema===void 0||G(n,a.key)||(r[a.key]=am(r=>{let i=Object.assign({},n);return i[a.key]=r,sm(e,t,i)}))}return r},cm=(e,t)=>{let n=im(e,t);if(n.type===`parallel`)return sm(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=im(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return am(e=>om({[r.key]:e}))},lm=(e,t)=>{if(typeof t!=`object`||!t||!G(t,Wp))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[Wp]},um=Symbol(`effect/Machine/InvocationEvent`),dm=(e,t,n)=>({[um]:!0,path:e,id:t,type:`done`,output:n}),fm=(e,t,n)=>({[um]:!0,path:e,id:t,type:`element`,element:n}),pm=(e,t,n)=>({[um]:!0,path:e,id:t,type:`failure`,error:n}),mm=(e,t,n)=>({[um]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),hm=e=>typeof e==`object`&&!!e&&um in e,gm=new WeakMap,_m=new WeakMap,vm=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},ym=(e,t)=>{let n=Object.create(e);return _m.set(n,vm(e,t)),n},bm=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return vm(e,n);let r=_m.get(e);if(r!==void 0)return r;let i=gm.get(e);if(i!==void 0)return i;let a=vm(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>ae(new Zu)},parent:void 0});return gm.set(e,a),a},xm=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}},Sm=(e,t,n)=>{let r=rm(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Cm=(e,t,n,r)=>{let i=rm(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Od(a.result)?{declined:!0}:{declined:!1,state:Td(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},wm=(e,t,n)=>{let r=rm(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Tm=(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)=>Gf(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=th(e,m,Nd(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=Md(i)?Dm(e,r,i,n):Ad(i)?Om(e,r,i,n):void 0;r=_p(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=td(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,Af(e,p,Hd({}))),u=!0;continue}let i=wm(e,t,{...bm(e,m),state:m.values.get(d),containingState:Qf(e,m,d),ancestors:Zf(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...qp(t)?{}:{builder:cm(e,d)}}),l=lm(d,i.value);a.set(p.path,Af(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:td(e).handlers[d]?.initialize,h=m===void 0?void 0:wm(e,m,{...bm(e,p),state:p.values.get(d),containingState:Qf(e,p,d),ancestors:Zf(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...qp(m)?{}:{builder:cm(e,d)}}),g=h===void 0?void 0:lm(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,Af(e,n,Hd({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&qp(m)){a.set(n.path,Af(e,n,Hd({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,Af(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 Em(e,t,n,r){let i=hp(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>Q(e,t).type===`choice`))return Tm(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=th(e,i,Nd(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=Md(t)?Dm(e,i,t,r):Ad(t)?Om(e,i,t,r):void 0;i=_p(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=Tm(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 Dm(e,t,n,r){let i=Em(e,t,n,r),a=np(e,i.configuration,n.path);return{target:Bd(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Om(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=fp(t,n.path);if(a!==void 0){let i=Tm(e,pp(e,t,a),r),o=np(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:Bd(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=td(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=Cm(e,s,{event:r,target:t=>Fp(e.stateNodes,t),owner:n.parent});if(c.state===void 0||Ad(c.state)||!Wd(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=$m(c.state)===void 0?void 0:th(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?cp(e,c.state):_p(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=_p(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=np(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:Bd(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 km=(e,t)=>{if(!t.transition.declinable)return t;let n=Cm(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},Am=(e,t)=>[...Uf(e,t)].reverse(),jm=(e,t,n)=>{let r=Uf(e,t),i=Uf(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},Mm=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||Vf(e,t)?t:e},Nm=(e,t,n)=>Im(e,Array.from(t.active).filter(e=>n===void 0||Vf(e,n))),Pm=(e,t,n)=>Lm(e,Array.from(t.active).filter(e=>n===void 0||Vf(e,n))),Fm=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),Im=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Uf(e,n).length-Uf(e,t).length;return r===0?Q(e,n).order-Q(e,t).order:r}),Lm=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Uf(e,t).length-Uf(e,n).length;return r===0?Gf(e,t,n):r}),Rm=(e,t,n,r)=>({...bm(e,t),state:t.values.get(n),containingState:Qf(e,t,n),ancestors:Zf(e,t,n),event:r}),zm=(e,t,n,r,i)=>({...bm(e,t),state:t.values.get(n),containingState:Qf(e,t,n),ancestors:Zf(e,t,n),event:r,snapshot:i}),Bm=(e,t,n,r,i,a)=>({...bm(e,t),state:t.values.get(n),containingState:Qf(e,t,n),ancestors:Zf(e,t,n),event:r,output:i,snapshot:a}),Vm=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=Sm(e,td(e).handlers[c]?.[i],Rm(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},Hm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=tp(e,t);for(let o of qf(e,t))for(let c of Am(e,o)){let l=xm(td(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=km(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...bm(e,t),state:t.values.get(c),containingState:Qf(e,t,c),ancestors:Zf(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},Um=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=tp(e,t);for(let o of r){let r=xm(td(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=km(e,{sourcePath:o.path,leafPath:Yf(e,t,o.path),trigger:{type:`done`},transition:r,context:Bm(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},Wm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=tp(e,t);for(let o of qf(e,t))for(let c of Am(e,o)){let l=xm(td(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=km(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:zm(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},Gm=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=td(e).handlers[n.path],i=nm(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=xm(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=tp(e,t),s={...bm(e,t),state:t.values.get(n.path),containingState:Qf(e,t,n.path),ancestors:Zf(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=km(e,{sourcePath:n.path,leafPath:Yf(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},Km=e=>{if(Ad(e)||Pd(e)||Vd(e)||Wd(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},qm=(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(`, `)}`)}},Jm=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},Ym=(e,t)=>Array.from(t).sort((t,n)=>Gf(e,t.selection.sourcePath,n.selection.sourcePath)),Xm=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&Vf(e.sourcePath,t.sourcePath))),Zm=(e,t)=>{let n=[];for(let r of Ym(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(Jm(r.exitPaths,i.exitPaths)||n){if(Vf(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},Qm=(e,t={})=>{let n={...t},r=[],i=e=>{if(Pd(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:Nd(e.path,e.parent,n),values:n}))},$m=(e,t={})=>Qm(e,t)[0],eh=(e,t)=>{if(Pd(e))return Nd(e.path,e.parent,{...t,...e.values??{}});if(Md(e))return{...e,values:{...t,...e.values}};if(!Vd(e)||Object.keys(t).length===0)return e;let n=e[rd];return Bd(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function th(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=Qm(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 Ju({machineId:e.id,state:d.target.path,maxIterations:rh});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=td(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,Af(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=Cm(e,p.transition,{...bm(e,h),containingState:Qf(e,h,f.path),ancestors:Zf(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`);qm(f.path,{type:`choice`},p.targets,g.state);let _=Km(g.state);n=eh(g.state,d.values);let v=$m(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(!Vd(n)&&!Wd(n)&&!Ad(n)&&!Md(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 nh=(e,t,n)=>{let r=n.leafPath,i=n.collected??Cm(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=bd(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||vd(o)?void 0:o;qm(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(vd(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:Af(e,n,c.value)}})(),u=l!==void 0&&(Md(s)||Pd(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:th(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&Md(f)?Dm(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=Ad(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&Ad(m)){let i=n.transition.reenter?Q(e,n.sourcePath).parent:jm(e,r,m.parent),a=g===void 0?Nm(e,t,i):Im(e,Array.from(t.active).filter(e=>Hf(e,m.parent)));h=Om(e,a.includes(m.parent)?dp(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(Md(r)){let i=Dm(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(!Ad(r)){S.push(r);continue}let i=Om(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?Km(_):Km(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:_p(e,t,_);for(let t of S)w=_p(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||!Fm(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:jm(e,r,C),O=Q(e,n.sourcePath).parent,k=n.transition.reenter?Mm(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?Nm(e,t,k):Im(e,Array.from(t.active).filter(e=>Hf(e,g.parent))),entryPaths:g===void 0?Pm(e,w,k):Lm(e,Array.from(w.active).filter(e=>Hf(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},rh=1e3,ih={_tag:Up},ah=(e,t)=>Cp(e,sp(e,t)),oh=(e,t,n)=>up(e,t).pipe(V(t=>Dp(e,t,n)),V(t=>{let n=Xf(e,t.configuration);return!Cp(e,t.configuration)||!t.configuration.outputs.has(n)?Kr(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):un(t.configuration.outputs.get(n))})),sh=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Of(e,e.input,void 0),t):[Of(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=Dm(e,i,r,ih),o=_p(e,i,a.target),s=tp(e,o),c=$f(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=Vm(e,o,c,ih,`entry`),p=lh(e,o,ih,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:ih,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:tp(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:tp(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}},ch=(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=Xm(r),a=[];for(let n of i)a.push(nh(e,t,n));let o=Zm(e,a),s=Ym(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:Km(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Km(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=_p(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=Im(e,s.flatMap(e=>e.exitPaths)),_=Lm(e,s.flatMap(e=>e.entryPaths));l=dp(e,t,l,g);let v=Vm(e,t,g,n,`exit`),y=Vm(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}},lh=(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 Ju({machineId:e.id,state:String(Jf(e,s)),maxIterations:rh});let t=Ap(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>td(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=Um(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=ch(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(Cp(e,s)){let t=Xf(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?Hm(e,s,c):[];if(h.length>0){let t=ch(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=Wm(e,s,_);if(v.length===0){l=!0;continue}let y=ch(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}},uh=(e,t,n)=>{let r=hm(n)?n:Tf(e,n);if(Cp(e,t)){let n=Ap(e,t,r),i=Xf(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=hm(r)?Gm(e,t,r):Wm(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=ch(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...lh(e,a.next,r,o,s,c,l),event:r}},dh=(e,...t)=>Or({try:()=>sh(e,...t),catch:ed}),fh=(e,t)=>({raise:n=>wf(e,n).pipe(V(e=>t.sendTo(t.self,e))),emit:n=>Ef(e,n).pipe(V(e=>t.emit(e)))}),ph=(e,t)=>_e(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),mh=(e,t)=>m(Array.from(e,e=>t.emit(e)),{discard:!0}),hh=new WeakMap,gh=e=>{let t=hh.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>ae(new Zu)},parent:void 0};return hh.set(e,n),n},_h=(e,t)=>{let n=t===void 0?gh(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},vh=new Set([`initialize`,`invoke`,`on`,`output`]),yh=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!vh.has(t))return!1;return!0},bh=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=td(e).handlers[a.path];if(!yh(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=xm(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)=>Gf(e,t,n)),r.sort((t,n)=>Gf(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=>Uf(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&&(td(e).handlers[``]===void 0||Reflect.ownKeys(td(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}},xh=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()}),Sh=(e,t)=>t?{...e,next:xh(e.next)}:e,Ch=(e,t,n)=>{e.values[t]=n},wh=(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}},Th=(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}},Eh=(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=Eh(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]=Eh(e,t,i)}i.states=a}return i},Dh=(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=Eh(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Oh=(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{..._h(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:Dh(t,n)}},kh=Object.freeze([]),Ah=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(Tf(e,t))},emit:t=>{(o??=[]).push(Df(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:Td(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??kh,raisedEvents:a??kh,emittedEvents:o??kh}},jh=(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:Oh(e,t,n,c,r,i)})}}}return a},Mh=(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},Nh=(e,t,n,r,i)=>{if((Vd(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&Vd(r)&&r[rd]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=Af(e,t.nodes[i],r.value),{...n,values:a}}return wh(t,_p(e,Th(t,n),r))},Ph=(e,t,n,r)=>{let i=Ah(e,r.transition.transition,r.context,r.transition.evaluate),a=bd(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(vd(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:Af(e,i,s.value)}})(),l=o===void 0||vd(o)?void 0:o;qm(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&Md(l)?Dm(e,(()=>{let e=Th(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&&!Vd(d)&&!Wd(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=xh(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():Nh(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||!Mh(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:Km(d),g=h===void 0?t.nodes[r.sourceIndex].parent:jm(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?Mm(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:Nm(e,Th(t,n),v),entryPaths:Pm(e,Th(t,f),v),choiceTransitions:u?.transitions??[]}},Fh=(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:Km(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Km(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=Ph(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=Ym(e,Zm(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&Vf(t.sourcePath,e.sourcePath))).map(r=>Ph(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=Nh(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?Im(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?Lm(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},Ih=(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 Ju({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:rh});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=Ap(e,Th(t,o),s).configuration,i=Xf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:wh(t,n),commands:c??kh,emittedEvents:u??kh,microsteps:d??kh,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=xm(td(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=Ah(e,h.transition,{..._h(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:Dh(t,o)},h.evaluate),f=vd(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`);Ch(o,n,Af(e,r,f.value))}if(qm(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!Vd(p)&&!Wd(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=Vd(p)?p[rd]===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]?Ch(o,n,Af(e,t.nodes[n],p.value)):g=Nh(e,t,o,p,n)}let _=h.reenter||!Mh(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:Km(p),resolvedTarget:p===void 0?void 0:Km(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:kh,entryPaths:_?[t.nodes[v].path]:kh,changed:_};o=g,(d??=[]).push(Sh(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??kh,emittedEvents:u??kh,microsteps:d??kh,done:!1,output:void 0};f+=1,s=g}},Lh=(e,t,n,r,i,a)=>{if(hm(r)){let i=uh(e,a===void 0?Th(t,n):Lf(Th(t,n),a),r);return{event:i.event,next:wh(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:wh(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=Tf(e,r);if(t.flat)return Ih(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=Th(t,n);if(Cp(e,r)){let n=Ap(e,r,o).configuration,i=Xf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:wh(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=jh(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=Fh(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[Sh(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new Ju({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:rh});if(t.finalIndices.some(e=>l.active[e]===1)){let n=Ap(e,Th(t,l),u).configuration;if(l=wh(t,n),Cp(e,n)){let t=Xf(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=jh(e,t,l,n,a);if(r.length===0)continue;let s=Fh(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(Sh(s,i))}},Rh=new WeakMap,zh=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>tp(e,t),plan:(t,n,r,i)=>uh(e,i===void 0?t:Lf(t,i),n)}),Bh=(e,t)=>({fromConfiguration:e=>wh(t,e),toConfiguration:e=>Th(t,e),snapshot:e=>Dh(t,e),plan:(n,r,i=!1,a)=>Lh(e,t,n,r,i,a),...Object.values(td(e).handlers).some(e=>e.initialize!==void 0&&!qp(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Of(e,e.input,void 0),n):[Of(e,e.input,n[0])],a=e.initial(...i),o=Md(a)?Em(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,ih).configuration:cp(e,a),s=Ap(e,r===void 0?o:Lf(o,r),ih).configuration,c=wh(t,s),l=Dh(t,c);if(!Cp(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:$f(e,s),done:!1,output:void 0};let u=Xf(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:$f(e,s),done:!0,output:s.outputs.get(u)}}}}),Vh=e=>{let t=Rh.get(e);if(t!==void 0)return t;let n=bh(e),r=n===void 0?zh(e):Bh(e,n);return Rh.set(e,r),r},Hh=`Machine.invocation:`,Uh=e=>e.startsWith(Hh),Wh=(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,At(t,K)}},Gh=e=>W(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,un(t)}let t=_r();return e.waiter=t,Tt(t).pipe(H(Gh(e)))}),Kh=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),qh=(e,t,n)=>{if(e.closed)return c();let r=e.children.get(t);return r!==void 0&&Kh(r,n)?gr(r.ref):c()},Jh=e=>{if(e.observers!==void 0)for(let t of e.observers)Wh(t,qh(e,t.id,t.child))},Yh=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&Jh(e))},Xh=(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`&&Jh(e),!0},Zh=e=>wt(function*(){let t=yield*E(),n=0,r=0,i=0,a=0;return{rootSessionId:e,stream:Sr(t).pipe(zn(U(()=>{n+=1})),fr(U(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>a++,publishUnsafe:i=>{n!==0&&x(t,{...i,sequence:r++,rootSessionId:e})},close:Mr(t)}}),Qh=e=>({id:e.id,sessionId:e.sessionId}),$h=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?Qh(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?Qh(t):{id:String(t.id)}}]:[]}return[]}),eg=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:$h(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),tg=Symbol.for(`effect/Machine/activeSnapshotObserver`),ng=Symbol.for(`effect/Machine/snapshotObserver`),rg=e=>typeof e==`object`&&!!e&&ng in e,ig=Symbol.for(`effect/Machine/sendParentOverride`),ag=Symbol.for(`effect/Machine/acknowledgedSend`),og=Symbol(`effect/Machine/AcknowledgedMessage`),sg=e=>typeof e==`object`&&!!e&&og in e,cg=e=>sg(e)?e.event:e,lg=(e,t)=>{e!==void 0&&sg(e)&&(e.deferred!==void 0&&At(e.deferred,un(t)),e.inspection?.complete(t))},ug=(e,t)=>{e!==void 0&&sg(e)&&e.deferred!==void 0&&At(e.deferred,lt(t))},dg=e=>{e!==void 0&&sg(e)&&e.deferred!==void 0&&At(e.deferred,ae(new Zu))},fg=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,pg=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),mg=e=>e?._tag===`Childless`||e?.childless===!0,hg=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},gg=e=>{if(e.items===void 0)return c();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),gr(t)},_g=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)dg(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},vg=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),yg=(e,t,n)=>{if(e.closed)return!1;for(hg(e,t),n?.();e.items!==void 0&&e.receivers.size>0;){let t=e.receivers.values().next().value;e.receivers.delete(t),t(K)}return!0},bg=e=>W(()=>{let t=gg(e);return Ct(t)?un(t.value):e.closed?yt:ee(t=>(e.receivers.add(t),U(()=>{e.receivers.delete(t)}))).pipe(H(bg(e)))}),xg=e=>{_g(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(yt)},Sg=class extends b()(`effect/Machine/MachineRuntime`){},Cg=(e,t)=>lr(e,Sg,t),wg=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(Mt);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(fn);return n===void 0?e.cause.reasons.find(Er)===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}}},Tg=(e,t)=>W(()=>e(t)).pipe(pt,Ae),Eg=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=U(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return U(()=>new n)},Dg=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Og=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&sg(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,kg=(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=eg(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{[og]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},Ag=(e,t,n)=>{if(!sg(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:Qh(t),event:r.event,causedBy:r.causedBy})},jg=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:K}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 W(()=>{if(this.registry.closed)return yt;if(this.has(t.key)||this.registry.children.has(t.id))return ae(new Xu({id:t.duplicateId}));let a=e(),o=this.registry.scope??=rr(`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()?pg(this.self,e,t,n):K,...this.sendAcknowledged===void 0?void 0:{[ag]:e=>i()?this.sendAcknowledged(e):yt}},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,Xh(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>Yh(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?V(this.runtime.nextSessionId,e=>this.runtime.startCompiledSync(a,c,this.scopedServices??=jr(this.services,_t,o),e)):this.runtime.start(a,c)).pipe(yr(e=>dr(e)?K:(Yh(this.registry,t.id,n),r===void 0?K:r.stop)));return(u?d:pe(d,o)).pipe(Ae)})}stopAll(){return W(()=>{let e=[];for(let t of this.registry.children.values())t.ownerActive&&e.push(this.stopEntry(t));return e.length===0?K:e.length===1?e[0]:m(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]:m(n,{concurrency:`unbounded`,discard:!0})}},Mg=Nt(c()).pipe(zt(Qn)),Ng=e=>K,Pg=(e,t)=>{},Fg=()=>void 0,Ig=Symbol(`effect/Machine/EmissionsClosed`),Lg=()=>{let e,t=W(()=>{let t=e;return t===Ig?un(void 0):t===void 0?E().pipe(V(t=>U(()=>{let n=e;return n===Ig?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(V(([e,n])=>n?Mr(t).pipe(De(e)):un(e))))):un(t)});return{emit:t=>W(()=>e===void 0||e===Ig?K:$e(e,t).pipe(Ae)),close:()=>{let t=e;return e=Ig,t===void 0||t===Ig?K:Mr(t)},stream:Dr(t.pipe(We(e=>e===void 0?qn:Sr(e))))}},Rg={close:()=>K,spawn:(()=>Kr(Error(`Childless machine logic cannot spawn a process`))),get:()=>un(c()),changes:()=>Mg,sendTo:()=>K,stop:()=>K,owned:{spawn:()=>Kr(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>K,stopPaths:()=>void 0}},zg=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>W(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return K;let t=ve(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?K:Array.isArray(a)?m(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>U(()=>Yh(i,e,t)),s=(e,t,n,r)=>U(()=>Xh(i,e,t,n,r)),l=e=>{let t=typeof e==`string`?e:e.id;return U(()=>{if(i.closed)return c();let n=i.children.get(t);return n!==void 0&&Kh(n,e)?gr(n.ref):c()})},u=e=>{let t=typeof e==`string`?e:e.id;return Pn(Lr((n,r)=>U(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(V(n=>{let a=U(()=>{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 ne(r,a).pipe(H(U(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),Wh(n,qh(i,t,e))})),De(Gh(n)))}))))},d=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return W(()=>{if(i.closed)return K;let o=i.children.get(a);return o!==void 0&&Kh(o,e)?pg(o.ref,t,n,r):K})},f=e=>{let t=typeof e==`string`?e:e.id;return W(()=>{if(i.closed)return K;let n=i.children.get(t);return n!==void 0&&Kh(n,e)?n.ref.stop:K})};function p(n,r){let a=typeof n==`object`&&n&&Gp in n?n:void 0,c=a===void 0?n:a[Gp](r?.input),l=a===void 0?r:{id:a.id,descriptor:a},u=Symbol(),d=l?.id??u,f;return W(()=>i.closed?yt:typeof d==`string`&&(i.children.has(d)||Uh(d))?ae(new Xu({id:d})):(i.scope??=rr(`parallel`),i.children.set(d,{_tag:`Starting`,token:u}),t.start(c,{detached:!0,...l?.id===void 0?void 0:{id:l.id},...l?.onOutcome===void 0?void 0:{onOutcome:l.onOutcome},...l?.[tg]===void 0?void 0:{onSnapshot:l[tg]},...l?.[ig]===void 0?void 0:{sendParent:l[ig]},onReady:(e,t)=>U(()=>{f=e}).pipe(H(s(d,u,e,l?.descriptor)),V(e=>e?K:t)),onStop:o(d,u),parent:e,runtime:t,origin:{_tag:`Spawn`,address:l?.id}}).pipe(yr(e=>Kn(e)?o(d,u).pipe(H(f===void 0?K:f.stop)):K),pe(i.scope))))}return{close:a,spawn:p,get:l,changes:u,sendTo:d,stop:f,owned:new jg(i,e,t,n,r)}},Bg=(e,t,n,r)=>U(()=>zg(e,t,n,r)),Vg=(e,t)=>`${e.length}:${e}${t}`,Hg=(e,t)=>`${Hh}${Vg(e,t)}`,Ug=e=>({initial:()=>K,run:()=>e}),Wg=(e,t,n)=>({initial:()=>K,run:({parent:r})=>{let i=r?.[ag];return i===void 0?Kr(Error(`Stream invocation requires an acknowledged parent machine`)):pn(e,e=>i(fm(t,n,e)).pipe(Ae,se(()=>yt)))}}),Gg=(e,t)=>typeof e==`function`?e(t):e,Kg=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),qg=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Ug(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:()=>Ug($t(Gg(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>Wg(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:()=>Gg(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[Gp](`input`in e?Gg(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},Jg=e=>e.length===0?K:e.length===1?e[0]:m(e,{discard:!0}),Yg=(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(Se(`StoppedError`,()=>K)),Xg=e=>e instanceof Ju||e instanceof qu||e instanceof Zu,Zg=(e,t,n,r,i,a,o,s,c,l,u,d)=>W(()=>{let f=Vg(n,r),p=u===void 0?o:()=>{let t=o();return{...t,run:i=>S(W(()=>t.run(i)),`Machine.invoke`,{attributes:{"machine.id":e.self.id,"machine.sessionId":e.self.sessionId,"machine.state.path":n,"machine.invoke.id":r,"machine.invoke.source":d??r,"machine.invoke.kind":u,"machine.invoke.sessionId":i.self.sessionId},captureStackTrace:!1})}};return t.spawn(p,{key:f,path:n,id:i,duplicateId:r,...a===void 0?void 0:{descriptor:a},...u===void 0?void 0:{activityKind:u},sendParent:(t,n)=>t()?e.self.send(n):K,onOutcome:(t,i,o)=>H(Nr,W(()=>i._tag===`Stopped`||!t()?K:i._tag===`Done`?s===void 0?e.failCause(Zt(Error(`Invocation "${r}" completed without the required onDone handler`))):Yg(e,dm(n,r,i.output),u===void 0?void 0:o):i._tag===`Failure`&&c!==void 0&&(a===void 0||!Xg(i.error))?Yg(e,pm(n,r,i.error),u===void 0?void 0:o):e.failCause(i.cause))),...l===void 0?void 0:{onSnapshot:(t,i)=>t()?Yg(e,mm(n,r,i)):K}})}),Qg=(e,t)=>Uh(e)?ae(new Xu({id:t})):void 0,$g=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:Qg(String(r.address),i);return a===void 0?Zg(e,t,n,i,r.address===void 0?Hg(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},e_=(e,t,n,r)=>{let i=r.child,a=Qg(i.id,i.id);return a===void 0?Zg(e,t,n,i.id,i.id,i,i[Gp],r.onDone,r.onFailure,r.onSnapshot,void 0):a},t_=(e,t,n,r,i,a)=>{let o=Kg(t),s=Lm(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...Rf(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:Qf(e,r,i),ancestors:Zf(e,r,i),event:a};return nm(vp(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?e_(t,n,i,e):$g(t,n,i,qg(e,s,i)))});return s.length===0?void 0:Jg(s)},n_=Symbol(`effect/Machine/CompiledStoppedCompletion`),r_=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[ag](e){return this.sendAcknowledgedEffect(e)}[ng](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=Rg;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=Dg(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:W(()=>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 Og(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:eg({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:Sn(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=zg(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?Ng:this.inspector===void 0?e.send:t=>pg(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)=>fg(e)?this.inspector===void 0?e.send(t):pg(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?Pg:(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(cn(e)),ae(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 i_(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?un(this):(this.runState=`Draining`,Wn(this.drainRuntime(),this.services).pipe(De(this)))}initialize(){let e=this;return wt(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*Bg(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?Ng:e.inspector===void 0?t.send:n=>pg(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)=>fg(t)?e.inspector===void 0?t.send(n):pg(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?Pg:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>Kn(t)?e.childRuntime.close(t):K,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(We(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(yr(t=>(Kn(t)&&e.publishStartFailed(t.cause),r(t))),v(U(()=>{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:an,poll:U(()=>Ot(gg(e.mailbox),cg)),receiveMessage:an,pollMessage:U(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:U(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new i_(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(Ae))),e.options.onSnapshot!==void 0&&(yield*Tg(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 U(()=>this.current.snapshot.state)}get snapshot(){return U(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return W(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=_r(),Tt(this.waiter)))}get stop(){return Hr(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return U(()=>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(Ae);return this.runState===`Initializing`?e:e.pipe(H(yt))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(V(e=>e?fe(this.settleRequestedTermination()).pipe(Ae):K))}sendAcknowledgedEffect(e){return Wt(t=>nn().pipe(V(n=>this.offerEvent(e,void 0,void 0,n).pipe(H(t(Tt(n)))))))}offerEvent(e,t,n,r){return W(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?kg(i,a,e,t,n,r):r===void 0?e:{[og]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return Hr(et(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return ae(new Zu);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&Ag(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&&hg(this.mailbox,e),this.runState!==`Idle`)return K;if(this.runState=`Draining`,o!==void 0){let n;try{n=o(a,e)}catch(e){n=Kr(e)}return n!==void 0||this.hasTerminationRequest()?this.startWorker(n):(this.runState=`Idle`,this.scheduleChangesFlush(t.currentDispatcher),K)}return this.startWorker(void 0)}))}startWorker(e){let t=Wn(this.drainRuntime(e),this.services);return(this.options.detached===!0?fe(t,{startImmediately:!0}):nr(t,{startImmediately:!0})).pipe(V(e=>U(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(V(t=>t?fe(this.interruptAndFinish(e)):K))),Ae)}stopEffect(){return W(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?K:this.requestTermination({_tag:`Stopped`}).pipe(V(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!==Ig||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=Ig;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,_g(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),dg(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=n_,this.lifecycle=`Completed`,this.waiter!==void 0&&(At(this.waiter,this.resolveCompletion(n_)),this.waiter=void 0),!0}settleRequestedTermination(){return W(()=>this.runState===`Draining`?this.worker===void 0?(this.interruptRequested=!0,this.awaitCompletion()):this.interruptAndFinish(this.worker).pipe(H(this.awaitCompletion())):this.finishRequestedTermination())}interruptAndFinish(e){return Pe(e).pipe(H(W(()=>this.lifecycle===`Completed`?K:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?K:this.join.pipe(pt,Ae)}resolveCompletion(e){if(e!==n_)return e;let t=ae(new Zu);return this.completion=t,t}drainRuntime(e){let t=this;return Wt(n=>wt(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(W(()=>{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(pt);if(t.flushPendingChanges(),Kn(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(Ct(e.value))return yield*t.requestTermination({_tag:`Done`,output:e.value.value}),yield*t.finishRequestedTermination();if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();if(t.offerRevision!==r)r=t.offerRevision;else{t.runState=`Idle`,t.worker=void 0;return}}}))}finishRequestedTermination(){return W(()=>{if(this.lifecycle!==`TerminationRequested`)return K;let e=this.termination;if(e===void 0)return K;let t=this.terminationSnapshot??this.reserveTermination(e);if(t===void 0)return this.awaitCompletion();let n=e._tag===`Stopped`?Nn:e._tag===`Done`?Kt(e.output):Sn(e.cause),r=e._tag===`Stopped`?n_:e._tag===`Done`?un(e.output):lt(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?K:W(()=>this.options.onOutcome(wg(t))).pipe(pt,Ae),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(H(U(()=>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`?Rt():n}))));return Hr(U(()=>{_g(this.mailbox)}).pipe(H(this.childRuntime.close(n)),H(this.setAndPublishSnapshot(t)),H(s),H(U(()=>{e._tag===`Failure`?ug(this.inFlightMessage,e.cause):dg(this.inFlightMessage),this.inFlightMessage=void 0})),H(i),H(this.options.onStop??K),H(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:K),H(U(()=>{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&&(At(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?un(e):$e(e.changes,[e]).pipe(De(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe(vn(()=>Tg(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?K:$e(e.changes,Kt(void 0)).pipe(Ae)}emitEvent(e){let t=this.externalEmissions===void 0?W(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===Ig?K:$e(this.emissionsPubSub,e).pipe(Ae)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe(vn(()=>U(()=>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=Ig,e===void 0||e===Ig?K:Mr(e)}getOrCreateEmissions(){return W(()=>{let e=this.emissionsPubSub;return e===Ig?un(void 0):e===void 0?E().pipe(V(e=>U(()=>{let t=this.emissionsPubSub;return t===Ig?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(V(([t,n])=>n?Mr(e).pipe(De(t)):un(t))))):un(e)})}emissionsStream(){return Dr(this.getOrCreateEmissions().pipe(We(e=>e===void 0?qn:Sr(e))))}setAndPublishSnapshot(e){return W(()=>{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(V(e=>this.completeChanges(e)),Ae)})}setActiveState(e){return W(()=>this.commitActiveState(e)??K)}pollCompiledMessage(){let e=gg(this.mailbox);return Ct(e)&&(this.inFlightMessage=sg(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=sg(e)?e:void 0}completeCompiledMessage(e){lg(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]:x(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:x(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:Tg(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,x(e.changes,t))}updateState(e){return W(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?K:e(t.snapshot.state).pipe(V(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?K:this.setActiveState(e)}))})}getOrCreateChanges(){return W(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?E({replay:1}).pipe(V(e=>U(()=>{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(V(([t,n])=>n?Mr(e).pipe(De(t)):un(t))))):un(e.changes):un(void 0)})}changesStream(){let e=this;return Dr(wt(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return Nt(e.current.snapshot);let n=yield*it(t),r=e.current;return r.snapshot.status===`active`?Nt(r.snapshot).pipe(zt(Pn(Ut(k(n))).pipe(qt(e=>e.revision>r.revision),ln(e=>e.snapshot)))):Nt(r.snapshot)}))}},i_=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return Ot(this.process.pollCompiledMessage(),cg)}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}},a_=L(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*Ye(),i=e.execution,a=new r_(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(yr(e=>Kn(e)?a.shutdownEmissions().pipe(H(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:K)):K))}),o_=(e,t,n,r)=>new r_(e,t,n,r).initializeCompiledSync(),s_=L(function*(e,t){let{detached:n,id:r,onOutcome:i,onReady:a,onReadySync:o,onSnapshot:s,onStop:c,onStopSync:l,parent:d,runtime:f,sendParent:p}=t,m=t.sessionId??(yield*f.nextSessionId),h=r??m,g=f.inspection,_=g===void 0?void 0:Dg(e,h,m),y=g===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:m},b,x,S=vg(),C=t.emissions??Lg(),w=yield*nn(),T=yield*nn(),D=Tt(T).pipe(pt,Ae),O=!0,A,j=sr(w,{_tag:`Stopped`}).pipe(Ae),M=(e,t)=>W(()=>yg(S,e,t)?K:ae(new Zu)),N=g===void 0?void 0:(e,t,n,r)=>W(()=>{let i=g.isActive()?kg(g,_,e,t,n,r):r===void 0?e:{[og]:!0,event:e,deferred:r};return M(i,()=>Ag(g,_,i))}),ee=e.execution?._tag===`Compiled`?e=>Wt(t=>nn().pipe(V(n=>(g===void 0?M({[og]:!0,event:e,deferred:n}):N(e,void 0,void 0,n)).pipe(H(t(Tt(n))))),We(e=>e))):void 0,P={id:h,sessionId:m,stop:W(()=>O?j:j.pipe(H(an))),send:g===void 0?e=>M(e):e=>N(e,void 0,void 0),...g===void 0?void 0:{inspectionSubject:_,sendInspected:N}},{changes:te,close:F,get:I,owned:L,sendTo:ne,spawn:re,stop:R}=Rg;mg(e.execution)||({changes:te,close:F,get:I,owned:L,sendTo:ne,spawn:re,stop:R}=yield*Bg(P,f,void 0,ee===void 0?void 0:e=>ee(e)));let ie=e=>dr(e)?K:(g!==void 0&&g.publishUnsafe(y===void 0?{_tag:`StartFailed`,subject:_,cause:e.cause}:{_tag:`ActivityStopped`,subject:y.owner,activity:y,exit:e}),F(e).pipe(H(C.close()),H(t.inspectionRoot===!0&&g!==void 0?g.close:K))),z=l===void 0?c??K:U(()=>l(ze)),B=g===void 0?Fg:()=>Og(A,O),oe=p??(d===void 0?Ng:g===void 0?d.send:e=>pg(d,e,_,B())),se=g===void 0?C.emit:e=>C.emit(e).pipe(vn(()=>U(()=>g.publishUnsafe({_tag:`Emitted`,subject:_,emission:e,causedBy:B()})))),ce={self:P,parent:d,spawn:re,sendParent:oe,emit:se,sendTo:g===void 0?((e,t)=>fg(e)?e.send(t):ne(e,t)):((e,t)=>fg(e)?pg(e,t,_,B()):ne(e,t,_,B())),stopChild:R,failCause:e=>sr(w,{_tag:`Failure`,cause:e}).pipe(Ae),inspectInitial:g===void 0?Pg:(e,t=[])=>{b=e,x=t}};g!==void 0&&g.publishUnsafe(y===void 0?{_tag:`Created`,subject:_,parent:d?.inspectionSubject,origin:t.origin??{_tag:`Root`},definition:e.inspection?.definition}:{_tag:`ActivityStarted`,subject:y.owner,activity:y});let le=yield*e.initial(ce).pipe(yr(ie),v(U(()=>{O=!1}))),ue=yield*Bn({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:le}});y===void 0&&g?.publishUnsafe({_tag:`Initialized`,subject:_,snapshot:{status:`active`,state:le},initialEntryPaths:b??[],microsteps:eg({microsteps:x??[]})});let pe=s===void 0?e=>e.changes===void 0?un(e):$e(e.changes,[e]).pipe(De(e)):e=>{let t=e.changes===void 0?un(e):$e(e.changes,[e]).pipe(De(e)),n=e.snapshot;return n.status===`active`?t.pipe(vn(()=>Tg(s,n))):t},me=e=>e.changes===void 0?K:$e(e.changes,Kt(void 0)).pipe(Ae),he=e=>e.snapshot.status===`active`?un(e):me(e).pipe(De(e)),ge=e=>hr(ue).pipe(V(t=>t.revision===e.revision?pe(e).pipe(V(he)):un(void 0))),_e=e=>bn(ue,t=>t.terminalizing?un([void 0,t]):We(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(V(e=>e===void 0?un(void 0):ge(e)),We(e=>e?.snapshot)),ve=e=>ar(ue,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(We(e=>e?.snapshot)),ye=e=>It(ue,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(V(pe),V(he),Ae),be=g===void 0?e=>_e(t=>un(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(Ae):t=>hr(ue).pipe(V(n=>_e(e=>un(e.status===`active`?{status:`active`,state:t}:void 0)).pipe(vn(r=>U(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&g.publishUnsafe({_tag:`StateChanged`,subject:_,before:n.snapshot.state,after:t,causedByDeliveryId:A!==void 0&&sg(A)?A.inspection?.deliveryId:void 0})})))),Ae),xe=(e,n,r)=>{let a=i===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?K:W(()=>i(wg(e))).pipe(pt,Ae),o=g===void 0?C.close():C.close().pipe(H(U(()=>g.publishUnsafe(y===void 0?{_tag:`Terminated`,subject:_,snapshot:e}:{_tag:`ActivityStopped`,subject:y.owner,activity:y,exit:e.status===`stopped`?Rt():n}))));return Hr(U(()=>xg(S)).pipe(H(F(n)),H(ye(e)),H(o),H(U(()=>{Kn(n)?ug(A,n.cause):dg(A),A=void 0})),H(a),H(z),H(t.inspectionRoot===!0&&g!==void 0?g.close:K),H(r)))},Se=ve(e=>({status:`stopped`,state:e.state})),Ce=e=>ve(t=>({status:`error`,state:t.state,cause:e})),we=e=>ve(t=>({status:`done`,state:t.state,output:e})),Te=e=>xe(e,Nn,Ge(T,new Zu)),Ee=(e,t)=>{let n=Sn(t);return xe(e,n,u(T,t))},Oe=(e,t)=>{let n=Kt(t);return xe(e,n,sr(T,t))},ke=Hr(j.pipe(H(D))),je=e.execution?._tag===`Compiled`?{receiveMessage:bg(S).pipe(vn(e=>U(()=>{A=sg(e)?e:void 0}))),pollMessage:U(()=>gg(S)).pipe(vn(e=>U(()=>{Ct(e)&&(A=sg(e.value)?e.value:void 0)}))),completeMessage:e=>{lg(A,e),A=void 0}}:void 0,Me=g===void 0||e.execution?._tag===`Compiled`?bg(S).pipe(We(cg)):bg(S).pipe(vn(e=>U(()=>{A=e})),We(cg)),Ne=g===void 0||e.execution?._tag===`Compiled`?U(()=>gg(S)).pipe(We(Ot(cg))):U(()=>gg(S)).pipe(vn(e=>U(()=>{Ct(e)&&(A=e.value)})),We(Ot(cg))),Fe=g===void 0?e=>_e(t=>t.status===`active`?e(t.state).pipe(We(e=>({status:`active`,state:e}))):un(void 0)).pipe(Ae):t=>hr(ue).pipe(V(n=>_e(e=>e.status===`active`?t(e.state).pipe(We(e=>({status:`active`,state:e}))):un(void 0)).pipe(vn(t=>U(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&g.publishUnsafe({_tag:`StateChanged`,subject:_,before:n.snapshot.state,after:t.state,causedByDeliveryId:A!==void 0&&sg(A)?A.inspection?.deliveryId:void 0})})))),Ae),Ie={...ce,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:L}:void 0,...je,receive:Me,poll:Ne,state:hr(ue).pipe(We(e=>e.snapshot.state)),setState:be,updateState:Fe},Le=bn(ue,e=>e.snapshot.status===`active`?e.changes===void 0?E({replay:1}).pipe(We(t=>[t,{...e,changes:t}])):un([e.changes,e]):un([void 0,e])),Re=Dr(wt(function*(){let e=yield*Le;if(e===void 0)return Nt((yield*hr(ue)).snapshot);let t=yield*it(e),n=yield*hr(ue);return n.snapshot.status===`active`?Nt(n.snapshot).pipe(zt(Pn(Ut(k(t))).pipe(qt(e=>e.revision>n.revision),ln(e=>e.snapshot)))):Nt(n.snapshot)})),ze={id:h,sessionId:m,...g===void 0?void 0:{inspectionSubject:_,sendInspected:N},state:hr(ue).pipe(We(e=>e.snapshot.state)),snapshot:hr(ue).pipe(We(e=>e.snapshot)),changes:Re,emissions:C.stream,join:Tt(T),stop:ke,send:P.send,...ee===void 0?void 0:{[ag]:ee},child:I,childChanges:te};o!==void 0&&!o(ze)?yield*j:a!==void 0&&(yield*a(ze,j)),s!==void 0&&(yield*Tg(s,{status:`active`,state:le}));let Be=e=>{switch(e._tag){case`Stopped`:return Se;case`Done`:return we(e.output);case`Failure`:return Ce(e.cause)}},Ve=(e,t)=>{switch(e._tag){case`Stopped`:return Te(t);case`Done`:return Oe(t,e.output);case`Failure`:return Ee(t,e.cause)}},He=e=>n===!0?fe(e,{startImmediately:!0}):nr(e,{startImmediately:!0}),Ue=yield*Hn(w),Ke=de(Ue)?yield*Wt(t=>t(W(()=>e.run(Ie))).pipe(pt,V(e=>sr(w,Kn(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(He):void 0;return yield*He(Wt(e=>wt(function*(){let t=Ct(Ue)?yield*Ue.value:yield*e(Tt(w)),n=yield*Be(t);return Ke!==void 0&&(yield*Pe(Ke)),n===void 0?yield*D:yield*Ve(t,n)}))),ze}),c_=((e,t)=>e.execution?._tag===`Compiled`?a_(e,t):s_(e,t)),l_=Eg(c_,o_),u_=new WeakMap,d_=e=>W(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),_e(t,e=>e.stop,{discard:!0})}),f_=()=>{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},p_=e=>V(Fn,t=>{let n=u_.get(t);if(n!==void 0)return e(n.hooks);let r=f_();return u_.set(t,r),H(ne(t,d_(r)),e(r.hooks))});L(function*(e,t,n){let r=yield*l_,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*p_(t=>s_(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*p_(t=>a_(e,{...i,...t})):yield*Kr(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*p_(t=>c_(e,{...i,...t}))});var m_=L(function*(e,t){let n=yield*l_;return yield*p_(r=>c_(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),h_=L(function*(e,t,n){let r=yield*l_,i=yield*r.nextSessionId,a=yield*Zh(i);r.inspection=a;let o=Lg(),s=yield*nn(),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*ze(p_(n=>{let r={...c,...n};return t===`generic`?s_(e,r):t===`compiled`?e.execution?._tag===`Compiled`?a_(e,r):Kr(Error(`Machine cannot force the compiled runtime for generic process logic`)):c_(e,r)}).pipe(yr(e=>bt(s,e))));return{id:n?.id??i,sessionId:i,changes:Dr(Tt(s).pipe(We(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),g_=((e,t)=>h_(e,`auto`,t));tt({_tag:hn(`MachineSnapshot`),version:hn(2),active:wr(tt({path:Rr,value:mt(yn)})),completed:mt(wr(tt({path:Rr,output:mt(yn)}))),history:mt(Ur(Rr,tt({mode:Ft([`shallow`,`deep`]),active:wr(Rr),values:Ur(Rr,yn)})))});var __=(e,t,n)=>{let r=Q(e,n);if(r.type===`compound`){let r=yp(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return __(e,t,r)}return r.output},v_=(e,t)=>wt(function*(){let n=yield*up(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)||!Sp(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=__(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*gf(e,o,t.output,{boundary:`output`,state:a}))}return tp(e,{...n,outputs:r})}).pipe(se(t=>y_(e,t))),y_=(e,t)=>{if(Rn(t))return lt(Br(t,t=>t instanceof qu?t:new qu({machineId:e.id,boundary:`configuration`,cause:cn(t)})));let n=Zn(t);return Ct(n)&&n.value instanceof qu?ae(n.value):ae(new qu({machineId:e.id,boundary:`configuration`,cause:t}))},b_=e=>e.length===0?K:e.length===1?e[0]:m(e,{discard:!0}),x_=(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}),S_=new WeakMap,C_=e=>{let t=S_.get(e);if(t!==void 0)return t;let n=Object.values(td(e).handlers).some(e=>e.invoke!==void 0);return S_.set(e,n),n},w_=un(c()),T_=(e,t)=>{let n=Vh(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=fh(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return ah(e,r)?oh(e,r,ih).pipe(We(gr)):void 0},o=e=>W(()=>c(e)??w_),s=(e,t,r,a,s)=>{let c=a.commands.length===0?void 0:ph(a.commands,e.scope),l=a.emittedEvents.length===0?void 0:mh(a.emittedEvents,i(e)),u=()=>{let i=W(()=>(t&&e.completeMessage({before:r,plan:x_(a,n.snapshot),after:s}),a.done?un(gr(a.output)):o(e)));return l===void 0?i:l.pipe(H(i))},d=()=>{let t=e.commit(s),n=u(),r=t===void 0?n:t.pipe(H(n));return t===void 0&&l===void 0?r:e.runAfterChanges(r)};return c===void 0?d():e.runAfterChanges(c.pipe(H(W(d))))},c=(t,r)=>{let i=r;for(;;){let r;if(i!==void 0)r=i,i=void 0,t.beginMessage(r);else{let e=t.pollMessage();if(de(e))return;r=e.value}let a=sg(r),c=a?r.event:r,l=t.state(),u;try{u=n.plan(t.executionState??n.fromConfiguration(cp(e,l)),c,a,t.scope)}catch(e){return $u(e)}if(t.executionState=u.next,u.microsteps.length===0){a&&t.completeMessage({before:l,plan:x_(u,n.snapshot),after:l});continue}let d=n.snapshot(u.next);if(u.commands.length>0||u.emittedEvents.length>0||u.done)return s(t,a,l,u,d);let f=t.commit(d);if(f!==void 0)return t.runAfterChanges(f.pipe(H(W(()=>(a&&t.completeMessage({before:l,plan:x_(u,n.snapshot),after:d}),o(t))))));a&&t.completeMessage({before:l,plan:x_(u,n.snapshot),after:d})}};return{run:e=>Cg(a(e)??o(e),e.scope),runSync:(e,t)=>{let n=a(e);n!==void 0&&e.beginMessage(t);let r=n??c(e,t);return r===void 0?void 0:Cg(r,e.scope)}}},E_=class{initialized=!1;initial;constructor(e){this.initial=e}},D_=(e,t)=>{let n=Vh(e);return r=>{let i=r.state();if(t&&ah(e,i))return oh(e,i,ih).pipe(We(gr));let a=r.scope,o=r.executionState,s=o instanceof E_?o:new E_;r.executionState=s;let l,u,d;return d=W(()=>{let t=r.pollMessage();if(de(t))return u=void 0,un(c());let o=t.value,s=sg(o),f=s?o.event:o,p=i,m;try{m=n.plan(u??n.fromConfiguration(cp(e,i)),f,s,a)}catch(e){return $u(e)}if(u=m.next,m.microsteps.length===0)return s&&r.completeMessage({before:p,plan:x_(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(ph(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(mh(m.emittedEvents,l??=fh(e,a))),m.done)x.push(r.ownedChildren.stopAll());else if(h)for(let[t,n]of _){let i=t_(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=W(()=>(s&&r.completeMessage({before:p,plan:x_(m,n.snapshot),after:y}),m.done?un(gr(m.output)):d));return x.length===0?e:b_(x).pipe(H(e))},w=()=>{let e=S(),t=C(),n=e===void 0?t:e.pipe(H(t));return e===void 0&&x.length===0?n:r.runAfterChanges(n)};return b.length===0?w():r.runAfterChanges(b_(b).pipe(H(W(w))))}),Cg(W(()=>{if(s.initialized)return d;let t=s.initial,o=t?.activeConfiguration??cp(e,i);u=t?.configuration??n.fromConfiguration(o);let c=t_(e,a,r.ownedChildren,o,t?.entryPaths??$f(e,o),ih);return s.initial=void 0,s.initialized=!0,c===void 0?d:c.pipe(H(d))}),a)}},O_=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},k_=(e,t)=>{let n=C_(e),r=Vh(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=O_(t);return n?{...r,executionState:new E_({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw ed(e)}},s=t=>a===void 0?Cg(dh(ym(e,t),...i).pipe(V(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:ph(n.commands,t),i=n.emittedEvents.length===0?void 0:mh(n.emittedEvents,fh(e,t)),a=un(O_(n));return r===void 0?i===void 0?a:i.pipe(H(a)):i===void 0?r.pipe(H(a)):r.pipe(H(i),H(a))})),t):Or({try:()=>o(t),catch:ed});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:D_(e,t._tag===`Resume`)}:{_tag:`Owned`,...T_(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?Cg(v_(e,t.snapshot),n):s(n).pipe(We(e=>e.state)),run:t=>Cg(wt(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*Kr(Error(`Machine statechart started without acknowledged mailbox access`));let l,u=yield*o;if(ah(e,u))return yield*oh(e,u,ih);if(!n){let n,o=c(),d;for(;l===void 0;){let f=Ct(o)?o.value:yield*a;o=c();let p=sg(f),m=p?f.event:f,h=u,g;try{g=uh(e,Lf(n??cp(e,u),t),m)}catch(e){return yield*$u(e)}if(n=g.next,g.microsteps.length>0){let n=tp(e,g.next);yield*ph(g.commands,t),yield*s(n),u=n,g.emittedEvents.length>0&&(yield*mh(g.emittedEvents,d??=fh(e,t))),g.done&&(l={output:g.output})}p&&r({before:h,plan:x_(g,t=>tp(e,t)),after:u}),l===void 0&&(o=yield*i,de(o)&&(n=void 0))}return l===void 0?yield*Kr(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):l.output}let d=t.ownedChildren;if(d===void 0)return yield*Kr(Error(`Invoking statechart started without an owned child runtime`));let f=(n,r,i)=>t_(e,t,d,n,r,i)??K,p=e=>d.stopPaths(e)??K;return yield*wt(function*(){let n=yield*up(e,u);yield*f(n,$f(e,n),ih),n=void 0;let o=c(),m;for(;l===void 0;){let h=Ct(o)?o.value:yield*a;o=c();let g=sg(h),_=g?h.event:h,v=u,y;try{y=uh(e,Lf(n??cp(e,u),t),_)}catch(e){return yield*$u(e)}if(n=y.next,y.microsteps.length>0){let n=y.microsteps.some(e=>e.changed),r=y.microsteps.flatMap(e=>e.exitPaths),i=new Map;for(let e of y.microsteps)if(e.changed)for(let t of e.entryPaths)i.set(t,e.event);let a=tp(e,y.next);if(yield*ph(y.commands,t),n&&(yield*p(r)),yield*s(a),u=a,y.emittedEvents.length>0&&(yield*mh(y.emittedEvents,m??=fh(e,t))),y.done)l={output:y.output},yield*d.stopAll();else if(n)for(let[e,t]of i)yield*f(y.next,[e],t)}g&&r({before:v,plan:x_(y,t=>tp(e,t)),after:u}),l===void 0&&(o=yield*i,de(o)&&(n=void 0))}return l===void 0?yield*Kr(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):l.output}).pipe(yr(()=>d.stopAll()))}),t)}},A_=new WeakMap,j_=(e,...t)=>{if(t.length>0)return k_(e,{_tag:`Initial`,args:t});let n=A_.get(e);if(n!==void 0)return n;let r=k_(e,{_tag:`Initial`,args:t});return A_.set(e,r),r},M_=(e,t)=>k_(e,{_tag:`Resume`,snapshot:t}),N_=(e,...t)=>g_(j_(e,...t),e.id===void 0?void 0:{id:e.id}),P_=(e,t)=>m_(M_(e,t),e.id===void 0?void 0:{id:e.id}),F_={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`]},I_=[`title`,`description`,`documentation`],L_=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),R_=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},z_=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},B_=e=>Number.isFinite(Number(e)),V_=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,H_=(e,t)=>{if(t.has(e))return`opaque`;if(jt(e)||me(e)||d(e)||rn(e)||Un(e)||ye(e))return`tagged`;if(ir(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return vr(e)?V_(e.types.map(e=>H_(e,n))):Ke(e)?H_(e.thunk(),n):re(e)?`opaque`:`untagged`},U_=(e,t=new Set)=>{if(t.has(e))return`opaque`;if(Et(e)){let n=e.propertySignatures.find(({name:e})=>e===`_tag`)?.type;return n===void 0||xt(n)?`untagged`:H_(n,new Set(t).add(e))}let n=new Set(t).add(e);return vr(e)?V_(e.types.map(e=>U_(e,n))):Ke(e)?U_(e.thunk(),n):re(e)?`opaque`:`untagged`},W_=e=>we(e)&&U_(cr(e.ast))!==`untagged`,G_=(e,t,n)=>{let r=R_(t,n);return typeof n==`symbol`?z_(e,r,`state keys must be strings, not symbols`):typeof n==`number`?z_(e,r,`state keys cannot use numeric forms`):n===``?z_(e,r,`state keys cannot be empty`):n===`__proto__`?z_(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?z_(e,r,`state keys cannot contain "."`):B_(n)?z_(e,r,`state keys cannot use numeric forms`):r},K_=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&z_(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&z_(e,R_(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},q_=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!L_(n,r))return;let a=n[r];(typeof a!=`object`||!a||we(a)||a.type!==`history`)&&z_(e,`${t}.${r}`,i)},J_=(e,t,n,r)=>{let i=F_[r];for(let a of Reflect.ownKeys(n))i.includes(a)||z_(e,t,`${r} states cannot declare property "${String(a)}"`)},Y_=(e,t,n)=>{K_(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))I_.includes(r)||z_(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&z_(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},X_=(e,t,n,r,i=!1)=>{K_(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:G_(e,n,a),s=t[a];if(we(s)){W_(s)||z_(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}K_(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:L_(s,`states`)?`compound`:`atomic`;if(J_(e,o,s,l),l===`history`||l===`choice`){r||z_(e,o,`${l} states must be declared below an active parent state`),L_(s,`annotations`)&&Y_(e,o,s.annotations),l===`history`&&L_(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&z_(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=L_(s,`schema`);u&&!W_(s.schema)&&z_(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&L_(s,`annotations`)&&z_(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&L_(s,`annotations`)&&Y_(e,o,s.annotations),l===`atomic`&&L_(s,`type`)&&s.type!==`active`&&z_(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&z_(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&L_(s,`type`)&&s.type!==`active`&&z_(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&z_(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&L_(s,`output`)&&!we(s.output)&&z_(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?(q_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&q_(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),X_(e,s.states,o,!0)):l===`parallel`&&(L_(s,`states`)||z_(e,`${o}.states`,`parallel states must declare child regions`),q_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),X_(e,s.states,o,!0))}},Z_=e=>typeof e==`object`&&e?Object.freeze({...e}):e,Q_=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(we(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=Q_(i.states)),`annotations`in i&&(a.annotations=Z_(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},$_=e=>Q_(e),ev=(e,t=``)=>{if(we(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(L_(n,`fields`)&&(L_(n,`schema`)&&z_(`Machine.state`,t,`declare fields or schema, not both`),K_(`Machine.state`,t,n.fields,`state fields`),L_(n.fields,`_tag`)&&z_(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=Pr(t,n.fields),delete r.fields),L_(n,`states`)){K_(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))G_(`Machine.state`,t,r),e[r]=ev(n.states[r],r);r.states=e}return t===``?(X_(`Machine.state`,{"":r},``,!1,!0),$_({"":r})[``]):r},tv=`~effect/Machine`,nv=`~effect/Machine/ChildMachine`,rv={...Lt,..._n,[tv]:tv,toJSON(){return{_id:`Machine`}}},iv=(e,t)=>{let n=Object.create(rv);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,uf(e,n),n},av=e=>e.kind===`none`?hd:md(e.kind,e.path,e.scope,e.updatePath),ov=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),sv=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],cv=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!G(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(!gd(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`||!Vf(r,e.path)||!Vf(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}},lv=(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(!vd(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(!bd(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(bd(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=bd(e)?e.target:e,i=typeof r==`object`&&r&&G(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&&Vf(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},uv=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:Dd};delete a.target;let o=e.resolve(a,n);if(Od(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return lv(o,e.selection,r),o},dv=e=>e.kind===`update`?void 0:e.path,fv=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},pv=(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||fv(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||!G(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!gd(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:av(a)})}))},mv=(e,t,n,r={},i)=>{let a=jp(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 yd(Nd(i.path,i.parent),Pp(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`?kd(n.path,n.parent):Nd(n.path,n.parent)}if(e.kind===`update`)return Pp(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 yd(Np(t,e.path,r,i),Pp(t,e.updatePath,n))}return Np(t,e.path,a,i)},hv=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>xd(t,a,e.key,e.selection.kind===`none`?wd():mv(e.selection,n,r,o,i))]))),gv=(e,t,n)=>{if(t.kind===`none`){if(!Td(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`);lv(e,t,n)}},_v=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),vv=(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:cv({target:()=>Vp(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?Dd():s(e,t)}}let p=Vp(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 Dd();if(s!==void 0)return s(e,a);if(h)return mv(p,r,t,{input:g(e)});let l=u(e);return mv(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)}}},yv=(e,t,n,r,i)=>{let a=vv(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(G(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=pv(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:Dd};delete s.target,s.select=hv(l,u,t,r,n);let d=a(s,o);if(Od(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(!Sd(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 gv(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=>dv(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:dv(e.selection),selection:ov(e.selection),updates:sv(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=cv(a,void 0,t,n,i),u=(e,r)=>({result:uv(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:dv(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:dv(l.selection),selection:ov(l.selection),updates:sv(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},bv=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=yv(e[a],t,n,r,a);return i},xv=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=Hp(r,e,n,e=>_v(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=yv(i[e],t,n,r,e));return $p(i,n)});return tm(i,n),Array.isArray(e)?Object.freeze(i):i[0]},Sv=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!G(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=bv(d,t,s,i)),u.always!==void 0&&(u.always=yv(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=yv(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=yv(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=xv(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!G(u.choice,`transition`)||typeof u.choice.transition!=`function`||!G(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=Fd(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`);Sv(e,t,r.states,s,i,l)}}},Cv=e=>e===``?Lp:e,wv=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=zd(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(!Vf(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${Cv(e.source)}" updates "${Cv(n)}" before choice "${t}", whose ${r} targets "${Cv(o)}" outside that owner`)}}}}}}},Tv=(e,t)=>(n=>{let r=Qp(t.root,n),i=Object.assign(Object.create(rv),e);if(uf(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=Id(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:Xp(n.root);i.initial=e=>({...jd(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);Sv(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Of(i,i.input,e))},{"":r.handlers});let s=iv(i,o);return wv(s),s}),Ev=e=>{let t=ev(e),n=Dv();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},Dv=()=>({path:(e=>e),get:((e,t)=>Gd(e,t).pipe(Ot(e=>e.value))),getWithParents:((e,t)=>{let n={};return Gd(e,t,n).pipe(Ot(e=>({value:e.value,parents:n})))}),getSnapshot:Gd,matches:((e,t)=>Ct(Gd(e,t)))}),Ov=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(_n);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??hf(`internal`,[]),n.emittedEvents=e.emittedEvents??hf(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=Tv(n,zp(e.root,e)),lf(n),n},kv=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?[]:[ot(e)]},Av=e=>hf(`public`,kv(e)),jv=(e,t)=>Mv(e,t,e=>t.input===void 0?j_(t):j_(t,e)),Mv=(e,t,n)=>({[nv]:nv,id:e,machine:t,[Gp]:n}),Nv=N_,Pv=P_,Fv=(e,t)=>{try{let n=sh(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},Iv=(e,t)=>{try{let n=Jt(v_(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!ah(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=Jt(oh(e,r,ih));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},Lv={spawn:()=>Kr(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>ae(new Zu),stop:()=>K},Rv=(e,t)=>{if(e.snapshot.status!==`active`)return c();try{let n=e.machine,r=cp(n,e.snapshot.state);for(let e of $f(n,r)){let i=vp(n,e);for(let a of nm(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({...Rf(r)??bm(n,r),children:Lv,state:r.values.get(e),containingState:Qf(n,r,e),ancestors:Zf(n,r,e),event:ih}):a.input);let s=Fv(i,i.input===void 0?[]:[o]);return s===void 0?void 0:gr(s)}}return c()}catch{return}},zv=class extends Qe(`ChildNotActiveError`){},Bv=new WeakMap,Vv=new WeakMap,Hv=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return zr(e);let t=at(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=A(t,n);Ct(r)&&r.value===e&&D(t,n)});return r=>{let i=A(t,r);if(Ct(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return Fe(t,r,o),n.register(a,{key:r,entry:o}),a}},Uv=(e,t)=>Cr(An(t,e=>e.stop).pipe(vn(t=>U(()=>e.setSelf(he(t)))),V(()=>an))),Wv=(e,t)=>Uv(e,e.result(t).pipe(V(e=>e.start))),Gv=(e,t,n)=>Uv(e,Pv(t,n)),Kv=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[Tr](t):t(e),qv=(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}},Jv=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},Yv=e=>e.snapshot,Xv=nt(e=>e.registry).pipe(Ze),Zv=e=>W(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,K):H(t,Zv(e))}),Qv=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},$v=(e,t,n)=>Te(n=>{let r=ht(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:ge(Ot(n.self(),ue),()=>Wr(!0))},(r,i)=>{let a=r.get(e),o=r.get(Xv),s=Qv(t,o);dt(a)||s.draining?(r.setSelf(Wr(!0)),s.pending.push(Oe(o,e).pipe(V(e=>n(e,i)),pt,We(e=>{let t=be(e);r.setSelf(s.pending.length===0?t:ue(t))}))),s.draining||(s.draining=!0,Bt(Zv(s)))):g(a)?r.setSelf(ht(a,()=>void 0)):wn(n(a.value,i),{onExit:e=>r.setSelf(be(e))})}).pipe(En),ey=e=>nt(t=>{let n=t(e);return dt(n)?Wr(n.waiting):g(n)?B(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?B(n.value.cause,{previous:t.self(),waiting:n.waiting}):he(n.value.state,{waiting:n.waiting})}).pipe(Me(Gn),f(qv(t=>[Kv(e,t)],e=>ht(e,e=>e.state)))),ty=e=>nt(t=>{let n=t(e);if(dt(n))return Wr(n.waiting);if(g(n))return B(n.cause,{previous:t.self(),waiting:n.waiting});if(de(n.value)){let e=t.self();return Ct(e)&&g(e.value)?e.value:he(c(),{waiting:n.waiting})}return n.value.value.status===`error`?B(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):he(gr(n.value.value.state),{waiting:n.waiting})}).pipe(Me(Gn),f(qv(t=>[Kv(e,t)],e=>ht(e,Ot(e=>e.state))))),ny=(e,t)=>nt(n=>{let r=n(e);if(dt(r))return Wr(r.waiting);if(g(r))return B(r.cause,{previous:n.self(),waiting:r.waiting});if(de(r.value))return he(c());let i=r.value.value,a=pr(i.child(t)),o=wn(Nr.pipe(H(i.childChanges(t).pipe(pn(e=>U(()=>n.setSelf(he(e))))))));return n.addFinalizer(o),he(a)}).pipe(En),ry=(e,t)=>rg(e)?e[ng](()=>t(pr(e.snapshot))):wn(e.changes.pipe(pn(e=>U(()=>t(e))))),iy=(e,t,n)=>{let r=nt(t=>{let n=t(e);if(dt(n))return Wr(n.waiting);if(g(n))return B(n.cause,{previous:t.self(),waiting:n.waiting});if(de(n.value))return he(c());let r=n.value.value;return t.addFinalizer(ry(r,e=>t.setSelf(he(gr(e))))),he(gr(pr(r.snapshot)))}).pipe(f(qv(()=>[],()=>{let e=n();return e===void 0?Wr(!0):he(Ot(e,Yv),{waiting:!0})}))),i=new WeakMap,a=e=>Ct(e)?un(e.value):ae(new zv({id:t.id})),o=$v(e,i,(e,t)=>V(a(e),e=>e.send(t))),s=$v(e,i,(e,t)=>V(a(e),e=>e.stop)),l=ay(e,n);return{ref:e,snapshot:r,result:ty(r),send:o,stop:s,child:l}},ay=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=zr(n=>{let r=jv(n,a);return iy(ny(e,r),r,Jv(()=>{let e=t();return e===void 0||de(e)?e:Rv(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},oy=(e,t,n)=>{let r=En(e),i=nt(e=>{let t=e(r);if(dt(t))return Wr(t.waiting);if(g(t))return B(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(ry(n,t=>e.setSelf(he(t,{waiting:t.status===`active`}))));let i=pr(n.snapshot);return he(i,{waiting:i.status===`active`})}).pipe(f(qv(()=>[],()=>{let e=n();return e===void 0?Wr(!0):he(Yv(e),{waiting:!0})}))),a=new WeakMap,o=$v(r,a,(e,t)=>e.send(t)),s=$v(r,a,(e,t)=>e.stop),c=ay(Ar(r,gr),()=>{let e=n();return e===void 0?void 0:gr(e)}),l={ref:r,snapshot:i,result:ey(i),send:o,stop:s,child:c};return Vv.set(l,t),l},sy=(e,t)=>Gd(e,t).pipe(Ot(e=>e.value)),cy=(e,t)=>Gd(e,t),ly=(e,t)=>Ar(e,t).pipe(Me(Gn),f(qv(t=>[Kv(e,t)],e=>ht(e,t)))),uy=new WeakMap,dy=(e,t,n,r)=>{let i=uy.get(e);i===void 0&&(i=new Map,uy.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},fy=(e,t)=>dy(e,`select`,t,()=>ly(e.result,e=>sy(e,t))),py=(e,t)=>dy(e,`selectSnapshot`,t,()=>ly(e.result,e=>cy(e,t))),my=(e,t)=>dy(e,`selectChild`,t,()=>ly(e.result,gt(e=>sy(e,t)))),hy=(e,t)=>dy(e,`selectSnapshotChild`,t,()=>ly(e.result,gt(e=>cy(e,t)))),gy=(e,t)=>dy(e,`matches`,t,()=>ly(e.result,e=>Ct(Gd(e,t)))),_y=(e,t)=>dy(e,`matchesChild`,t,()=>ly(e.result,ie(e=>Ct(Gd(e,t))))),vy=(e,t,n)=>{let r=e.atom(()=>Nv(t,...n)),i=oy(e.atom(e=>Wv(e,r)),t,Jv(()=>Fv(t,n)));return Bv.set(i,r),i},yy=(e,t,n)=>oy(e.atom(e=>Gv(e,t,n)),t,Jv(()=>Iv(t,n))),by=(e,t,n)=>{let r={owner:e,source:t},i=w(t,e=>e(r.source),{initialValueTarget:t}).pipe(Me((e,t)=>r.source.equals(e,t)),f(e=>Kv(r.source,e)));return n!==void 0&&(i=i.pipe(On(n))),i},xy=(e,t)=>{let n=Hv(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=Hv(r=>{let a=n(r);return by(a,i(a.bridge),t.label?.(r,e))})}return r},Sy=e=>{let t=((t,...n)=>vy(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>yy(e,t,n)),family:((t,n)=>xy(n=>vy(e,t,[n]),n))}},Cy=Xn(2,fy);Xn(2,py),Xn(2,my),Xn(2,hy),Xn(2,gy),Xn(2,_y);var wy=Sy,Ty=e=>Ey(X.useContext(ju),e),Ey=(e,t)=>{let n=X.useMemo(()=>{let n,r,i=e=>R(e)?(n=e,e):dt(e)&&n!==void 0?n:e;return{subscribe:n=>e.subscribe(t,n),snapshot:()=>i(e.get(t)),serverSnapshot:()=>r??=i(Fr(t,e))}},[e,t]);return X.useSyncExternalStore(n.subscribe,n.snapshot,n.serverSnapshot)},Dy=Ty,Oy=e(t(),1);function ky(e){let t=Oy.unstable_scheduleCallback(4,e);return()=>Oy.unstable_cancelCallback(t)}var Ay=X.createContext(Le({scheduleTask:ky,defaultIdleTTL:400})),jy=new WeakMap,My=0,Ny=new Set;function Py(e){My++;try{return e()}finally{My--}}function Fy(e){if(My===0)return e();Ny.size===0&&queueMicrotask(Iy),Ny.add(e)}function Iy(){for(let e of Ny)Ny.delete(e),e()}function Ly(e,t){let n=jy.get(e);n===void 0&&(n=new WeakMap,jy.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,()=>Fy(n));return()=>{i--,Ny.delete(n),r()}},snapshot(){return Py(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Py(()=>Fr(t,e))}),a.value}};return n.set(t,o),o}function Ry(e,t){let n=Ly(e,t);return X.useEffect(Iy),X.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function zy(e,t,n){let r=Ly(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(Iy),X.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var By=(e,t)=>{let n=X.useContext(Ay);return t?zy(n,e,t):Ry(n,e)},$=r(),Vy=1,Hy=.9,Uy=.8,Wy=.17,Gy=.1,Ky=.999,qy=.9999,Jy=.99,Yy=/[\\\/_+.#"@\[\(\{&]/,Xy=/[\\\/_+.#"@\[\(\{&]/g,Zy=/[\s-]/,Qy=/[\s-]/g;function $y(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Vy:Jy;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=$y(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Vy:Yy.test(e.charAt(l-1))?(d*=Uy,p=e.slice(i,l-1).match(Xy),p&&i>0&&(d*=Ky**+p.length)):Zy.test(e.charAt(l-1))?(d*=Hy,m=e.slice(i,l-1).match(Qy),m&&i>0&&(d*=Ky**+m.length)):(d*=Wy,i>0&&(d*=Ky**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=qy)),(d<Gy&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=$y(e,t,n,r,l+1,a+2,o),f*Gy>d&&(d=f*Gy)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function eb(e){return e.toLowerCase().replace(Qy,` `)}function tb(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,$y(e,t,eb(e),eb(t),0,0,{})}var nb=Object.defineProperty,rb=(e,t)=>nb(e,`name`,{value:t,configurable:!0}),ib=!!(typeof window<`u`&&window.document&&window.document.createElement);function ab(e,t,{checkForDefaultPrevented:n=!0}={}){return rb(function(r){if(e?.(r),n===!1||!r||!r.defaultPrevented)return t?.(r)},`handleEvent`)}rb(ab,`composeEventHandlers`);function ob(e){if(!ib)throw Error(`Cannot access window outside of the DOM`);return e?.ownerDocument?.defaultView??window}rb(ob,`getOwnerWindow`);function sb(e){if(!ib)throw Error(`Cannot access document outside of the DOM`);return e?.ownerDocument??document}rb(sb,`getOwnerDocument`);function cb(e,t=!1){let{activeElement:n}=sb(e);if(!n?.nodeName)return null;if(lb(n)&&n.contentDocument)return cb(n.contentDocument.body,t);if(t){let e=n.getAttribute(`aria-activedescendant`);if(e){let t=sb(n).getElementById(e);if(t)return t}}return n}rb(cb,`getActiveElement`);function lb(e){return e.tagName===`IFRAME`}rb(lb,`isFrame`);var ub=Object.defineProperty,db=(e,t)=>ub(e,`name`,{value:t,configurable:!0});function fb(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}db(fb,`setRef`);function pb(...e){return t=>{let n=!1,r=e.map(e=>{let r=fb(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():fb(e[t],null)}}}}db(pb,`composeRefs`);function mb(...e){return X.useCallback(pb(...e),e)}db(mb,`useComposedRefs`);var hb=Object.defineProperty,gb=(e,t)=>hb(e,`name`,{value:t,configurable:!0});function _b(e,t){let n=X.createContext(t);n.displayName=e+`Context`;let r=gb(e=>{let{children:t,...r}=e,i=X.useMemo(()=>r,Object.values(r));return(0,Z.jsx)(n.Provider,{value:i,children:t})},`Provider`);r.displayName=e+`Provider`;function i(r,i={}){let{optional:a=!1}=i,o=X.useContext(n);if(o)return o;if(t!==void 0)return t;if(!a)throw Error(`\`${r}\` must be used within \`${e}\``)}return gb(i,`useContext`),[r,i]}gb(_b,`createContext`);function vb(e,t=[]){let n=[];function r(t,r){let i=X.createContext(r);i.displayName=t+`Context`;let a=n.length;n=[...n,r];let o=gb(t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,c=X.useMemo(()=>o,Object.values(o));return(0,Z.jsx)(s.Provider,{value:c,children:r})},`Provider`);o.displayName=t+`Provider`;function s(n,o,s={}){let{optional:c=!1}=s,l=o?.[e]?.[a]||i,u=X.useContext(l);if(u)return u;if(r!==void 0)return r;if(!c)throw Error(`\`${n}\` must be used within \`${t}\``)}return gb(s,`useContext`),[o,s]}gb(r,`createContext`);let i=gb(()=>{let t=n.map(e=>X.createContext(e));return gb(function(n){let r=n?.[e]||t;return X.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])},`useScope`)},`createScope`);return i.scopeName=e,[r,yb(i,...t)]}gb(vb,`createContextScope`);function yb(...e){let t=e[0];if(e.length===1)return t;let n=gb(()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return gb(function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return X.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])},`useComposedScopes`)},`createScope`);return n.scopeName=t.scopeName,n}gb(yb,`composeContextScopes`);var bb=globalThis?.document?X.useLayoutEffect:()=>{},xb=Object.defineProperty,Sb=(e,t)=>xb(e,`name`,{value:t,configurable:!0}),Cb=X.useId||(()=>void 0),wb=0;function Tb(e){let[t,n]=X.useState(Cb());return bb(()=>{e||n(e=>e??String(wb++))},[e]),e||(t?`radix-${t}`:``)}Sb(Tb,`useId`);var Eb=Object.defineProperty,Db=(e,t)=>Eb(e,`name`,{value:t,configurable:!0}),Ob=X.useEffectEvent,kb=X.useInsertionEffect;function Ab(e){if(typeof Ob==`function`)return Ob(e);let t=X.useRef(()=>{throw Error(`Cannot call an event handler while rendering.`)});return typeof kb==`function`?kb(()=>{t.current=e}):bb(()=>{t.current=e}),X.useMemo(()=>((...e)=>t.current?.(...e)),[])}Db(Ab,`useEffectEvent`);var jb=Object.defineProperty,Mb=(e,t)=>jb(e,`name`,{value:t,configurable:!0}),Nb=X.useInsertionEffect||bb;function Pb({prop:e,defaultProp:t,onChange:n=Mb(()=>{},`onChange`),caller:r}){let[i,a,o]=Fb({defaultProp:t,onChange:n}),s=e!==void 0;return[s?e:i,X.useCallback(t=>{if(s){let n=Ib(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}Mb(Pb,`useControllableState`);function Fb({defaultProp:e,onChange:t}){let[n,r]=X.useState(e),i=X.useRef(n),a=X.useRef(t);return Nb(()=>{a.current=t},[t]),X.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}Mb(Fb,`useUncontrolledState`);function Ib(e){return typeof e==`function`}Mb(Ib,`isFunction`);var Lb=Symbol(`RADIX:SYNC_STATE`);function Rb(e,t,n,r){let{prop:i,defaultProp:a,onChange:o,caller:s}=t,c=i!==void 0,l=Ab(o),u=[{...n,state:a}];r&&u.push(r);let[d,f]=X.useReducer((t,n)=>{if(n.type===Lb)return{...t,state:n.state};let r=e(t,n);return c&&!Object.is(r.state,t.state)&&l(r.state),r},...u),p=d.state,m=X.useRef(p);X.useEffect(()=>{m.current!==p&&(m.current=p,c||l(p))},[p,m,c]);let h=X.useMemo(()=>i===void 0?d:{...d,state:i},[d,i]);return X.useEffect(()=>{c&&!Object.is(i,d.state)&&f({type:Lb,state:i})},[i,d.state,c]),[h,f]}Mb(Rb,`useControllableStateReducer`);var zb=Object.defineProperty,Bb=(e,t)=>zb(e,`name`,{value:t,configurable:!0});function Vb(e){let t=X.forwardRef((t,n)=>{let{children:r,...i}=t,a=null,o=!1,s=[];r=Zb(r),X.Children.forEach(r,e=>{if(qb(e)){o=!0;let t=e,n=`child`in t.props?t.props.child:t.props.children;for(;Yb(n)&&typeof tx==`function`;)n=tx(n._payload);a=Wb(t,n),s.push(a?.props?.children)}else s.push(e)}),a?a=X.cloneElement(a,void 0,s):!o&&X.Children.count(r)===1&&X.isValidElement(r)&&(a=r);let c=a?Kb(a):void 0,l=mb(n,c);if(!a){if(r||r===0)throw Error(o?ex(e):$b(e));return r}let u=Gb(i,a.props??{});return a.type!==X.Fragment&&(u.ref=n?l:c),X.cloneElement(a,u)});return t.displayName=`${e}.Slot`,t}Bb(Vb,`createSlot`);var Hb=Symbol.for(`radix.slottable`);function Ub(e){let t=Bb(e=>`child`in e?e.children(e.child):e.children,`Slottable`);return t.displayName=`${e}.Slottable`,t.__radixId=Hb,t}Bb(Ub,`createSlottable`);var Wb=Bb((e,t)=>`child`in e.props?X.isValidElement(t)?X.cloneElement(t,void 0,e.props.children(t.props.children)):null:X.isValidElement(t)?t:null,`getSlottableElementFromSlottable`);function Gb(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`?n[r]=[i,a].filter(Boolean).join(` `):r===`aria-describedby`&&(n[r]=Qb(a,i))}return{...e,...n}}Bb(Gb,`mergeProps`);function Kb(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Bb(Kb,`getElementRef`);function qb(e){return X.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===Hb}Bb(qb,`isSlottable`);var Jb=Symbol.for(`react.lazy`);function Yb(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===Jb&&`_payload`in e&&Xb(e._payload)}Bb(Yb,`isLazyComponent`);function Xb(e){return typeof e==`object`&&!!e&&`then`in e}Bb(Xb,`isPromiseLike`);function Zb(e){let t=e;for(;Yb(t)&&typeof tx==`function`;)t=tx(t._payload);return t}Bb(Zb,`useUnwrappedLazy`);function Qb(...e){let t=new Set;for(let n of e)if(typeof n==`string`)for(let e of String(n).trim().split(/\s+/))e&&t.add(e);return t.size>0?Array.from(t).join(` `):void 0}Bb(Qb,`concatAriaDescribedby`);var $b=Bb(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,`createSlotError`),ex=Bb(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,`createSlottableError`),tx=X.use,nx=Object.defineProperty,rx=(e,t)=>nx(e,`name`,{value:t,configurable:!0}),ix=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=Vb(`Primitive.${t}`),r=X.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,Z.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function ax(e,t){e&&nc.flushSync(()=>e.dispatchEvent(t))}rx(ax,`dispatchDiscreteCustomEvent`);var ox=Object.defineProperty,sx=(e,t)=>ox(e,`name`,{value:t,configurable:!0}),cx=X.useInsertionEffect;function lx(e){let t=X.useRef(e);return typeof cx==`function`?cx(()=>{t.current=e}):bb(()=>{t.current=e}),X.useMemo(()=>((...e)=>t.current?.(...e)),[])}sx(lx,`useCallbackRef`);var ux=Object.defineProperty,dx=(e,t)=>ux(e,`name`,{value:t,configurable:!0}),fx=`dismissableLayer.update`,px=`dismissableLayer.pointerDownOutside`,mx=`dismissableLayer.focusOutside`,hx,gx=X.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),_x=X.forwardRef(dx(function(e,t){let{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:i,onPointerDownOutside:a,onFocusOutside:o,onInteractOutside:s,onDismiss:c,...l}=e,u=X.useContext(gx),[d,f]=X.useState(null),p=d?.ownerDocument??globalThis?.document,[,m]=X.useState({}),h=mb(t,f),g=Array.from(u.layers),[_]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=_?g.indexOf(_):-1,y=d?g.indexOf(d):-1,b=u.layersWithOutsidePointerEventsDisabled.size>0,x=y>=v,S=X.useRef(!1),C=bx(e=>{a?.(e),s?.(e),e.defaultPrevented||c?.()},{ownerDocument:p,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:u.dismissableSurfaces,shouldHandlePointerDownOutside:X.useCallback(e=>{if(!(e instanceof Node))return!1;let t=[...u.branches].some(t=>t.contains(e));return x&&!t},[u.branches,x])}),w=xx(e=>{if(r&&S.current)return;let t=e.target;[...u.branches].some(e=>e.contains(t))||(o?.(e),s?.(e),e.defaultPrevented||c?.())},p),T=d?y===g.length-1:!1,E=lx(e=>{e.key===`Escape`&&(i?.(e),!e.defaultPrevented&&c&&(e.preventDefault(),c()))});return X.useEffect(()=>{if(T)return p.addEventListener(`keydown`,E,{capture:!0}),()=>p.removeEventListener(`keydown`,E,{capture:!0})},[p,T,E]),X.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(hx=p.body.style.pointerEvents,p.body.style.pointerEvents=`none`),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Sx(),()=>{n&&(u.layersWithOutsidePointerEventsDisabled.delete(d),u.layersWithOutsidePointerEventsDisabled.size===0&&(p.body.style.pointerEvents=hx))}},[d,p,n,u]),X.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Sx())},[d,u]),X.useEffect(()=>{let e=dx(()=>m({}),`handleUpdate`);return document.addEventListener(fx,e),()=>document.removeEventListener(fx,e)},[]),(0,Z.jsx)(ix.div,{...l,ref:h,style:{pointerEvents:b?x?`auto`:`none`:void 0,...e.style},onFocusCapture:ab(e.onFocusCapture,w.onFocusCapture),onBlurCapture:ab(e.onBlurCapture,w.onBlurCapture),onPointerDownCapture:ab(e.onPointerDownCapture,C.onPointerDownCapture)})},`DismissableLayer`));function vx(){let e=X.useContext(gx),[t,n]=X.useState(null);return X.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}dx(vx,`useDismissableLayerSurface`);var yx=dx(()=>!0,`IS_TRUE`);function bx(e,t){let{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:o=yx}=t,s=lx(e),c=X.useRef(!1),l=X.useRef(!1),u=X.useRef(new Map),d=X.useRef(()=>{});return X.useEffect(()=>{function e(){l.current=!1,i.current=!1,u.current.clear()}dx(e,`resetOutsideInteraction`);function t(){return Array.from(u.current.values()).some(Boolean)}dx(t,`isOutsideInteractionIntercepted`);function f(e){if(!l.current)return;let t=e.target;t instanceof Node&&[...a].some(e=>e.contains(t))||u.current.set(e.type,!0),e.type===`click`&&window.setTimeout(()=>{l.current&&d.current()},0)}dx(f,`handleInteractionCapture`);function p(e){l.current&&u.current.set(e.type,!1)}dx(p,`handleInteractionBubble`);let m=dx(a=>{if(a.target&&!c.current){let f=function(){n.removeEventListener(`click`,d.current);let r=t();e(),r||Cx(px,s,p,{discrete:!0})};if(dx(f,`handleAndDispatchPointerDownOutsideEvent`),!o(a.target)){n.removeEventListener(`click`,d.current),e(),c.current=!1;return}let p={originalEvent:a};l.current=!0,i.current=r&&a.button===0,u.current.clear(),!r||a.button!==0?f():(n.removeEventListener(`click`,d.current),d.current=f,n.addEventListener(`click`,d.current,{once:!0}))}else n.removeEventListener(`click`,d.current),e();c.current=!1},`handlePointerDown`),h=[`pointerup`,`mousedown`,`mouseup`,`touchstart`,`touchend`,`click`];for(let e of h)n.addEventListener(e,f,!0),n.addEventListener(e,p);let g=window.setTimeout(()=>{n.addEventListener(`pointerdown`,m)},0);return()=>{window.clearTimeout(g),n.removeEventListener(`pointerdown`,m),n.removeEventListener(`click`,d.current);for(let e of h)n.removeEventListener(e,f,!0),n.removeEventListener(e,p)}},[n,s,r,i,a,o]),{onPointerDownCapture:dx(()=>c.current=!0,`onPointerDownCapture`)}}dx(bx,`usePointerDownOutside`);function xx(e,t=globalThis?.document){let n=lx(e),r=X.useRef(!1);return X.useEffect(()=>{let e=dx(e=>{e.target&&!r.current&&Cx(mx,n,{originalEvent:e},{discrete:!1})},`handleFocus`);return t.addEventListener(`focusin`,e),()=>t.removeEventListener(`focusin`,e)},[t,n]),{onFocusCapture:dx(()=>r.current=!0,`onFocusCapture`),onBlurCapture:dx(()=>r.current=!1,`onBlurCapture`)}}dx(xx,`useFocusOutside`);function Sx(){let e=new CustomEvent(fx);document.dispatchEvent(e)}dx(Sx,`dispatchUpdate`);function Cx(e,t,n,{discrete:r}){let i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?ax(i,a):i.dispatchEvent(a)}dx(Cx,`handleAndDispatchCustomEvent`);var wx=Object.defineProperty,Tx=(e,t)=>wx(e,`name`,{value:t,configurable:!0}),Ex=`focusScope.autoFocusOnMount`,Dx=`focusScope.autoFocusOnUnmount`,Ox={bubbles:!1,cancelable:!0},kx=X.forwardRef(Tx(function(e,t){let{loop:n=!1,trapped:r=!1,branches:i,onMountAutoFocus:a,onUnmountAutoFocus:o,...s}=e,[c,l]=X.useState(null),u=lx(a),d=lx(o),f=X.useRef(null),p=mb(t,l),m=X.useRef(i);X.useEffect(()=>{m.current=i});let h=X.useCallback(e=>e?c?.contains(e)?!0:!!m.current?.some(t=>t.contains(e)):!1,[c]),g=X.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;X.useEffect(()=>{if(r){let e=function(e){if(g.paused||!c)return;let t=e.target;h(t)?f.current=t:Bx(f.current,{select:!0})},t=function(e){if(g.paused||!c)return;let t=e.relatedTarget;t!==null&&(h(t)||Bx(f.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&Bx(c)};Tx(e,`handleFocusIn`),Tx(t,`handleFocusOut`),Tx(n,`handleMutations`),document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return c&&r.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,c,g.paused,h]),X.useEffect(()=>{if(c){Vx.add(g);let e=document.activeElement;if(!c.contains(e)){let t=new CustomEvent(Ex,Ox);c.addEventListener(Ex,u),c.dispatchEvent(t),t.defaultPrevented||(Px(Wx(Ix(c)),{select:!0}),document.activeElement===e&&Bx(c))}return()=>{c.removeEventListener(Ex,u);let t=c.ownerDocument,n=CustomEvent;setTimeout(()=>{let r=new n(Dx,Ox);c.addEventListener(Dx,d),c.dispatchEvent(r),r.defaultPrevented||Bx(e??t.body,{select:!0}),c.removeEventListener(Dx,d),Vx.remove(g)},0)}}},[c,u,d,g]);let _=X.useCallback(e=>{if(!n&&!r||g.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=Fx(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&Bx(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&Bx(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,g.paused]);return(0,Z.jsx)(ix.div,{tabIndex:-1,...s,ref:p,onKeyDown:_})},`FocusScope`)),Ax=X.createContext(null);function jx({registry:e,children:t}){return e?(0,Z.jsx)(Ax.Provider,{value:e,children:t}):t}Tx(jx,`FocusScopeBranchProvider`);function Mx(){let[e,t]=X.useState([]);return{nodes:e,registry:X.useMemo(()=>({add:Tx(e=>t(t=>t.includes(e)?t:[...t,e]),`add`),remove:Tx(e=>t(t=>t.filter(t=>t!==e)),`remove`)}),[])}}Tx(Mx,`useFocusScopeBranchRegistry`);function Nx(e){let t=X.useContext(Ax);X.useEffect(()=>{if(e&&t)return t.add(e),()=>t.remove(e)},[e,t])}Tx(Nx,`useFocusScopeBranch`);function Px(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(Bx(r,{select:t}),document.activeElement!==n)return}Tx(Px,`focusFirst`);function Fx(e){let t=Ix(e);return[Lx(t,e),Lx(t.reverse(),e)]}Tx(Fx,`getTabbableEdges`);function Ix(e){let t=[],n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Tx(e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},`acceptNode`)});for(;n.nextNode();)t.push(n.currentNode);return t}Tx(Ix,`getTabbableCandidates`);function Lx(e,t){let n=typeof t.checkVisibility==`function`&&t.checkVisibility({checkVisibilityCSS:!0});for(let r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Rx(r,{upTo:t})))return r}Tx(Lx,`findVisible`);function Rx(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}Tx(Rx,`isHidden`);function zx(e){return e.tagName===`INPUT`&&typeof e.select==`function`}Tx(zx,`isSelectableInput`);function Bx(e,{select:t=!1}={}){if(e&&e.focus){let n=(e.ownerDocument??document).activeElement;e.focus({preventScroll:!0}),e!==n&&zx(e)&&t&&e.select()}}Tx(Bx,`focus`);var Vx=Hx();function Hx(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=Ux(e,t),e.unshift(t)},remove(t){e=Ux(e,t),e[0]?.resume()}}}Tx(Hx,`createFocusScopesStack`);function Ux(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}Tx(Ux,`arrayRemove`);function Wx(e){return e.filter(e=>e.tagName!==`A`)}Tx(Wx,`removeLinks`);var Gx=Object.defineProperty,Kx=X.forwardRef(((e,t)=>Gx(e,`name`,{value:t,configurable:!0}))(function(e,t){let{container:n,...r}=e,[i,a]=X.useState(!1);bb(()=>a(!0),[]);let o=n||i&&globalThis?.document?.body;return o?nc.createPortal((0,Z.jsx)(ix.div,{...r,ref:t}),o):null},`Portal`)),qx=Object.defineProperty,Jx=(e,t)=>qx(e,`name`,{value:t,configurable:!0});function Yx(e,t){return X.useReducer((e,n)=>t[e][n]??e,e)}Jx(Yx,`useStateMachine`);var Xx=Jx(e=>{let{present:t,children:n}=e,r=Zx(t),i=typeof n==`function`?n({present:r.isPresent}):X.Children.only(n),a=$x(r.ref,tS(i));return typeof n==`function`||r.isPresent?X.cloneElement(i,{ref:a}):null},`Presence`);function Zx(e){let[t,n]=X.useState(),r=X.useRef(null),i=X.useRef(e),a=X.useRef(`none`),o=X.useRef(void 0),[s,c]=Yx(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return X.useEffect(()=>{s===`mounted`?(a.current=o.current??eS(r.current),o.current=void 0):a.current=`none`},[s]),bb(()=>{let t=r.current,n=i.current;if(n!==e){let r=a.current,s=eS(t);e?(o.current=s,c(`MOUNT`)):s===`none`||t?.display===`none`?c(`UNMOUNT`):c(n&&r!==s?`ANIMATION_OUT`:`UNMOUNT`),i.current=e}},[e,c]),bb(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,o=Jx(a=>{let o=eS(r.current).includes(CSS.escape(a.animationName));if(a.target===t&&o&&(c(`ANIMATION_END`),!i.current)){let r=t.style.animationFillMode;t.style.animationFillMode=`forwards`,e=n.setTimeout(()=>{t.style.animationFillMode===`forwards`&&(t.style.animationFillMode=r)})}},`handleAnimationEnd`),s=Jx(e=>{e.target===t&&(a.current=eS(r.current))},`handleAnimationStart`);return t.addEventListener(`animationstart`,s),t.addEventListener(`animationcancel`,o),t.addEventListener(`animationend`,o),()=>{n.clearTimeout(e),t.removeEventListener(`animationstart`,s),t.removeEventListener(`animationcancel`,o),t.removeEventListener(`animationend`,o)}}c(`ANIMATION_END`)},[t,c]),{isPresent:[`mounted`,`unmountSuspended`].includes(s),ref:X.useCallback(e=>{if(e){let t=getComputedStyle(e);r.current=t,o.current=eS(t)}else r.current=null;n(e)},[])}}Jx(Zx,`usePresence`);function Qx(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}Jx(Qx,`setRef`);function $x(...e){let t=X.useRef(e);return t.current=e,X.useCallback(e=>{let n=t.current,r=!1,i=n.map(t=>{let n=Qx(t,e);return!r&&typeof n==`function`&&(r=!0),n});if(r)return()=>{for(let e=0;e<i.length;e++){let t=i[e];typeof t==`function`?t():Qx(n[e],null)}}},[])}Jx($x,`useStableComposedRefs`);function eS(e){return e?.animationName||`none`}Jx(eS,`getAnimationName`);function tS(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Jx(tS,`getElementRef`);var nS=Object.defineProperty,rS=(e,t)=>nS(e,`name`,{value:t,configurable:!0}),iS=0,aS=null;function oS(e){return sS(),e.children}rS(oS,`FocusGuards`);function sS(){X.useEffect(()=>{aS||={start:cS(),end:cS()};let{start:e,end:t}=aS;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement(`afterbegin`,e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement(`beforeend`,t),iS++,()=>{iS===1&&(aS?.start.remove(),aS?.end.remove(),aS=null),iS=Math.max(0,iS-1)}},[])}rS(sS,`useFocusGuards`);function cS(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}rS(cS,`createFocusGuard`);var lS=function(){return lS=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},lS.apply(this,arguments)};function uS(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function dS(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var fS=`right-scroll-bar-position`,pS=`width-before-scroll-bar`,mS=`with-scroll-bars-hidden`,hS=`--removed-body-scroll-bar-size`;function gS(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function _S(e,t){var n=(0,X.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var vS=typeof window<`u`?X.useLayoutEffect:X.useEffect,yS=new WeakMap;function bS(e,t){var n=_S(t||null,function(t){return e.forEach(function(e){return gS(e,t)})});return vS(function(){var t=yS.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||gS(e,null)}),i.forEach(function(e){r.has(e)||gS(e,a)})}yS.set(n,e)},[e]),n}function xS(e){return e}function SS(e,t){t===void 0&&(t=xS);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function CS(e){e===void 0&&(e={});var t=SS(null);return t.options=lS({async:!0,ssr:!1},e),t}var wS=function(e){var t=e.sideCar,n=uS(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return X.createElement(r,lS({},n))};wS.isSideCarExport=!0;function TS(e,t){return e.useMedium(t),wS}var ES=CS(),DS=function(){},OS=X.forwardRef(function(e,t){var n=X.useRef(null),r=X.useState({onScrollCapture:DS,onWheelCapture:DS,onTouchMoveCapture:DS}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noRelative,m=e.noIsolation,h=e.inert,g=e.allowPinchZoom,_=e.as,v=_===void 0?`div`:_,y=e.gapMode,b=uS(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),x=f,S=bS([n,t]),C=lS(lS({},b),i);return X.createElement(X.Fragment,null,u&&X.createElement(x,{sideCar:ES,removeScrollBar:l,shards:d,noRelative:p,noIsolation:m,inert:h,setCallbacks:a,allowPinchZoom:!!g,lockRef:n,gapMode:y}),o?X.cloneElement(X.Children.only(s),lS(lS({},C),{ref:S})):X.createElement(v,lS({},C,{className:c,ref:S}),s))});OS.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},OS.classNames={fullWidth:pS,zeroRight:fS};var kS=function(){if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function AS(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=kS();return t&&e.setAttribute(`nonce`,t),e}function jS(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function MS(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var NS=function(){var e=0,t=null;return{add:function(n){e==0&&(t=AS())&&(jS(t,n),MS(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},PS=function(){var e=NS();return function(t,n){X.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},FS=function(){var e=PS();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},IS={left:0,top:0,right:0,gap:0},LS=function(e){return parseInt(e||``,10)||0},RS=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[LS(n),LS(r),LS(i)]},zS=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return IS;var t=RS(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},BS=FS(),VS=`data-scroll-locked`,HS=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
|
|
2
|
+
.${mS} {
|
|
3
|
+
overflow: hidden ${r};
|
|
4
|
+
padding-right: ${s}px ${r};
|
|
5
|
+
}
|
|
6
|
+
body[${VS}] {
|
|
7
|
+
overflow: hidden ${r};
|
|
8
|
+
overscroll-behavior: contain;
|
|
9
|
+
${[t&&`position: relative ${r};`,n===`margin`&&`
|
|
10
|
+
padding-left: ${i}px;
|
|
11
|
+
padding-top: ${a}px;
|
|
12
|
+
padding-right: ${o}px;
|
|
13
|
+
margin-left:0;
|
|
14
|
+
margin-top:0;
|
|
15
|
+
margin-right: ${s}px ${r};
|
|
16
|
+
`,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.${fS} {
|
|
20
|
+
right: ${s}px ${r};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.${pS} {
|
|
24
|
+
margin-right: ${s}px ${r};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.${fS} .${fS} {
|
|
28
|
+
right: 0 ${r};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.${pS} .${pS} {
|
|
32
|
+
margin-right: 0 ${r};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
body[${VS}] {
|
|
36
|
+
${hS}: ${s}px;
|
|
37
|
+
}
|
|
38
|
+
`},US=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},WS=function(){X.useEffect(function(){return document.body.setAttribute(VS,(US()+1).toString()),function(){var e=US()-1;e<=0?document.body.removeAttribute(VS):document.body.setAttribute(VS,e.toString())}},[])},GS=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;WS();var a=X.useMemo(function(){return zS(i)},[i]);return X.createElement(BS,{styles:HS(a,!t,i,n?``:`!important`)})},KS=!1;if(typeof window<`u`)try{var qS=Object.defineProperty({},"passive",{get:function(){return KS=!0,!0}});window.addEventListener(`test`,qS,qS),window.removeEventListener(`test`,qS,qS)}catch{KS=!1}var JS=KS?{passive:!1}:!1,YS=function(e){return e.tagName===`TEXTAREA`},XS=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!YS(e)&&n[t]===`visible`)},ZS=function(e){return XS(e,`overflowY`)},QS=function(e){return XS(e,`overflowX`)},$S=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),nC(e,r)){var i=rC(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},eC=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},tC=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},nC=function(e,t){return e===`v`?ZS(t):QS(t)},rC=function(e,t){return e===`v`?eC(t):tC(t)},iC=function(e,t){return e===`h`&&t===`rtl`?-1:1},aC=function(e,t,n,r,i){var a=iC(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=rC(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&nC(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},oC=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},sC=function(e){return[e.deltaX,e.deltaY]},cC=function(e){return e&&`current`in e?e.current:e},lC=function(e,t){return e[0]===t[0]&&e[1]===t[1]},uC=function(e){return`
|
|
39
|
+
.block-interactivity-${e} {pointer-events: none;}
|
|
40
|
+
.allow-interactivity-${e} {pointer-events: all;}
|
|
41
|
+
`},dC=0,fC=[];function pC(e){var t=X.useRef([]),n=X.useRef([0,0]),r=X.useRef(),i=X.useState(dC++)[0],a=X.useState(FS)[0],o=X.useRef(e);X.useEffect(function(){o.current=e},[e]),X.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=dS([e.lockRef.current],(e.shards||[]).map(cC),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=X.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=oC(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=$S(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=$S(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return aC(h,t,e,h===`h`?s:c,!0)},[]),c=X.useCallback(function(e){var n=e;if(fC.length&&fC[fC.length-1]===a){var r=`deltaY`in n?sC(n):oC(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&lC(e.delta,r)})[0];if(i&&i.should)n.cancelable&&n.preventDefault();else if(!i){var c=(o.current.shards||[]).map(cC).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=X.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:mC(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=X.useCallback(function(e){n.current=oC(e),r.current=void 0},[]),d=X.useCallback(function(t){l(t.type,sC(t),t.target,s(t,e.lockRef.current))},[]),f=X.useCallback(function(t){l(t.type,oC(t),t.target,s(t,e.lockRef.current))},[]);X.useEffect(function(){return fC.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,JS),document.addEventListener(`touchmove`,c,JS),document.addEventListener(`touchstart`,u,JS),function(){fC=fC.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,JS),document.removeEventListener(`touchmove`,c,JS),document.removeEventListener(`touchstart`,u,JS)}},[]);var p=e.removeScrollBar,m=e.inert;return X.createElement(X.Fragment,null,m?X.createElement(a,{styles:uC(i)}):null,p?X.createElement(GS,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function mC(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var hC=TS(ES,pC),gC=X.forwardRef(function(e,t){return X.createElement(OS,lS({},e,{ref:t,sideCar:hC}))});gC.classNames=OS.classNames;var _C=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},vC=new WeakMap,yC=new WeakMap,bC={},xC=0,SC=function(e){return e&&(e.host||SC(e.parentNode))},CC=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=SC(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},wC=function(e,t,n,r){var i=CC(t,Array.isArray(e)?e:[e]);bC[n]||(bC[n]=new WeakMap);var a=bC[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(vC.get(e)||0)+1,l=(a.get(e)||0)+1;vC.set(e,c),a.set(e,l),o.push(e),c===1&&i&&yC.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),xC++,function(){o.forEach(function(e){var t=vC.get(e)-1,i=a.get(e)-1;vC.set(e,t),a.set(e,i),t||(yC.has(e)||e.removeAttribute(r),yC.delete(e)),i||e.removeAttribute(n)}),xC--,xC||(vC=new WeakMap,vC=new WeakMap,yC=new WeakMap,bC={})}},TC=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||_C(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),wC(r,i,n,`aria-hidden`)):function(){return null}},EC=Object.defineProperty,DC=(e,t)=>EC(e,`name`,{value:t,configurable:!0}),OC=`Dialog`,[kC,AC]=vb(OC),[jC,MC]=kC(OC),NC=DC(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=X.useRef(null),c=X.useRef(null),{nodes:l,registry:u}=Mx(),[d,f]=Pb({prop:r,defaultProp:i??!1,onChange:a,caller:OC}),[p,m]=X.useState(0),[h,g]=X.useState(0);return(0,Z.jsx)(jC,{scope:t,triggerRef:s,contentRef:c,contentId:Tb(),titleId:Tb(),descriptionId:Tb(),titlePresent:p>0,descriptionPresent:h>0,setTitleCount:m,setDescriptionCount:g,open:d,onOpenChange:f,onOpenToggle:X.useCallback(()=>f(e=>!e),[f]),modal:o,branchNodes:l,branchRegistry:u,children:n})},`Dialog`),PC=`DialogPortal`,[FC,IC]=kC(PC,{forceMount:void 0}),LC=DC(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=MC(PC,t);return(0,Z.jsx)(FC,{scope:t,forceMount:n,children:X.Children.map(r,e=>(0,Z.jsx)(Xx,{present:n||a.open,children:(0,Z.jsx)(Kx,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),RC=`DialogOverlay`,zC=X.forwardRef(DC(function(e,t){let n=IC(RC,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=MC(RC,e.__scopeDialog);return a.modal?(0,Z.jsx)(Xx,{present:r||a.open,children:(0,Z.jsx)(VC,{...i,ref:t})}):null},`DialogOverlay`)),BC=Vb(`DialogOverlay.RemoveScroll`),VC=X.forwardRef(DC(function(e,t){let{__scopeDialog:n,...r}=e,i=MC(RC,n),a=mb(t,vx());return(0,Z.jsx)(gC,{as:BC,allowPinchZoom:!0,shards:X.useMemo(()=>[i.contentRef,...i.branchNodes.map(e=>({current:e}))],[i.contentRef,i.branchNodes]),children:(0,Z.jsx)(ix.div,{"data-state":JC(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),HC=`DialogContent`,UC=X.forwardRef(DC(function(e,t){let n=IC(HC,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=MC(HC,e.__scopeDialog);return(0,Z.jsx)(Xx,{present:r||a.open,children:a.modal?(0,Z.jsx)(WC,{...i,ref:t}):(0,Z.jsx)(GC,{...i,ref:t})})},`DialogContent`)),WC=X.forwardRef(DC(function(e,t){let n=MC(HC,e.__scopeDialog),r=X.useRef(null),i=mb(t,n.contentRef,r);return X.useEffect(()=>{let e=r.current;if(e)return TC(e)},[]),(0,Z.jsx)(KC,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:ab(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:ab(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:ab(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),GC=X.forwardRef(DC(function(e,t){let n=MC(HC,e.__scopeDialog),r=X.useRef(!1),i=X.useRef(!1);return(0,Z.jsx)(KC,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),KC=X.forwardRef(DC(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,"aria-describedby":o,children:s,...c}=e,l=MC(HC,n);return sS(),(0,Z.jsx)(jx,{registry:l.branchRegistry,children:(0,Z.jsx)(kx,{asChild:!0,loop:!0,trapped:r,branches:l.branchNodes,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,Z.jsx)(_x,{role:`dialog`,id:l.contentId,"aria-labelledby":l.titlePresent?l.titleId:void 0,"aria-describedby":l.descriptionPresent?qC(o,l.descriptionId):o,"data-state":JC(l.open),...c,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1),children:s})})})},`DialogContentImpl`));function qC(...e){let t=new Set;for(let n of e)if(typeof n==`string`)for(let e of String(n).trim().split(/\s+/))e&&t.add(e);return t.size>0?Array.from(t).join(` `):void 0}DC(qC,`concatAriaDescribedby`);function JC(e){return e?`open`:`closed`}DC(JC,`getState`);var YC=`[cmdk-group=""]`,XC=`[cmdk-group-items=""]`,ZC=`[cmdk-group-heading=""]`,QC=`[cmdk-item=""]`,$C=`${QC}:not([aria-disabled="true"])`,ew=`cmdk-item-select`,tw=`data-value`,nw=(e,t,n)=>tb(e,t,n),rw=X.createContext(void 0),iw=()=>X.useContext(rw),aw=X.createContext(void 0),ow=()=>X.useContext(aw),sw=X.createContext(void 0),cw=X.forwardRef((e,t)=>{let n=Sw(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=Sw(()=>new Set),i=Sw(()=>new Map),a=Sw(()=>new Map),o=Sw(()=>new Set),s=bw(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=Tb(),y=Tb(),b=Tb(),x=X.useRef(null),S=Tw();xw(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,C.emit()}},[u]),xw(()=>{S(6,k)},[]);let C=X.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)O(),E(),S(1,D);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(b);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(S(7,()=>{n.current.selectedItemId=A()?.id,C.emit()}),r||S(5,k),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),w=X.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,T(t,r)),S(2,()=>{E(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),S(3,()=>{O(),E(),n.current.value||D(),C.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=A();S(4,()=>{O(),t?.getAttribute(`id`)===e&&D(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:b,labelId:y,listInnerRef:x}),[]);function T(e,t){let r=s.current?.filter??nw;return e?r(e,n.current.search,t):0}function E(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=x.current;j().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(XC);t?t.appendChild(e.parentElement===t?e:e.closest(`${XC} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${XC} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=x.current?.querySelector(`${YC}[${tw}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function D(){let e=j().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(tw);C.setState(`value`,e||void 0)}function O(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=T(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function k(){var e;let t=A();t&&(t.parentElement?.firstChild===t&&((e=t.closest(YC)?.querySelector(ZC))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function A(){return x.current?.querySelector(`${QC}[aria-selected="true"]`)}function j(){return Array.from(x.current?.querySelectorAll($C)||[])}function M(e){let t=j()[e];t&&C.setState(`value`,t.getAttribute(tw))}function N(e){var t;let n=A(),r=j(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&C.setState(`value`,a.getAttribute(tw))}function ee(e){let t=A()?.closest(YC),n;for(;t&&!n;)t=e>0?vw(t,YC):yw(t,YC),n=t?.querySelector($C);n?C.setState(`value`,n.getAttribute(tw)):N(e)}let P=()=>M(j().length-1),te=e=>{e.preventDefault(),e.metaKey?P():e.altKey?ee(1):N(1)},F=e=>{e.preventDefault(),e.metaKey?M(0):e.altKey?ee(-1):N(-1)};return X.createElement(ix.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&te(e);break;case`ArrowDown`:te(e);break;case`p`:case`k`:g&&e.ctrlKey&&F(e);break;case`ArrowUp`:F(e);break;case`Home`:e.preventDefault(),M(0);break;case`End`:e.preventDefault(),P();break;case`Enter`:{e.preventDefault();let t=A();if(t){let e=new Event(ew);t.dispatchEvent(e)}}}}},X.createElement(`label`,{"cmdk-label":``,htmlFor:w.inputId,id:w.labelId,style:Ow},c),Dw(e,e=>X.createElement(aw.Provider,{value:C},X.createElement(rw.Provider,{value:w},e))))}),lw=X.forwardRef((e,t)=>{let n=Tb(),r=X.useRef(null),i=X.useContext(sw),a=iw(),o=bw(e),s=o.current?.forceMount??i?.forceMount;xw(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=ww(n,r,[e.value,e.children,r],e.keywords),l=ow(),u=Cw(e=>e.value&&e.value===c.current),d=Cw(e=>s||a.filter()===!1?!0:!e.search||e.filtered.items.get(n)>0);X.useEffect(()=>{let t=r.current;if(t&&!e.disabled)return t.addEventListener(ew,f),()=>t.removeEventListener(ew,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:v,...y}=e;return X.createElement(ix.div,{ref:pb(r,t),...y,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),uw=X.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=Tb(),s=X.useRef(null),c=X.useRef(null),l=Tb(),u=iw(),d=Cw(e=>i||u.filter()===!1?!0:!e.search||e.filtered.groups.has(o));xw(()=>u.group(o),[]),ww(o,s,[e.value,e.heading,c]);let f=X.useMemo(()=>({id:o,forceMount:i}),[i]);return X.createElement(ix.div,{ref:pb(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:!d||void 0},n&&X.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),Dw(e,e=>X.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},X.createElement(sw.Provider,{value:f},e))))}),dw=X.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=X.useRef(null),a=Cw(e=>!e.search);return!n&&!a?null:X.createElement(ix.div,{ref:pb(i,t),...r,"cmdk-separator":``,role:`separator`})}),fw=X.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=ow(),o=Cw(e=>e.search),s=Cw(e=>e.selectedItemId),c=iw();return X.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),X.createElement(ix.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),pw=X.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=X.useRef(null),o=X.useRef(null),s=Cw(e=>e.selectedItemId),c=iw();return X.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),X.createElement(ix.div,{ref:pb(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},Dw(e,e=>X.createElement(`div`,{ref:pb(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),mw=X.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return X.createElement(NC,{open:n,onOpenChange:r},X.createElement(LC,{container:o},X.createElement(zC,{"cmdk-overlay":``,className:i}),X.createElement(UC,{"aria-label":e.label,"cmdk-dialog":``,className:a},X.createElement(cw,{ref:t,...s}))))}),hw=X.forwardRef((e,t)=>Cw(e=>e.filtered.count===0)?X.createElement(ix.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),gw=X.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return X.createElement(ix.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Dw(e,e=>X.createElement(`div`,{"aria-hidden":!0},e)))}),_w=Object.assign(cw,{List:pw,Item:lw,Input:fw,Group:uw,Separator:dw,Dialog:mw,Empty:hw,Loading:gw});function vw(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function yw(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function bw(e){let t=X.useRef(e);return xw(()=>{t.current=e}),t}var xw=typeof window>`u`?X.useEffect:X.useLayoutEffect;function Sw(e){let t=X.useRef();return t.current===void 0&&(t.current=e()),t}function Cw(e){let t=ow(),n=()=>e(t.snapshot());return X.useSyncExternalStore(t.subscribe,n,n)}function ww(e,t,n,r=[]){let i=X.useRef(),a=iw();return xw(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(tw,s),i.current=s}),i}var Tw=()=>{let[e,t]=X.useState(),n=Sw(()=>new Map);return xw(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Ew(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function Dw({asChild:e,children:t},n){return e&&X.isValidElement(t)?X.cloneElement(Ew(t),{ref:t.ref},n(t.props.children)):n(t)}var Ow={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`},kw=X.createContext(void 0);function Aw(e){let t=X.useContext(kw);if(!e&&t===void 0)throw Error(Gi(27));return t}var jw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=Aw(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`),d={open:c,transitionStatus:s.useState(`transitionStatus`)};return $r(`div`,e,{state:d,ref:[s.context.backdropRef,t],stateAttributesMapping:Po,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),Mw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=Aw(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=li({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,$i(Na,e.nativeEvent))}return $r(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})});function Nw(e){return ji(e,`base-ui`)}var Pw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Aw(),c=Nw(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),$r(`p`,e,{ref:t,props:[{id:c},o]})}),Fw=X.createContext(void 0);function Iw(){let e=X.useContext(Fw);if(e===void 0)throw Error(Gi(26));return e}var Lw=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),Rw=`--nested-dialogs`,zw=`data-nested-dialog-open`,Bw={...No,...Fa,nestedDialogOpen(e){return e?{[zw]:``}:null}},Vw=X.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=Aw(),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`);Iw(),wi({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?ic(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=$r(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...rc,hidden:!m,onKeyDown(e){Lw.has(e.key)&&e.stopPropagation()},style:{[Rw]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:Bw});return(0,Z.jsx)(Js,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})}),Hw=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}})}),Uw=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=Aw(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Z.jsx)(Fw.Provider,{value:n,children:(0,Z.jsxs)(Aa,{ref:t,...r,children:[a&&o===!0&&(0,Z.jsx)(Hw,{ref:i.context.internalBackdropRef,inert:Si(!s)}),e.children]})}):null}),Ww={},Gw={},Kw=``;function qw(e,t){return La(e)?e:t}function Jw(e,t,n){return/hidden|clip/.test(e.getComputedStyle(qw(t,n)).overflowY)}function Yw(e){if(typeof document>`u`)return!1;let t=Ba(e);return ra(t).innerWidth-t.documentElement.clientWidth>0}function Xw(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=Ba(e),n=t.documentElement,r=t.body,i=qw(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 Zw(e){let t=Ba(e),n=t.documentElement,r=t.body,i=qw(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 Qw(e){let t=Ba(e),n=t.documentElement,r=t.body,i=ra(n),a=0,o=0,s=!1,c=ba.create();if(so&&(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,Ww={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Kw=n.style.scrollBehavior,Gw={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=qw(n,r);s=Xw(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,Ww),Object.assign(r.style,Gw),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=Kw)}function d(){u(),c.request(l)}l();let f=fi(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var $w=new class{lockCount=0;restore=null;timeoutLock=ti.create();timeoutUnlock=ti.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=Ba(e),n=t.documentElement,r=t.body,i=ra(n);if(Jw(i,n,r)){let t=new i.MutationObserver(()=>{Jw(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=io||!Yw(e);this.restore=a?Zw(e):Qw(e)}};function eT(e=!0,t=null){J(()=>{if(e)return $w.acquire(t)},[e,t])}function tT({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=Qs(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=Yi(t);if(p&&!a){if(o){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||Y(n,s)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return eT(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]),mc(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var nT={...Tc,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},rT=class extends Fi{constructor(e,t,n){let r=new gc,i=iT(e,r,t,n);super(i,aT(r),nT)}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(lc(this.state,e,t.trigger)))}};function iT(e,t,n,r=!1){return{...yc(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 aT(e){return{popupRef:X.createRef(),backdropRef:X.createRef(),internalBackdropRef:X.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function oT(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=Aw(!0),y={modal:h,disablePointerDismissal:g,nested:v!=null,role:_},b=ac((e,t)=>new rT({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`);hc(b,x),fc(b);let{forceUnmount:w}=pc(x,b);X.useImperativeHandle(l,()=>({unmount:w,close:()=>b.setOpen(!1,$i(wa))}),[w,b]);let T=x||S||u!=null;return(0,Z.jsxs)(kw.Provider,{value:b,children:[u&&(0,Z.jsx)(oc,{handle:u,store:b}),T&&(0,Z.jsx)(tT,{store:b,parentContext:v?.context,isDrawer:p}),typeof n==`function`?n({payload:C}):n]})}var sT=ai(function(e){return oT(`dialog`,e)}),cT=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Aw(),c=Nw(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),$r(`h2`,e,{ref:t,props:[{id:c},o]})});function lT(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 uT(e,t){let n=X.useRef(e),r=q(t);J(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function dT(e,t){let{onClick:n,onPointerDown:r}=lT(q((n,r)=>{(typeof e==`function`?e():e)||t(r||(io?`touch`:``))}));return X.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function fT(e){let[t,n]=X.useState(null),r=dT(e,n);return uT(e,t=>{t&&!e&&n(null)}),X.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}function pT(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)(sT,{"data-slot":`dialog`,...n}),t[2]=n,t[3]=r),r}function mT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(Uw,{"data-slot":`dialog-portal`,...n}),t[2]=n,t[3]=r),r}function hT(e){let t=(0,$.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Z.jsx)(Mw,{"data-slot":`dialog-close`,...n}),t[2]=n,t[3]=r),r}function gT(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=$a(`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)(jw,{"data-slot":`dialog-overlay`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function _T(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)(gT,{}),t[5]=s):s=t[5];let c;t[6]===r?c=t[7]:(c=$a(`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)(Mw,{"data-slot":`dialog-close`,render:(0,Z.jsx)(Ai,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,Z.jsx)(ea,{}),(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)(mT,{children:[s,(0,Z.jsxs)(Vw,{"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 vT(e){let t=(0,$.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=$a(`flex flex-col gap-1`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`div`,{"data-slot":`dialog-header`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function yT(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=$a(`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)(Mw,{render:(0,Z.jsx)(Ai,{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 bT(e){let t=(0,$.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=$a(`text-sm font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(cT,{"data-slot":`dialog-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function xT(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=$a(`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)(Pw,{"data-slot":`dialog-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var ST=`data-valid`,CT=`data-invalid`,wT={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},TT={disabled:!1,valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},ET={valid(e){return e===null?null:e?{[ST]:``}:{[CT]:``}}},DT={invalid:void 0,name:void 0,validityData:{state:wT,errors:[],error:``,value:``,initialValue:null},setValidityData:Li,disabled:void 0,setTouched:Li,setDirty:Li,setFilled:Li,setFocused:Li,focusOwnerRef:{current:void 0},validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:TT,registerFieldControl:Li,validation:{getValidationProps:(e,t=di)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Li,getInputControl:()=>null,commit:async()=>{},change:Li}},OT=X.createContext(DT);function kT(e=!0){let t=X.useContext(OT);if(t.setValidityData===Li&&!e)throw Error(Gi(28));return t}var AT=X.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Li,validationMode:`onSubmit`,submitCountRef:{current:0}});function jT(){return X.useContext(AT)}var MT=X.createContext({controlId:void 0,registerControlId:Li,resetControlId:Li,labelId:void 0,setLabelId:Li,messageIds:[],setMessageIds:Li,getDescriptionProps:e=>e});function NT(){return X.useContext(MT)}function PT(e,t,n){let{setFocused:r,focusOwnerRef:i}=kT(),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}function FT(e,t,n,r,i=!0,a){let{registerFieldControl:o}=kT(),s=Yr(()=>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])}function IT(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=NT(),o=Nw(),s=Yr(()=>Symbol()),c=X.useRef(!1),l=X.useRef(!1),u=q(()=>{c.current&&i!==Li&&(c.current=!1,i(s.current,void 0))});return J(()=>{if(!n||i===Li){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}var LT=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}=kT(),{clearErrors:S,elementRef:C,submitCountRef:w}=jT(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=NT(),k=IT({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=q(()=>x.inputRef.current?.value);FT(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]),uT(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=X.useRef(null),ee=PT(T,N),P=to();return $r(`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=$i(Ia,e.nativeEvent);c?.(t,n),A||(_(t!==(v.initialValue??``)),y(t!==``),!e.nativeEvent.defaultPrevented&&!n.isCanceled&&(S(E),x.change(t)))},onFocus(){ee(!0)},onBlur(e){if(g(!0),ee(!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;P.start(0,()=>{w.current===n&&x.commit(t.value)})}else x.commit(t)}}},f,e=>x.getValidationProps(T,e)],stateAttributesMapping:ET})}),RT=X.forwardRef(function(e,t){return(0,Z.jsx)(LT,{ref:t,...e})});function zT(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=$a(`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)(RT,{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 BT(e){let t=(0,$.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=$a(`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 VT=oo(`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 HT(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=$a(VT({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:UT,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function UT(e){e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`input`)?.focus()}oo(`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 WT(e){let t=(0,$.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=$a(`flex size-full flex-col overflow-hidden rounded-xl bg-popover p-1 text-popover-foreground`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(_w,{"data-slot":`command`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function GT(e){let t=(0,$.c)(24),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]):({title:a,description:o,children:n,className:r,showCloseButton: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?`Command Palette`:a,l=o===void 0?`Search for a command to run...`:o,u=s!==void 0&&s,d;t[7]===c?d=t[8]:(d=(0,Z.jsx)(bT,{children:c}),t[7]=c,t[8]=d);let f;t[9]===l?f=t[10]:(f=(0,Z.jsx)(xT,{children:l}),t[9]=l,t[10]=f);let p;t[11]!==d||t[12]!==f?(p=(0,Z.jsxs)(vT,{className:`sr-only`,children:[d,f]}),t[11]=d,t[12]=f,t[13]=p):p=t[13];let m;t[14]===r?m=t[15]:(m=$a(`top-1/3 translate-y-0 overflow-hidden rounded-xl! p-0`,r),t[14]=r,t[15]=m);let h;t[16]!==n||t[17]!==u||t[18]!==m?(h=(0,Z.jsx)(_T,{className:m,showCloseButton:u,children:n}),t[16]=n,t[17]=u,t[18]=m,t[19]=h):h=t[19];let g;return t[20]!==i||t[21]!==p||t[22]!==h?(g=(0,Z.jsxs)(pT,{...i,children:[p,h]}),t[20]=i,t[21]=p,t[22]=h,t[23]=g):g=t[23],g}function KT(e){let t=(0,$.c)(11),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=$a(`w-full text-xs/relaxed outline-hidden disabled:cursor-not-allowed disabled:opacity-50`,n),t[3]=n,t[4]=i);let a;t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(_w.Input,{"data-slot":`command-input`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7];let o;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(HT,{children:(0,Z.jsx)(So,{className:`size-3.5 shrink-0 opacity-50`})}),t[8]=o):o=t[8];let s;return t[9]===a?s=t[10]:(s=(0,Z.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1 pr-10 pb-0`,children:(0,Z.jsxs)(BT,{className:`h-8! bg-input/20 dark:bg-input/30`,children:[a,o]})}),t[9]=a,t[10]=s),s}function qT(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=$a(`no-scrollbar max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto outline-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(_w.List,{"data-slot":`command-list`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}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=$a(`py-6 text-center text-xs/relaxed`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(_w.Empty,{"data-slot":`command-empty`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function YT(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=$a(`overflow-hidden p-1 text-foreground **:[[cmdk-group-heading]]:px-2.5 **:[[cmdk-group-heading]]:py-1.5 **:[[cmdk-group-heading]]:text-xs **:[[cmdk-group-heading]]:font-medium **:[[cmdk-group-heading]]:text-muted-foreground`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(_w.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function XT(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=$a(`-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)(_w.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ZT(e){let t=(0,$.c)(10),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=$a(`group/command-item relative flex min-h-7 cursor-default items-center gap-2 rounded-md px-2.5 py-1.5 text-xs/relaxed outline-hidden select-none in-data-[slot=dialog-content]:rounded-md data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-selected:bg-muted data-selected:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 data-selected:*:[svg]:text-foreground`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(_w.Item,{"data-slot":`command-item`,className:a,...i,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function QT(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=$a(`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 $T=[{name:`deploy`,url:`https://deploy.mp281x.xyz`},{name:`scope`,url:`https://scope.mp281x.xyz`},{name:`gateway`,url:`https://gateway.mp281x.xyz`},{name:`auth`,url:`https://auth.mp281x.xyz`},{name:`signal`,url:`https://signal.mp281x.xyz`},{name:`portfolio`,url:`https://mp281x.xyz`}];function eE(e){let t=(0,$.c)(5),[n,r]=(0,X.useState)(!1);if(n){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(fo,{className:`text-muted-foreground size-4`}),t[0]=e):e=t[0],e}let i=`${e.url}/icon`,a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(!0),t[1]=a):a=t[1];let o;return t[2]!==e.name||t[3]!==i?(o=(0,Z.jsx)(`img`,{src:i,alt:``,className:`pixelated size-4`,onError:a,title:e.name}),t[2]=e.name,t[3]=i,t[4]=o):o=t[4],o}function tE(e){let t=(0,$.c)(10),n=`${e.group}:${e.item.id??e.item.label}`,r;t[0]===e.item.label?r=t[1]:(r=(0,Z.jsx)(`span`,{className:`min-w-0 shrink truncate`,children:e.item.label}),t[0]=e.item.label,t[1]=r);let i;t[2]===e.item.detail?i=t[3]:(i=e.item.detail!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground ml-auto max-w-1/2 truncate text-xs`,children:e.item.detail}),t[2]=e.item.detail,t[3]=i);let a;return t[4]!==e.item.icon||t[5]!==e.onSelect||t[6]!==n||t[7]!==r||t[8]!==i?(a=(0,Z.jsxs)(ZT,{value:n,onSelect:e.onSelect,children:[e.item.icon,r,i]}),t[4]=e.item.icon,t[5]=e.onSelect,t[6]=n,t[7]=r,t[8]=i,t[9]=a):a=t[9],a}function nE(e){let t=(0,$.c)(33),n;t[0]===e?n=t[1]:(n=function(t){e.onOpenChange(!1),t.run()},t[0]=e,t[1]=n);let r=n,i;t[2]===e.groups?i=t[3]:(i=Je([...p(e.groups,sE),...Re($T,oE)]),t[2]=e.groups,t[3]=i);let a=i,o=e.open,s=e.onOpenChange,c;t[4]===a?c=t[5]:(c=(e,t)=>nw(ge(Gr(a,e),()=>e),t),t[4]=a,t[5]=c);let l=`Search ${e.current??`Deslop`}…`,u;t[6]===l?u=t[7]:(u=(0,Z.jsx)(KT,{autoFocus:!0,placeholder:l}),t[6]=l,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(JT,{children:`No results.`}),t[8]=d):d=t[8];let f;if(t[9]!==e.groups||t[10]!==r){let n;t[12]===r?n=t[13]:(n=e=>(0,Z.jsx)(YT,{heading:e.label,children:Re(e.items,t=>(0,Z.jsx)(tE,{group:e.label,item:t,onSelect:()=>r(t)},`${e.label}:${t.id??t.label}`))},e.label),t[12]=r,t[13]=n),f=Re(kn(e.groups,aE),n),t[9]=e.groups,t[10]=r,t[11]=f}else f=t[11];let m;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Z.jsx)(XT,{}),t[14]=m):m=t[14];let h;t[15]!==e.current||t[16]!==r?(h=Re($T,t=>{let n={detail:`${new URL(t.url).hostname}${rt(t.name===e.current,{onFalse:iE,onTrue:rE})}`,icon:(0,Z.jsx)(eE,{name:t.name,url:t.url}),keywords:new URL(t.url).hostname,label:t.name,run:()=>{location.assign(t.url)}};return(0,Z.jsx)(tE,{group:`Deslop`,item:n,onSelect:()=>r(n)},t.name)}),t[15]=e.current,t[16]=r,t[17]=h):h=t[17];let g;t[18]===h?g=t[19]:(g=(0,Z.jsx)(YT,{heading:`Other apps`,children:h}),t[18]=h,t[19]=g);let _;t[20]!==g||t[21]!==f?(_=(0,Z.jsxs)(qT,{className:`max-h-96`,children:[d,f,m,g]}),t[20]=g,t[21]=f,t[22]=_):_=t[22];let v;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(QT,{children:`↑`}),(0,Z.jsx)(QT,{children:`↓`}),(0,Z.jsx)(`span`,{children:`navigate`})]}),t[23]=v):v=t[23];let y;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsxs)(`div`,{className:`text-muted-foreground hidden items-center justify-between border-t px-3 py-2 text-xs sm:flex`,children:[v,(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(QT,{children:`↵`}),(0,Z.jsx)(`span`,{children:`open`}),(0,Z.jsx)(QT,{children:`esc`}),(0,Z.jsx)(`span`,{children:`close`})]})]}),t[24]=y):y=t[24];let b;t[25]!==_||t[26]!==c||t[27]!==u?(b=(0,Z.jsxs)(WT,{filter:c,children:[u,_,y]}),t[25]=_,t[26]=c,t[27]=u,t[28]=b):b=t[28];let x;return t[29]!==e.onOpenChange||t[30]!==e.open||t[31]!==b?(x=(0,Z.jsx)(GT,{open:o,onOpenChange:s,title:`Search or run a command`,description:`Jump to a record, run an action, or open another Deslop tool.`,showCloseButton:!0,className:`sm:max-w-lg`,children:b}),t[29]=e.onOpenChange,t[30]=e.open,t[31]=b,t[32]=x):x=t[32],x}function rE(){return` · current`}function iE(){return``}function aE(e){return Ee(e.items)}function oE(e){return[`Deslop:${e.name}`,`${e.name} ${new URL(e.url).hostname}`]}function sE(e){return Re(e.items,t=>[`${e.label}:${t.id??t.label}`,`${t.label} ${t.detail??``} ${t.keywords??``}`])}function cE(e){let t=(0,$.c)(13),n=(0,X.useSyncExternalStore)(hE,mE,pE),r;t[0]===n?r=t[1]:(r=rt(n,{onFalse:fE,onTrue:dE}),t[0]=n,t[1]=r);let i=e.label,a=e.onClick,o,s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(So,{className:`size-3.5`}),s=(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:`Search`}),t[2]=o,t[3]=s):(o=t[2],s=t[3]);let c;t[4]===n?c=t[5]:(c=rt(n,{onFalse:uE,onTrue:lE}),t[4]=n,t[5]=c);let l;t[6]===c?l=t[7]:(l=(0,Z.jsx)(`span`,{className:`ml-auto`,children:(0,Z.jsx)(QT,{children:c})}),t[6]=c,t[7]=l);let u;return t[8]!==e.label||t[9]!==e.onClick||t[10]!==r||t[11]!==l?(u=(0,Z.jsxs)(Ai,{variant:`outline`,size:`lg`,"aria-keyshortcuts":r,"aria-label":i,onClick:a,className:`hidden w-64 justify-start sm:flex lg:absolute lg:top-2 lg:left-1/2 lg:-translate-x-1/2`,children:[o,s,l]}),t[8]=e.label,t[9]=e.onClick,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}function lE(){return`⌘K`}function uE(){return`Ctrl K`}function dE(){return`Meta+K`}function fE(){return`Control+K`}function pE(){return!0}function mE(){return Ct(Be(/Mac|iPhone|iPad/u)(navigator.userAgent))}function hE(){return gE}function gE(){}function _E(e){let t=(0,$.c)(4),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(So,{}),t[0]=n):n=t[0];let r;return t[1]!==e.label||t[2]!==e.onClick?(r=(0,Z.jsx)(Ai,{variant:`ghost`,size:`icon`,"aria-label":e.label,onClick:e.onClick,className:`max-sm:size-11 sm:hidden`,children:n}),t[1]=e.label,t[2]=e.onClick,t[3]=r):r=t[3],r}var vE=X.createContext(void 0);function yE(){let e=X.useContext(vE);if(e===void 0)throw Error(Gi(13));return e}var bE={imageLoadingStatus:()=>null},xE=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=$r(`span`,e,{state:c,ref:t,props:a,stateAttributesMapping:bE});return(0,Z.jsx)(vE.Provider,{value:l,children:u})});function SE(e,{referrerPolicy:t,crossOrigin:n,sizes:r,srcSet:i},a){let o=X.useState(`idle`),s=o[1];return J(()=>{if(!a)return Li;if(!e&&!i)return s(`error`),Li;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 CE={...bE,...Fa},wE=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}=yE(),[f,p]=SE(l,e,!a),m=f===`loaded`,{mounted:h,transitionStatus:g,setMounted:_}=ec(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]),wi({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=$r(`img`,e,{state:S,ref:[t,v],props:[b,u,w],stateAttributesMapping:CE,enabled:C});return C?T:null}),TE=X.forwardRef(function(e,t){let{className:n,render:r,delay:i=0,style:a,...o}=e,{imageLoadingStatus:s}=yE(),[c,l]=X.useState(i===0),u=to();return X.useEffect(()=>(i>0?u.start(i,()=>l(!0)):l(!0),u.clear),[u,i]),$r(`span`,e,{state:{imageLoadingStatus:s},ref:t,props:o,stateAttributesMapping:bE,enabled:s!==`loaded`&&(i===0||c)})});function EE(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=$a(`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)(xE,{"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 DE(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=$a(`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)(wE,{"data-slot":`avatar-image`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function OE(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=$a(`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)(TE,{"data-slot":`avatar-fallback`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var kE=X.createContext(void 0);function AE(e){let t=X.useContext(kE);if(t===void 0&&!e)throw Error(Gi(33));return t}var jE=X.createContext(void 0);function ME(e){let t=X.useContext(jE);if(t===void 0&&!e)throw Error(Gi(36));return t}var NE=X.createContext(void 0);function PE(e=!0){let t=X.useContext(NE);if(t===void 0&&!e)throw Error(Gi(25));return t}var FE=X.createContext(null);function IE(e=`root`){let t=X.useContext(FE),n=X.useContext(jE);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var LE={visible:!0,ref:null};function RE(){return LE}function zE(e,t,n=`root`){let r=IE(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??RE)({label:e.label,children:e.children,render:e.render}),a=Vi(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function BE(e){e.preventDefault()}function VE(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=ME(),u=PE(!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?BE: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:Ya})},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&&!Ni&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&_i(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var HE={type:`regular-item`};function UE(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}=li({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=VE({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=X.useCallback(e=>Ui(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Vi(u,f);return X.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var WE=X.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function GE(){return X.useContext(WE)}function KE(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=GE(),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 qE=X.createContext(void 0);function JE(){let e=X.useContext(qE);if(e===void 0)throw Error(Gi(31));return e}var YE=X.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=X.useState(void 0),c=$r(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,Z.jsx)(qE.Provider,{value:s,children:c})}),XE=X.forwardRef(function(e,t){let n=IE()?.Group??YE;return(0,Z.jsx)(n,{...e,ref:t})}),ZE=X.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Nw(a),c=JE();return J(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),$r(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),QE=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}=ME(),f=KE({guess:!0,label:a}),p=Nw(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}=UE({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:HE});return $r(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),$E=X.forwardRef(function(e,t){let n=zE(e,t);return n.visible?(0,Z.jsx)(QE,{...e,ref:n.ref}):null}),eD=X.createContext(void 0);function tD(e){let t=X.useContext(eD);if(t===void 0&&!e)throw Error(Gi(69));return t}var nD=X.createContext(void 0);function rD(){return X.useContext(nD)}function iD(e,t){let n=lo(e.render);if(X.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function aD(e,t,n){let r=iD(e,t),i=r===t?void 0:r;return[r,X.useCallback(e=>n?.(e?i:void 0),[i,n])]}function oD(e,t,n){let r=lo(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 sD=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}=ME(),m=rD(),{side:h,align:g}=AE(),_=tD(!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`),ee=l.useState(`listElement`),[P,te]=aD(e,u,d),F=oD(e,C,N),I=w.type===`menu`?m:void 0,L=w.type===`context-menu`,ne=s??w.type!==`menu`;s===void 0&&ee&&w.type!==`menu`&&(ne=()=>l.state.activeIndex===null&&ee),wi({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),X.useEffect(()=>{function e(e){l.setOpen(!1,$i(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),Bc(D,{enabled:A&&!j&&!L&&w.type!==`menubar`,closeDelay:k});let re=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:R,handleFocus:ie}=(X.useContext(FE)?.useParentHandoff??lD)(l,w,v,f),ae={transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},z=$r(`div`,e,{state:ae,ref:[t,l.context.popupRef,re,te],stateAttributesMapping:Po,props:[b,{id:P,...ee?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":F},onKeyDown(e){I?.onPopupKeyDown?.(e),_&&Lw.has(e.key)&&e.stopPropagation()},onFocus:ie},Du(y),c,{"data-rootownerid":E}]}),B=w.type===void 0||L;(C||w.type===`menubar`&&T!==`outside-press`)&&(B=!0);let oe=I?.getReturnElement??R;return(0,Z.jsx)(Js,{context:D,openInteractionType:M,modal:L,disabled:!x,returnFocus:a??oe??B,explicitReturnFocus:a===void 0&&oe?!1:void 0,initialFocus:ne,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:z})}),cD={parentVirtualFocusRef:void 0,handleFocus:void 0};function lD(){return cD}var uD=X.forwardRef(function(e,t){let n=IE()?.Popup??sD;return(0,Z.jsx)(n,{...e,ref:t})}),dD=X.createContext(void 0);function fD(){let e=X.useContext(dD);if(e===void 0)throw Error(Gi(32));return e}var pD=X.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=ME();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Z.jsx)(dD.Provider,{value:n,children:(0,Z.jsx)(Aa,{ref:t,...r,portalOwnerRole:o})})});function mD(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=q(i),[,o]=X.useState(0),s=Yr(gD).current,c=Yr(hD).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(!yD(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&bD(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=vD(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=q(()=>{let[e,t]=_D(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)(WE.Provider,{value:b,children:t})}function hD(){return new Map}function gD(){return new Set}function _D(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)=>bD(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 vD(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function yD(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 bD(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function xD(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=X.useRef(null),o=X.useRef(null),s=Sa(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 SD=20;function CD(e,t,n,r){let[i,a]=X.useState(!1);J(()=>{if(!e||!t||n==null){a(!1);return}let r=Ba(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-SD)},[e,t,n]),eT(e&&(!t||i),r)}var wD=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=ii,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=ME(),x=fD(),S=PE(!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`),ee=v.useState(`adaptiveOrigin`),P=v.useState(`lastOpenChangeReason`),te=v.useState(`floatingNodeId`),F=v.useState(`floatingParentNodeId`),I=w.useState(`domReferenceElement`),L=n,ne=c,re=l,R=s,ie=h;C.type===`context-menu`&&(L=n??C.context?.anchor,R??=`start`,!o&&R!==`center`&&(re=e.alignOffset??2,ne=e.sideOffset??-5));let ae=o,z=R;C.type===`menu`?(ae??=`inline-end`,z??=`start`,ie=e.collisionAvoidance??ni):C.type===`menubar`&&(ae??=C.context.orientation===`vertical`?`inline-end`:`bottom`,z??=`start`);let B=C.type===`context-menu`,oe=wu({anchor:L,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ae,sideOffset:ne,align:z,alignOffset:re,arrowPadding:B?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:te,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:ie,shift:B?{crossAxis:!(`side`in ie&&ie.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:ee,lazyFlip:y?`placement`:!1});X.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===te&&v.set(`hoverEnabled`,!1),e.nodeId!==te&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,$i(fa)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,te]),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,$i(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let se=to();X.useEffect(()=>{D||se.clear()},[D,se]),X.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?se.isStarted()||se.start(e,()=>{v.setOpen(!1,$i(fa))}):v.setOpen(!1,$i(fa))}else se.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,se]),X.useEffect(()=>{let e={open:D,nodeId:te,parentNodeId:F,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,te,F]),xD({store:v,domReference:I,positionerElement:M,open:D});let ce={open:D,side:oe.side,align:oe.align,anchorHidden:oe.anchorHidden,nested:C.type===`menu`,instant:N},le=C.type===`menubar`&&C.context.modal;CD(D&&(le||O&&P!==`trigger-hover`),k===`touch`,M,A);let ue=Ou(e,ce,{styles:oe.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),de=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&P!==`trigger-hover`||C.type===`menubar`&&C.context.modal),fe=null;return C.type===`menubar`?fe=C.context.contentElement:C.type===void 0&&(fe=A),(0,Z.jsxs)(kE.Provider,{value:oe,children:[de&&(0,Z.jsx)(Hw,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:Si(!D),cutout:fe}),(0,Z.jsx)(Rs,{id:te,children:(0,Z.jsx)(mD,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:ue})})]})}),TD=X.createContext(null);function ED(e){let t=X.useContext(TD);if(t===null&&!e)throw Error(Gi(5));return t}function DD(e){return e==null?Ia:e.type.startsWith(`key`)?ia:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?ma:Ia}var OD={...Tc,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=Tc.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>so&&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`&&!Tc.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`)}},kD=class extends Fi{constructor(e,t,n=!1){let r=new gc,i=jD(r,t,n,e);super(i,AD(r),OD),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 AD(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 jD(e,t,n=!1,r){return{...yc(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:di,inputProps:di,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new Ms,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:di,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var MD=X.createContext(null);function ND(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function PD(e,t){return e===`list-navigation`||ND(e,t)}var FD=ai(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=PE(!0),C=ME(!0),w=ED(!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=Nw(),k=Nw(),[A,j]=X.useState(void 0),M=(A??k)||void 0,N=Fs(),ee=D.type===`menu`?D.store:void 0,P=(n??o)&&ee?.state.transitionStatus===`starting`,te=Yr(()=>P?ee?.state.instantType:void 0).current,F=Yr(()=>{let e=new kD({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:te},M,N!=null);return e.context.virtualFocusRef=y,e}).current;F.useControlledProp(`openProp`,n),F.useControlledProp(`triggerIdProp`,m),F.useContextCallback(`onOpenChangeComplete`,i);let I=F.useState(`floatingTreeRoot`),L=Ls(I),ne=F.useState(`open`),re=F.useState(`activeTriggerElement`),R=F.useState(`positionerElement`),ie=F.useState(`hoverEnabled`),ae=F.useState(`disabled`),z=F.useState(`lastOpenChangeReason`),B=F.useState(`parent`),oe=F.useState(`activeIndex`),se=F.useState(`keyboardOpen`),ce=F.useState(`payload`),le=F.useState(`floatingParentNodeId`),ue=X.useRef(null),de=X.useRef(B.type!==`context-menu`),fe=to(),pe=X.useRef(!0),me=to(),he=le!=null,{openMethod:ge,triggerProps:_e}=fT(ne);F.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:B.type===void 0?c:void 0,openMethod:ge,rootId:O}),fc(F);let{forceUnmount:ve,transitionStatus:ye}=pc(ne,F,()=>{F.set(`allowMouseEnter`,!1)},P),be=Sa(F.context.popupRef);X.useEffect(()=>{if(te===void 0)return;let e=()=>{F.state.instantType===te&&F.set(`instantType`,void 0)};if(!ne){e();return}if(ye!==void 0)return;if(F.context.popupRef.current==null){e();return}let t=new AbortController;return be(e,t.signal),()=>{t.abort()}},[te,ne,ye,be,F]),J(()=>{S&&!C?F.update({parent:{type:`context-menu`,context:S},floatingNodeId:L,floatingParentNodeId:N}):(C||!F.select(`activeTriggerElement`))&&F.update({floatingNodeId:L,floatingParentNodeId:N})},[S,C,L,N,re,F]),X.useEffect(()=>{ne||(ue.current=null),B.type===`context-menu`&&(ne?fe.start(500,()=>{de.current=!0}):(fe.clear(),de.current=!1))},[fe,ne,B.type]),J(()=>{!ne&&!ie&&F.set(`hoverEnabled`,!0)},[ne,ie,F]);let xe=q((e,t)=>{let n=t.reason;if(!e&&!F.select(`open`)||ne===e&&t.trigger===re&&z===n)return;let i=uc(t);if(!e&&t.trigger==null&&(t.trigger=re??void 0),r?.(e,t),t.isCanceled)return;F.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!pe.current)return;e&&n===`trigger-focus`?(pe.current=!1,me.start(300,()=>{pe.current=!0})):(pe.current=!0,me.clear());let o=!e&&(n===`escape-key`||n==null);ue.current=t.event;let s=lc(F.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&PD(n,a),s.instantType=B.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:ND(n,a)?`click`:o?`dismiss`:void 0,F.update(s)}),Se=$s({popupStore:F,floatingRootContext:F.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:xe}),Ce=Se.context.events;J(()=>{let e=({open:e,eventDetails:t})=>xe(e,t);return Ce.on(`setOpen`,e),()=>{Ce?.off(`setOpen`,e)}},[Ce,xe]),J(()=>F.subscribeToParentMenu(),[F]);let we=X.useCallback(()=>{F.setOpen(!1,$i(wa))},[F]);X.useImperativeHandle(d,()=>({unmount:ve,close:we}),[ve,we]);let Te;B.type===`context-menu`&&(Te=B.context),X.useImperativeHandle(Te?.positionerRef,()=>R,[R]),X.useImperativeHandle(Te?.actionsRef,()=>({setOpen:xe}),[xe]);let Ee=Qs(Se,{enabled:!ae,bubbles:{escapeKey:f&&B.type===`menu`},outsidePress(){return B.type!==`context-menu`||ue.current?.type===`contextmenu`||de.current},externalTree:he?I:void 0}),De=uu(),Oe=Yc(Se,{enabled:!ae,listRef:F.context.itemDomElements,activeIndex:oe,virtual:v,nested:B.type===`menubar`||!v&&B.type!==void 0,parentOrientation:B.type===`menubar`?B.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?se:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:De===`rtl`,disabledIndices:zi,onNavigate(e,t){F.setActiveIndex(e,DD(t),t?.nativeEvent)},openOnArrowKeyDown:B.type!==`context-menu`&&!(v&&_),externalTree:!v&&he?I:void 0,nestedReturnFocusRef:ee?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),ke=X.useCallback(e=>{F.context.typingRef.current=e},[F]),Ae=Xc(Se,{enabled:!ae&&!v,listRef:F.context.itemLabels,elementsRef:F.context.itemDomElements,activeIndex:oe,resetMs:500,onMatch:(e,t)=>{ne&&e!==oe&&F.setActiveIndex(e,ia,t.nativeEvent)},onTyping:ke}),je=q(a),Me=X.useRef(-1),Ne=q(()=>{let e=F.state.activeIndex,t=e===null?void 0:F.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Me.current===n&&F.context.reportedItem===t)return;Me.current=n,F.context.reportedItem=t,v&&F.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=F.context;F.context.highlightReason=Ia,F.context.highlightEvent=void 0,a&&je(t,no(r,i,{label:t===void 0?void 0:F.context.itemLabels.current[n]??void 0}))});J(()=>{Ne()},[oe,Ne]);let Pe=X.useMemo(()=>{if(!v)return Oe.reference;if(!Oe.trigger)return di;let{onFocus:e,...t}=Oe.trigger;return t},[v,Oe.reference,Oe.trigger]);F.useSyncedValue(`inputProps`,v?Oe.reference??di:di);let Fe=X.useMemo(()=>{let e=Ui(Ae.reference,Pe,Ee.reference,{onMouseMove(){F.set(`allowMouseEnter`,!0)}},_e);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=ne,e},[F,Ae.reference,Pe,Ee.reference,_e,ne]),Ie=X.useMemo(()=>{let e=Ui(Oe.trigger,Ee.trigger,_e);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Oe.trigger,Ee.trigger,_e]);Yr(()=>(F.update({inactiveTriggerProps:Ie}),null)),mc(F,{floatingRootContext:Se,activeTriggerProps:Fe,inactiveTriggerProps:Ie,popupProps:X.useMemo(()=>Ui(rc,{onMouseMove(){F.set(`allowMouseEnter`,!0),B.type===`menu`&&F.set(`hoverEnabled`,!1)},onClick(){F.select(`hoverEnabled`)&&F.set(`hoverEnabled`,!1)},onKeyDown(e){let t=F.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ae.floating,Oe.floating,Ee.floating),[B.type,F,Ae.floating,Oe.floating,Ee.floating]),itemProps:Oe.item??di});let Le=X.useMemo(()=>({store:F,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Ne}),[F,D,u,l,b,k,v,E,Ne]),Re=typeof t==`function`?t({payload:ce}):t,ze=(0,Z.jsxs)(jE.Provider,{value:Le,children:[p&&(0,Z.jsx)(oc,{handle:p,store:F}),Re]});return(B.type===void 0||B.type===`context-menu`)&&(ze=(0,Z.jsx)(zs,{externalTree:I,children:ze})),ze});function ID(e){let t=X.useContext(MD);if(t===null)return(0,Z.jsx)(FD,{...e});let n=t.Root;return(0,Z.jsx)(MD.Provider,{value:null,children:(0,Z.jsx)(n,{...t.options,...e})})}var LD=5;function RD(e,t){let n=zD(t);return e.clientX>=n.left-LD&&e.clientX<=n.right+LD&&e.clientY>=n.top-LD&&e.clientY<=n.bottom+LD}function zD(e){let t=e.getBoundingClientRect(),n=ra(e);if(eo)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 BD(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=hi(),{ref:i,index:a}=KE(e),o=n===a,s=X.useRef(null),c=Vi(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 VD(e){let{render:t,className:n,style:r,state:i=di,props:a=zi,refs:o=zi,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=BD({metadata:s});return $r(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function HD(e){if(aa(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!ua(e))return HD(Ga(e))}function UD(e,t){function n(n,r,i){let a=n.currentTarget;nc.flushSync(()=>{e.setOpen(!1,$i(na,n.nativeEvent,a))}),Qr(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&&Ri(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function WD(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,Ba(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:di,[t,n,r])}var GD=ri(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=ME(!0),h=Dc(d)??m?.store;if(!h)throw Error(Gi(85));let g=Nw(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=X.useRef(null),S=qD(),C=hi(!0),w=Is(),T=X.useMemo(()=>w??new Ms,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=dc(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:Ls(T),floatingParentNodeId:Fs(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=li({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),ee=to(),P=q(e=>{if(!N.current)return;ee.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;Y(N.current,t)||Y(h.select(`positionerElement`),t)||t===N.current||t!=null&&HD(t)===h.select(`rootId`)||RD(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:Xi})});X.useEffect(()=>{let e=Ba(N.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,P,{once:!0}),()=>{e.removeEventListener(`mouseup`,P)}},[y,P,h]);let te=O&&S.context.hasSubmenuOpen,F=Hc(v,{enabled:(c??te)&&!A&&(!O||te&&!D),handleClose:il({blockPointerEvents:!O}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),I=KD(y,h.select(`lastOpenChangeReason`)),L=Ys(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&I}),ne=kc(v,{enabled:!A&&te}),re=WD({open:y,enabled:O,mouseDownAction:`open`}),R=X.useMemo(()=>Ui(ne.reference,L.reference),[ne.reference,L.reference]),ie=h.useState(`triggerProps`,D),ae=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:z,handleFocusTargetFocus:B}=UD(h,x),oe={disabled:A,open:y},se=[N,t,M,E,x],ce=[R,F??di,ie,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(ee.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),Ba(e.currentTarget).addEventListener(`mouseup`,P,{once:!0}))}},ae,O?{role:`menuitem`}:{},re,p,j],le=$r(`button`,e,{enabled:!O,stateAttributesMapping:Mo,state:oe,ref:se,props:ce});return O?(0,Z.jsx)(VD,{tag:`button`,render:n,className:r,style:i,state:oe,refs:se,props:ce,stateAttributesMapping:Mo}):y?(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(Ei,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:z},`${g}-pre-focus-guard`),(0,Z.jsx)(X.Fragment,{children:le},g),(0,Z.jsx)(Ei,{ref:h.context.triggerFocusTargetRef,onFocus:B},`${g}-post-focus-guard`)]}):(0,Z.jsx)(X.Fragment,{children:le},g)});function KD(e,t){let n=to(),[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 qD(){let e=ED(!0);return X.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var JD=X.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return $r(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})});function YD(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)(ID,{"data-slot":`dropdown-menu`,...n}),t[2]=n,t[3]=r),r}function XD(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)(GD,{"data-slot":`dropdown-menu-trigger`,...n}),t[2]=n,t[3]=r),r}function ZD(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=$a(`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)(uD,{"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)(pD,{children:(0,Z.jsx)(wD,{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 QD(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)(XE,{"data-slot":`dropdown-menu-group`,...n}),t[2]=n,t[3]=r),r}function $D(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=$a(`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)(ZE,{"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 eO(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=$a(`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)($E,{"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 tO(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=$a(`-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)(JD,{"data-slot":`dropdown-menu-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var nO=tt({id:Rr,name:Rr,signOut:en}),rO=O(St).atom(Ln(Dt(`/auth/user`),V(He),V(s(nO))));function iO(){let e=(0,$.c)(27),t=By(rO);if(!R(t))return null;let n;e[0]===t.value.id?n=e[1]:(n=P(`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)(DE,{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=Ce(ce(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)(OE,{children:a}),e[7]=a,e[8]=o);let s;e[9]!==i||e[10]!==o?(s=(0,Z.jsx)(XD,{"aria-label":`Account`,className:`flex items-center justify-center max-sm:size-11`,children:(0,Z.jsxs)(EE,{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)(QD,{children:(0,Z.jsxs)($D,{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)(tO,{}),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)(eO,{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)(ZD,{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)(YD,{children:[s,h]}),e[24]=h,e[25]=s,e[26]=g):g=e[26],g}function aO(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)(Ai,{"aria-label":e.label,className:`max-sm:size-11`,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 oO(e){let t=(0,$.c)(44),[n,r]=(0,X.useState)(!1),i,a;t[0]===e.palette?(i=t[1],a=t[2]):(i=()=>{if(e.palette===void 0)return;let t=function(e){e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),r(!0))};return addEventListener(`keydown`,t),()=>removeEventListener(`keydown`,t)},a=[e.palette],t[0]=e.palette,t[1]=i,t[2]=a),(0,X.useEffect)(i,a);let o;if(t[3]!==e.back||t[4]!==e.icon||t[5]!==e.name||t[6]!==e.title){let n;t[8]!==e.icon||t[9]!==e.name?(n=()=>(0,Z.jsxs)(`a`,{href:`/`,className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsx)(`img`,{src:e.icon,alt:``,className:`pixelated size-8`}),(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name})]}),t[8]=e.icon,t[9]=e.name,t[10]=n):n=t[10];let r;t[11]!==e.back||t[12]!==e.icon||t[13]!==e.name?(r=t=>(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink items-center gap-1.5`,children:[Ue(I(e.back),{onNone:()=>(0,Z.jsx)(`a`,{href:`/`,"aria-label":e.name,className:`flex size-8 shrink-0 items-center justify-center max-sm:size-11`,children:(0,Z.jsx)(`img`,{src:e.icon,alt:``,className:`pixelated size-8`})}),onSome:lO}),(0,Z.jsx)(`span`,{className:`max-w-40 min-w-0 truncate text-sm font-medium`,children:t})]}),t[11]=e.back,t[12]=e.icon,t[13]=e.name,t[14]=r):r=t[14],o=Ue(I(e.title),{onNone:n,onSome:r}),t[3]=e.back,t[4]=e.icon,t[5]=e.name,t[6]=e.title,t[7]=o}else o=t[7];let s;t[15]===e.tabs?s=t[16]:(s=e.tabs!==void 0&&(0,Z.jsx)(`nav`,{"aria-label":`Sections`,className:`flex items-center gap-1`,children:e.tabs}),t[15]=e.tabs,t[16]=s);let c;if(t[17]!==e.name||t[18]!==e.palette){let n;t[20]===e.name?n=t[21]:(n=()=>(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(cE,{label:`Search ${e.name}`,onClick:()=>r(!0)}),(0,Z.jsx)(_E,{label:`Search ${e.name}`,onClick:()=>r(!0)})]}),t[20]=e.name,t[21]=n),c=Ue(I(e.palette),{onNone:cO,onSome:n}),t[17]=e.name,t[18]=e.palette,t[19]=c}else c=t[19];let l;t[22]===c?l=t[23]:(l=(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center justify-end sm:justify-center`,children:c}),t[22]=c,t[23]=l);let u;t[24]===e.account?u=t[25]:(u=e.account??(0,Z.jsx)(iO,{}),t[24]=e.account,t[25]=u);let d;t[26]!==e.action||t[27]!==u?(d=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[e.action,u]}),t[26]=e.action,t[27]=u,t[28]=d):d=t[28];let f;t[29]!==o||t[30]!==s||t[31]!==l||t[32]!==d?(f=(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-3`,children:[o,s,l,d]}),t[29]=o,t[30]=s,t[31]=l,t[32]=d,t[33]=f):f=t[33];let p;if(t[34]!==n||t[35]!==e.name||t[36]!==e.palette){let i;t[38]!==n||t[39]!==e.name?(i=t=>(0,Z.jsx)(nE,{current:e.name,groups:t,open:n,onOpenChange:r}),t[38]=n,t[39]=e.name,t[40]=i):i=t[40],p=Ue(I(e.palette),{onNone:sO,onSome:i}),t[34]=n,t[35]=e.name,t[36]=e.palette,t[37]=p}else p=t[37];let m;return t[41]!==f||t[42]!==p?(m=(0,Z.jsxs)(Z.Fragment,{children:[f,p]}),t[41]=f,t[42]=p,t[43]=m):m=t[43],m}function sO(){return null}function cO(){return null}function lO(e){return(0,Z.jsx)(Ai,{variant:`ghost`,size:`icon`,className:`max-sm:size-11`,"aria-label":e.label,onClick:e.onClick,children:(0,Z.jsx)(go,{className:`size-4`})})}function uO(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=$a(`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 dO(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-8 items-center gap-3 border-b px-1 max-sm:h-11`,children:[e.media===!0&&(0,Z.jsx)(uO,{className:`size-5`}),(0,Z.jsx)(uO,{className:`h-4 w-1/3`})]},t),t[3]=e.media,t[4]=n),r=Re(oe(1,e.rows),n),t[0]=e.media,t[1]=e.rows,t[2]=r}else r=t[2];let i;return t[5]!==e.label||t[6]!==r?(i=(0,Z.jsx)(`div`,{"aria-busy":`true`,"aria-label":n,role:`status`,children:r}),t[5]=e.label,t[6]=r,t[7]=i):i=t[7],i}function fO(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=$a(`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 pO=oo(`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 mO(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=$a(pO({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 hO(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=$a(`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)(fO,{"data-slot":`field-label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function gO(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(vO)).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(_O)}),t[7]=r,t[8]=a),o=a}let s=o;if(!s)return null;let c;t[9]===r?c=t[10]:(c=$a(`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 _O(e,t){return e?.message&&(0,Z.jsx)(`li`,{children:e.message},t)}function vO(e){return[e?.message,e]}function yO(e){let t=(0,$.c)(5),n=e.className,r;t[0]===e.result?r=t[1]:(r=tr(Ot(M(e.result),bO)),t[0]=e.result,t[1]=r);let i;return t[2]!==e.className||t[3]!==r?(i=(0,Z.jsx)(gO,{className:n,children:r}),t[2]=e.className,t[3]=r,t[4]=i):i=t[4],i}function bO(e){return e.message}var xO=oo(`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 SO(e){let t=(0,$.c)(6),n;t[0]!==e.className||t[1]!==e.status||t[2]!==e.waiting?(n=$a(xO({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 CO(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=ji(),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)(NE.Provider,{value:u,children:(0,Z.jsx)(jE.Provider,{value:void 0,children:(0,Z.jsx)(ID,{...e})})})}var wO=500,TO=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}=PE(!1),{store:m}=ME(!1),h=m.useState(`open`),g=m.useState(`disabled`),_=X.useRef(null),v=X.useRef(null),y=to(),b=to(),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,$i(ao,n)),b.start(wO,()=>{x.current=!0})}function w(e){if(g)return;d.current=!0,Lo(e),C(e.clientX,e.clientY,e.nativeEvent);let t=Ba(_.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=Yi(e);Y(u.current,t)||p&&t&&HD(t)===p||s.current?.setOpen(!1,$i(Xi,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(wO,()=>{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=Yi(e);(Y(_.current,t)||Y(c.current,t)||Y(l.current,t))&&e.preventDefault()}let t=Ba(_.current);return fi(t,`contextmenu`,e)},[l,g,c]),$r(`div`,e,{state:{open:h},ref:[_,t],props:[{onContextMenu:w,onTouchStart:E,onTouchMove:D,onTouchEnd:T,onTouchCancel:T,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:Mo})}),EO=wD;function DO(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)(CO,{"data-slot":`context-menu`,...n}),t[2]=n,t[3]=r),r}function OO(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=$a(`select-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(TO,{"data-slot":`context-menu-trigger`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function kO(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=$a(`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)(uD,{"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)(pD,{children:(0,Z.jsx)(EO,{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 AO(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=$a(`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)($E,{"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}var jO=mr(Yt(Yn(`AUTH_URL`)),de);wt(function*(){let e=Vt(Rr,`GITHUB_ADMINS`);return(yield*jO)?yield*In(e,[`0`]):yield*e});function MO(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function NO(e){return je(xa)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}b()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var PO=class e extends Mn()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:xa}){static layerClient=t=>xr(e,e=>wt(function*(){return yield*e.next({...e.request,headers:Cn(e.request.headers,`authorization`,`Bearer ${yield*t}`)})}))},FO=Ev,IO=Ov,LO=Av,RO=class extends C()(`UpstreamError`,{cause:dn()}){},zO=Rr.check(le(/^[a-z0-9][a-z0-9_-]{0,23}$/u)),BO=kr.check(te(2048),qr(e=>ie(_(on(e)),e=>e.protocol===`https:`&&e.username===``&&e.password===``&&e.hash===``),{expected:`a public HTTPS URL without credentials or a fragment`})),VO=tt({url:BO}),HO=tt({id:zO}),UO=tt({authorization_endpoint:kr,authorization_response_iss_parameter_supported:mt(en),client_id_metadata_document_supported:mt(en),issuer:kr,registration_endpoint:mt(kr),token_endpoint:kr});tt({client_id:kr});var WO=tt({access_token:kr,expires_in:mt($n.check(Ve(0))),refresh_token:mt(kr),token_type:Rr.check(le(/^Bearer$/iu))}),GO=tt({client:ot({Document:{},Registered:{clientId:kr}}),metadata:UO,scope:Rr}),KO=ot({Authorized:{expiresAt:$n,token:WO},Connected:{},Disconnected:{}}),qO=tt({src:Rr,theme:mt(Ft([`light`,`dark`]))}),JO=tt({error:mt(Rr),generation:kr,icons:mt(wr(qO)),id:zO,instructions:mt(Rr),link:KO,mode:Ft([`oauth`,`public`]),name:kr,oauth:mt(GO),toolDescriptions:mt(Ur(Rr,Rr)),tools:wr(Rr),url:BO});Ur(Rr,JO);var YO=tt({description:mt(Rr),name:kr}),XO=tt({error:mt(Rr),icons:wr(qO),id:zO,name:kr,status:Ft([`Connected`,`Not connected`,`Expired`]),tools:wr(YO),url:BO});ot({Discovered:{icons:wr(qO),instructions:mt(Rr),toolDescriptions:mt(Ur(Rr,Rr)),tools:wr(Rr)},Failed:{error:Rr}}),tt({code:mt(kr),error:mt(Rr),iss:mt(kr),state:kr});var ZO=class extends Xt(gn(`gateway.servers`,{error:xa,stream:!0,success:wr(XO)}),gn(`gateway.calls`,{error:xa,stream:!0,success:zO}),gn(`gateway.add`,{error:xa,payload:VO,success:XO}),gn(`gateway.remove`,{error:xa,payload:HO})).middleware(PO){},QO=`${window.location.origin}/mcp`,$O=class extends sn()(`@deslop/gateway/lib/utils/RpcClient`,{group:ZO,protocol:Ca(`@deslop/gateway`)}){};function ek(e){return`/oauth/connect?${new URLSearchParams({id:e})}`}var tk=Ze($O.runtime.atom(Zr(Dr(We($O,e=>e(`gateway.servers`,void 0)))))),nk=Ze($O.runtime.atom(Zr(Vr(Dr(We($O,e=>e(`gateway.calls`,void 0))))))),rk=zr(e=>y(t=>{let n=ge(t.self(),()=>-1);return F(t(nk),{onFailure:()=>n,onInitial:()=>n,onSuccess:t=>rt(t.value[0]===e,{onFalse:()=>n,onTrue:()=>t.value[1]})})})),ik=zr(e=>$O.runtime.fn(()=>V($O,t=>t(`gateway.remove`,{id:e})))),ak=wy($O.runtime).make(IO({effects:{add:L(function*(e){yield*Ln(Ie(BO)(e),l(e=>xa.make({cause:e,message:`Enter a public HTTPS MCP URL without credentials or a fragment, outside the gateway itself.`})));let t=yield*(yield*$O)(`gateway.add`,{url:e});t.status!==`Connected`&&location.assign(ek(t.id))})},events:LO({Cancel:{},Open:{},Submit:{},Typed:{url:Rr}}),root:FO({states:{Adding:{fields:{url:Rr}},Closed:{},Editing:{fields:{error:Rr,url:Rr}}}})}).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`}}}}})),ok=zr(e=>Ht(()=>Ln(Pt({catch:e=>RO.make({cause:e}),try:()=>navigator.clipboard.writeText(e)}),mn(()=>U(()=>Ka.add({description:e,title:`Cannot copy`,type:`error`}))),H($t(`1500 millis`))))),sk=`/assets/icon-61pmFc-p.svg`,ck=xn(or,e=>Ln(ur(e.status),Tn(`Expired`,()=>0),Tn(()=>e.error!==void 0,()=>0),Tn(`Not connected`,()=>1),br(()=>2)));function lk(e){let t=(0,$.c)(10),n;t[0]===e.server.id?n=t[1]:(n=rk(e.server.id),t[0]=e.server.id,t[1]=n);let r=Vu(n),i;t[2]===r?i=t[3]:(i=rt(r>=0,{onFalse:mk,onTrue:pk}),t[2]=r,t[3]=i);let a;t[4]===e.server.status?a=t[5]:(a=Ln(ur(e.server.status),Tn(`Connected`,fk),Tn(`Expired`,dk),br(uk)),t[4]=e.server.status,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(SO,{className:i,status:a},r),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function uk(){return`off`}function dk(){return`error`}function fk(){return`live`}function pk(){return`animate-port-blink`}function mk(){}function hk(e){return Ln(ur(e.status),Tn(`Expired`,()=>`Sign-in expired`),Tn(`Not connected`,()=>`Not connected`),br(()=>new URL(e.url).hostname))}function gk(e){let t=(0,$.c)(29),n;t[0]===e.server.id?n=t[1]:(n=ik(e.server.id),t[0]=e.server.id,t[1]=n);let[r,i]=Ku(n),a=e.open,o=e.onOpenChange,s;t[2]===e.server.name?s=t[3]:(s=(0,Z.jsxs)(bT,{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)(xT,{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)(yO,{result:r}),t[5]=r,t[6]=l);let u;t[7]===r?u=t[8]:(u=st(r),t[7]=r,t[8]=u);let d;t[9]===u?d=t[10]:(d=(0,Z.jsx)(hT,{render:(0,Z.jsx)(Ai,{variant:`ghost`,disabled:u}),children:`Cancel`}),t[9]=u,t[10]=d);let f;t[11]===r?f=t[12]:(f=st(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)(Ai,{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)(yT,{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)(_T,{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)(pT,{open:a,onOpenChange:o,children:g}),t[25]=e.onOpenChange,t[26]=e.open,t[27]=g,t[28]=_):_=t[28],_}function _k(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-full object-contain`,onError:()=>r(n+1)}),t[3]=n,t[4]=a),i=Ue(Dn(e.sources,n),{onNone:vk,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 vk(){return(0,Z.jsx)(wo,{className:`text-muted-foreground size-4`})}function yk(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=T([...Re(xe(e.server.icons,xn(Vn,xk)),bk),`https://${a}/favicon.ico`,`https://${P(/^(?:api|app|mcp)\./u,``)(a)}/favicon.ico`]),n=_k,i=ke(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 bk(e){return e.src}function xk(e){return e.theme!==`dark`}function Sk(e){return Ln(ur(e.server.status),Tn(`Expired`,()=>(0,Z.jsx)(`span`,{className:`text-destructive truncate`,children:`Sign-in expired`})),Tn(`Not connected`,()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate`,children:`Not connected`})),br(()=>(0,Z.jsx)(`span`,{className:`text-muted-foreground truncate font-mono text-xs`,children:new URL(e.server.url).hostname})))}function Ck(e){let t=document.getElementById(`server-${e.id}`);t?.focus(),t?.scrollIntoView({block:`center`})}function wk(e){let t=(0,$.c)(43),[n,r]=(0,X.useState)(!1),i=e.server.status===`Connected`,a;t[0]!==n||t[1]!==e.server?(a=(0,Z.jsx)(gk,{open:n,onOpenChange:r,server:e.server}),t[0]=n,t[1]=e.server,t[2]=a):a=t[2];let o=`server-${e.server.id}`,s=e.server.name,c;t[3]===e.server?c=t[4]:(c=hk(e.server),t[3]=e.server,t[4]=c);let l=`${s}, ${c}`,u;t[5]!==o||t[6]!==l?(u=(0,Z.jsx)(`div`,{id:o,role:`button`,tabIndex:0,"aria-haspopup":`menu`,"aria-label":l,className:`hover:bg-muted/50 focus-visible:ring-ring/30 flex h-8 items-center gap-2 px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset max-sm:h-11`}),t[5]=o,t[6]=l,t[7]=u):u=t[7];let d;t[8]===e.server?d=t[9]:(d=(0,Z.jsx)(yk,{server:e.server}),t[8]=e.server,t[9]=d);let f;t[10]===e.server.name?f=t[11]:(f=(0,Z.jsx)(`span`,{className:`max-w-56 min-w-0 shrink truncate text-sm font-medium`,children:e.server.name}),t[10]=e.server.name,t[11]=f);let p;t[12]===e.server?p=t[13]:(p=(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-1`,children:(0,Z.jsx)(Sk,{server:e.server})}),t[12]=e.server,t[13]=p);let m;t[14]===e.server.tools?m=t[15]:(m=Ee(e.server.tools)&&(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 font-mono text-xs max-sm:hidden`,title:`Tools`,children:rt(e.server.tools.length===1,{onFalse:()=>`${e.server.tools.length} tools`,onTrue:Dk})}),t[14]=e.server.tools,t[15]=m);let h;t[16]===e.server?h=t[17]:(h=(0,Z.jsx)(lk,{server:e.server}),t[16]=e.server,t[17]=h);let g;t[18]!==e.server.status||t[19]!==h?(g=(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:h}),t[18]=e.server.status,t[19]=h,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==e.server.error||t[23]!==e.server.id||t[24]!==e.server.status?(_=(!i||e.server.error!==void 0)&&(0,Z.jsx)(Ai,{variant:`ghost`,size:`sm`,className:`max-sm:h-11`,onClick:()=>location.assign(ek(e.server.id)),children:rt(e.server.status===`Not connected`,{onFalse:Ek,onTrue:Tk})}),t[21]=i,t[22]=e.server.error,t[23]=e.server.id,t[24]=e.server.status,t[25]=_):_=t[25];let v;t[26]!==g||t[27]!==_||t[28]!==u||t[29]!==d||t[30]!==f||t[31]!==p||t[32]!==m?(v=(0,Z.jsxs)(OO,{render:u,children:[d,f,p,m,g,_]}),t[26]=g,t[27]=_,t[28]=u,t[29]=d,t[30]=f,t[31]=p,t[32]=m,t[33]=v):v=t[33];let y;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsx)(kO,{className:`w-auto min-w-36`,children:(0,Z.jsx)(AO,{variant:`destructive`,onClick:()=>r(!0),children:`Remove`})}),t[34]=y):y=t[34];let b;t[35]===v?b=t[36]:(b=(0,Z.jsxs)(DO,{children:[v,y]}),t[35]=v,t[36]=b);let x;t[37]===e.server.error?x=t[38]:(x=e.server.error!==void 0&&(0,Z.jsx)(gO,{className:`mr-1 mb-2 ml-9 wrap-anywhere`,children:e.server.error}),t[37]=e.server.error,t[38]=x);let S;return t[39]!==a||t[40]!==b||t[41]!==x?(S=(0,Z.jsxs)(`div`,{role:`listitem`,className:`border-b`,children:[a,b,x]}),t[39]=a,t[40]=b,t[41]=x,t[42]=S):S=t[42],S}function Tk(){return`Connect`}function Ek(){return`Reconnect`}function Dk(){return`1 tool`}function Ok(e){let t=(0,$.c)(8),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:`Servers`}),t[0]=n):n=t[0];let r;t[1]===e.servers.length?r=t[2]:(r=(0,Z.jsxs)(`header`,{className:`bg-background sticky top-0 z-20 flex h-8 shrink-0 items-center gap-2 border-b px-3`,children:[n,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:e.servers.length})]}),t[1]=e.servers.length,t[2]=r);let i;t[3]===e.servers?i=t[4]:(i=N(e.servers,{onEmpty:jk,onNonEmpty:kk}),t[3]=e.servers,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Z.jsx)(`section`,{"aria-label":`MCP servers`,className:`pb-safe-bottom flex min-h-0 flex-col overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-1 flex-col`,children:[r,i]})}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function kk(e){return(0,Z.jsx)(`div`,{role:`list`,"aria-label":`MCP servers`,children:Re(e,Ak)})}function Ak(e){return(0,Z.jsx)(wk,{server:e},e.id)}function jk(){return(0,Z.jsx)(Di,{children:(0,Z.jsxs)(pi,{children:[(0,Z.jsx)(yi,{children:`No servers yet`}),(0,Z.jsx)(si,{children:`Add one from the bar to offer its tools.`})]})})}function Mk(e){let t=(0,$.c)(31),n=Gu(ak.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)(bT,{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)(hO,{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)(zT,{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)(gO,{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)(mO,{"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)(hT,{render:(0,Z.jsx)(Ai,{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=rt(e.adding,{onFalse:Pk,onTrue:Nk}),t[19]=e.adding,t[20]=m);let h;t[21]!==e.adding||t[22]!==m?(h=(0,Z.jsx)(Ai,{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)(yT,{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 Nk(){return`Adding…`}function Pk(){return`Add server`}function Fk(){let e=(0,$.c)(11),t=Gu(ak.send),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=Cy(ak,`Editing`),e[0]=n):n=e[0];let r=qe(Dy(n),c),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=Cy(ak,`Adding`),e[1]=i):i=e[1];let a=qe(Dy(i),c),o=tn(Ot(r,zk),()=>Ot(a,Rk)),s=pT,l=Ct(o),u=e=>{!e&&Ct(r)&&t({_tag:`Cancel`})},d=_T,f=de(a),p=Ue(o,{onNone:Lk,onSome:Ik}),m;e[2]!==d||e[3]!==f||e[4]!==p?(m=(0,Z.jsx)(d,{showCloseButton:f,children:p}),e[2]=d,e[3]=f,e[4]=p,e[5]=m):m=e[5];let h;return e[6]!==s||e[7]!==l||e[8]!==u||e[9]!==m?(h=(0,Z.jsx)(s,{open:l,onOpenChange:u,children:m}),e[6]=s,e[7]=l,e[8]=u,e[9]=m,e[10]=h):h=e[10],h}function Ik(e){return(0,Z.jsx)(Mk,{...e})}function Lk(){return null}function Rk(e){return{adding:!0,error:``,url:e.url}}function zk(e){return{adding:!1,error:e.error,url:e.url}}function Bk(e){let t=(0,$.c)(8);if(!je(xa)(e.error)){let n;return t[0]===e.error?n=t[1]:(n=(0,Z.jsx)(xi,{error:e.error,reset:Hk}),t[0]=e.error,t[1]=n),n}if(e.error.error===`access_denied`){let n;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(yi,{children:`Admins only`}),t[2]=n):n=t[2];let r;return t[3]===e.error.message?r=t[4]:(r=(0,Z.jsx)(Di,{children:(0,Z.jsxs)(pi,{children:[n,(0,Z.jsx)(si,{children:e.error.message})]})}),t[3]=e.error.message,t[4]=r),r}if(!NO(e.error)){let n;return t[5]===e.error?n=t[6]:(n=(0,Z.jsx)(xi,{error:e.error,reset:Vk}),t[5]=e.error,t[6]=n),n}let n;return t[7]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(Ci,{href:MO(location.href)}),t[7]=n):n=t[7],n}function Vk(){return location.reload()}function Hk(){return location.reload()}function Uk(){let e=(0,$.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Z.jsx)(`header`,{className:`bg-background flex h-8 shrink-0 items-center gap-2 border-b px-3`,children:(0,Z.jsx)(uO,{className:`h-4 w-20`})}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(`section`,{"aria-busy":`true`,role:`status`,"aria-label":`MCP servers`,className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-1 flex-col`,children:[t,(0,Z.jsx)(`div`,{className:`p-2`,children:(0,Z.jsx)(dO,{label:`MCP servers`,media:!0,rows:5})})]})}),e[1]=n):n=e[1],n}function Wk(){let e=(0,$.c)(8),t=Gu(ak.send),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=ok(QO),e[0]=n):n=e[0];let[r,i]=Ku(n),a=st(r),o=Vu(tk),s=er(o),c=M(o),l=ct(c,je(xa)),u=xe(ge(s,iA),ck),d=de(l)&&Ct(s),f={items:Re(kn(u,rA),nA),label:`Needs you`},p={items:Re(u,eA),label:`Servers`},m;e[1]===t?m=e[2]:(m=()=>[{icon:(0,Z.jsx)(bo,{}),label:`Add server`,run:()=>t({_tag:`Open`})}],e[1]=t,e[2]=m);let h;e[3]===i?h=e[4]:(h=()=>i(),e[3]=i,e[4]=h);let g={items:[...rt(d,{onFalse:$k,onTrue:m}),{icon:rt(a,{onFalse:Qk,onTrue:Zk}),label:`Copy MCP URL`,run:h}],label:`Actions`},_;e[5]===i?_=e[6]:(_=()=>i(),e[5]=i,e[6]=_);let v;return e[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Z.jsx)(Fk,{}),e[7]=v):v=e[7],(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsx)(oO,{icon:sk,name:`gateway`,palette:rt(Ct(l),{onFalse:()=>[g,f,p],onTrue:Xk}),action:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(aO,{icon:rt(a,{onFalse:Yk,onTrue:Jk}),label:`Copy MCP URL`,variant:`outline`,onClick:_}),d&&(0,Z.jsx)(aO,{icon:(0,Z.jsx)(bo,{}),label:`Add server`,onClick:()=>t({_tag:`Open`})})]})}),Ue(l,{onNone:()=>Ue(s,{onNone:()=>Ue(c,{onNone:qk,onSome:Kk}),onSome:()=>(0,Z.jsx)(Ok,{servers:u})}),onSome:Gk}),v]})}function Gk(e){return(0,Z.jsx)(Bk,{error:e})}function Kk(e){return(0,Z.jsx)(Bk,{error:e})}function qk(){return(0,Z.jsx)(Uk,{})}function Jk(){return(0,Z.jsx)(mo,{className:`text-primary`})}function Yk(){return(0,Z.jsx)(vo,{})}function Xk(){return[]}function Zk(){return(0,Z.jsx)(mo,{className:`text-primary`})}function Qk(){return(0,Z.jsx)(vo,{})}function $k(){return[]}function eA(e){return{detail:new URL(e.url).hostname,icon:(0,Z.jsx)(yk,{server:e}),id:e.id,keywords:`${e.name} ${e.url} ${ke(Re(e.tools,tA),` `)}`,label:e.name,run:()=>Ck(e)}}function tA(e){return e.name}function nA(e){return{detail:hk(e),icon:(0,Z.jsx)(yk,{server:e}),id:e.id,keywords:`${e.name} ${e.url}`,label:e.name,run:()=>Ck(e)}}function rA(e){return e.status!==`Connected`||e.error!==void 0}function iA(){return Ne()}export{Wk as component};
|