/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/redux-automata@3.0.1/lib/redux-automata.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _inheritsLoose=require("@babel/runtime/helpers/inheritsLoose");function _interopDefaultLegacy(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var _inheritsLoose__default=_interopDefaultLegacy(_inheritsLoose),ACTION_TYPE_PREFIX="@@AUTOMATA",StateOptionsEx=function(){function t(t,e){this.options=t,this.stateOptions=e}var e=t.prototype;return e.in=function(t){return this.options.in(t)},e.on=function(t){return this.stateOptions.on(t)},t}(),ActionOptions=function(){function t(t,e,n,i){this.sourceStates=t,this.actionType=e,this.smOptions=n,this.stateOptions=i,this.transitions=[]}var e=t.prototype;return e.goTo=function(t){return this.targetState=t.stateName,new StateOptionsEx(this.smOptions,this.stateOptions)},e.execute=function(t){return this.transitions.push(t),this},e.noop=function(){return new StateOptionsEx(this.smOptions,this.stateOptions)},e.createArcs=function(){var t=this.sourceStates,e=this.actionType,n=this.targetState,i=this.transitions;return t.map((function(t){return{actionType:e,sourceState:t,targetState:n,transitions:i}}))},t}(),StateOptions=function(){function t(t,e){this.sourceStates=t,this.smOptions=e,this.builders=[]}var e=t.prototype;return e.on=function(t){var e=new ActionOptions(this.sourceStates,t.actionType,this.smOptions,this);return this.builders.push(e),e},e.or=function(t){return this.sourceStates.push(t.stateName),this},e.getArcs=function(){return this.builders.reduce((function(t,e){return t.concat(e.createArcs())}),[])},t}(),Automata=function(){function t(t){this.automataName=t,this.states=[],this.options=[],this.initial=Object.assign({}),this.current=this.initial}var e=t.prototype;return e.in=function(t){var e=this.states.find((function(e){return e.stateName===t.stateName}));if(!e)throw new Error("State should be defined using this.state(...) method.");var n=new StateOptions([e.stateName],this);return this.options.push(n),n},e.inAny=function(){var t=new StateOptions(this.states.map((function(t){return t.stateName})),this);return this.options.push(t),t},e.beginWith=function(t){this.graphCache=void 0;var e=this.states.find((function(e){return e.stateName===t.stateName}));if(!e)throw new Error("State should be previously defined using this.state(...) method.");this.initial=Object.assign(t({},void 0),{__sm_state:e.stateName})},e.state=function(t,e){if(this.graphCache=void 0,!t)throw new Error("State name can't be empty, null or undefined.");if(this.states.find((function(e){return e.stateName===t})))throw new Error("State with the same name already exist: "+t);var n=Object.assign(e,{stateName:t});return this.states.push(n),n},e.action=function(t){var e=this;this.graphCache=void 0;var n=ACTION_TYPE_PREFIX+" "+this.automataName+" / "+t;return Object.assign((function(t){return{payload:t,type:n}}),{actionType:n,isInvocable:function(t){return e.hasTransition(t.__sm_state||"",n)}})},e.getGraph=function(){if(this.graphCache)return this.graphCache;var t=this.options.reduce((function(t,e){return t.concat(e.getArcs())}),new Array);return this.graphCache=this.states.map((function(e){var n=t.filter((function(t){return t.sourceState===e.stateName})).map((function(t){return{actionType:t.actionType,targetState:t.targetState,transitions:t.transitions}}));return{actions:n=n.filter((function(t,e){return n.findIndex((function(e){return e.actionType===t.actionType}))===e})),entry:e}})),this.graphCache},e.hasTransition=function(t,e){var n=this.getGraph().find((function(e){return e.entry.stateName===t}));return void 0!==n&&n.actions.findIndex((function(t){return t.actionType===e}))>-1},e.mergeState=function(t){return Object.assign({},this.current,t)},t}();function automataMiddleware(t){return function(e){return function(n){if(!n.type.startsWith(ACTION_TYPE_PREFIX))return e(n);var i=!0;Object.assign(n,{dispatch:function(e){return i?(setTimeout((function(){return t.dispatch(e)}),0),e):t.dispatch(e)}});var r=e(n);return i=!1,r}}}function automataReducer(t){if(void 0===t.initial.__sm_state)throw new Error("No initial state specified. Use BeginWith() method to specify initial state.");t.current=t.initial;var e=t.getGraph();if(!e.find((function(e){return e.entry.stateName===t.current.__sm_state})))throw new Error("Can't find initial state.");return function(n,i){if(void 0===n&&(n=t.initial),"string"!=typeof i.type||!i.type.startsWith(ACTION_TYPE_PREFIX))return n;var r=e.find((function(t){return t.entry.stateName===n.__sm_state}));if(!r)return n;var a=r.actions.find((function(t){return t.actionType===i.type}));if(!a)return n;var s=n;if(a.targetState){var o=e.find((function(t){return t.entry.stateName===a.targetState}));if(!o)throw new Error("Can't find state "+a.targetState);t.current=n,(s=o.entry(n,i.payload)).__sm_state=o.entry.stateName,t.current=s}if(!i.dispatch)throw new Error("Dispatch is not defined to perform transitions. It seems `automataMiddleware` was not applied.");var u=Object.assign(i.dispatch,{dispatch:i.dispatch,getState:function(){return t.current}});return a.transitions.forEach((function(t){return t(u,i.payload)})),s}}var TaskAutomata=function(t){function e(e,n,i,r){var a;return(a=t.call(this,e+" Automata")||this).Name=e,a.Process=n,a.OnSuccess=i,a.OnFailure=r,a.Idle=a.state("Idle",(function(){return a.getDefaultState()})),a.Processing=a.state("Processing",(function(){return a.mergeState({error:null,isProcessing:!0})})),a.Completed=a.state("Completed",(function(t,e){return a.mergeState({error:null,isProcessing:!1,result:e})})),a.Failure=a.state("Failure",(function(t,e){return a.mergeState({error:e,isProcessing:!1})})),a.Start=a.action(a.Name+" Start"),a.Restart=a.action(a.Name+" Restart"),a.Cancel=a.action(a.Name+" Cancel"),a.End=a.action(a.Name+" Success"),a.Fail=a.action(a.Name+" Fail"),a.BeginProcessing=function(t,e){return a.Process(e).then((function(n){var i=t(a.End(n));return a.OnSuccess&&a.OnSuccess(t,n,e),i})).catch((function(n){var i=t(a.Fail(n));return a.OnFailure&&a.OnFailure(t,n,e),i}))},a}_inheritsLoose__default.default(e,t);var n=e.prototype;return n.setupProcessIn=function(t){var e=this.Idle,n=this.Processing,i=this.Completed,r=this.Failure,a=this.Start,s=this.Restart,o=this.End,u=this.Fail,c=this.Cancel,h=this.BeginProcessing;this.in(t).on(a).execute(h).goTo(n).in(n).on(o).goTo(i).on(u).goTo(r).on(c).goTo(e).in(r).on(c).goTo(e).in(i).or(r).on(s).execute(h).goTo(n)},n.getDefaultState=function(){return{isProcessing:!1}},e}(Automata);function createTaskAutomation(t,e,n,i){var r=new TaskAutomata(t,e,n,i);r.setupProcessIn(r.Idle),r.beginWith(r.Idle);var a=automataReducer(r);return{cancel:r.Cancel,reducer:a,restart:r.Restart,start:r.Start}}exports.ACTION_TYPE_PREFIX=ACTION_TYPE_PREFIX,exports.Automata=Automata,exports.TaskAutomata=TaskAutomata,exports.automataMiddleware=automataMiddleware,exports.automataReducer=automataReducer,exports.createTaskAutomation=createTaskAutomation;
//# sourceMappingURL=/sm/43fc0da4929e39858438a2ddcdde9ef42fc81040cbe9f857e75686e554ce4569.map