import{c as t}from"./p-35c4916d.js";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function n(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,i,o=r.call(t),a=[];try{for(;(void 0===n||n-- >0)&&!(e=o.next()).done;)a.push(e.value)}catch(t){i={error:t}}finally{try{e&&!e.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}var r;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(r||(r={}));var e={type:"xstate.init"};function i(t){return void 0===t?[]:[].concat(t)}function o(t,n){return"string"==typeof(t="string"==typeof t&&n&&n[t]?n[t]:t)?{type:t}:"function"==typeof t?{type:t.name,exec:t}:t}function a(t){return function(n){return t===n}}function f(t){return"string"==typeof t?{type:t}:t}function u(t,n){return{value:t,context:n,actions:[],changed:!1,matches:a(t)}}function c(t,n,r){var e=n,i=!1;return[t.filter((function(t){if("xstate.assign"===t.type){i=!0;var n=Object.assign({},e);return"function"==typeof t.assignment?n=t.assignment(e,r):Object.keys(t.assignment).forEach((function(i){n[i]="function"==typeof t.assignment[i]?t.assignment[i](e,r):t.assignment[i]})),e=n,!1}return!0})),e,i]}var s=function(t,n){return t.actions.forEach((function(r){var e=r.exec;return e&&e(t.context,n)}))};function d(t){var n=t.initialState,i=r.NotStarted,o=new Set,u={_machine:t,send:function(e){i===r.Running&&(n=t.transition(n,e),s(n,f(e)),o.forEach((function(t){return t(n)})))},subscribe:function(t){return o.add(t),t(n),{unsubscribe:function(){return o.delete(t)}}},start:function(o){if(o){var f="object"==typeof o?o:{context:t.config.context,value:o};n={value:f.value,actions:[],context:f.context,matches:a(f.value)}}return i=r.Running,s(n,e),u},stop:function(){return i=r.Stopped,o.clear(),u},get state(){return n},get status(){return i}};return u}const p=function(t,r){void 0===r&&(r={});var s=n(c(i(t.states[t.initial].entry).map((function(t){return o(t,r.actions)})),t.context,e),2),d={config:t,_options:r,initialState:{value:t.initial,actions:s[0],context:s[1],matches:a(t.initial)},transition:function(r,e){var s,p,v="string"==typeof r?{value:r,context:t.context}:r,y=v.value,g=v.context,l=f(e),E=t.states[y];if(E.on){var m=i(E.on[l.type]);try{for(var R=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(m),b=R.next();!b.done;b=R.next()){var x=b.value;if(void 0===x)return u(y,g);var h="string"==typeof x?{target:x}:x,S=h.target,I=h.actions,C=void 0===I?[]:I,T=h.cond,O=void 0===S,D=t.states[null!=S?S:y];if((void 0===T?function(){return!0}:T)(g,l)){var J=n(c((O?i(C):[].concat(E.exit,C,D.entry).filter((function(t){return t}))).map((function(t){return o(t,d._options.actions)})),g,l),3),N=J[0],j=null!=S?S:y;return{value:j,context:J[1],actions:N,changed:S!==y||N.length>0||J[2],matches:a(j)}}}}catch(t){s={error:t}}finally{try{b&&!b.done&&(p=R.return)&&p.call(R)}finally{if(s)throw s.error}}}return u(y,g)}};return d}({id:"fetch",initial:"draft",context:{retries:3},states:{draft:{on:{PAID:"confirming",FINALIZE:"finalizing",FETCH:"updating",REJECT:"draft"}},updating:{on:{RESOLVE:"draft",EXPIRE:"expired",REJECT:"draft"}},finalizing:{on:{PAYING:"paying",REJECT:"draft",PAID:"confirming"}},paying:{on:{PAID:"confirming",REJECT:"draft"}},confirming:{on:{CONFIRMED:"confirmed"}},paid:{on:{CONFIRMED:"confirmed",REDIRECT:"redirecting",REJECT:"draft"}},expired:{},confirmed:{on:{REDIRECT:"redirecting"}},redirecting:{},failure:{on:{RETRY:{target:"updating",actions:{type:"xstate.assign",assignment:{retries:t=>t.retries+1}}}}}}}),{state:v}=t({formState:p.initialState},((t,n)=>JSON.stringify(t)!==JSON.stringify(n)));export{p as c,v as s,d as v}