@clicktap/state 0.12.16 → 0.12.17

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.
Files changed (3) hide show
  1. package/index.js +3 -5
  2. package/index.mjs +1287 -2701
  3. package/package.json +1 -2
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("react/jsx-runtime"),M=require("react");function ln(){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 dn(){const t=ln();if(t.__xstate__)return t.__xstate__}const hn=t=>{if(typeof window>"u")return;const e=dn();e&&e.register(t)};class Gt{constructor(e){this._process=e,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(e){const n={value:e,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 e=this._current;this._process(e.value),this._current=e.next}this._last=null}}const Te=".",pn="",ve="",yn="#",mn="*",be="xstate.init",gn="xstate.error",K="xstate.stop";function Sn(t,e){return{type:`xstate.after.${t}.${e}`}}function _t(t,e){return{type:`xstate.done.state.${t}`,output:e}}function En(t,e){return{type:`xstate.done.actor.${t}`,output:e}}function Ae(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function xe(t){return{type:be,input:t}}function x(t){setTimeout(()=>{throw t})}const wn=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function Xt(t,e){return`${t.sessionId}.${e}`}let _n=0;function Tn(t,e){const n=new Map,s=new Map,r=new WeakMap,i=new Set,o={},a=e.clock,u={schedule:(f,p,y,h,m=Math.random().toString(36).slice(2))=>{const S={source:f,target:p,event:y,delay:h,id:m,startedAt:Date.now()},E=Xt(f,m);l._snapshot._scheduledEvents[E]=S;const O=a.setTimeout(()=>{delete o[E],delete l._snapshot._scheduledEvents[E],l._relay(f,p,y)},h);o[E]=O},cancel:(f,p)=>{const y=Xt(f,p),h=o[y];delete o[y],delete l._snapshot._scheduledEvents[y],a.clearTimeout(h)},cancelAll:f=>{for(const p in l._snapshot._scheduledEvents){const y=l._snapshot._scheduledEvents[p];y.source===f&&u.cancel(f,y.id)}}},c=f=>{if(!i.size)return;const p={...f,rootId:t.sessionId};i.forEach(y=>{var h;return(h=y.next)==null?void 0:h.call(y,p)})},l={_snapshot:{_scheduledEvents:((e==null?void 0:e.snapshot)&&e.snapshot.scheduler)??{}},_bookId:()=>`x:${_n++}`,_register:(f,p)=>(n.set(f,p),f),_unregister:f=>{n.delete(f.sessionId);const p=r.get(f);p!==void 0&&(s.delete(p),r.delete(f))},get:f=>s.get(f),_set:(f,p)=>{const y=s.get(f);if(y&&y!==p)throw new Error(`Actor with system ID '${f}' already exists.`);s.set(f,p),r.set(p,f)},inspect:f=>{i.add(f)},_sendInspectionEvent:c,_relay:(f,p,y)=>{l._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:p,event:y}),p._send(y)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const f=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const p in f){const{source:y,target:h,event:m,delay:S,id:E}=f[p];u.schedule(y,h,m,S,E)}}};return l}function Re(t,e){const n=Yt(t),s=Yt(e);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(r=>r in s?Re(n[r],s[r]):!1)}function It(t){if(ke(t))return t;let e=[],n="";for(let s=0;s<t.length;s++){switch(t.charCodeAt(s)){case 92:n+=t[s+1],s++;continue;case 46:e.push(n),n="";continue}n+=t[s]}return e.push(n),e}function Yt(t){if(Qn(t))return t.value;if(typeof t!="string")return t;const e=It(t);return vn(e)}function vn(t){if(t.length===1)return t[0];const e={};let n=e;for(let s=0;s<t.length-1;s++)if(s===t.length-2)n[t[s]]=t[s+1];else{const r=n;n={},r[t[s]]=n}return e}function Zt(t,e){const n={},s=Object.keys(t);for(let r=0;r<s.length;r++){const i=s[r];n[i]=e(t[i],i,t,r)}return n}function Oe(t){return ke(t)?t:[t]}function I(t){return t===void 0?[]:Oe(t)}function Tt(t,e,n,s){return typeof t=="function"?t({context:e,event:n,self:s}):t}function ke(t){return Array.isArray(t)}function bn(t){return t.type.startsWith("xstate.error.actor")}function N(t){return Oe(t).map(e=>typeof e>"u"||typeof e=="string"?{target:e}:e)}function Ie(t){if(!(t===void 0||t===pn))return I(t)}function Qt(t,e,n){var i,o,a;const s=typeof t=="object",r=s?t:void 0;return{next:(i=s?t.next:t)==null?void 0:i.bind(r),error:(o=s?t.error:e)==null?void 0:o.bind(r),complete:(a=s?t.complete:n)==null?void 0:a.bind(r)}}function te(t,e){return`${e}.${t}`}function Ct(t,e){const n=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return t.implementations.actors[e];const[,s,r]=n,o=t.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}const Pt=1;let _=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const An={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class xn{constructor(e,n){this.logic=e,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Gt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=_.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={...An,...n},{clock:r,logger:i,parent:o,syncSnapshot:a,id:u,systemId:c,inspect:l}=s;this.system=o?o.system:Tn(this,{clock:r}),l&&!o&&this.system.inspect(Qt(l)),this.sessionId=this.system._bookId(),this.id=u??this.sessionId,this.logger=i,this.clock=r,this._parent=o,this._syncSnapshot=a,this.options=s,this.src=s.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:f=>{this._deferred.push(f)},system:this.system,stopChild:f=>{if(f._parent!==this)throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);f._stop()},emit:f=>{const p=this.eventListeners.get(f.type);if(p)for(const y of Array.from(p))y(f)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this._systemId=c,this.system._set(c,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),c&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(e){var n;try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e: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(e,n){var r,i;this._snapshot=e;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...e,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(r=o.next)==null||r.call(o,e)}catch(a){x(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,e)}catch(a){x(a)}this._stopProcedure(),this._complete(),this._doneEvent=En(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:e})}subscribe(e,n,s){var i;const r=Qt(e,n,s);if(this._processingStatus!==_.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){x(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)x(o);else try{r.error(o)}catch(a){x(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(e,n){let s=this.eventListeners.get(e);s||(s=new Set,this.eventListeners.set(e,s));const r=n.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===_.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=_.Running;const e=xe(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case"done":return this.update(this._snapshot,e),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,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let n,s;try{n=this.logic.transition(this._snapshot,e,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,e),e.type===K&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===_.Stopped?this:(this.mailbox.clear(),this._processingStatus===_.NotStarted?(this._processingStatus=_.Stopped,this):(this.mailbox.enqueue({type:K}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var e;for(const n of this.observers)try{(e=n.complete)==null||e.call(n)}catch(s){x(s)}this.observers.clear()}_reportError(e){if(!this.observers.size){this._parent||x(e);return}let n=!1;for(const s of this.observers){const r=s.error;n||(n=!r);try{r==null||r(e)}catch(i){x(i)}}this.observers.clear(),n&&x(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,Ae(this.id,e))}_stopProcedure(){return this._processingStatus!==_.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Gt(this._process.bind(this)),this._processingStatus=_.Stopped,this.system._unregister(this),this)}_send(e){this._processingStatus!==_.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){const{devTools:e}=this.options;e&&(typeof e=="function"?e:hn)(this)}toJSON(){return{xstate$$type:Pt,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[wn](){return this}getSnapshot(){return this._snapshot}}function L(t,...[e]){return new xn(t,e)}function Rn(t,e,n,s,{sendId:r}){const i=typeof r=="function"?r(n,s):r;return[e,i]}function On(t,e){t.defer(()=>{t.system.scheduler.cancel(t.self,e)})}function kn(t){function e(n,s){}return e.type="xstate.cancel",e.sendId=t,e.resolve=Rn,e.execute=On,e}function In(t,e,n,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:u}){const c=typeof o=="string"?Ct(e.machine,o):o,l=typeof r=="function"?r(n):r;let f;return c&&(f=L(c,{id:l,src:o,parent:t.self,syncSnapshot:u,systemId:i,input:typeof a=="function"?a({context:e.context,event:n.event,self:t.self}):a})),[U(e,{children:{...e.children,[l]:f}}),{id:r,actorRef:f}]}function Cn(t,{id:e,actorRef:n}){n&&t.defer(()=>{n._processingStatus!==_.Stopped&&n.start()})}function Pn(...[t,{id:e,systemId:n,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=n,i.src=t,i.input=s,i.syncSnapshot=r,i.resolve=In,i.execute=Cn,i}function Dn(t,e,n,s,{actorRef:r}){const i=typeof r=="function"?r(n,s):r,o=typeof i=="string"?e.children[i]:i;let a=e.children;return o&&(a={...a},delete a[o.id]),[U(e,{children:a}),o]}function Mn(t,e){if(e){if(t.system._unregister(e),e._processingStatus!==_.Running){t.stopChild(e);return}t.defer(()=>{t.stopChild(e)})}}function Ce(t){function e(n,s){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=Dn,e.execute=Mn,e}function Dt(t,e,n,s){const{machine:r}=s,i=typeof t=="function",o=i?t:r.implementations.guards[typeof t=="string"?t:t.type];if(!i&&!o)throw new Error(`Guard '${typeof t=="string"?t:t.type}' is not implemented.'.`);if(typeof o!="function")return Dt(o,e,n,s);const a={context:e,event:n},u=i||typeof t=="string"?void 0:"params"in t?typeof t.params=="function"?t.params({context:e,event:n}):t.params:void 0;return"check"in o?o.check(s,a,o):o(a,u)}const Mt=t=>t.type==="atomic"||t.type==="final";function B(t){return Object.values(t.states).filter(e=>e.type!=="history")}function G(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function rt(t){const e=new Set(t),n=De(e);for(const s of e)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))ee(s).forEach(r=>e.add(r));else if(s.type==="parallel"){for(const r of B(s))if(r.type!=="history"&&!e.has(r)){const i=ee(r);for(const o of i)e.add(o)}}for(const s of e){let r=s.parent;for(;r;)e.add(r),r=r.parent}return e}function Pe(t,e){const n=e.get(t);if(!n)return{};if(t.type==="compound"){const r=n[0];if(r){if(Mt(r))return r.key}else return{}}const s={};for(const r of n)s[r.key]=Pe(r,e);return s}function De(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function Me(t,e){const n=rt(e);return Pe(t,De(n))}function Ut(t,e){return e.type==="compound"?B(e).some(n=>n.type==="final"&&t.has(n)):e.type==="parallel"?B(e).every(n=>Ut(t,n)):e.type==="final"}const ct=t=>t[0]===yn;function Un(t,e){return t.transitions.get(e)||[...t.transitions.keys()].filter(s=>{if(s===mn)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=e.split(".");for(let o=0;o<r.length;o++){const a=r[o],u=i[o];if(a==="*")return o===r.length-1;if(a!==u)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>t.transitions.get(s))}function jn(t){const e=t.config.after;if(!e)return[];const n=(r,i)=>{const o=Sn(r,t.id),a=o.type;return t.entry.push(cs(o,{id:a,delay:r})),t.exit.push(kn(a)),a};return Object.keys(e).flatMap((r,i)=>{const o=e[r],a=typeof o=="string"?{target:o}:o,u=Number.isNaN(+r)?r:+r,c=n(u);return I(a).map(l=>({...l,event:c,delay:u}))}).map(r=>{const{delay:i}=r;return{...P(t,r.event,r),delay:i}})}function P(t,e,n){const s=Ie(n.target),r=n.reenter??!1,i=Ln(t,s),o={...n,actions:I(n.actions),guard:n.guard,target:i,source:t,reenter:r,eventType:e,toJSON:()=>({...o,source:`#${t.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function Nn(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===ve)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,N(s).map(r=>P(t,n,r)))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,N(t.config.onDone).map(s=>P(t,n,s)))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,N(n.onDone).map(r=>P(t,s,r)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,N(n.onError).map(r=>P(t,s,r)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,N(n.onSnapshot).map(r=>P(t,s,r)))}}for(const n of t.after){let s=e.get(n.eventType);s||(s=[],e.set(n.eventType,s)),s.push(n)}return e}function $n(t,e){const n=typeof e=="string"?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:!e||typeof e=="string"?[]:I(e.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}function Ln(t,e){if(e!==void 0)return e.map(n=>{if(typeof n!="string")return n;if(ct(n))return t.machine.getStateNodeById(n);const s=n[0]===Te;if(s&&!t.parent)return it(t,n.slice(1));const r=s?t.key+n:n;if(t.parent)try{return it(t.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${t.id}':
2
- ${i.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Ue(t){const e=Ie(t.config.target);return e?{target:e.map(n=>typeof n=="string"?it(t.parent,n):n)}:t.parent.initial}function D(t){return t.type==="history"}function ee(t){const e=je(t);for(const n of e)for(const s of G(n,t))e.add(s);return e}function je(t){const e=new Set;function n(s){if(!e.has(s)){if(e.add(s),s.type==="compound")n(s.initial.target[0]);else if(s.type==="parallel")for(const r of B(s))n(r)}}return n(t),e}function F(t,e){if(ct(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function it(t,e){if(typeof e=="string"&&ct(e))try{return t.machine.getStateNodeById(e)}catch{}const n=It(e).slice();let s=t;for(;n.length;){const r=n.shift();if(!r.length)break;s=F(s,r)}return s}function ot(t,e){if(typeof e=="string"){const r=t.states[e];if(!r)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,r]}const n=Object.keys(e),s=n.map(r=>F(t,r)).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce((r,i)=>{const o=F(t,i);if(!o)return r;const a=ot(o,e[i]);return r.concat(a)},[]))}function Bn(t,e,n,s){const i=F(t,e).next(n,s);return!i||!i.length?t.next(n,s):i}function Fn(t,e,n,s){const r=Object.keys(e),i=F(t,r[0]),o=jt(i,e[r[0]],n,s);return!o||!o.length?t.next(n,s):o}function Hn(t,e,n,s){const r=[];for(const i of Object.keys(e)){const o=e[i];if(!o)continue;const a=F(t,i),u=jt(a,o,n,s);u&&r.push(...u)}return r.length?r:t.next(n,s)}function jt(t,e,n,s){return typeof e=="string"?Bn(t,e,n,s):Object.keys(e).length===1?Fn(t,e,n,s):Hn(t,e,n,s)}function qn(t){return Object.keys(t.states).map(e=>t.states[e]).filter(e=>e.type==="history")}function C(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function zn(t,e){const n=new Set(t),s=new Set(e);for(const r of n)if(s.has(r))return!0;for(const r of s)if(n.has(r))return!0;return!1}function Ne(t,e,n){const s=new Set;for(const r of t){let i=!1;const o=new Set;for(const a of s)if(zn(vt([r],e,n),vt([a],e,n)))if(C(r.source,a.source))o.add(a);else{i=!0;break}if(!i){for(const a of o)s.delete(a);s.add(r)}}return Array.from(s)}function Jn(t){const[e,...n]=t;for(const s of G(e,void 0))if(n.every(r=>C(r,s)))return s}function Nt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(D(s))if(e[s.id])for(const r of e[s.id])n.add(r);else for(const r of Nt(Ue(s),e))n.add(r);else n.add(s);return[...n]}function $e(t,e){const n=Nt(t,e);if(!n)return;if(!t.reenter&&n.every(r=>r===t.source||C(r,t.source)))return t.source;const s=Jn(n.concat(t.source));if(s)return s;if(!t.reenter)return t.source.machine.root}function vt(t,e,n){var r;const s=new Set;for(const i of t)if((r=i.target)!=null&&r.length){const o=$e(i,n);i.reenter&&i.source===o&&s.add(o);for(const a of e)C(a,o)&&s.add(a)}return[...s]}function Wn(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}function bt(t,e,n,s,r,i){if(!t.length)return e;const o=new Set(e._nodes);let a=e.historyValue;const u=Ne(t,o,a);let c=e;r||([c,a]=Xn(c,s,n,u,o,a,i)),c=H(c,s,n,u.flatMap(f=>f.actions),i),c=Vn(c,s,n,u,o,i,a,r);const l=[...o];c.status==="done"&&(c=H(c,s,n,l.sort((f,p)=>p.order-f.order).flatMap(f=>f.exit),i));try{return a===e.historyValue&&Wn(e._nodes,o)?c:U(c,{_nodes:l,historyValue:a})}catch(f){throw f}}function Kn(t,e,n,s,r){if(s.output===void 0)return;const i=_t(r.id,r.output!==void 0&&r.parent?Tt(r.output,t.context,e,n.self):void 0);return Tt(s.output,t.context,i,n.self)}function Vn(t,e,n,s,r,i,o,a){let u=t;const c=new Set,l=new Set;Gn(s,o,l,c),a&&l.add(t.machine.root);const f=new Set;for(const p of[...c].sort((y,h)=>y.order-h.order)){r.add(p);const y=[];y.push(...p.entry);for(const h of p.invoke)y.push(Pn(h.src,{...h,syncSnapshot:!!h.onSnapshot}));if(l.has(p)){const h=p.initial.actions;y.push(...h)}if(u=H(u,e,n,y,i,p.invoke.map(h=>h.id)),p.type==="final"){const h=p.parent;let m=(h==null?void 0:h.type)==="parallel"?h:h==null?void 0:h.parent,S=m||p;for((h==null?void 0:h.type)==="compound"&&i.push(_t(h.id,p.output!==void 0?Tt(p.output,u.context,e,n.self):void 0));(m==null?void 0:m.type)==="parallel"&&!f.has(m)&&Ut(r,m);)f.add(m),i.push(_t(m.id)),S=m,m=m.parent;if(m)continue;u=U(u,{status:"done",output:Kn(u,e,n,u.machine.root,S)})}}return u}function Gn(t,e,n,s){for(const r of t){const i=$e(r,e);for(const a of r.target||[])!D(a)&&(r.source!==a||r.source!==i||r.reenter)&&(s.add(a),n.add(a)),$(a,e,n,s);const o=Nt(r,e);for(const a of o){const u=G(a,i);(i==null?void 0:i.type)==="parallel"&&u.push(i),Le(s,e,n,u,!r.source.parent&&r.reenter?void 0:i)}}}function $(t,e,n,s){var r;if(D(t))if(e[t.id]){const i=e[t.id];for(const o of i)s.add(o),$(o,e,n,s);for(const o of i)pt(o,t.parent,s,e,n)}else{const i=Ue(t);for(const o of i.target)s.add(o),i===((r=t.parent)==null?void 0:r.initial)&&n.add(t.parent),$(o,e,n,s);for(const o of i.target)pt(o,t.parent,s,e,n)}else if(t.type==="compound"){const[i]=t.initial.target;D(i)||(s.add(i),n.add(i)),$(i,e,n,s),pt(i,t,s,e,n)}else if(t.type==="parallel")for(const i of B(t).filter(o=>!D(o)))[...s].some(o=>C(o,i))||(D(i)||(s.add(i),n.add(i)),$(i,e,n,s))}function Le(t,e,n,s,r){for(const i of s)if((!r||C(i,r))&&t.add(i),i.type==="parallel")for(const o of B(i).filter(a=>!D(a)))[...t].some(a=>C(a,o))||(t.add(o),$(o,e,n,t))}function pt(t,e,n,s,r){Le(n,s,r,G(t,e))}function Xn(t,e,n,s,r,i,o){let a=t;const u=vt(s,r,i);u.sort((l,f)=>f.order-l.order);let c;for(const l of u)for(const f of qn(l)){let p;f.history==="deep"?p=y=>Mt(y)&&C(y,l):p=y=>y.parent===l,c??(c={...i}),c[f.id]=Array.from(r).filter(p)}for(const l of u)a=H(a,e,n,[...l.exit,...l.invoke.map(f=>Ce(f.id))],o),r.delete(l);return[a,c||i]}function Be(t,e,n,s,r,i){const{machine:o}=t;let a=t;for(const u of s){let y=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof u=="string"?u:typeof u=="object"?u.type:u.name||"(anonymous)",params:p}}),l(f,p)};const c=typeof u=="function",l=c?u:o.implementations.actions[typeof u=="string"?u:u.type];if(!l)continue;const f={context:a.context,event:e,self:n.self,system:n.system},p=c||typeof u=="string"?void 0:"params"in u?typeof u.params=="function"?u.params({context:a.context,event:e}):u.params:void 0;if(!("resolve"in l)){n.self._processingStatus===_.Running?y():n.defer(()=>{y()});continue}const h=l,[m,S,E]=h.resolve(n,a,f,p,l,r);a=m,"retryResolve"in h&&(i==null||i.push([h,S])),"execute"in h&&(n.self._processingStatus===_.Running?h.execute(n,S):n.defer(h.execute.bind(null,n,S))),E&&(a=Be(a,e,n,E,r,i))}return a}function H(t,e,n,s,r,i){const o=i?[]:void 0,a=Be(t,e,n,s,{internalQueue:r,deferredActorIds:i},o);return o==null||o.forEach(([u,c])=>{u.retryResolve(n,a,c)}),a}function yt(t,e,n,s=[]){let r=t;const i=[];function o(c,l,f){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:l,snapshot:c,_transitions:f}),i.push(c)}if(e.type===K)return r=U(ne(r,e,n),{status:"stopped"}),o(r,e,[]),{snapshot:r,microstates:i};let a=e;if(a.type!==be){const c=a,l=bn(c),f=se(c,r);if(l&&!f.length)return r=U(t,{status:"error",error:c.error}),o(r,c,[]),{snapshot:r,microstates:i};r=bt(f,t,n,a,!1,s),o(r,c,f)}let u=!0;for(;r.status==="active";){let c=u?Yn(r,a):[];const l=c.length?r:void 0;if(!c.length){if(!s.length)break;a=s.shift(),c=se(a,r)}r=bt(c,r,n,a,!1,s),u=r!==l,o(r,a,c)}return r.status!=="active"&&ne(r,a,n),{snapshot:r,microstates:i}}function ne(t,e,n){return H(t,e,n,Object.values(t.children).map(s=>Ce(s)),[])}function se(t,e){return e.machine.getTransitionData(e,t)}function Yn(t,e){const n=new Set,s=t._nodes.filter(Mt);for(const r of s)t:for(const i of[r].concat(G(r,void 0)))if(i.always){for(const o of i.always)if(o.guard===void 0||Dt(o.guard,t.context,e,t)){n.add(o);break t}}return Ne(Array.from(n),new Set(t._nodes),t.historyValue)}function Zn(t,e){const n=rt(ot(t,e));return Me(t,[...n])}function Qn(t){return!!t&&typeof t=="object"&&"machine"in t&&"value"in t}const ts=function(e){return Re(e,this.value)},es=function(e){return this.tags.has(e)},ns=function(e){const n=this.machine.getTransitionData(this,e);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},ss=function(){const{_nodes:e,tags:n,machine:s,getMeta:r,toJSON:i,can:o,hasTag:a,matches:u,...c}=this;return{...c,tags:Array.from(n)}},rs=function(){return this._nodes.reduce((e,n)=>(n.meta!==void 0&&(e[n.id]=n.meta),e),{})};function Q(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:Me(e.root,t._nodes),tags:new Set(t._nodes.flatMap(n=>n.tags)),children:t.children,historyValue:t.historyValue||{},matches:ts,hasTag:es,can:ns,getMeta:rs,toJSON:ss}}function U(t,e={}){return Q({...t,...e},t.machine)}function is(t,e){const{_nodes:n,tags:s,machine:r,children:i,context:o,can:a,hasTag:u,matches:c,getMeta:l,toJSON:f,...p}=t,y={};for(const m in i){const S=i[m];y[m]={snapshot:S.getPersistedSnapshot(e),src:S.src,systemId:S._systemId,syncSnapshot:S._syncSnapshot}}return{...p,context:Fe(o),children:y}}function Fe(t){let e;for(const n in t){const s=t[n];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)e??(e=Array.isArray(t)?t.slice():{...t}),e[n]={xstate$$type:Pt,id:s.id};else{const r=Fe(s);r!==s&&(e??(e=Array.isArray(t)?t.slice():{...t}),e[n]=r)}}return e??t}function os(t,e,n,s,{event:r,id:i,delay:o},{internalQueue:a}){const u=e.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const c=typeof r=="function"?r(n,s):r;let l;if(typeof o=="string"){const f=u&&u[o];l=typeof f=="function"?f(n,s):f}else l=typeof o=="function"?o(n,s):o;return typeof l!="number"&&a.push(c),[e,{event:c,id:i,delay:l}]}function as(t,e){const{event:n,delay:s,id:r}=e;if(typeof s=="number"){t.defer(()=>{const i=t.self;t.system.scheduler.schedule(i,i,n,s,r)});return}}function cs(t,e){function n(s,r){}return n.type="xstate.raise",n.event=t,n.id=e==null?void 0:e.id,n.delay=e==null?void 0:e.delay,n.resolve=os,n.execute=as,n}const re=new WeakMap;function us(t){return{config:t,start:(n,s)=>{const{self:r,system:i}=s,o={receivers:void 0,dispose:void 0};re.set(r,o),o.dispose=t({input:n.input,system:i,self:r,sendBack:a=>{r.getSnapshot().status!=="stopped"&&r._parent&&i._relay(r,r._parent,a)},receive:a=>{o.receivers??(o.receivers=new Set),o.receivers.add(a)}})},transition:(n,s,r)=>{var o,a;const i=re.get(r.self);return s.type===K?(n={...n,status:"stopped",error:void 0},(o=i.dispose)==null||o.call(i),n):((a=i.receivers)==null||a.forEach(u=>u(s)),n)},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}const ie="xstate.promise.resolve",oe="xstate.promise.reject";function mt(t){return{config:t,transition:(n,s)=>{if(n.status!=="active")return n;switch(s.type){case ie:{const r=s.data;return{...n,status:"done",output:r,input:void 0}}case oe:return{...n,status:"error",error:s.data,input:void 0};case K:return{...n,status:"stopped",input:void 0};default:return n}},start:(n,{self:s,system:r})=>{if(n.status!=="active")return;Promise.resolve(t({input:n.input,system:r,self:s})).then(o=>{s.getSnapshot().status==="active"&&r._relay(s,s,{type:ie,data:o})},o=>{s.getSnapshot().status==="active"&&r._relay(s,s,{type:oe,data:o})})},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}function fs(t,{machine:e,context:n},s,r){const i=(o,a={})=>{const{systemId:u,input:c}=a;if(typeof o=="string"){const l=Ct(e,o);if(!l)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=L(l,{id:a.id,parent:t.self,syncSnapshot:a.syncSnapshot,input:typeof c=="function"?c({context:n,event:s,self:t.self}):c,src:o,systemId:u});return r[f.id]=f,f}else return L(o,{id:a.id,parent:t.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:u})};return(o,a)=>{const u=i(o,a);return r[u.id]=u,t.defer(()=>{u._processingStatus!==_.Stopped&&u.start()}),u}}function ls(t,e,n,s,{assignment:r}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,spawn:fs(t,e,n.event,i),self:t.self,system:t.system};let a={};if(typeof r=="function")a=r(o,s);else for(const c of Object.keys(r)){const l=r[c];a[c]=typeof l=="function"?l(o,s):l}const u=Object.assign({},e.context,a);return[U(e,{context:u,children:Object.keys(i).length?{...e.children,...i}:e.children})]}function v(t){function e(n,s){}return e.type="xstate.assign",e.assignment=t,e.resolve=ls,e}let ae=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ds(t,e,n,s,{to:r,event:i,id:o,delay:a},u){var h;const c=e.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const l=typeof i=="function"?i(n,s):i;let f;if(typeof a=="string"){const m=c&&c[a];f=typeof m=="function"?m(n,s):m}else f=typeof a=="function"?a(n,s):a;const p=typeof r=="function"?r(n,s):r;let y;if(typeof p=="string"){if(p===ae.Parent?y=t.self._parent:p===ae.Internal?y=t.self:p.startsWith("#_")?y=e.children[p.slice(2)]:y=(h=u.deferredActorIds)!=null&&h.includes(p)?p:e.children[p],!y)throw new Error(`Unable to send event to actor '${p}' from machine '${e.machine.id}'.`)}else y=p||t.self;return[e,{to:y,event:l,id:o,delay:f}]}function hs(t,e,n){typeof n.to=="string"&&(n.to=e.children[n.to])}function ps(t,e){t.defer(()=>{const{to:n,event:s,delay:r,id:i}=e;if(typeof r=="number"){t.system.scheduler.schedule(t.self,n,s,r,i);return}t.system._relay(t.self,n,s.type===gn?Ae(t.self.id,s.data):s)})}function ce(t,e,n){function s(r,i){}return s.type="xsnapshot.sendTo",s.to=t,s.event=e,s.id=n==null?void 0:n.id,s.delay=n==null?void 0:n.delay,s.resolve=ds,s.retryResolve=hs,s.execute=ps,s}const ue=new WeakMap;function j(t,e,n){let s=ue.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},ue.set(t,s)),s[e]}const ys={},J=t=>typeof t=="string"?{type:t}:typeof t=="function"?"resolve"in t?{type:t.type}:{type:t.name}:t;class $t{constructor(e,n){if(this.config=e,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(Te),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?Zt(this.config.states,(s,r)=>new $t(s,{_parent:this,_key:r,_machine:this.machine})):ys,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(e.tags).slice()}_initialize(){this.transitions=Nn(this),this.config.always&&(this.always=N(this.config.always).map(e=>P(this,ve,e))),Object.keys(this.states).forEach(e=>{this.states[e]._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(J),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(J),eventType:null})}:void 0,history:this.history,states:Zt(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(J)})),entry:this.entry.map(J),exit:this.exit.map(J),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 j(this,"invoke",()=>I(this.config.invoke).map((e,n)=>{const{src:s,systemId:r}=e,i=e.id??te(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${te(this.id,n)}`;return{...e,src:o,id:i,systemId:r,toJSON(){const{onDone:a,onError:u,...c}=e;return{...c,type:"xstate.invoke",src:o,id:i}}}}))}get on(){return j(this,"on",()=>[...this.transitions].flatMap(([n,s])=>s.map(r=>[n,r])).reduce((n,[s,r])=>(n[s]=n[s]||[],n[s].push(r),n),{}))}get after(){return j(this,"delayedTransitions",()=>jn(this))}get initial(){return j(this,"initial",()=>$n(this,this.config.initial))}next(e,n){const s=n.type,r=[];let i;const o=j(this,`candidates-${s}`,()=>Un(this,s));for(const a of o){const{guard:u}=a,c=e.context;let l=!1;try{l=!u||Dt(u,c,n,e)}catch(f){const p=typeof u=="string"?u:typeof u=="object"?u.type:void 0;throw new Error(`Unable to evaluate guard ${p?`'${p}' `:""}in transition for event '${s}' in state node '${this.id}':
3
- ${f.message}`)}if(l){r.push(...a.actions),i=a;break}}return i?[i]:void 0}get events(){return j(this,"events",()=>{const{states:e}=this,n=new Set(this.ownEvents);if(e)for(const s of Object.keys(e)){const r=e[s];if(r.states)for(const i of r.events)n.add(`${i}`)}return Array.from(n)})}get ownEvents(){const e=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(e)}}const ms="#";class Lt{constructor(e,n){this.config=e,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=e.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 $t(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(e){const{actions:n,guards:s,actors:r,delays:i}=this.implementations;return new Lt(this.config,{actions:{...n,...e.actions},guards:{...s,...e.guards},actors:{...r,...e.actors},delays:{...i,...e.delays}})}resolveState(e){const n=Zn(this.root,e.value),s=rt(ot(this.root,n));return Q({_nodes:[...s],context:e.context||{},children:{},status:Ut(s,this.root)?"done":e.status||"active",output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,n,s){return yt(e,n,s).snapshot}microstep(e,n,s){return yt(e,n,s).microstates}getTransitionData(e,n){return jt(this.root,e.value,e,n)||[]}getPreInitialState(e,n,s){const{context:r}=this.config,i=Q({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?H(i,n,e,[v(({spawn:a,event:u,self:c})=>r({spawn:a,input:u.input,self:c}))],s):i}getInitialSnapshot(e,n){const s=xe(n),r=[],i=this.getPreInitialState(e,s,r),o=bt([{target:[...je(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,e,s,!0,r),{snapshot:a}=yt(o,s,e,r);return a}start(e){Object.values(e.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(e){const n=It(e),s=n.slice(1),r=ct(n[0])?n[0].slice(ms.length):n[0],i=this.idMap.get(r);if(!i)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return it(i,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,n){return is(e,n)}restoreSnapshot(e,n){const s={},r=e.children;Object.keys(r).forEach(u=>{const c=r[u],l=c.snapshot,f=c.src,p=typeof f=="string"?Ct(this,f):f;if(!p)return;const y=L(p,{id:u,parent:n.self,syncSnapshot:c.syncSnapshot,snapshot:l,src:f,systemId:c.systemId});s[u]=y});const i=Q({...e,children:s,_nodes:Array.from(rt(ot(this.root,e.value)))},this);let o=new Set;function a(u,c){if(!o.has(u)){o.add(u);for(let l in u){const f=u[l];if(f&&typeof f=="object"){if("xstate$$type"in f&&f.xstate$$type===Pt){u[l]=c[f.id];continue}a(f,c)}}}}return a(i.context,s),i}}function gs(t,e){return new Lt(t,e)}function Bt({schemas:t,actors:e,actions:n,guards:s,delays:r}){return{createMachine:i=>gs({...i,schemas:t},{actors:e,actions:n,guards:s,delays:r})}}function He(t,e){return function(){return t.apply(e,arguments)}}const{toString:Ss}=Object.prototype,{getPrototypeOf:Ft}=Object,ut=(t=>e=>{const n=Ss.call(e);return t[n]||(t[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),A=t=>(t=t.toLowerCase(),e=>ut(e)===t),ft=t=>e=>typeof e===t,{isArray:z}=Array,V=ft("undefined");function Es(t){return t!==null&&!V(t)&&t.constructor!==null&&!V(t.constructor)&&T(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const qe=A("ArrayBuffer");function ws(t){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&qe(t.buffer),e}const _s=ft("string"),T=ft("function"),ze=ft("number"),lt=t=>t!==null&&typeof t=="object",Ts=t=>t===!0||t===!1,tt=t=>{if(ut(t)!=="object")return!1;const e=Ft(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)},vs=A("Date"),bs=A("File"),As=A("Blob"),xs=A("FileList"),Rs=t=>lt(t)&&T(t.pipe),Os=t=>{let e;return t&&(typeof FormData=="function"&&t instanceof FormData||T(t.append)&&((e=ut(t))==="formdata"||e==="object"&&T(t.toString)&&t.toString()==="[object FormData]"))},ks=A("URLSearchParams"),Is=t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function X(t,e,{allOwnKeys:n=!1}={}){if(t===null||typeof t>"u")return;let s,r;if(typeof t!="object"&&(t=[t]),z(t))for(s=0,r=t.length;s<r;s++)e.call(null,t[s],s,t);else{const i=n?Object.getOwnPropertyNames(t):Object.keys(t),o=i.length;let a;for(s=0;s<o;s++)a=i[s],e.call(null,t[a],a,t)}}function Je(t,e){e=e.toLowerCase();const n=Object.keys(t);let s=n.length,r;for(;s-- >0;)if(r=n[s],e===r.toLowerCase())return r;return null}const We=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),Ke=t=>!V(t)&&t!==We;function At(){const{caseless:t}=Ke(this)&&this||{},e={},n=(s,r)=>{const i=t&&Je(e,r)||r;tt(e[i])&&tt(s)?e[i]=At(e[i],s):tt(s)?e[i]=At({},s):z(s)?e[i]=s.slice():e[i]=s};for(let s=0,r=arguments.length;s<r;s++)arguments[s]&&X(arguments[s],n);return e}const Cs=(t,e,n,{allOwnKeys:s}={})=>(X(e,(r,i)=>{n&&T(r)?t[i]=He(r,n):t[i]=r},{allOwnKeys:s}),t),Ps=t=>(t.charCodeAt(0)===65279&&(t=t.slice(1)),t),Ds=(t,e,n,s)=>{t.prototype=Object.create(e.prototype,s),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),n&&Object.assign(t.prototype,n)},Ms=(t,e,n,s)=>{let r,i,o;const a={};if(e=e||{},t==null)return e;do{for(r=Object.getOwnPropertyNames(t),i=r.length;i-- >0;)o=r[i],(!s||s(o,t,e))&&!a[o]&&(e[o]=t[o],a[o]=!0);t=n!==!1&&Ft(t)}while(t&&(!n||n(t,e))&&t!==Object.prototype);return e},Us=(t,e,n)=>{t=String(t),(n===void 0||n>t.length)&&(n=t.length),n-=e.length;const s=t.indexOf(e,n);return s!==-1&&s===n},js=t=>{if(!t)return null;if(z(t))return t;let e=t.length;if(!ze(e))return null;const n=new Array(e);for(;e-- >0;)n[e]=t[e];return n},Ns=(t=>e=>t&&e instanceof t)(typeof Uint8Array<"u"&&Ft(Uint8Array)),$s=(t,e)=>{const s=(t&&t[Symbol.iterator]).call(t);let r;for(;(r=s.next())&&!r.done;){const i=r.value;e.call(t,i[0],i[1])}},Ls=(t,e)=>{let n;const s=[];for(;(n=t.exec(e))!==null;)s.push(n);return s},Bs=A("HTMLFormElement"),Fs=t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,s,r){return s.toUpperCase()+r}),fe=(({hasOwnProperty:t})=>(e,n)=>t.call(e,n))(Object.prototype),Hs=A("RegExp"),Ve=(t,e)=>{const n=Object.getOwnPropertyDescriptors(t),s={};X(n,(r,i)=>{let o;(o=e(r,i,t))!==!1&&(s[i]=o||r)}),Object.defineProperties(t,s)},qs=t=>{Ve(t,(e,n)=>{if(T(t)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const s=t[n];if(T(s)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},zs=(t,e)=>{const n={},s=r=>{r.forEach(i=>{n[i]=!0})};return z(t)?s(t):s(String(t).split(e)),n},Js=()=>{},Ws=(t,e)=>(t=+t,Number.isFinite(t)?t:e),gt="abcdefghijklmnopqrstuvwxyz",le="0123456789",Ge={DIGIT:le,ALPHA:gt,ALPHA_DIGIT:gt+gt.toUpperCase()+le},Ks=(t=16,e=Ge.ALPHA_DIGIT)=>{let n="";const{length:s}=e;for(;t--;)n+=e[Math.random()*s|0];return n};function Vs(t){return!!(t&&T(t.append)&&t[Symbol.toStringTag]==="FormData"&&t[Symbol.iterator])}const Gs=t=>{const e=new Array(10),n=(s,r)=>{if(lt(s)){if(e.indexOf(s)>=0)return;if(!("toJSON"in s)){e[r]=s;const i=z(s)?[]:{};return X(s,(o,a)=>{const u=n(o,r+1);!V(u)&&(i[a]=u)}),e[r]=void 0,i}}return s};return n(t,0)},Xs=A("AsyncFunction"),Ys=t=>t&&(lt(t)||T(t))&&T(t.then)&&T(t.catch),d={isArray:z,isArrayBuffer:qe,isBuffer:Es,isFormData:Os,isArrayBufferView:ws,isString:_s,isNumber:ze,isBoolean:Ts,isObject:lt,isPlainObject:tt,isUndefined:V,isDate:vs,isFile:bs,isBlob:As,isRegExp:Hs,isFunction:T,isStream:Rs,isURLSearchParams:ks,isTypedArray:Ns,isFileList:xs,forEach:X,merge:At,extend:Cs,trim:Is,stripBOM:Ps,inherits:Ds,toFlatObject:Ms,kindOf:ut,kindOfTest:A,endsWith:Us,toArray:js,forEachEntry:$s,matchAll:Ls,isHTMLForm:Bs,hasOwnProperty:fe,hasOwnProp:fe,reduceDescriptors:Ve,freezeMethods:qs,toObjectSet:zs,toCamelCase:Fs,noop:Js,toFiniteNumber:Ws,findKey:Je,global:We,isContextDefined:Ke,ALPHABET:Ge,generateString:Ks,isSpecCompliantForm:Vs,toJSONObject:Gs,isAsyncFn:Xs,isThenable:Ys};function g(t,e,n,s,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=t,this.name="AxiosError",e&&(this.code=e),n&&(this.config=n),s&&(this.request=s),r&&(this.response=r)}d.inherits(g,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:d.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Xe=g.prototype,Ye={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{Ye[t]={value:t}});Object.defineProperties(g,Ye);Object.defineProperty(Xe,"isAxiosError",{value:!0});g.from=(t,e,n,s,r,i)=>{const o=Object.create(Xe);return d.toFlatObject(t,o,function(u){return u!==Error.prototype},a=>a!=="isAxiosError"),g.call(o,t.message,e,n,s,r),o.cause=t,o.name=t.name,i&&Object.assign(o,i),o};const Zs=null;function xt(t){return d.isPlainObject(t)||d.isArray(t)}function Ze(t){return d.endsWith(t,"[]")?t.slice(0,-2):t}function de(t,e,n){return t?t.concat(e).map(function(r,i){return r=Ze(r),!n&&i?"["+r+"]":r}).join(n?".":""):e}function Qs(t){return d.isArray(t)&&!t.some(xt)}const tr=d.toFlatObject(d,{},null,function(e){return/^is[A-Z]/.test(e)});function dt(t,e,n){if(!d.isObject(t))throw new TypeError("target must be an object");e=e||new FormData,n=d.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,S){return!d.isUndefined(S[m])});const s=n.metaTokens,r=n.visitor||l,i=n.dots,o=n.indexes,u=(n.Blob||typeof Blob<"u"&&Blob)&&d.isSpecCompliantForm(e);if(!d.isFunction(r))throw new TypeError("visitor must be a function");function c(h){if(h===null)return"";if(d.isDate(h))return h.toISOString();if(!u&&d.isBlob(h))throw new g("Blob is not supported. Use a Buffer instead.");return d.isArrayBuffer(h)||d.isTypedArray(h)?u&&typeof Blob=="function"?new Blob([h]):Buffer.from(h):h}function l(h,m,S){let E=h;if(h&&!S&&typeof h=="object"){if(d.endsWith(m,"{}"))m=s?m:m.slice(0,-2),h=JSON.stringify(h);else if(d.isArray(h)&&Qs(h)||(d.isFileList(h)||d.endsWith(m,"[]"))&&(E=d.toArray(h)))return m=Ze(m),E.forEach(function(Z,fn){!(d.isUndefined(Z)||Z===null)&&e.append(o===!0?de([m],fn,i):o===null?m:m+"[]",c(Z))}),!1}return xt(h)?!0:(e.append(de(S,m,i),c(h)),!1)}const f=[],p=Object.assign(tr,{defaultVisitor:l,convertValue:c,isVisitable:xt});function y(h,m){if(!d.isUndefined(h)){if(f.indexOf(h)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(h),d.forEach(h,function(E,O){(!(d.isUndefined(E)||E===null)&&r.call(e,E,d.isString(O)?O.trim():O,m,p))===!0&&y(E,m?m.concat(O):[O])}),f.pop()}}if(!d.isObject(t))throw new TypeError("data must be an object");return y(t),e}function he(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(s){return e[s]})}function Ht(t,e){this._pairs=[],t&&dt(t,this,e)}const Qe=Ht.prototype;Qe.append=function(e,n){this._pairs.push([e,n])};Qe.toString=function(e){const n=e?function(s){return e.call(this,s,he)}:he;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function er(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function tn(t,e,n){if(!e)return t;const s=n&&n.encode||er,r=n&&n.serialize;let i;if(r?i=r(e,n):i=d.isURLSearchParams(e)?e.toString():new Ht(e,n).toString(s),i){const o=t.indexOf("#");o!==-1&&(t=t.slice(0,o)),t+=(t.indexOf("?")===-1?"?":"&")+i}return t}class nr{constructor(){this.handlers=[]}use(e,n,s){return this.handlers.push({fulfilled:e,rejected:n,synchronous:s?s.synchronous:!1,runWhen:s?s.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){d.forEach(this.handlers,function(s){s!==null&&e(s)})}}const pe=nr,en={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},sr=typeof URLSearchParams<"u"?URLSearchParams:Ht,rr=typeof FormData<"u"?FormData:null,ir=typeof Blob<"u"?Blob:null,or=(()=>{let t;return typeof navigator<"u"&&((t=navigator.product)==="ReactNative"||t==="NativeScript"||t==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),ar=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),b={isBrowser:!0,classes:{URLSearchParams:sr,FormData:rr,Blob:ir},isStandardBrowserEnv:or,isStandardBrowserWebWorkerEnv:ar,protocols:["http","https","file","blob","url","data"]};function cr(t,e){return dt(t,new b.classes.URLSearchParams,Object.assign({visitor:function(n,s,r,i){return b.isNode&&d.isBuffer(n)?(this.append(s,n.toString("base64")),!1):i.defaultVisitor.apply(this,arguments)}},e))}function ur(t){return d.matchAll(/\w+|\[(\w*)]/g,t).map(e=>e[0]==="[]"?"":e[1]||e[0])}function fr(t){const e={},n=Object.keys(t);let s;const r=n.length;let i;for(s=0;s<r;s++)i=n[s],e[i]=t[i];return e}function nn(t){function e(n,s,r,i){let o=n[i++];const a=Number.isFinite(+o),u=i>=n.length;return o=!o&&d.isArray(r)?r.length:o,u?(d.hasOwnProp(r,o)?r[o]=[r[o],s]:r[o]=s,!a):((!r[o]||!d.isObject(r[o]))&&(r[o]=[]),e(n,s,r[o],i)&&d.isArray(r[o])&&(r[o]=fr(r[o])),!a)}if(d.isFormData(t)&&d.isFunction(t.entries)){const n={};return d.forEachEntry(t,(s,r)=>{e(ur(s),r,n,0)}),n}return null}function lr(t,e,n){if(d.isString(t))try{return(e||JSON.parse)(t),d.trim(t)}catch(s){if(s.name!=="SyntaxError")throw s}return(n||JSON.stringify)(t)}const qt={transitional:en,adapter:b.isNode?"http":"xhr",transformRequest:[function(e,n){const s=n.getContentType()||"",r=s.indexOf("application/json")>-1,i=d.isObject(e);if(i&&d.isHTMLForm(e)&&(e=new FormData(e)),d.isFormData(e))return r&&r?JSON.stringify(nn(e)):e;if(d.isArrayBuffer(e)||d.isBuffer(e)||d.isStream(e)||d.isFile(e)||d.isBlob(e))return e;if(d.isArrayBufferView(e))return e.buffer;if(d.isURLSearchParams(e))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let a;if(i){if(s.indexOf("application/x-www-form-urlencoded")>-1)return cr(e,this.formSerializer).toString();if((a=d.isFileList(e))||s.indexOf("multipart/form-data")>-1){const u=this.env&&this.env.FormData;return dt(a?{"files[]":e}:e,u&&new u,this.formSerializer)}}return i||r?(n.setContentType("application/json",!1),lr(e)):e}],transformResponse:[function(e){const n=this.transitional||qt.transitional,s=n&&n.forcedJSONParsing,r=this.responseType==="json";if(e&&d.isString(e)&&(s&&!this.responseType||r)){const o=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(a){if(o)throw a.name==="SyntaxError"?g.from(a,g.ERR_BAD_RESPONSE,this,null,this.response):a}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:b.classes.FormData,Blob:b.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};d.forEach(["delete","get","head","post","put","patch"],t=>{qt.headers[t]={}});const zt=qt,dr=d.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),hr=t=>{const e={};let n,s,r;return t&&t.split(`
4
- `).forEach(function(o){r=o.indexOf(":"),n=o.substring(0,r).trim().toLowerCase(),s=o.substring(r+1).trim(),!(!n||e[n]&&dr[n])&&(n==="set-cookie"?e[n]?e[n].push(s):e[n]=[s]:e[n]=e[n]?e[n]+", "+s:s)}),e},ye=Symbol("internals");function W(t){return t&&String(t).trim().toLowerCase()}function et(t){return t===!1||t==null?t:d.isArray(t)?t.map(et):String(t)}function pr(t){const e=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let s;for(;s=n.exec(t);)e[s[1]]=s[2];return e}const yr=t=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim());function St(t,e,n,s,r){if(d.isFunction(s))return s.call(this,e,n);if(r&&(e=n),!!d.isString(e)){if(d.isString(s))return e.indexOf(s)!==-1;if(d.isRegExp(s))return s.test(e)}}function mr(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,n,s)=>n.toUpperCase()+s)}function gr(t,e){const n=d.toCamelCase(" "+e);["get","set","has"].forEach(s=>{Object.defineProperty(t,s+n,{value:function(r,i,o){return this[s].call(this,e,r,i,o)},configurable:!0})})}class ht{constructor(e){e&&this.set(e)}set(e,n,s){const r=this;function i(a,u,c){const l=W(u);if(!l)throw new Error("header name must be a non-empty string");const f=d.findKey(r,l);(!f||r[f]===void 0||c===!0||c===void 0&&r[f]!==!1)&&(r[f||u]=et(a))}const o=(a,u)=>d.forEach(a,(c,l)=>i(c,l,u));return d.isPlainObject(e)||e instanceof this.constructor?o(e,n):d.isString(e)&&(e=e.trim())&&!yr(e)?o(hr(e),n):e!=null&&i(n,e,s),this}get(e,n){if(e=W(e),e){const s=d.findKey(this,e);if(s){const r=this[s];if(!n)return r;if(n===!0)return pr(r);if(d.isFunction(n))return n.call(this,r,s);if(d.isRegExp(n))return n.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,n){if(e=W(e),e){const s=d.findKey(this,e);return!!(s&&this[s]!==void 0&&(!n||St(this,this[s],s,n)))}return!1}delete(e,n){const s=this;let r=!1;function i(o){if(o=W(o),o){const a=d.findKey(s,o);a&&(!n||St(s,s[a],a,n))&&(delete s[a],r=!0)}}return d.isArray(e)?e.forEach(i):i(e),r}clear(e){const n=Object.keys(this);let s=n.length,r=!1;for(;s--;){const i=n[s];(!e||St(this,this[i],i,e,!0))&&(delete this[i],r=!0)}return r}normalize(e){const n=this,s={};return d.forEach(this,(r,i)=>{const o=d.findKey(s,i);if(o){n[o]=et(r),delete n[i];return}const a=e?mr(i):String(i).trim();a!==i&&delete n[i],n[a]=et(r),s[a]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const n=Object.create(null);return d.forEach(this,(s,r)=>{s!=null&&s!==!1&&(n[r]=e&&d.isArray(s)?s.join(", "):s)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,n])=>e+": "+n).join(`
5
- `)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...n){const s=new this(e);return n.forEach(r=>s.set(r)),s}static accessor(e){const s=(this[ye]=this[ye]={accessors:{}}).accessors,r=this.prototype;function i(o){const a=W(o);s[a]||(gr(r,o),s[a]=!0)}return d.isArray(e)?e.forEach(i):i(e),this}}ht.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);d.reduceDescriptors(ht.prototype,({value:t},e)=>{let n=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(s){this[n]=s}}});d.freezeMethods(ht);const R=ht;function Et(t,e){const n=this||zt,s=e||n,r=R.from(s.headers);let i=s.data;return d.forEach(t,function(a){i=a.call(n,i,r.normalize(),e?e.status:void 0)}),r.normalize(),i}function sn(t){return!!(t&&t.__CANCEL__)}function Y(t,e,n){g.call(this,t??"canceled",g.ERR_CANCELED,e,n),this.name="CanceledError"}d.inherits(Y,g,{__CANCEL__:!0});function Sr(t,e,n){const s=n.config.validateStatus;!n.status||!s||s(n.status)?t(n):e(new g("Request failed with status code "+n.status,[g.ERR_BAD_REQUEST,g.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}const Er=b.isStandardBrowserEnv?function(){return{write:function(n,s,r,i,o,a){const u=[];u.push(n+"="+encodeURIComponent(s)),d.isNumber(r)&&u.push("expires="+new Date(r).toGMTString()),d.isString(i)&&u.push("path="+i),d.isString(o)&&u.push("domain="+o),a===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(n){const s=document.cookie.match(new RegExp("(^|;\\s*)("+n+")=([^;]*)"));return s?decodeURIComponent(s[3]):null},remove:function(n){this.write(n,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}();function wr(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function _r(t,e){return e?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):t}function rn(t,e){return t&&!wr(e)?_r(t,e):e}const Tr=b.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");let s;function r(i){let o=i;return e&&(n.setAttribute("href",o),o=n.href),n.setAttribute("href",o),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return s=r(window.location.href),function(o){const a=d.isString(o)?r(o):o;return a.protocol===s.protocol&&a.host===s.host}}():function(){return function(){return!0}}();function vr(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function br(t,e){t=t||10;const n=new Array(t),s=new Array(t);let r=0,i=0,o;return e=e!==void 0?e:1e3,function(u){const c=Date.now(),l=s[i];o||(o=c),n[r]=u,s[r]=c;let f=i,p=0;for(;f!==r;)p+=n[f++],f=f%t;if(r=(r+1)%t,r===i&&(i=(i+1)%t),c-o<e)return;const y=l&&c-l;return y?Math.round(p*1e3/y):void 0}}function me(t,e){let n=0;const s=br(50,250);return r=>{const i=r.loaded,o=r.lengthComputable?r.total:void 0,a=i-n,u=s(a),c=i<=o;n=i;const l={loaded:i,total:o,progress:o?i/o:void 0,bytes:a,rate:u||void 0,estimated:u&&o&&c?(o-i)/u:void 0,event:r};l[e?"download":"upload"]=!0,t(l)}}const Ar=typeof XMLHttpRequest<"u",xr=Ar&&function(t){return new Promise(function(n,s){let r=t.data;const i=R.from(t.headers).normalize(),o=t.responseType;let a;function u(){t.cancelToken&&t.cancelToken.unsubscribe(a),t.signal&&t.signal.removeEventListener("abort",a)}d.isFormData(r)&&(b.isStandardBrowserEnv||b.isStandardBrowserWebWorkerEnv?i.setContentType(!1):i.setContentType("multipart/form-data;",!1));let c=new XMLHttpRequest;if(t.auth){const y=t.auth.username||"",h=t.auth.password?unescape(encodeURIComponent(t.auth.password)):"";i.set("Authorization","Basic "+btoa(y+":"+h))}const l=rn(t.baseURL,t.url);c.open(t.method.toUpperCase(),tn(l,t.params,t.paramsSerializer),!0),c.timeout=t.timeout;function f(){if(!c)return;const y=R.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders()),m={data:!o||o==="text"||o==="json"?c.responseText:c.response,status:c.status,statusText:c.statusText,headers:y,config:t,request:c};Sr(function(E){n(E),u()},function(E){s(E),u()},m),c=null}if("onloadend"in c?c.onloadend=f:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(f)},c.onabort=function(){c&&(s(new g("Request aborted",g.ECONNABORTED,t,c)),c=null)},c.onerror=function(){s(new g("Network Error",g.ERR_NETWORK,t,c)),c=null},c.ontimeout=function(){let h=t.timeout?"timeout of "+t.timeout+"ms exceeded":"timeout exceeded";const m=t.transitional||en;t.timeoutErrorMessage&&(h=t.timeoutErrorMessage),s(new g(h,m.clarifyTimeoutError?g.ETIMEDOUT:g.ECONNABORTED,t,c)),c=null},b.isStandardBrowserEnv){const y=(t.withCredentials||Tr(l))&&t.xsrfCookieName&&Er.read(t.xsrfCookieName);y&&i.set(t.xsrfHeaderName,y)}r===void 0&&i.setContentType(null),"setRequestHeader"in c&&d.forEach(i.toJSON(),function(h,m){c.setRequestHeader(m,h)}),d.isUndefined(t.withCredentials)||(c.withCredentials=!!t.withCredentials),o&&o!=="json"&&(c.responseType=t.responseType),typeof t.onDownloadProgress=="function"&&c.addEventListener("progress",me(t.onDownloadProgress,!0)),typeof t.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",me(t.onUploadProgress)),(t.cancelToken||t.signal)&&(a=y=>{c&&(s(!y||y.type?new Y(null,t,c):y),c.abort(),c=null)},t.cancelToken&&t.cancelToken.subscribe(a),t.signal&&(t.signal.aborted?a():t.signal.addEventListener("abort",a)));const p=vr(l);if(p&&b.protocols.indexOf(p)===-1){s(new g("Unsupported protocol "+p+":",g.ERR_BAD_REQUEST,t));return}c.send(r||null)})},nt={http:Zs,xhr:xr};d.forEach(nt,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const on={getAdapter:t=>{t=d.isArray(t)?t:[t];const{length:e}=t;let n,s;for(let r=0;r<e&&(n=t[r],!(s=d.isString(n)?nt[n.toLowerCase()]:n));r++);if(!s)throw s===!1?new g(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT"):new Error(d.hasOwnProp(nt,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`);if(!d.isFunction(s))throw new TypeError("adapter is not a function");return s},adapters:nt};function wt(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new Y(null,t)}function ge(t){return wt(t),t.headers=R.from(t.headers),t.data=Et.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),on.getAdapter(t.adapter||zt.adapter)(t).then(function(s){return wt(t),s.data=Et.call(t,t.transformResponse,s),s.headers=R.from(s.headers),s},function(s){return sn(s)||(wt(t),s&&s.response&&(s.response.data=Et.call(t,t.transformResponse,s.response),s.response.headers=R.from(s.response.headers))),Promise.reject(s)})}const Se=t=>t instanceof R?t.toJSON():t;function q(t,e){e=e||{};const n={};function s(c,l,f){return d.isPlainObject(c)&&d.isPlainObject(l)?d.merge.call({caseless:f},c,l):d.isPlainObject(l)?d.merge({},l):d.isArray(l)?l.slice():l}function r(c,l,f){if(d.isUndefined(l)){if(!d.isUndefined(c))return s(void 0,c,f)}else return s(c,l,f)}function i(c,l){if(!d.isUndefined(l))return s(void 0,l)}function o(c,l){if(d.isUndefined(l)){if(!d.isUndefined(c))return s(void 0,c)}else return s(void 0,l)}function a(c,l,f){if(f in e)return s(c,l);if(f in t)return s(void 0,c)}const u={url:i,method:i,data:i,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:a,headers:(c,l)=>r(Se(c),Se(l),!0)};return d.forEach(Object.keys(Object.assign({},t,e)),function(l){const f=u[l]||r,p=f(t[l],e[l],l);d.isUndefined(p)&&f!==a||(n[l]=p)}),n}const an="1.5.0",Jt={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{Jt[t]=function(s){return typeof s===t||"a"+(e<1?"n ":" ")+t}});const Ee={};Jt.transitional=function(e,n,s){function r(i,o){return"[Axios v"+an+"] Transitional option '"+i+"'"+o+(s?". "+s:"")}return(i,o,a)=>{if(e===!1)throw new g(r(o," has been removed"+(n?" in "+n:"")),g.ERR_DEPRECATED);return n&&!Ee[o]&&(Ee[o]=!0,console.warn(r(o," has been deprecated since v"+n+" and will be removed in the near future"))),e?e(i,o,a):!0}};function Rr(t,e,n){if(typeof t!="object")throw new g("options must be an object",g.ERR_BAD_OPTION_VALUE);const s=Object.keys(t);let r=s.length;for(;r-- >0;){const i=s[r],o=e[i];if(o){const a=t[i],u=a===void 0||o(a,i,t);if(u!==!0)throw new g("option "+i+" must be "+u,g.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new g("Unknown option "+i,g.ERR_BAD_OPTION)}}const Rt={assertOptions:Rr,validators:Jt},k=Rt.validators;class at{constructor(e){this.defaults=e,this.interceptors={request:new pe,response:new pe}}request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=q(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:i}=n;s!==void 0&&Rt.assertOptions(s,{silentJSONParsing:k.transitional(k.boolean),forcedJSONParsing:k.transitional(k.boolean),clarifyTimeoutError:k.transitional(k.boolean)},!1),r!=null&&(d.isFunction(r)?n.paramsSerializer={serialize:r}:Rt.assertOptions(r,{encode:k.function,serialize:k.function},!0)),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=i&&d.merge(i.common,i[n.method]);i&&d.forEach(["delete","get","head","post","put","patch","common"],h=>{delete i[h]}),n.headers=R.concat(o,i);const a=[];let u=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(u=u&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let l,f=0,p;if(!u){const h=[ge.bind(this),void 0];for(h.unshift.apply(h,a),h.push.apply(h,c),p=h.length,l=Promise.resolve(n);f<p;)l=l.then(h[f++],h[f++]);return l}p=a.length;let y=n;for(f=0;f<p;){const h=a[f++],m=a[f++];try{y=h(y)}catch(S){m.call(this,S);break}}try{l=ge.call(this,y)}catch(h){return Promise.reject(h)}for(f=0,p=c.length;f<p;)l=l.then(c[f++],c[f++]);return l}getUri(e){e=q(this.defaults,e);const n=rn(e.baseURL,e.url);return tn(n,e.params,e.paramsSerializer)}}d.forEach(["delete","get","head","options"],function(e){at.prototype[e]=function(n,s){return this.request(q(s||{},{method:e,url:n,data:(s||{}).data}))}});d.forEach(["post","put","patch"],function(e){function n(s){return function(i,o,a){return this.request(q(a||{},{method:e,headers:s?{"Content-Type":"multipart/form-data"}:{},url:i,data:o}))}}at.prototype[e]=n(),at.prototype[e+"Form"]=n(!0)});const st=at;class Wt{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(i){n=i});const s=this;this.promise.then(r=>{if(!s._listeners)return;let i=s._listeners.length;for(;i-- >0;)s._listeners[i](r);s._listeners=null}),this.promise.then=r=>{let i;const o=new Promise(a=>{s.subscribe(a),i=a}).then(r);return o.cancel=function(){s.unsubscribe(i)},o},e(function(i,o,a){s.reason||(s.reason=new Y(i,o,a),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}static source(){let e;return{token:new Wt(function(r){e=r}),cancel:e}}}const Or=Wt;function kr(t){return function(n){return t.apply(null,n)}}function Ir(t){return d.isObject(t)&&t.isAxiosError===!0}const Ot={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ot).forEach(([t,e])=>{Ot[e]=t});const Cr=Ot;function cn(t){const e=new st(t),n=He(st.prototype.request,e);return d.extend(n,st.prototype,e,{allOwnKeys:!0}),d.extend(n,e,null,{allOwnKeys:!0}),n.create=function(r){return cn(q(t,r))},n}const w=cn(zt);w.Axios=st;w.CanceledError=Y;w.CancelToken=Or;w.isCancel=sn;w.VERSION=an;w.toFormData=dt;w.AxiosError=g;w.Cancel=w.CanceledError;w.all=function(e){return Promise.all(e)};w.spread=kr;w.isAxiosError=Ir;w.mergeConfig=q;w.AxiosHeaders=R;w.formToJSON=t=>nn(d.isHTMLForm(t)?new FormData(t):t);w.getAdapter=on.getAdapter;w.HttpStatusCode=Cr;w.default=w;const Pr=w;async function we(t,e){const n=await fetch(t,e);return n.status===200?n.json():Promise.resolve({message:n.statusText,success:!1})}const kt=Bt({types:{context:{},events:{},input:{}},actions:{setUserContext:v(({context:t,event:e})=>{if(!e.type.includes("xstate.done.actor"))return t;const n=e;return n.output.type!=="AUTHENTICATE_SUCCESS"?t:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetUserContext:v(()=>({user:null,accessToken:"",refreshToken:"",ignoreRefreshToken:!1})),setAccessToken:v(({context:t,event:e})=>{if(!e.type.includes("xstate.done.actor"))return t;const n=e;return n.output.type!=="REFRESH_TOKEN_SUCCESS"?t:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetRefreshToken:v(()=>({refreshToken:""})),setIgnoreRefreshToken:v(()=>({ignoreRefreshToken:!0})),addError:v(({context:t,event:e})=>{if(!e.type.includes("xstate.error.actor"))return t;const n=e;return{errors:[...t.errors,String(n.error).replace("Error: ","")]}}),clearErrors:v(()=>({errors:[]}))},actors:{refreshAccessToken:mt(async({input:t})=>{let e;if(typeof window>"u"){if(t.context.refreshToken==="")throw new Error("Unauthorized.");try{const n=await Pr.post(t.context.endpoints.ssrRefresh,{},{headers:{Cookie:`refresh_token=${t.context.refreshToken}`,"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},withCredentials:!0});console.log("refreshAccessToken axios res",n);const{data:s}=n;if(console.log("refreshAccessToken axios res.data",s),typeof s.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:s.accessToken}}catch(n){throw console.log(n),new Error("Could not complete refresh request (server)")}}else{e=await we(t.context.endpoints.refresh,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({grant_type:"refresh_token"}).toString()}),console.log("refreshAccessToken fetch response",e);const n=e;if(typeof n.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:n.accessToken}}}),authenticate:mt(async({input:t})=>{var s;const n=await we(t.context.endpoints.login,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({username:t.username,password:t.password}).toString()});if(!n.success)throw new Error(((s=n.message)==null?void 0:s.toString())??"Sign in failed. Please try again.");return{type:"AUTHENTICATE_SUCCESS",accessToken:n.accessToken}}),unauthenticate:mt(async({input:t})=>(await fetch(t.context.endpoints.logout,{method:"POST",mode:"cors",credentials:"include",headers:{"clicktap-scope":"view","clicktap-scope-id":"default"}}),{type:"UNAUTHENTICATE"}))}}).createMachine({id:"auth",context:({input:t})=>{var e,n;return{user:null,accessToken:"",refreshToken:((e=t==null?void 0:t.initialContext)==null?void 0:e.refreshToken)??"",ignoreRefreshToken:!1,endpoints:((n=t==null?void 0:t.initialContext)==null?void 0:n.endpoints)??{login:"",logout:"",refresh:"",ssrRefresh:""},errors:[]}},initial:"refreshing",states:{authenticating:{invoke:{src:"authenticate",input:({context:t,event:e})=>e.type!=="LOGIN"?{context:t,username:"",password:""}:{context:t,username:e.username,password:e.password},onDone:[{actions:"setUserContext",target:"loggedIn"}],onError:[{actions:"addError",target:"loggedOut"}]}},unauthenticating:{invoke:{src:"unauthenticate",input:({context:t})=>({context:t}),onDone:[{actions:"unsetUserContext",target:"loggedOut"}],onError:[{actions:["unsetUserContext","setIgnoreRefreshToken"],target:"loggedOut"}]}},refreshing:{invoke:{src:"refreshAccessToken",input:({context:t})=>({context:t}),onDone:[{actions:["unsetRefreshToken","setAccessToken"],target:"loggedIn"}],onError:[{actions:"unsetRefreshToken",target:"unauthenticating"}]}},loggedOut:{on:{LOGIN:{target:"authenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}},loggedIn:{after:{84e4:{guard:()=>typeof window<"u",target:"refreshing"}},on:{LOGOUT:{target:"unauthenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}}}}),Kt=M.createContext({}),Dr=()=>{const t=M.useContext(Kt),[e,n]=M.useState(typeof window<"u"&&t.getSnapshot().value==="loggedIn");return M.useEffect(()=>{if(typeof window>"u")return;const s=t.subscribe(r=>{(r.value==="loggedIn"||r.value==="loggedOut")&&n(r.value==="loggedIn")});return()=>{s.unsubscribe()}},[t]),{authActor:t,isLoggedIn:e}},Mr=async(t="",e={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),L(kt,{inspect:e.inspect,input:{initialContext:{endpoints:e.endpoints}}}).start()):L(kt,{input:{initialContext:{endpoints:e.endpoints,refreshToken:t}},inspect:e.inspect}).start();function Ur({actor:t,children:e}){return _e.jsx(Kt.Provider,{value:t,children:e})}let jr=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,n)=>(n&=63,n<36?e+=n.toString(36):n<62?e+=(n-26).toString(36).toUpperCase():n>62?e+="-":e+="_",e),"");const un=Bt({actors:{tick:us(({sendBack:t,input:e})=>{const n=setInterval(()=>{t({type:"TICK"})},e.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:t})=>({elapsed:0,duration:t.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:t})=>t.elapsed<t.duration}}},running:{invoke:{input:({context:t})=>({interval:t.interval}),src:"tick"},always:[{target:"completed",guard:({context:t})=>t.elapsed>=t.duration}],on:{TICK:{actions:v(({context:t,event:e})=>e.type!=="TICK"?t:{elapsed:t.elapsed+t.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),Nr=Bt({actors:{timer:un},types:{context:{},events:{},input:{}},actions:{addItem:v(({context:t,event:e})=>{if(e.type!=="ADD_ITEM")return t;const n=`notification-${jr()}`,s=e.duration??t.duration,r=M.cloneElement(e.item,{duration:s,id:n,key:e.item.key??n,...e.item.props}),i={duration:s,id:n,element:r},o=t.items;return t.order==="desc"?o.push(i):o.unshift(i),{items:o,activeItem:n}}),removeItem:v(({context:t,event:e})=>{if(e.type!=="REMOVE_ITEM"&&e.type!=="xstate.done.actor.timer")return t;const n=t.items;return t.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:t})=>t.items[t.items.length-1].duration??t.duration},guards:{itemHasTimeout:({context:t})=>t.items[t.items.length-1].duration>0||t.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{id:"timer",src:"timer",input:({context:t})=>({initialContext:{duration:t.items[t.items.length-1].duration??t.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:ce("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:ce("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),Vt=M.createContext({}),$r=()=>M.useContext(Vt);function Lr({children:t,actor:e}){return _e.jsx(Vt.Provider,{value:e,children:t})}exports.AuthContext=Kt;exports.AuthProvider=Ur;exports.ToastContext=Vt;exports.ToastProvider=Lr;exports.authMachine=kt;exports.getAuth=Mr;exports.timerMachine=un;exports.toastMachine=Nr;exports.useAuth=Dr;exports.useToast=$r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const xt=require("react/jsx-runtime"),x=require("react");function Yt(){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 Vt(){const e=Yt();if(e.__xstate__)return e.__xstate__}const Zt=e=>{if(typeof window>"u")return;const t=Vt();t&&t.register(e)};class dt{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 kt=".",Ft="",bt="",Nt="#",Qt="*",At="xstate.init",te="xstate.error",D="xstate.stop";function ee(e,t){return{type:`xstate.after.${e}.${t}`}}function K(e,t){return{type:`xstate.done.state.${e}`,output:t}}function ne(e,t){return{type:`xstate.done.actor.${e}`,output:t}}function Rt(e,t){return{type:`xstate.error.actor.${e}`,error:t}}function Ct(e){return{type:At,input:e}}function S(e){setTimeout(()=>{throw e})}const se=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function ft(e,t){return`${e.sessionId}.${t}`}let ie=0;function re(e,t){const n=new Map,s=new Map,i=new WeakMap,r=new Set,o={},c=t.clock,a={schedule:(u,h,l,p,y=Math.random().toString(36).slice(2))=>{const g={source:u,target:h,event:l,delay:p,id:y,startedAt:Date.now()},_=ft(u,y);f._snapshot._scheduledEvents[_]=g;const Xt=c.setTimeout(()=>{delete o[_],delete f._snapshot._scheduledEvents[_],f._relay(u,h,l)},p);o[_]=Xt},cancel:(u,h)=>{const l=ft(u,h),p=o[l];delete o[l],delete f._snapshot._scheduledEvents[l],c.clearTimeout(p)},cancelAll:u=>{for(const h in f._snapshot._scheduledEvents){const l=f._snapshot._scheduledEvents[h];l.source===u&&a.cancel(u,l.id)}}},d=u=>{if(!r.size)return;const h={...u,rootId:e.sessionId};r.forEach(l=>{var p;return(p=l.next)==null?void 0:p.call(l,h)})},f={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${ie++}`,_register:(u,h)=>(n.set(u,h),u),_unregister:u=>{n.delete(u.sessionId);const h=i.get(u);h!==void 0&&(s.delete(h),i.delete(u))},get:u=>s.get(u),_set:(u,h)=>{const l=s.get(u);if(l&&l!==h)throw new Error(`Actor with system ID '${u}' already exists.`);s.set(u,h),i.set(h,u)},inspect:u=>{r.add(u)},_sendInspectionEvent:d,_relay:(u,h,l)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:u,actorRef:h,event:l}),h._send(l)},scheduler:a,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const u=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const h in u){const{source:l,target:p,event:y,delay:g,id:_}=u[h];a.schedule(l,p,y,g,_)}}};return f}function Mt(e,t){const n=ht(e),s=ht(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?Mt(n[i],s[i]):!1)}function F(e){if(Ot(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 ht(e){if(Ue(e))return e.value;if(typeof e!="string")return e;const t=F(e);return oe(t)}function oe(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 lt(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 $t(e){return Ot(e)?e:[e]}function T(e){return e===void 0?[]:$t(e)}function X(e,t,n,s){return typeof e=="function"?e({context:t,event:n,self:s}):e}function Ot(e){return Array.isArray(e)}function ce(e){return e.type.startsWith("xstate.error.actor")}function A(e){return $t(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function jt(e){if(!(e===void 0||e===Ft))return T(e)}function pt(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 yt(e,t){return`${t}.${e}`}function N(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 Q=1;let m=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const ae={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class ue{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 dt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=m.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={...ae,...n},{clock:i,logger:r,parent:o,syncSnapshot:c,id:a,systemId:d,inspect:f}=s;this.system=o?o.system:re(this,{clock:i}),f&&!o&&this.system.inspect(pt(f)),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 h=this.eventListeners.get(u.type);if(h)for(const l of Array.from(h))l(u)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),d&&(this._systemId=d,this.system._set(d,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),d&&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){S(c)}break;case"done":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(c){S(c)}this._stopProcedure(),this._complete(),this._doneEvent=ne(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=pt(t,n,s);if(this._processingStatus!==m.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{(r=i.complete)==null||r.call(i)}catch(o){S(o)}break;case"error":{const o=this._snapshot.error;if(!i.error)S(o);else try{i.error(o)}catch(c){S(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===m.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=m.Running;const t=Ct(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===D&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===m.Stopped?this:(this.mailbox.clear(),this._processingStatus===m.NotStarted?(this._processingStatus=m.Stopped,this):(this.mailbox.enqueue({type:D}),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){S(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||S(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){S(r)}}this.observers.clear(),n&&S(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Rt(this.id,t))}_stopProcedure(){return this._processingStatus!==m.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new dt(this._process.bind(this)),this._processingStatus=m.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==m.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:Zt)(this)}toJSON(){return{xstate$$type:Q,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[se](){return this}getSnapshot(){return this._snapshot}}function C(e,...[t]){return new ue(e,t)}function de(e,t,n,s,{sendId:i}){const r=typeof i=="function"?i(n,s):i;return[t,r]}function fe(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function he(e){function t(n,s){}return t.type="xstate.cancel",t.sendId=e,t.resolve=de,t.execute=fe,t}function le(e,t,n,s,{id:i,systemId:r,src:o,input:c,syncSnapshot:a}){const d=typeof o=="string"?N(t.machine,o):o,f=typeof i=="function"?i(n):i;let u;return d&&(u=C(d,{id:f,src:o,parent:e.self,syncSnapshot:a,systemId:r,input:typeof c=="function"?c({context:t.context,event:n.event,self:e.self}):c})),[k(t,{children:{...t.children,[f]:u}}),{id:i,actorRef:u}]}function pe(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==m.Stopped&&n.start()})}function ye(...[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=le,r.execute=pe,r}function ge(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]),[k(t,{children:c}),o]}function me(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==m.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Dt(e){function t(n,s){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=ge,t.execute=me,t}function tt(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 tt(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 et=e=>e.type==="atomic"||e.type==="final";function M(e){return Object.values(e.states).filter(t=>t.type!=="history")}function U(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 L(e){const t=new Set(e),n=Pt(t);for(const s of t)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))gt(s).forEach(i=>t.add(i));else if(s.type==="parallel"){for(const i of M(s))if(i.type!=="history"&&!t.has(i)){const r=gt(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 Ut(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const i=n[0];if(i){if(et(i))return i.key}else return{}}const s={};for(const i of n)s[i.key]=Ut(i,t);return s}function Pt(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 Lt(e,t){const n=L(t);return Ut(e,Pt(n))}function nt(e,t){return t.type==="compound"?M(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?M(t).every(n=>nt(e,n)):t.type==="final"}const G=e=>e[0]===Nt;function ve(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(s=>{if(s===Qt)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 _e(e){const t=e.config.after;if(!t)return[];const n=(i,r)=>{const o=ee(i,e.id),c=o.type;return e.entry.push(We(o,{id:c,delay:i})),e.exit.push(he(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,d=n(a);return T(c).map(f=>({...f,event:d,delay:a}))}).map(i=>{const{delay:r}=i;return{...w(e,i.event,i),delay:r}})}function w(e,t,n){const s=jt(n.target),i=n.reenter??!1,r=Ee(e,s),o={...n,actions:T(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 Se(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===bt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=e.config.on[n];t.set(n,A(s).map(i=>w(e,n,i)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,A(e.config.onDone).map(s=>w(e,n,s)))}for(const n of e.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;t.set(s,A(n.onDone).map(i=>w(e,s,i)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;t.set(s,A(n.onError).map(i=>w(e,s,i)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;t.set(s,A(n.onSnapshot).map(i=>w(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 Te(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"?[]:T(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return s}function Ee(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(G(n))return e.machine.getStateNodeById(n);const s=n[0]===kt;if(s&&!e.parent)return J(e,n.slice(1));const i=s?e.key+n:n;if(e.parent)try{return J(e.parent,i)}catch(r){throw new Error(`Invalid transition definition for state node '${e.id}':
2
+ ${r.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Jt(e){const t=jt(e.config.target);return t?{target:t.map(n=>typeof n=="string"?J(e.parent,n):n)}:e.parent.initial}function I(e){return e.type==="history"}function gt(e){const t=zt(e);for(const n of t)for(const s of U(n,e))t.add(s);return t}function zt(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 M(s))n(i)}}return n(e),t}function $(e,t){if(G(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 J(e,t){if(typeof t=="string"&&G(t))try{return e.machine.getStateNodeById(t)}catch{}const n=F(t).slice();let s=e;for(;n.length;){const i=n.shift();if(!i.length)break;s=$(s,i)}return s}function z(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=>$(e,i)).filter(Boolean);return[e.machine.root,e].concat(s,n.reduce((i,r)=>{const o=$(e,r);if(!o)return i;const c=z(o,t[r]);return i.concat(c)},[]))}function we(e,t,n,s){const r=$(e,t).next(n,s);return!r||!r.length?e.next(n,s):r}function Ie(e,t,n,s){const i=Object.keys(t),r=$(e,i[0]),o=st(r,t[i[0]],n,s);return!o||!o.length?e.next(n,s):o}function xe(e,t,n,s){const i=[];for(const r of Object.keys(t)){const o=t[r];if(!o)continue;const c=$(e,r),a=st(c,o,n,s);a&&i.push(...a)}return i.length?i:e.next(n,s)}function st(e,t,n,s){return typeof t=="string"?we(e,t,n,s):Object.keys(t).length===1?Ie(e,t,n,s):xe(e,t,n,s)}function ke(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function E(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function be(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 Gt(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(be(Y([i],t,n),Y([c],t,n)))if(E(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 Ae(e){const[t,...n]=e;for(const s of U(t,void 0))if(n.every(i=>E(i,s)))return s}function it(e,t){if(!e.target)return[];const n=new Set;for(const s of e.target)if(I(s))if(t[s.id])for(const i of t[s.id])n.add(i);else for(const i of it(Jt(s),t))n.add(i);else n.add(s);return[...n]}function qt(e,t){const n=it(e,t);if(!n)return;if(!e.reenter&&n.every(i=>i===e.source||E(i,e.source)))return e.source;const s=Ae(n.concat(e.source));if(s)return s;if(!e.reenter)return e.source.machine.root}function Y(e,t,n){var i;const s=new Set;for(const r of e)if((i=r.target)!=null&&i.length){const o=qt(r,n);r.reenter&&r.source===o&&s.add(o);for(const c of t)E(c,o)&&s.add(c)}return[...s]}function Re(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function V(e,t,n,s,i,r){if(!e.length)return t;const o=new Set(t._nodes);let c=t.historyValue;const a=Gt(e,o,c);let d=t;i||([d,c]=Oe(d,s,n,a,o,c,r)),d=O(d,s,n,a.flatMap(u=>u.actions),r),d=Me(d,s,n,a,o,r,c,i);const f=[...o];d.status==="done"&&(d=O(d,s,n,f.sort((u,h)=>h.order-u.order).flatMap(u=>u.exit),r));try{return c===t.historyValue&&Re(t._nodes,o)?d:k(d,{_nodes:f,historyValue:c})}catch(u){throw u}}function Ce(e,t,n,s,i){if(s.output===void 0)return;const r=K(i.id,i.output!==void 0&&i.parent?X(i.output,e.context,t,n.self):void 0);return X(s.output,e.context,r,n.self)}function Me(e,t,n,s,i,r,o,c){let a=e;const d=new Set,f=new Set;$e(s,o,f,d),c&&f.add(e.machine.root);const u=new Set;for(const h of[...d].sort((l,p)=>l.order-p.order)){i.add(h);const l=[];l.push(...h.entry);for(const p of h.invoke)l.push(ye(p.src,{...p,syncSnapshot:!!p.onSnapshot}));if(f.has(h)){const p=h.initial.actions;l.push(...p)}if(a=O(a,t,n,l,r,h.invoke.map(p=>p.id)),h.type==="final"){const p=h.parent;let y=(p==null?void 0:p.type)==="parallel"?p:p==null?void 0:p.parent,g=y||h;for((p==null?void 0:p.type)==="compound"&&r.push(K(p.id,h.output!==void 0?X(h.output,a.context,t,n.self):void 0));(y==null?void 0:y.type)==="parallel"&&!u.has(y)&&nt(i,y);)u.add(y),r.push(K(y.id)),g=y,y=y.parent;if(y)continue;a=k(a,{status:"done",output:Ce(a,t,n,a.machine.root,g)})}}return a}function $e(e,t,n,s){for(const i of e){const r=qt(i,t);for(const c of i.target||[])!I(c)&&(i.source!==c||i.source!==r||i.reenter)&&(s.add(c),n.add(c)),R(c,t,n,s);const o=it(i,t);for(const c of o){const a=U(c,r);(r==null?void 0:r.type)==="parallel"&&a.push(r),Bt(s,t,n,a,!i.source.parent&&i.reenter?void 0:r)}}}function R(e,t,n,s){var i;if(I(e))if(t[e.id]){const r=t[e.id];for(const o of r)s.add(o),R(o,t,n,s);for(const o of r)q(o,e.parent,s,t,n)}else{const r=Jt(e);for(const o of r.target)s.add(o),r===((i=e.parent)==null?void 0:i.initial)&&n.add(e.parent),R(o,t,n,s);for(const o of r.target)q(o,e.parent,s,t,n)}else if(e.type==="compound"){const[r]=e.initial.target;I(r)||(s.add(r),n.add(r)),R(r,t,n,s),q(r,e,s,t,n)}else if(e.type==="parallel")for(const r of M(e).filter(o=>!I(o)))[...s].some(o=>E(o,r))||(I(r)||(s.add(r),n.add(r)),R(r,t,n,s))}function Bt(e,t,n,s,i){for(const r of s)if((!i||E(r,i))&&e.add(r),r.type==="parallel")for(const o of M(r).filter(c=>!I(c)))[...e].some(c=>E(c,o))||(e.add(o),R(o,t,n,e))}function q(e,t,n,s,i){Bt(n,s,i,U(e,t))}function Oe(e,t,n,s,i,r,o){let c=e;const a=Y(s,i,r);a.sort((f,u)=>u.order-f.order);let d;for(const f of a)for(const u of ke(f)){let h;u.history==="deep"?h=l=>et(l)&&E(l,f):h=l=>l.parent===f,d??(d={...r}),d[u.id]=Array.from(i).filter(h)}for(const f of a)c=O(c,t,n,[...f.exit,...f.invoke.map(u=>Dt(u.id))],o),i.delete(f);return[c,d||r]}function Ht(e,t,n,s,i,r){const{machine:o}=e;let c=e;for(const a of s){let l=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:h}}),f(u,h)};const d=typeof a=="function",f=d?a:o.implementations.actions[typeof a=="string"?a:a.type];if(!f)continue;const u={context:c.context,event:t,self:n.self,system:n.system},h=d||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 f)){n.self._processingStatus===m.Running?l():n.defer(()=>{l()});continue}const p=f,[y,g,_]=p.resolve(n,c,u,h,f,i);c=y,"retryResolve"in p&&(r==null||r.push([p,g])),"execute"in p&&(n.self._processingStatus===m.Running?p.execute(n,g):n.defer(p.execute.bind(null,n,g))),_&&(c=Ht(c,t,n,_,i,r))}return c}function O(e,t,n,s,i,r){const o=r?[]:void 0,c=Ht(e,t,n,s,{internalQueue:i,deferredActorIds:r},o);return o==null||o.forEach(([a,d])=>{a.retryResolve(n,c,d)}),c}function B(e,t,n,s=[]){let i=e;const r=[];function o(d,f,u){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:f,snapshot:d,_transitions:u}),r.push(d)}if(t.type===D)return i=k(mt(i,t,n),{status:"stopped"}),o(i,t,[]),{snapshot:i,microstates:r};let c=t;if(c.type!==At){const d=c,f=ce(d),u=vt(d,i);if(f&&!u.length)return i=k(e,{status:"error",error:d.error}),o(i,d,[]),{snapshot:i,microstates:r};i=V(u,e,n,c,!1,s),o(i,d,u)}let a=!0;for(;i.status==="active";){let d=a?je(i,c):[];const f=d.length?i:void 0;if(!d.length){if(!s.length)break;c=s.shift(),d=vt(c,i)}i=V(d,i,n,c,!1,s),a=i!==f,o(i,c,d)}return i.status!=="active"&&mt(i,c,n),{snapshot:i,microstates:r}}function mt(e,t,n){return O(e,t,n,Object.values(e.children).map(s=>Dt(s)),[])}function vt(e,t){return t.machine.getTransitionData(t,e)}function je(e,t){const n=new Set,s=e._nodes.filter(et);for(const i of s)t:for(const r of[i].concat(U(i,void 0)))if(r.always){for(const o of r.always)if(o.guard===void 0||tt(o.guard,e.context,t,e)){n.add(o);break t}}return Gt(Array.from(n),new Set(e._nodes),e.historyValue)}function De(e,t){const n=L(z(e,t));return Lt(e,[...n])}function Ue(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const Pe=function(t){return Mt(t,this.value)},Le=function(t){return this.tags.has(t)},Je=function(t){const n=this.machine.getTransitionData(this,t);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},ze=function(){const{_nodes:t,tags:n,machine:s,getMeta:i,toJSON:r,can:o,hasTag:c,matches:a,...d}=this;return{...d,tags:Array.from(n)}},Ge=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function P(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Lt(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:Pe,hasTag:Le,can:Je,getMeta:Ge,toJSON:ze}}function k(e,t={}){return P({...e,...t},e.machine)}function qe(e,t){const{_nodes:n,tags:s,machine:i,children:r,context:o,can:c,hasTag:a,matches:d,getMeta:f,toJSON:u,...h}=e,l={};for(const y in r){const g=r[y];l[y]={snapshot:g.getPersistedSnapshot(t),src:g.src,systemId:g._systemId,syncSnapshot:g._syncSnapshot}}return{...h,context:Wt(o),children:l}}function Wt(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:Q,id:s.id};else{const i=Wt(s);i!==s&&(t??(t=Array.isArray(e)?e.slice():{...e}),t[n]=i)}}return t??e}function Be(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 d=typeof i=="function"?i(n,s):i;let f;if(typeof o=="string"){const u=a&&a[o];f=typeof u=="function"?u(n,s):u}else f=typeof o=="function"?o(n,s):o;return typeof f!="number"&&c.push(d),[t,{event:d,id:r,delay:f}]}function He(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 We(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=Be,n.execute=He,n}const _t=new WeakMap;function Ke(e){return{config:e,start:(n,s)=>{const{self:i,system:r}=s,o={receivers:void 0,dispose:void 0};_t.set(i,o),o.dispose=e({input:n.input,system:r,self:i,sendBack:c=>{i.getSnapshot().status!=="stopped"&&i._parent&&r._relay(i,i._parent,c)},receive:c=>{o.receivers??(o.receivers=new Set),o.receivers.add(c)}})},transition:(n,s,i)=>{var o,c;const r=_t.get(i.self);return s.type===D?(n={...n,status:"stopped",error:void 0},(o=r.dispose)==null||o.call(r),n):((c=r.receivers)==null||c.forEach(a=>a(s)),n)},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}const St="xstate.promise.resolve",Tt="xstate.promise.reject";function H(e){return{config:e,transition:(n,s)=>{if(n.status!=="active")return n;switch(s.type){case St:{const i=s.data;return{...n,status:"done",output:i,input:void 0}}case Tt:return{...n,status:"error",error:s.data,input:void 0};case D:return{...n,status:"stopped",input:void 0};default:return n}},start:(n,{self:s,system:i})=>{if(n.status!=="active")return;Promise.resolve(e({input:n.input,system:i,self:s})).then(o=>{s.getSnapshot().status==="active"&&i._relay(s,s,{type:St,data:o})},o=>{s.getSnapshot().status==="active"&&i._relay(s,s,{type:Tt,data:o})})},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}function Xe(e,{machine:t,context:n},s,i){const r=(o,c={})=>{const{systemId:a,input:d}=c;if(typeof o=="string"){const f=N(t,o);if(!f)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const u=C(f,{id:c.id,parent:e.self,syncSnapshot:c.syncSnapshot,input:typeof d=="function"?d({context:n,event:s,self:e.self}):d,src:o,systemId:a});return i[u.id]=u,u}else return C(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!==m.Stopped&&a.start()}),a}}function Ye(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:Xe(e,t,n.event,r),self:e.self,system:e.system};let c={};if(typeof i=="function")c=i(o,s);else for(const d of Object.keys(i)){const f=i[d];c[d]=typeof f=="function"?f(o,s):f}const a=Object.assign({},t.context,c);return[k(t,{context:a,children:Object.keys(r).length?{...t.children,...r}:t.children})]}function v(e){function t(n,s){}return t.type="xstate.assign",t.assignment=e,t.resolve=Ye,t}let Et=function(e){return e.Parent="#_parent",e.Internal="#_internal",e}({});function Ve(e,t,n,s,{to:i,event:r,id:o,delay:c},a){var p;const d=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 f=typeof r=="function"?r(n,s):r;let u;if(typeof c=="string"){const y=d&&d[c];u=typeof y=="function"?y(n,s):y}else u=typeof c=="function"?c(n,s):c;const h=typeof i=="function"?i(n,s):i;let l;if(typeof h=="string"){if(h===Et.Parent?l=e.self._parent:h===Et.Internal?l=e.self:h.startsWith("#_")?l=t.children[h.slice(2)]:l=(p=a.deferredActorIds)!=null&&p.includes(h)?h:t.children[h],!l)throw new Error(`Unable to send event to actor '${h}' from machine '${t.machine.id}'.`)}else l=h||e.self;return[t,{to:l,event:f,id:o,delay:u}]}function Ze(e,t,n){typeof n.to=="string"&&(n.to=t.children[n.to])}function Fe(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===te?Rt(e.self.id,s.data):s)})}function wt(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=Ve,s.retryResolve=Ze,s.execute=Fe,s}const It=new WeakMap;function b(e,t,n){let s=It.get(e);return s?t in s||(s[t]=n()):(s={[t]:n()},It.set(e,s)),s[t]}const Ne={},j=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class rt{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(kt),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?lt(this.config.states,(s,i)=>new rt(s,{_parent:this,_key:i,_machine:this.machine})):Ne,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=T(this.config.entry).slice(),this.exit=T(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=T(t.tags).slice()}_initialize(){this.transitions=Se(this),this.config.always&&(this.always=A(this.config.always).map(t=>w(this,bt,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(j),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(j),eventType:null})}:void 0,history:this.history,states:lt(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(j)})),entry:this.entry.map(j),exit:this.exit.map(j),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 b(this,"invoke",()=>T(this.config.invoke).map((t,n)=>{const{src:s,systemId:i}=t,r=t.id??yt(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${yt(this.id,n)}`;return{...t,src:o,id:r,systemId:i,toJSON(){const{onDone:c,onError:a,...d}=t;return{...d,type:"xstate.invoke",src:o,id:r}}}}))}get on(){return b(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 b(this,"delayedTransitions",()=>_e(this))}get initial(){return b(this,"initial",()=>Te(this,this.config.initial))}next(t,n){const s=n.type,i=[];let r;const o=b(this,`candidates-${s}`,()=>ve(this,s));for(const c of o){const{guard:a}=c,d=t.context;let f=!1;try{f=!a||tt(a,d,n,t)}catch(u){const h=typeof a=="string"?a:typeof a=="object"?a.type:void 0;throw new Error(`Unable to evaluate guard ${h?`'${h}' `:""}in transition for event '${s}' in state node '${this.id}':
3
+ ${u.message}`)}if(f){i.push(...c.actions),r=c;break}}return r?[r]:void 0}get events(){return b(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 Qe="#";class ot{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 rt(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 ot(this.config,{actions:{...n,...t.actions},guards:{...s,...t.guards},actors:{...i,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const n=De(this.root,t.value),s=L(z(this.root,n));return P({_nodes:[...s],context:t.context||{},children:{},status:nt(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,s){return B(t,n,s).snapshot}microstep(t,n,s){return B(t,n,s).microstates}getTransitionData(t,n){return st(this.root,t.value,t,n)||[]}getPreInitialState(t,n,s){const{context:i}=this.config,r=P({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?O(r,n,t,[v(({spawn:c,event:a,self:d})=>i({spawn:c,input:a.input,self:d}))],s):r}getInitialSnapshot(t,n){const s=Ct(n),i=[],r=this.getPreInitialState(t,s,i),o=V([{target:[...zt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,s,!0,i),{snapshot:c}=B(o,s,t,i);return c}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=F(t),s=n.slice(1),i=G(n[0])?n[0].slice(Qe.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 J(r,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return qe(t,n)}restoreSnapshot(t,n){const s={},i=t.children;Object.keys(i).forEach(a=>{const d=i[a],f=d.snapshot,u=d.src,h=typeof u=="string"?N(this,u):u;if(!h)return;const l=C(h,{id:a,parent:n.self,syncSnapshot:d.syncSnapshot,snapshot:f,src:u,systemId:d.systemId});s[a]=l});const r=P({...t,children:s,_nodes:Array.from(L(z(this.root,t.value)))},this);let o=new Set;function c(a,d){if(!o.has(a)){o.add(a);for(let f in a){const u=a[f];if(u&&typeof u=="object"){if("xstate$$type"in u&&u.xstate$$type===Q){a[f]=d[u.id];continue}c(u,d)}}}}return c(r.context,s),r}}function tn(e,t){return new ot(e,t)}function ct({schemas:e,actors:t,actions:n,guards:s,delays:i}){return{createMachine:r=>tn({...r,schemas:e},{actors:t,actions:n,guards:s,delays:i})}}async function W(e,t){const n=await fetch(e,t);return n.status===200?n.json():Promise.resolve({message:n.statusText,success:!1})}const Z=ct({types:{context:{},events:{},input:{}},actions:{setUserContext:v(({context:e,event:t})=>{if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="AUTHENTICATE_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetUserContext:v(()=>({user:null,accessToken:"",refreshToken:"",ignoreRefreshToken:!1})),setAccessToken:v(({context:e,event:t})=>{if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="REFRESH_TOKEN_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetRefreshToken:v(()=>({refreshToken:""})),setIgnoreRefreshToken:v(()=>({ignoreRefreshToken:!0})),addError:v(({context:e,event:t})=>{if(!t.type.includes("xstate.error.actor"))return e;const n=t;return{errors:[...e.errors,String(n.error).replace("Error: ","")]}}),clearErrors:v(()=>({errors:[]}))},actors:{refreshAccessToken:H(async({input:e})=>{let t;if(typeof window>"u"){if(e.context.refreshToken==="")throw new Error("Unauthorized.");try{const s=await W(e.context.endpoints.ssrRefresh,{method:"POST",mode:"cors",credentials:"include",headers:{Cookie:`refresh_token=${e.context.refreshToken}`,"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"}});if(typeof s.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:s.accessToken}}catch(n){throw console.log(n),new Error("Could not complete refresh request (server)")}}else{t=await W(e.context.endpoints.refresh,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({grant_type:"refresh_token"}).toString()});const n=t;if(typeof n.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:n.accessToken}}}),authenticate:H(async({input:e})=>{var s;const n=await W(e.context.endpoints.login,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({username:e.username,password:e.password}).toString()});if(!n.success)throw new Error(((s=n.message)==null?void 0:s.toString())??"Sign in failed. Please try again.");return{type:"AUTHENTICATE_SUCCESS",accessToken:n.accessToken}}),unauthenticate:H(async({input:e})=>(await fetch(e.context.endpoints.logout,{method:"POST",mode:"cors",credentials:"include",headers:{"clicktap-scope":"view","clicktap-scope-id":"default"}}),{type:"UNAUTHENTICATE"}))}}).createMachine({id:"auth",context:({input:e})=>{var t,n;return{user:null,accessToken:"",refreshToken:((t=e==null?void 0:e.initialContext)==null?void 0:t.refreshToken)??"",ignoreRefreshToken:!1,endpoints:((n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints)??{login:"",logout:"",refresh:"",ssrRefresh:""},errors:[]}},initial:"refreshing",states:{authenticating:{invoke:{src:"authenticate",input:({context:e,event:t})=>t.type!=="LOGIN"?{context:e,username:"",password:""}:{context:e,username:t.username,password:t.password},onDone:[{actions:"setUserContext",target:"loggedIn"}],onError:[{actions:"addError",target:"loggedOut"}]}},unauthenticating:{invoke:{src:"unauthenticate",input:({context:e})=>({context:e}),onDone:[{actions:"unsetUserContext",target:"loggedOut"}],onError:[{actions:["unsetUserContext","setIgnoreRefreshToken"],target:"loggedOut"}]}},refreshing:{invoke:{src:"refreshAccessToken",input:({context:e})=>({context:e}),onDone:[{actions:["unsetRefreshToken","setAccessToken"],target:"loggedIn"}],onError:[{actions:"unsetRefreshToken",target:"unauthenticating"}]}},loggedOut:{on:{LOGIN:{target:"authenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}},loggedIn:{after:{84e4:{guard:()=>typeof window<"u",target:"refreshing"}},on:{LOGOUT:{target:"unauthenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}}}}),at=x.createContext({}),en=()=>{const e=x.useContext(at),[t,n]=x.useState(typeof window<"u"&&e.getSnapshot().value==="loggedIn");return x.useEffect(()=>{if(typeof window>"u")return;const s=e.subscribe(i=>{(i.value==="loggedIn"||i.value==="loggedOut")&&n(i.value==="loggedIn")});return()=>{s.unsubscribe()}},[e]),{authActor:e,isLoggedIn:t}},nn=async(e="",t={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),C(Z,{inspect:t.inspect,input:{initialContext:{endpoints:t.endpoints}}}).start()):C(Z,{input:{initialContext:{endpoints:t.endpoints,refreshToken:e}},inspect:t.inspect}).start();function sn({actor:e,children:t}){return xt.jsx(at.Provider,{value:e,children:t})}let rn=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const Kt=ct({actors:{tick:Ke(({sendBack:e,input:t})=>{const n=setInterval(()=>{e({type:"TICK"})},t.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:e})=>({elapsed:0,duration:e.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:e})=>e.elapsed<e.duration}}},running:{invoke:{input:({context:e})=>({interval:e.interval}),src:"tick"},always:[{target:"completed",guard:({context:e})=>e.elapsed>=e.duration}],on:{TICK:{actions:v(({context:e,event:t})=>t.type!=="TICK"?e:{elapsed:e.elapsed+e.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),on=ct({actors:{timer:Kt},types:{context:{},events:{},input:{}},actions:{addItem:v(({context:e,event:t})=>{if(t.type!=="ADD_ITEM")return e;const n=`notification-${rn()}`,s=t.duration??e.duration,i=x.cloneElement(t.item,{duration:s,id:n,key:t.item.key??n,...t.item.props}),r={duration:s,id:n,element:i},o=e.items;return e.order==="desc"?o.push(r):o.unshift(r),{items:o,activeItem:n}}),removeItem:v(({context:e,event:t})=>{if(t.type!=="REMOVE_ITEM"&&t.type!=="xstate.done.actor.timer")return e;const n=e.items;return e.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:e})=>e.items[e.items.length-1].duration??e.duration},guards:{itemHasTimeout:({context:e})=>e.items[e.items.length-1].duration>0||e.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{id:"timer",src:"timer",input:({context:e})=>({initialContext:{duration:e.items[e.items.length-1].duration??e.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:wt("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:wt("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),ut=x.createContext({}),cn=()=>x.useContext(ut);function an({children:e,actor:t}){return xt.jsx(ut.Provider,{value:t,children:e})}exports.AuthContext=at;exports.AuthProvider=sn;exports.ToastContext=ut;exports.ToastProvider=an;exports.authMachine=Z;exports.getAuth=nn;exports.timerMachine=Kt;exports.toastMachine=on;exports.useAuth=en;exports.useToast=cn;