import{c as t}from"./p-03631502.js";import{g as n}from"./p-9dbc54d6.js";function r(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),a=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return a}var e;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(e||(e={}));var i={type:"xstate.init"};function o(t){return void 0===t?[]:[].concat(t)}function c(t){return{type:"xstate.assign",assignment:t}}function u(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 s(t,n){return{value:t,context:n,actions:[],changed:!1,matches:a(t)}}function d(t,n,e){var r=n,i=!1;return[t.filter((function(t){if("xstate.assign"===t.type){i=!0;var n=Object.assign({},r);return"function"==typeof t.assignment?n=t.assignment(r,e):Object.keys(t.assignment).forEach((function(i){n[i]="function"==typeof t.assignment[i]?t.assignment[i](r,e):t.assignment[i]})),r=n,!1}return!0})),r,i]}function p(t,n){void 0===n&&(n={});var e=r(d(o(t.states[t.initial].entry).map((function(t){return u(t,n.actions)})),t.context,i),2),c=e[0],l=e[1],g={config:t,_options:n,initialState:{value:t.initial,actions:c,context:l,matches:a(t.initial)},transition:function(n,e){var i,c,l="string"==typeof n?{value:n,context:t.context}:n,p=l.value,y=l.context,m=f(e),v=t.states[p];if(v.on){var E=o(v.on[m.type]);try{for(var x=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(E),S=x.next();!S.done;S=x.next()){var _=S.value;if(void 0===_)return s(p,y);var R="string"==typeof _?{target:_}:_,h=R.target,b=R.actions,w=void 0===b?[]:b,C=R.cond,T=void 0===C?function(){return!0}:C,I=void 0===h,O=null!=h?h:p,D=t.states[O];if(T(y,m)){var N=r(d((I?o(w):[].concat(v.exit,w,D.entry).filter((function(t){return t}))).map((function(t){return u(t,g._options.actions)})),y,m),3),J=N[0],j=N[1],A=N[2],P=null!=h?h:p;return{value:P,context:j,actions:J,changed:h!==p||J.length>0||A,matches:a(P)}}}}catch(t){i={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(i)throw i.error}}}return s(p,y)}};return g}var g=function(t,n){return t.actions.forEach((function(e){var r=e.exec;return r&&r(t.context,n)}))};function l(t){var n=t.initialState,r=e.NotStarted,o=new Set,c={_machine:t,send:function(i){r===e.Running&&(n=t.transition(n,i),g(n,f(i)),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 u="object"==typeof o?o:{context:t.config.context,value:o};n={value:u.value,actions:[],context:u.context,matches:a(u.value)}}return r=e.Running,g(n,i),c},stop:function(){return r=e.Stopped,o.clear(),c},get state(){return n},get status(){return r}};return c}const y=p({id:"fetch",initial:"draft",context:{retries:3},states:{draft:{on:{PAID:"confirming",FINALIZE:"finalizing",FETCH:"updating",REJECT:"draft",LOCK:"locked"}},updating:{on:{RESOLVE:"draft",EXPIRE:"expired",REJECT:"draft",LOCK:"locked"}},finalizing:{on:{PAYING:"paying",REJECT:"draft",PAID:"confirming",TEST_MODE_RESTRICTED:"test_mode_restricted"}},paying:{on:{PAID:"confirming",REJECT:"draft"}},confirming:{on:{CONFIRMED:"confirmed"}},paid:{on:{CONFIRMED:"confirmed",REDIRECT:"redirecting",REJECT:"draft"}},expired:{},locked:{},confirmed:{on:{REDIRECT:"redirecting"}},test_mode_restricted:{},redirecting:{},failure:{on:{RETRY:{target:"updating",actions:c({retries:t=>t.retries+1})}}}}}),{form:v}=n(),{state:m,onChange:E,on:b,set:R,get:S,dispose:x}=t({formState:y.initialState,text:{loading:{finalizing:wp.i18n.__("Submitting...","surecart"),paying:wp.i18n.__("Processing...","surecart"),confirming:wp.i18n.__("Finalizing...","surecart"),confirmed:wp.i18n.__("Success!","surecart"),redirecting:wp.i18n.__("Success! Redirecting...","surecart")},success:{title:wp.i18n.__("Thank you!","surecart"),description:wp.i18n.__("Your payment was successful. A receipt is on its way to your inbox.","surecart"),button:wp.i18n.__("Continue","surecart")}},...v},((t,n,e)=>"formState"===e?t.value!==n.value:JSON.stringify(t)!==JSON.stringify(n)));export{y as c,E as o,m as s,l as v};