import{r as Gt}from"./resolve-element-BBLIckCr.js";import{f as we,c as xe,d as be,e as Ee,g as Te,H as Ae,v as et,h as Ie,j as ke,k as $e,l as Me,n as Oe,o as Ce,r as Re,p as Pt,q as je,t as De,w as qe,x as Le,y as Wt,z as Je}from"./index-CsFiLw7C.js";import{r as S}from"./isSSR-BoRVR0fW.js";import{s as ze}from"./useIsWindowVisible-ykYkuvsL.js";function Ge(e,t){let n;const s=()=>{const{currentTime:i}=t,o=(i===null?0:i.value)/100;n!==o&&e(o),n=o};return we.update(s,!0),()=>xe(s)}const Pe=be(()=>window.ScrollTimeline!==void 0);class Bt{constructor(t){this.animations=t.filter(Boolean)}then(t,n){return Promise.all(this.animations).then(t).catch(n)}getAll(t){return this.animations[0][t]}setAll(t,n){for(let s=0;s<this.animations.length;s++)this.animations[s][t]=n}attachTimeline(t){const n=this.animations.map(s=>{if(Pe()&&s.attachTimeline)s.attachTimeline(t);else return s.pause(),Ge(i=>{s.time=s.duration*i},t)});return()=>{n.forEach((s,i)=>{s&&s(),this.animations[i].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get duration(){let t=0;for(let n=0;n<this.animations.length;n++)t=Math.max(t,this.animations[n].duration);return t}runAll(t){this.animations.forEach(n=>n[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}stop(){this.runAll("stop")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function We(e){return typeof e=="object"&&!Array.isArray(e)}function Be(e){const t={presenceContext:null,props:{},visualState:{renderState:{transform:{},transformOrigin:{},style:{},vars:{},attrs:{}},latestValues:{}}},n=Ee(e)?new Te(t,{enableHardwareAcceleration:!1}):new Ae(t,{enableHardwareAcceleration:!0});n.mount(e),et.set(e,n)}function Ue(e,t=100){const n=Ie({keyframes:[0,t],...e}),s=Math.min(ke(n),$e);return{type:"keyframes",ease:i=>n.next(s*i).value/t,duration:Me(s)}}function It(e,t,n,s){var i;return typeof t=="number"?t:t.startsWith("-")||t.startsWith("+")?Math.max(0,e+parseFloat(t)):t==="<"?n:(i=s.get(t))!==null&&i!==void 0?i:e}const Ve=(e,t,n)=>{const s=t-e;return((n-e)%s+s)%s+e};function Ke(e,t){return Oe(e)?e[Ve(0,e.length,t)]:e}function He(e,t,n){for(let s=0;s<e.length;s++){const i=e[s];i.at>t&&i.at<n&&(Re(e,i),s--)}}function Xe(e,t,n,s,i,r){He(e,i,r);for(let o=0;o<t.length;o++)e.push({value:t[o],at:Ce(i,r,s[o]),easing:Ke(n,o)})}function Ye(e,t){return e.at===t.at?e.value===null?1:t.value===null?-1:0:e.at-t.at}const Fe="easeInOut";function Ze(e,{defaultTransition:t={},...n}={},s){const i=t.duration||.3,r=new Map,o=new Map,c={},a=new Map;let f=0,h=0,u=0;for(let l=0;l<e.length;l++){const d=e[l];if(typeof d=="string"){a.set(d,h);continue}else if(!Array.isArray(d)){a.set(d.name,It(h,d.at,f,a));continue}let[p,y,m={}]=d;m.at!==void 0&&(h=It(h,m.at,f,a));let g=0;const T=(w,x,A,P=0,W=0)=>{const _=Qe(w),{delay:Q=0,times:C=je(_),type:ve="keyframes",..._e}=x;let{ease:vt=t.ease||"easeOut",duration:b}=x;const _t=typeof Q=="function"?Q(P,W):Q,St=_.length;if(St<=2&&ve==="spring"){let Et=100;if(St===2&&en(_)){const Se=_[1]-_[0];Et=Math.abs(Se)}const Tt={..._e};b!==void 0&&(Tt.duration=Le(b));const At=Ue(Tt,Et);vt=At.ease,b=At.duration}b??(b=i);const wt=h+_t,xt=wt+b;C.length===1&&C[0]===0&&(C[1]=1);const bt=C.length-_.length;bt>0&&De(C,bt),_.length===1&&_.unshift(null),Xe(A,_,vt,C,wt,xt),g=Math.max(_t+b,g),u=Math.max(xt,u)};if(Pt(p)){const w=kt(p,o);T(y,m,$t("default",w))}else{const w=Gt(p,s,c),x=w.length;for(let A=0;A<x;A++){y=y,m=m;const P=w[A],W=kt(P,o);for(const _ in y)T(y[_],Ne(m,_),$t(_,W),A,x)}}f=h,h+=g}return o.forEach((l,d)=>{for(const p in l){const y=l[p];y.sort(Ye);const m=[],g=[],T=[];for(let x=0;x<y.length;x++){const{at:A,value:P,easing:W}=y[x];m.push(P),g.push(qe(0,u,A)),T.push(W||"easeOut")}g[0]!==0&&(g.unshift(0),m.unshift(m[0]),T.unshift(Fe)),g[g.length-1]!==1&&(g.push(1),m.push(null)),r.has(d)||r.set(d,{keyframes:{},transition:{}});const w=r.get(d);w.keyframes[p]=m,w.transition[p]={...t,duration:u,ease:T,times:g,...n}}}),r}function kt(e,t){return!t.has(e)&&t.set(e,{}),t.get(e)}function $t(e,t){return t[e]||(t[e]=[]),t[e]}function Qe(e){return Array.isArray(e)?e:[e]}function Ne(e,t){return e[t]?{...e,...e[t]}:{...e}}const tn=e=>typeof e=="number",en=e=>e.every(tn);function Ut(e,t,n,s){const i=Gt(e,s),r=i.length,o=[];for(let c=0;c<r;c++){const a=i[c];et.has(a)||Be(a);const f=et.get(a),h={...n};typeof h.delay=="function"&&(h.delay=h.delay(c,r)),o.push(...Je(f,{...t,transition:h},{}))}return new Bt(o)}const nn=e=>Array.isArray(e)&&Array.isArray(e[0]);function sn(e,t,n){const s=[];return Ze(e,t,n).forEach(({keyframes:r,transition:o},c)=>{let a;Pt(c)?a=Wt(c,r.default,o.default):a=Ut(c,r,o),s.push(a)}),new Bt(s)}const rn=e=>{function t(n,s,i){let r;return nn(n)?r=sn(n,s,e):We(s)?r=Ut(n,s,i,e):r=Wt(n,s,i),e&&e.animations.push(r),r}return t},js=rn();function on(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function cn(){const e=on();if(e.__xstate__)return e.__xstate__}const an=e=>{if(typeof window>"u")return;const t=cn();t&&t.register(e)};class Mt{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Vt=".",un="",Kt="",fn="#",hn="*",Ht="xstate.init",ln="xstate.error",nt="xstate.stop";function dn(e,t){return{type:`xstate.after.${e}.${t}`}}function st(e,t){return{type:`xstate.done.state.${e}`,output:t}}function pn(e,t){return{type:`xstate.done.actor.${e}`,output:t}}function Xt(e,t){return{type:`xstate.error.actor.${e}`,error:t}}function Yt(e){return{type:Ht,input:e}}function E(e){setTimeout(()=>{throw e})}const yn=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Ot(e,t){return`${e.sessionId}.${t}`}let mn=0;function gn(e,t){const n=new Map,s=new Map,i=new WeakMap,r=new Set,o={},c=t.clock,a={schedule:(u,l,d,p,y=Math.random().toString(36).slice(2))=>{const m={source:u,target:l,event:d,delay:p,id:y,startedAt:Date.now()},g=Ot(u,y);h._snapshot._scheduledEvents[g]=m;const T=c.setTimeout(()=>{delete o[g],delete h._snapshot._scheduledEvents[g],h._relay(u,l,d)},p);o[g]=T},cancel:(u,l)=>{const d=Ot(u,l),p=o[d];delete o[d],delete h._snapshot._scheduledEvents[d],c.clearTimeout(p)},cancelAll:u=>{for(const l in h._snapshot._scheduledEvents){const d=h._snapshot._scheduledEvents[l];d.source===u&&a.cancel(u,d.id)}}},f=u=>{if(!r.size)return;const l={...u,rootId:e.sessionId};r.forEach(d=>{var p;return(p=d.next)==null?void 0:p.call(d,l)})},h={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${mn++}`,_register:(u,l)=>(n.set(u,l),u),_unregister:u=>{n.delete(u.sessionId);const l=i.get(u);l!==void 0&&(s.delete(l),i.delete(u))},get:u=>s.get(u),_set:(u,l)=>{const d=s.get(u);if(d&&d!==l)throw new Error(`Actor with system ID '${u}' already exists.`);s.set(u,l),i.set(l,u)},inspect:u=>{r.add(u)},_sendInspectionEvent:f,_relay:(u,l,d)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:u,actorRef:l,event:d}),l._send(d)},scheduler:a,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const u=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const l in u){const{source:d,target:p,event:y,delay:m,id:g}=u[l];a.schedule(d,p,y,m,g)}}};return h}function Ft(e,t){const n=Ct(e),s=Ct(t);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(i=>i in s?Ft(n[i],s[i]):!1)}function at(e){if(Qt(e))return e;let t=[],n="";for(let s=0;s<e.length;s++){switch(e.charCodeAt(s)){case 92:n+=e[s+1],s++;continue;case 46:t.push(n),n="";continue}n+=e[s]}return t.push(n),t}function Ct(e){if(Hn(e))return e.value;if(typeof e!="string")return e;const t=at(e);return vn(t)}function vn(e){if(e.length===1)return e[0];const t={};let n=t;for(let s=0;s<e.length-1;s++)if(s===e.length-2)n[e[s]]=e[s+1];else{const i=n;n={},i[e[s]]=n}return t}function Rt(e,t){const n={},s=Object.keys(e);for(let i=0;i<s.length;i++){const r=s[i];n[r]=t(e[r],r,e,i)}return n}function Zt(e){return Qt(e)?e:[e]}function I(e){return e===void 0?[]:Zt(e)}function it(e,t,n,s){return typeof e=="function"?e({context:t,event:n,self:s}):e}function Qt(e){return Array.isArray(e)}function _n(e){return e.type.startsWith("xstate.error.actor")}function j(e){return Zt(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Nt(e){if(!(e===void 0||e===un))return I(e)}function jt(e,t,n){var r,o,c;const s=typeof e=="object",i=s?e:void 0;return{next:(r=s?e.next:e)==null?void 0:r.bind(i),error:(o=s?e.error:t)==null?void 0:o.bind(i),complete:(c=s?e.complete:n)==null?void 0:c.bind(i)}}function Dt(e,t){return`${t}.${e}`}function ut(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,s,i]=n,o=e.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[s]:o).src}const ft=1;let v=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const Sn={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class wn{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Mt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=v.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...Sn,...n},{clock:i,logger:r,parent:o,syncSnapshot:c,id:a,systemId:f,inspect:h}=s;this.system=o?o.system:gn(this,{clock:i}),h&&!o&&this.system.inspect(jt(h)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=r,this.clock=i,this._parent=o,this._syncSnapshot=c,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:u=>{this._deferred.push(u)},system:this.system,stopChild:u=>{if(u._parent!==this)throw new Error(`Cannot stop child actor ${u.id} of ${this.id} because it is not a child`);u._stop()},emit:u=>{const l=this.eventListeners.get(u.type);if(l)for(const d of Array.from(l))d(u)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),f&&(this._systemId=f,this.system._set(f,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),f&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var n;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,n){var i,r;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(c){E(c)}break;case"done":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(c){E(c)}this._stopProcedure(),this._complete(),this._doneEvent=pn(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,s){var r;const i=jt(t,n,s);if(this._processingStatus!==v.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{(r=i.complete)==null||r.call(i)}catch(o){E(o)}break;case"error":{const o=this._snapshot.error;if(!i.error)E(o);else try{i.error(o)}catch(c){E(c)}break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,n){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const i=n.bind(void 0);return s.add(i),{unsubscribe:()=>{s.delete(i)}}}start(){if(this._processingStatus===v.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=v.Running;const t=Yt(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,s;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(i){s={err:i}}if(s){const{err:i}=s;this._snapshot={...this._snapshot,status:"error",error:i},this._error(i);return}this.update(n,t),t.type===nt&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===v.Stopped?this:(this.mailbox.clear(),this._processingStatus===v.NotStarted?(this._processingStatus=v.Stopped,this):(this.mailbox.enqueue({type:nt}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const n of this.observers)try{(t=n.complete)==null||t.call(n)}catch(s){E(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||E(t);return}let n=!1;for(const s of this.observers){const i=s.error;n||(n=!i);try{i==null||i(t)}catch(r){E(r)}}this.observers.clear(),n&&E(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Xt(this.id,t))}_stopProcedure(){return this._processingStatus!==v.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Mt(this._process.bind(this)),this._processingStatus=v.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==v.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:an)(this)}toJSON(){return{xstate$$type:ft,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[yn](){return this}getSnapshot(){return this._snapshot}}function L(e,...[t]){return new wn(e,t)}function xn(e,t,n,s,{sendId:i}){const r=typeof i=="function"?i(n,s):i;return[t,r]}function bn(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function te(e){function t(n,s){}return t.type="xstate.cancel",t.sendId=e,t.resolve=xn,t.execute=bn,t}function En(e,t,n,s,{id:i,systemId:r,src:o,input:c,syncSnapshot:a}){const f=typeof o=="string"?ut(t.machine,o):o,h=typeof i=="function"?i(n):i;let u;return f&&(u=L(f,{id:h,src:o,parent:e.self,syncSnapshot:a,systemId:r,input:typeof c=="function"?c({context:t.context,event:n.event,self:e.self}):c})),[O(t,{children:{...t.children,[h]:u}}),{id:i,actorRef:u}]}function Tn(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==v.Stopped&&n.start()})}function ee(...[e,{id:t,systemId:n,input:s,syncSnapshot:i=!1}={}]){function r(o,c){}return r.type="snapshot.spawnChild",r.id=t,r.systemId=n,r.src=e,r.input=s,r.syncSnapshot=i,r.resolve=En,r.execute=Tn,r}function An(e,t,n,s,{actorRef:i}){const r=typeof i=="function"?i(n,s):i,o=typeof r=="string"?t.children[r]:r;let c=t.children;return o&&(c={...c},delete c[o.id]),[O(t,{children:c}),o]}function In(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==v.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function ht(e){function t(n,s){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=An,t.execute=In,t}function kn(e,{context:t,event:n},{guards:s}){return s.every(i=>U(i,t,n,e))}function Ds(e){function t(n,s){return!1}return t.check=kn,t.guards=e,t}function U(e,t,n,s){const{machine:i}=s,r=typeof e=="function",o=r?e:i.implementations.guards[typeof e=="string"?e:e.type];if(!r&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return U(o,t,n,s);const c={context:t,event:n},a=r||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(s,c,o):o(c,a)}const lt=e=>e.type==="atomic"||e.type==="final";function J(e){return Object.values(e.states).filter(t=>t.type!=="history")}function V(e,t){const n=[];if(t===e)return n;let s=e.parent;for(;s&&s!==t;)n.push(s),s=s.parent;return n}function H(e){const t=new Set(e),n=se(t);for(const s of t)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))qt(s).forEach(i=>t.add(i));else if(s.type==="parallel"){for(const i of J(s))if(i.type!=="history"&&!t.has(i)){const r=qt(i);for(const o of r)t.add(o)}}for(const s of t){let i=s.parent;for(;i;)t.add(i),i=i.parent}return t}function ne(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const i=n[0];if(i){if(lt(i))return i.key}else return{}}const s={};for(const i of n)s[i.key]=ne(i,t);return s}function se(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function ie(e,t){const n=H(t);return ne(e,se(n))}function dt(e,t){return t.type==="compound"?J(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?J(t).every(n=>dt(e,n)):t.type==="final"}const F=e=>e[0]===fn;function $n(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(s=>{if(s===hn)return!0;if(!s.endsWith(".*"))return!1;const i=s.split("."),r=t.split(".");for(let o=0;o<i.length;o++){const c=i[o],a=r[o];if(c==="*")return o===i.length-1;if(c!==a)return!1}return!0}).sort((s,i)=>i.length-s.length).flatMap(s=>e.transitions.get(s))}function Mn(e){const t=e.config.after;if(!t)return[];const n=(i,r)=>{const o=dn(i,e.id),c=o.type;return e.entry.push(le(o,{id:c,delay:i})),e.exit.push(te(c)),c};return Object.keys(t).flatMap((i,r)=>{const o=t[i],c=typeof o=="string"?{target:o}:o,a=Number.isNaN(+i)?i:+i,f=n(a);return I(c).map(h=>({...h,event:f,delay:a}))}).map(i=>{const{delay:r}=i;return{...$(e,i.event,i),delay:r}})}function $(e,t,n){const s=Nt(n.target),i=n.reenter??!1,r=Rn(e,s),o={...n,actions:I(n.actions),guard:n.guard,target:r,source:e,reenter:i,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:r?r.map(c=>`#${c.id}`):void 0})};return o}function On(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===Kt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=e.config.on[n];t.set(n,j(s).map(i=>$(e,n,i)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,j(e.config.onDone).map(s=>$(e,n,s)))}for(const n of e.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;t.set(s,j(n.onDone).map(i=>$(e,s,i)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;t.set(s,j(n.onError).map(i=>$(e,s,i)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;t.set(s,j(n.onSnapshot).map(i=>$(e,s,i)))}}for(const n of e.after){let s=t.get(n.eventType);s||(s=[],t.set(n.eventType,s)),s.push(n)}return t}function Cn(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const s={source:e,actions:!t||typeof t=="string"?[]:I(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return s}function Rn(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(F(n))return e.machine.getStateNodeById(n);const s=n[0]===Vt;if(s&&!e.parent)return X(e,n.slice(1));const i=s?e.key+n:n;if(e.parent)try{return X(e.parent,i)}catch(r){throw new Error(`Invalid transition definition for state node '${e.id}':
${r.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function re(e){const t=Nt(e.config.target);return t?{target:t.map(n=>typeof n=="string"?X(e.parent,n):n)}:e.parent.initial}function M(e){return e.type==="history"}function qt(e){const t=oe(e);for(const n of t)for(const s of V(n,e))t.add(s);return t}function oe(e){const t=new Set;function n(s){if(!t.has(s)){if(t.add(s),s.type==="compound")n(s.initial.target[0]);else if(s.type==="parallel")for(const i of J(s))n(i)}}return n(e),t}function z(e,t){if(F(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function X(e,t){if(typeof t=="string"&&F(t))try{return e.machine.getStateNodeById(t)}catch{}const n=at(t).slice();let s=e;for(;n.length;){const i=n.shift();if(!i.length)break;s=z(s,i)}return s}function Y(e,t){if(typeof t=="string"){const i=e.states[t];if(!i)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,i]}const n=Object.keys(t),s=n.map(i=>z(e,i)).filter(Boolean);return[e.machine.root,e].concat(s,n.reduce((i,r)=>{const o=z(e,r);if(!o)return i;const c=Y(o,t[r]);return i.concat(c)},[]))}function jn(e,t,n,s){const r=z(e,t).next(n,s);return!r||!r.length?e.next(n,s):r}function Dn(e,t,n,s){const i=Object.keys(t),r=z(e,i[0]),o=pt(r,t[i[0]],n,s);return!o||!o.length?e.next(n,s):o}function qn(e,t,n,s){const i=[];for(const r of Object.keys(t)){const o=t[r];if(!o)continue;const c=z(e,r),a=pt(c,o,n,s);a&&i.push(...a)}return i.length?i:e.next(n,s)}function pt(e,t,n,s){return typeof t=="string"?jn(e,t,n,s):Object.keys(t).length===1?Dn(e,t,n,s):qn(e,t,n,s)}function Ln(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function k(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function Jn(e,t){const n=new Set(e),s=new Set(t);for(const i of n)if(s.has(i))return!0;for(const i of s)if(n.has(i))return!0;return!1}function ce(e,t,n){const s=new Set;for(const i of e){let r=!1;const o=new Set;for(const c of s)if(Jn(rt([i],t,n),rt([c],t,n)))if(k(i.source,c.source))o.add(c);else{r=!0;break}if(!r){for(const c of o)s.delete(c);s.add(i)}}return Array.from(s)}function zn(e){const[t,...n]=e;for(const s of V(t,void 0))if(n.every(i=>k(i,s)))return s}function yt(e,t){if(!e.target)return[];const n=new Set;for(const s of e.target)if(M(s))if(t[s.id])for(const i of t[s.id])n.add(i);else for(const i of yt(re(s),t))n.add(i);else n.add(s);return[...n]}function ae(e,t){const n=yt(e,t);if(!n)return;if(!e.reenter&&n.every(i=>i===e.source||k(i,e.source)))return e.source;const s=zn(n.concat(e.source));if(s)return s;if(!e.reenter)return e.source.machine.root}function rt(e,t,n){var i;const s=new Set;for(const r of e)if((i=r.target)!=null&&i.length){const o=ae(r,n);r.reenter&&r.source===o&&s.add(o);for(const c of t)k(c,o)&&s.add(c)}return[...s]}function Gn(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function ot(e,t,n,s,i,r){if(!e.length)return t;const o=new Set(t._nodes);let c=t.historyValue;const a=ce(e,o,c);let f=t;i||([f,c]=Un(f,s,n,a,o,c,r)),f=G(f,s,n,a.flatMap(u=>u.actions),r),f=Wn(f,s,n,a,o,r,c,i);const h=[...o];f.status==="done"&&(f=G(f,s,n,h.sort((u,l)=>l.order-u.order).flatMap(u=>u.exit),r));try{return c===t.historyValue&&Gn(t._nodes,o)?f:O(f,{_nodes:h,historyValue:c})}catch(u){throw u}}function Pn(e,t,n,s,i){if(s.output===void 0)return;const r=st(i.id,i.output!==void 0&&i.parent?it(i.output,e.context,t,n.self):void 0);return it(s.output,e.context,r,n.self)}function Wn(e,t,n,s,i,r,o,c){let a=e;const f=new Set,h=new Set;Bn(s,o,h,f),c&&h.add(e.machine.root);const u=new Set;for(const l of[...f].sort((d,p)=>d.order-p.order)){i.add(l);const d=[];d.push(...l.entry);for(const p of l.invoke)d.push(ee(p.src,{...p,syncSnapshot:!!p.onSnapshot}));if(h.has(l)){const p=l.initial.actions;d.push(...p)}if(a=G(a,t,n,d,r,l.invoke.map(p=>p.id)),l.type==="final"){const p=l.parent;let y=(p==null?void 0:p.type)==="parallel"?p:p==null?void 0:p.parent,m=y||l;for((p==null?void 0:p.type)==="compound"&&r.push(st(p.id,l.output!==void 0?it(l.output,a.context,t,n.self):void 0));(y==null?void 0:y.type)==="parallel"&&!u.has(y)&&dt(i,y);)u.add(y),r.push(st(y.id)),m=y,y=y.parent;if(y)continue;a=O(a,{status:"done",output:Pn(a,t,n,a.machine.root,m)})}}return a}function Bn(e,t,n,s){for(const i of e){const r=ae(i,t);for(const c of i.target||[])!M(c)&&(i.source!==c||i.source!==r||i.reenter)&&(s.add(c),n.add(c)),D(c,t,n,s);const o=yt(i,t);for(const c of o){const a=V(c,r);(r==null?void 0:r.type)==="parallel"&&a.push(r),ue(s,t,n,a,!i.source.parent&&i.reenter?void 0:r)}}}function D(e,t,n,s){var i;if(M(e))if(t[e.id]){const r=t[e.id];for(const o of r)s.add(o),D(o,t,n,s);for(const o of r)N(o,e.parent,s,t,n)}else{const r=re(e);for(const o of r.target)s.add(o),r===((i=e.parent)==null?void 0:i.initial)&&n.add(e.parent),D(o,t,n,s);for(const o of r.target)N(o,e.parent,s,t,n)}else if(e.type==="compound"){const[r]=e.initial.target;M(r)||(s.add(r),n.add(r)),D(r,t,n,s),N(r,e,s,t,n)}else if(e.type==="parallel")for(const r of J(e).filter(o=>!M(o)))[...s].some(o=>k(o,r))||(M(r)||(s.add(r),n.add(r)),D(r,t,n,s))}function ue(e,t,n,s,i){for(const r of s)if((!i||k(r,i))&&e.add(r),r.type==="parallel")for(const o of J(r).filter(c=>!M(c)))[...e].some(c=>k(c,o))||(e.add(o),D(o,t,n,e))}function N(e,t,n,s,i){ue(n,s,i,V(e,t))}function Un(e,t,n,s,i,r,o){let c=e;const a=rt(s,i,r);a.sort((h,u)=>u.order-h.order);let f;for(const h of a)for(const u of Ln(h)){let l;u.history==="deep"?l=d=>lt(d)&&k(d,h):l=d=>d.parent===h,f??(f={...r}),f[u.id]=Array.from(i).filter(l)}for(const h of a)c=G(c,t,n,[...h.exit,...h.invoke.map(u=>ht(u.id))],o),i.delete(h);return[c,f||r]}function fe(e,t,n,s,i,r){const{machine:o}=e;let c=e;for(const a of s){let d=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof a=="string"?a:typeof a=="object"?a.type:a.name||"(anonymous)",params:l}}),h(u,l)};const f=typeof a=="function",h=f?a:o.implementations.actions[typeof a=="string"?a:a.type];if(!h)continue;const u={context:c.context,event:t,self:n.self,system:n.system},l=f||typeof a=="string"?void 0:"params"in a?typeof a.params=="function"?a.params({context:c.context,event:t}):a.params:void 0;if(!("resolve"in h)){n.self._processingStatus===v.Running?d():n.defer(()=>{d()});continue}const p=h,[y,m,g]=p.resolve(n,c,u,l,h,i);c=y,"retryResolve"in p&&(r==null||r.push([p,m])),"execute"in p&&(n.self._processingStatus===v.Running?p.execute(n,m):n.defer(p.execute.bind(null,n,m))),g&&(c=fe(c,t,n,g,i,r))}return c}function G(e,t,n,s,i,r){const o=r?[]:void 0,c=fe(e,t,n,s,{internalQueue:i,deferredActorIds:r},o);return o==null||o.forEach(([a,f])=>{a.retryResolve(n,c,f)}),c}function tt(e,t,n,s=[]){let i=e;const r=[];function o(f,h,u){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:h,snapshot:f,_transitions:u}),r.push(f)}if(t.type===nt)return i=O(Lt(i,t,n),{status:"stopped"}),o(i,t,[]),{snapshot:i,microstates:r};let c=t;if(c.type!==Ht){const f=c,h=_n(f),u=Jt(f,i);if(h&&!u.length)return i=O(e,{status:"error",error:f.error}),o(i,f,[]),{snapshot:i,microstates:r};i=ot(u,e,n,c,!1,s),o(i,f,u)}let a=!0;for(;i.status==="active";){let f=a?Vn(i,c):[];const h=f.length?i:void 0;if(!f.length){if(!s.length)break;c=s.shift(),f=Jt(c,i)}i=ot(f,i,n,c,!1,s),a=i!==h,o(i,c,f)}return i.status!=="active"&&Lt(i,c,n),{snapshot:i,microstates:r}}function Lt(e,t,n){return G(e,t,n,Object.values(e.children).map(s=>ht(s)),[])}function Jt(e,t){return t.machine.getTransitionData(t,e)}function Vn(e,t){const n=new Set,s=e._nodes.filter(lt);for(const i of s)t:for(const r of[i].concat(V(i,void 0)))if(r.always){for(const o of r.always)if(o.guard===void 0||U(o.guard,e.context,t,e)){n.add(o);break t}}return ce(Array.from(n),new Set(e._nodes),e.historyValue)}function Kn(e,t){const n=H(Y(e,t));return ie(e,[...n])}function Hn(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const Xn=function(t){return Ft(t,this.value)},Yn=function(t){return this.tags.has(t)},Fn=function(t){const n=this.machine.getTransitionData(this,t);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},Zn=function(){const{_nodes:t,tags:n,machine:s,getMeta:i,toJSON:r,can:o,hasTag:c,matches:a,...f}=this;return{...f,tags:Array.from(n)}},Qn=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function K(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:ie(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:Xn,hasTag:Yn,can:Fn,getMeta:Qn,toJSON:Zn}}function O(e,t={}){return K({...e,...t},e.machine)}function Nn(e,t){const{_nodes:n,tags:s,machine:i,children:r,context:o,can:c,hasTag:a,matches:f,getMeta:h,toJSON:u,...l}=e,d={};for(const y in r){const m=r[y];d[y]={snapshot:m.getPersistedSnapshot(t),src:m.src,systemId:m._systemId,syncSnapshot:m._syncSnapshot}}return{...l,context:he(o),children:d}}function he(e){let t;for(const n in e){const s=e[n];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)t??(t=Array.isArray(e)?e.slice():{...e}),t[n]={xstate$$type:ft,id:s.id};else{const i=he(s);i!==s&&(t??(t=Array.isArray(e)?e.slice():{...e}),t[n]=i)}}return t??e}function ts(e,t,n,s,{event:i,id:r,delay:o},{internalQueue:c}){const a=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const f=typeof i=="function"?i(n,s):i;let h;if(typeof o=="string"){const u=a&&a[o];h=typeof u=="function"?u(n,s):u}else h=typeof o=="function"?o(n,s):o;return typeof h!="number"&&c.push(f),[t,{event:f,id:r,delay:h}]}function es(e,t){const{event:n,delay:s,id:i}=t;if(typeof s=="number"){e.defer(()=>{const r=e.self;e.system.scheduler.schedule(r,r,n,s,i)});return}}function le(e,t){function n(s,i){}return n.type="xstate.raise",n.event=e,n.id=t==null?void 0:t.id,n.delay=t==null?void 0:t.delay,n.resolve=ts,n.execute=es,n}function ns(e,{machine:t,context:n},s,i){const r=(o,c={})=>{const{systemId:a,input:f}=c;if(typeof o=="string"){const h=ut(t,o);if(!h)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const u=L(h,{id:c.id,parent:e.self,syncSnapshot:c.syncSnapshot,input:typeof f=="function"?f({context:n,event:s,self:e.self}):f,src:o,systemId:a});return i[u.id]=u,u}else return L(o,{id:c.id,parent:e.self,syncSnapshot:c.syncSnapshot,input:c.input,src:o,systemId:a})};return(o,c)=>{const a=r(o,c);return i[a.id]=a,e.defer(()=>{a._processingStatus!==v.Stopped&&a.start()}),a}}function ss(e,t,n,s,{assignment:i}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={},o={context:t.context,event:n.event,spawn:ns(e,t,n.event,r),self:e.self,system:e.system};let c={};if(typeof i=="function")c=i(o,s);else for(const f of Object.keys(i)){const h=i[f];c[f]=typeof h=="function"?h(o,s):h}const a=Object.assign({},t.context,c);return[O(t,{context:a,children:Object.keys(r).length?{...t.children,...r}:t.children})]}function q(e){function t(n,s){}return t.type="xstate.assign",t.assignment=e,t.resolve=ss,t}function is(e,t,n,s,{event:i}){const r=typeof i=="function"?i(n,s):i;return[t,{event:r}]}function rs(e,{event:t}){e.defer(()=>e.emit(t))}function os(e){function t(n,s){}return t.type="xstate.emit",t.event=e,t.resolve=is,t.execute=rs,t}let ct=function(e){return e.Parent="#_parent",e.Internal="#_internal",e}({});function cs(e,t,n,s,{to:i,event:r,id:o,delay:c},a){var p;const f=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${r}" }) instead`);const h=typeof r=="function"?r(n,s):r;let u;if(typeof c=="string"){const y=f&&f[c];u=typeof y=="function"?y(n,s):y}else u=typeof c=="function"?c(n,s):c;const l=typeof i=="function"?i(n,s):i;let d;if(typeof l=="string"){if(l===ct.Parent?d=e.self._parent:l===ct.Internal?d=e.self:l.startsWith("#_")?d=t.children[l.slice(2)]:d=(p=a.deferredActorIds)!=null&&p.includes(l)?l:t.children[l],!d)throw new Error(`Unable to send event to actor '${l}' from machine '${t.machine.id}'.`)}else d=l||e.self;return[t,{to:d,event:h,id:o,delay:u}]}function as(e,t,n){typeof n.to=="string"&&(n.to=t.children[n.to])}function us(e,t){e.defer(()=>{const{to:n,event:s,delay:i,id:r}=t;if(typeof i=="number"){e.system.scheduler.schedule(e.self,n,s,i,r);return}e.system._relay(e.self,n,s.type===ln?Xt(e.self.id,s.data):s)})}function de(e,t,n){function s(i,r){}return s.type="xsnapshot.sendTo",s.to=e,s.event=t,s.id=n==null?void 0:n.id,s.delay=n==null?void 0:n.delay,s.resolve=cs,s.retryResolve=as,s.execute=us,s}function qs(e,t){return de(ct.Parent,e,t)}function fs(e,t,n,s,{collect:i}){const r=[],o=function(a){r.push(a)};return o.assign=(...c)=>{r.push(q(...c))},o.cancel=(...c)=>{r.push(te(...c))},o.raise=(...c)=>{r.push(le(...c))},o.sendTo=(...c)=>{r.push(de(...c))},o.spawnChild=(...c)=>{r.push(ee(...c))},o.stopChild=(...c)=>{r.push(ht(...c))},o.emit=(...c)=>{r.push(os(...c))},i({context:n.context,event:n.event,enqueue:o,check:c=>U(c,t.context,n.event,t),self:e.self,system:e.system},s),[t,void 0,r]}function Ls(e){function t(n,s){}return t.type="xstate.enqueueActions",t.collect=e,t.resolve=fs,t}const zt=new WeakMap;function R(e,t,n){let s=zt.get(e);return s?t in s||(s[t]=n()):(s={[t]:n()},zt.set(e,s)),s[t]}const hs={},B=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class mt{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Vt),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Rt(this.config.states,(s,i)=>new mt(s,{_parent:this,_key:i,_machine:this.machine})):hs,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=I(this.config.entry).slice(),this.exit=I(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=I(t.tags).slice()}_initialize(){this.transitions=On(this),this.config.always&&(this.always=j(this.config.always).map(t=>$(this,Kt,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(B),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(B),eventType:null})}:void 0,history:this.history,states:Rt(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(B)})),entry:this.entry.map(B),exit:this.exit.map(B),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return R(this,"invoke",()=>I(this.config.invoke).map((t,n)=>{const{src:s,systemId:i}=t,r=t.id??Dt(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${Dt(this.id,n)}`;return{...t,src:o,id:r,systemId:i,toJSON(){const{onDone:c,onError:a,...f}=t;return{...f,type:"xstate.invoke",src:o,id:r}}}}))}get on(){return R(this,"on",()=>[...this.transitions].flatMap(([n,s])=>s.map(i=>[n,i])).reduce((n,[s,i])=>(n[s]=n[s]||[],n[s].push(i),n),{}))}get after(){return R(this,"delayedTransitions",()=>Mn(this))}get initial(){return R(this,"initial",()=>Cn(this,this.config.initial))}next(t,n){const s=n.type,i=[];let r;const o=R(this,`candidates-${s}`,()=>$n(this,s));for(const c of o){const{guard:a}=c,f=t.context;let h=!1;try{h=!a||U(a,f,n,t)}catch(u){const l=typeof a=="string"?a:typeof a=="object"?a.type:void 0;throw new Error(`Unable to evaluate guard ${l?`'${l}' `:""}in transition for event '${s}' in state node '${this.id}':
${u.message}`)}if(h){i.push(...c.actions),r=c;break}}return r?[r]:void 0}get events(){return R(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const i=t[s];if(i.states)for(const r of i.events)n.add(`${r}`)}return Array.from(n)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(t)}}const ls="#";class gt{constructor(t,n){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:(n==null?void 0:n.actors)??{},actions:(n==null?void 0:n.actions)??{},delays:(n==null?void 0:n.delays)??{},guards:(n==null?void 0:n.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new mt(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:s,actors:i,delays:r}=this.implementations;return new gt(this.config,{actions:{...n,...t.actions},guards:{...s,...t.guards},actors:{...i,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const n=Kn(this.root,t.value),s=H(Y(this.root,n));return K({_nodes:[...s],context:t.context||{},children:{},status:dt(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,s){return tt(t,n,s).snapshot}microstep(t,n,s){return tt(t,n,s).microstates}getTransitionData(t,n){return pt(this.root,t.value,t,n)||[]}getPreInitialState(t,n,s){const{context:i}=this.config,r=K({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?G(r,n,t,[q(({spawn:c,event:a,self:f})=>i({spawn:c,input:a.input,self:f}))],s):r}getInitialSnapshot(t,n){const s=Yt(n),i=[],r=this.getPreInitialState(t,s,i),o=ot([{target:[...oe(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,s,!0,i),{snapshot:c}=tt(o,s,t,i);return c}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=at(t),s=n.slice(1),i=F(n[0])?n[0].slice(ls.length):n[0],r=this.idMap.get(i);if(!r)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return X(r,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return Nn(t,n)}restoreSnapshot(t,n){const s={},i=t.children;Object.keys(i).forEach(a=>{const f=i[a],h=f.snapshot,u=f.src,l=typeof u=="string"?ut(this,u):u;if(!l)return;const d=L(l,{id:a,parent:n.self,syncSnapshot:f.syncSnapshot,snapshot:h,src:u,systemId:f.systemId});s[a]=d});const r=K({...t,children:s,_nodes:Array.from(H(Y(this.root,t.value)))},this);let o=new Set;function c(a,f){if(!o.has(a)){o.add(a);for(let h in a){const u=a[h];if(u&&typeof u=="object"){if("xstate$$type"in u&&u.xstate$$type===ft){a[h]=f[u.id];continue}c(u,f)}}}}return c(r.context,s),r}}function pe(e,t){return new gt(e,t)}function Js({schemas:e,actors:t,actions:n,guards:s,delays:i}){return{createMachine:r=>pe({...r,schemas:e},{actors:t,actions:n,guards:s,delays:i})}}var ds=S.useLayoutEffect,ye={exports:{}},me={};/**
 * @license React
 * use-sync-external-store-shim/with-selector.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var Z=S,ps=ze;function ys(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var ms=typeof Object.is=="function"?Object.is:ys,gs=ps.useSyncExternalStore,vs=Z.useRef,_s=Z.useEffect,Ss=Z.useMemo,ws=Z.useDebugValue;me.useSyncExternalStoreWithSelector=function(e,t,n,s,i){var r=vs(null);if(r.current===null){var o={hasValue:!1,value:null};r.current=o}else o=r.current;r=Ss(function(){function a(d){if(!f){if(f=!0,h=d,d=s(d),i!==void 0&&o.hasValue){var p=o.value;if(i(p,d))return u=p}return u=d}if(p=u,ms(h,d))return p;var y=s(d);return i!==void 0&&i(p,y)?p:(h=d,u=y)}var f=!1,h,u,l=n===void 0?null:n;return[function(){return a(t())},l===null?void 0:function(){return a(l())}]},[t,n,s,i]);var c=gs(e,r[0],r[1]);return _s(function(){o.hasValue=!0,o.value=c},[c]),ws(c),c};ye.exports=me;var xs=ye.exports;const ge=(e,t)=>{t(e);const n=e.getSnapshot().children;n&&Object.values(n).forEach(s=>{ge(s,t)})};function bs(e){var s,i;const t=[];ge(e,r=>{t.push([r,r.getSnapshot()]),r.observers=new Set});const n=(i=(s=e.system).getSnapshot)==null?void 0:i.call(s);e.stop(),e.system._snapshot=n,t.forEach(([r,o])=>{r._processingStatus=0,r._snapshot=o})}function Es(e,t){let[[n,s],i]=S.useState(()=>{const r=L(e,t);return[e.config,r]});if(e.config!==n){const r=L(e,{...t,snapshot:s.getPersistedSnapshot({__unsafeAllowInlineActors:!0})});i([e.config,r]),s=r}return ds(()=>{s.logic.implementations=e.implementations}),s}function Ts(e,t={},n){const s=Es(e,t);return S.useEffect(()=>{},[n]),S.useEffect(()=>(s.start(),()=>{bs(s)}),[s]),s}function As(e,t){return e===t}function Is(e,t,n=As){const s=S.useCallback(o=>{if(!e)return()=>{};const{unsubscribe:c}=e.subscribe(o);return c},[e]),i=S.useCallback(()=>e==null?void 0:e.getSnapshot(),[e]);return xs.useSyncExternalStoreWithSelector(s,i,i,t,n)}function ks(e,t){const n=S.createContext(null),s=n.Provider;function i({children:c,logic:a=e,machine:f,options:h}){if(f)throw new Error('The "machine" prop has been deprecated. Please use "logic" instead.');const u=Ts(a,{...t,...h});return S.createElement(s,{value:u,children:c})}i.displayName="ActorProvider";function r(){const c=S.useContext(n);if(!c)throw new Error(`You used a hook from "${i.displayName}" but it's not inside a <${i.displayName}> component.`);return c}function o(c,a){const f=r();return Is(f,c,a)}return{Provider:i,useActorRef:r,useSelector:o}}const $s=pe({id:"oneTimeView",initial:"idle",types:{events:{},context:{}},context:{queue:[],activeItem:void 0},states:{idle:{always:{target:"active",guard:({context:e})=>e.queue.length>0,description:"This is an eventless transition. If we get back to idle and there are more items in the queue, transition to active."},on:{REQUEST_OPEN:{actions:q({queue:({context:e,event:t})=>[...e.queue,t.config]})}}},active:{entry:q({activeItem:({context:e})=>{var t;return e.activeItem?e.activeItem:(t=e.queue[0])==null?void 0:t.id},queue:({context:e})=>e.activeItem?e.queue:e.queue.slice(1)}),on:{REQUEST_CLOSE:{target:"idle",guard:({context:e,event:t})=>e.activeItem===t.id,actions:q({activeItem:({context:e,event:t})=>e.activeItem===t.id?void 0:e.activeItem,queue:({context:e,event:t})=>e.queue.filter(n=>n.id!==t.id)})},REQUEST_OPEN:{actions:q({queue:({context:e,event:t})=>[...e.queue,t.config]})}}}}}),zs=ks($s);export{zs as O,nt as X,js as a,q as b,rn as c,qs as d,Ls as e,Ds as f,os as g,ks as h,le as r,Js as s,Is as u};
