import{k as e,s as t,a as n,b as a,f as r,c,C as o,e as s,o as i,M as f,d as u,r as l,n as v,S as d,g as h,T as p,P as y,A as b,R as m,h as k,i as E,F as x,J as j,j as R,l as S,m as M,p as T,q as w,G as A,t as C,u as O,v as N,w as I,x as D,y as q,z,B as L,D as P,E as F,H as G,I as _,K as B,L as H,N as J,O as K,Q,U,V,W,X,Y,Z,_ as $,$ as ee}from"./io-3ad0e761.js";export{g as CANCEL,a1 as SAGA_LOCATION,a0 as buffers,a2 as detach}from"./io-3ad0e761.js";var te=[],ne=0;function ae(e){try{oe(),e()}finally{se()}}function re(e){te.push(e),ne||(oe(),ie())}function ce(e){try{return oe(),e()}finally{ie()}}function oe(){ne++}function se(){ne--}function ie(){var e;for(se();!ne&&void 0!==(e=te.shift());)ae(e)}var fe=e=>t=>e.some(e=>he(e)(t)),ue=e=>t=>e(t),le=e=>t=>t.type===e+"",ve=e=>t=>t.type===e,de=()=>e;function he(e){var o="*"===e?de:t(e)?le:n(e)?fe:a(e)?le:r(e)?ue:c(e)?ve:null;if(null===o)throw Error("invalid pattern: "+e);return o(e)}var ge={type:o},pe=e=>e&&e.type===o;function ye(e){void 0===e&&(e=s());var t=!1,n=[];return{take:function(a){t&&e.isEmpty()?a(ge):e.isEmpty()?(n.push(a),a.cancel=(()=>{l(n,a)})):a(e.take())},put:function(a){if(!t){if(0===n.length)return e.put(a);n.shift()(a)}},flush:function(n){t&&e.isEmpty()?n(ge):n(e.flush())},close:function(){if(!t){t=!0;var e=n;n=[];for(var a=0,r=e.length;r>a;a++)(0,e[a])(ge)}}}}function be(e,t){void 0===t&&(t=v());var n,a=!1,c=ye(t),o=()=>{a||(a=!0,r(n)&&n(),c.close())};return n=e(e=>{pe(e)?o():c.put(e)}),n=i(n),a&&n(),{take:c.take,flush:c.flush,close:o}}function me(){var e=!1,t=[],n=t,a=()=>{n===t&&(n=t.slice())},r=()=>{e=!0;var a=t=n;n=[],a.forEach(e=>{e(ge)})};return{[f]:!0,put(a){if(!e)if(pe(a))r();else for(var c=t=n,o=0,s=c.length;s>o;o++){var i=c[o];i[u](a)&&(i.cancel(),i(a))}},take(t,r){void 0===r&&(r=de),e?t(ge):(t[u]=r,a(),n.push(t),t.cancel=i(()=>{a(),l(n,t)}))},close:r}}function ke(){var e=me(),{put:t}=e;return e.put=(e=>{e[d]?t(e):re(()=>{t(e)})}),e}!function(e){var t,n=e.Symbol;"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable"}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")());var Ee=function(){return Math.random().toString(36).substring(7).split("").join(".")};Ee(),Ee();var xe=0,je=1,Re=2,Se=3;function Me(e,t){var n=e[h];r(n)&&(t.cancel=n),e.then(t,e=>{t(e,!0)})}var Te=0,we=()=>++Te;function Ae(e){e.isRunning()&&e.cancel()}var Ce={[p]:function(e,t,n){var{channel:a=e.channel,pattern:r,maybe:c}=t,o=e=>{e instanceof Error?n(e,!0):!pe(e)||c?n(e):n(_)};try{a.take(o,N(r)?he(r):null)}catch(e){return void n(e,!0)}n.cancel=o.cancel},[y]:function(e,t,n){var{channel:a,action:r,resolve:c}=t;re(()=>{var t;try{t=(a?a.put:e.dispatch)(r)}catch(e){return void n(e,!0)}c&&O(t)?Me(t,n):n(t)})},[b]:function(e,t,a,r){var{digestEffect:c}=r,o=Te,s=Object.keys(t);if(0!==s.length){var i=z(t,a);s.forEach(e=>{c(t[e],o,i[e],e)})}else a(n(t)?[]:{})},[m]:function(e,t,a,r){var{digestEffect:c}=r,o=Te,s=Object.keys(t),i=n(t)?P(s.length):{},f={},u=!1;s.forEach(e=>{var t=(t,n)=>{u||(n||B(t)?(a.cancel(),a(t,n)):(a.cancel(),u=!0,i[e]=t,a(i)))};t.cancel=H,f[e]=t}),a.cancel=(()=>{u||(u=!0,s.forEach(e=>f[e].cancel()))}),s.forEach(e=>{u||c(t[e],o,f[e],e)})},[k]:function(e,t,n,a){var{context:r,fn:c,args:o}=t,{task:s}=a;try{var i=c.apply(r,o);if(O(i))return void Me(i,n);if(I(i))return void _e(e,i,s.context,Te,D(c),!1,n);n(i)}catch(e){n(e,!0)}},[E]:function(e,t,n){var{context:a,fn:r,args:c}=t;try{var o=(e,t)=>{q(e)?n(t):n(e,!0)};r.apply(a,c.concat(o)),o.cancel&&(n.cancel=o.cancel)}catch(e){n(e,!0)}},[x]:function(e,t,n,a){var{context:r,fn:c,args:o,detached:s}=t,{task:i}=a,f=function(e){var{context:t,fn:n,args:a}=e;try{var r=n.apply(t,a);if(I(r))return r;var c=!1;return G(e=>c?{value:e,done:!0}:(c=!0,{value:r,done:!O(r)}))}catch(e){return G(()=>{throw e})}}({context:r,fn:c,args:o}),u=function(e,t){return e.isSagaIterator?{name:e.meta.name}:D(t)}(f,c);ce(()=>{var t=_e(e,f,i.context,Te,u,s,void 0);s?n(t):t.isRunning()?(i.queue.addTask(t),n(t)):t.isAborted()?i.queue.abort(t.error()):n(t)})},[j]:function(e,t,a,r){var{task:c}=r,o=(e,t)=>{if(e.isRunning()){var n={task:c,cb:t};t.cancel=(()=>{e.isRunning()&&l(e.joiners,n)}),e.joiners.push(n)}else e.isAborted()?t(e.error(),!0):t(e.result())};if(n(t)){if(0===t.length)return void a([]);var s=z(t,a);t.forEach((e,t)=>{o(e,s[t])})}else o(t,a)},[R]:function(e,t,a,r){var{task:c}=r;t===L?Ae(c):n(t)?t.forEach(Ae):Ae(t),a()},[S]:function(e,t,n){var{selector:a,args:r}=t;try{n(a(e.getState(),...r))}catch(e){n(e,!0)}},[M]:function(e,t,n){var{pattern:a,buffer:r}=t,c=ye(r),o=he(a),s=t=>{pe(t)||e.channel.take(s,o),c.put(t)},{close:i}=c;c.close=(()=>{s.cancel(),i()}),e.channel.take(s,o),n(c)},[T]:function(e,t,n,a){var{task:r}=a;n(r.isCancelled())},[w]:function(e,t,n){t.flush(n)},[A]:function(e,t,n,a){var{task:r}=a;n(r.context[t])},[C]:function(e,t,n,a){var{task:r}=a;F(r.context,t),n()}};function Oe(e,t){return e+"?"+t}function Ne(e){var{name:t,location:n}=e;return n?t+" "+Oe(n.fileName,n.lineNumber):t}function Ie(e){var t=J(e=>e.cancelledTasks,e);return t.length?["Tasks cancelled due to error:",...t].join("\n"):""}var De=null,qe=[],ze=e=>{e.crashedEffect=De,qe.push(e)},Le=()=>{De=null,qe.length=0},Pe=e=>{De=e},Fe=()=>{var[e,...t]=qe,n=e.crashedEffect?function(e){var t=K(e);if(t){var{code:n,fileName:a,lineNumber:r}=t;return n+" "+Oe(a,r)}return""}(e.crashedEffect):null;return["The above error occurred in task "+Ne(e.meta)+(n?" \n when executing effect "+n:""),...t.map(e=>" created by "+Ne(e.meta)),Ie(qe)].join("\n")};function Ge(e,t,n,a,r,c,o){void 0===o&&(o=H);var s,i,f=xe,u=null,v=[],d=Object.create(n),h=function(e,t,n){var a,r=[],c=!1;function o(e){t(),i(),n(e,!0)}function s(t){r.push(t),t.cont=((s,i)=>{c||(l(r,t),t.cont=H,i?o(s):(t===e&&(a=s),r.length||(c=!0,n(a))))})}function i(){c||(c=!0,r.forEach(e=>{e.cont=H,e.cancel()}),r=[])}return s(e),{addTask:s,cancelAll:i,abort:o,getTasks:()=>r}}(t,function(){v.push(...h.getTasks().map(e=>e.meta.name))},g);function g(t,n){if(n){if(f=Re,ze({meta:r,cancelledTasks:v}),p.isRoot){var a=Fe();Le(),e.onError(t,{sagaStack:a})}i=t,u&&u.reject(t)}else t===U?f=je:f!==je&&(f=Se),s=t,u&&u.resolve(t);p.cont(t,n),p.joiners.forEach(e=>{e.cb(t,n)}),p.joiners=null}var p={[Q]:!0,id:a,meta:r,isRoot:c,context:d,joiners:[],queue:h,cancel:function(){f===xe&&(f=je,h.cancelAll(),g(U,!1))},cont:o,end:g,setContext:function(e){F(d,e)},toPromise:function(){return u?u.promise:((e={}).promise=new Promise((t,n)=>{e.resolve=t,e.reject=n}),u=e,f===Re?u.reject(i):f!==xe&&u.resolve(s),u.promise);var e},isRunning:()=>f===xe,isCancelled:()=>f===je||f===xe&&t.status===je,isAborted:()=>f===Re,result:()=>s,error:()=>i};return p}function _e(e,t,n,a,c,o,s){var i=e.finalizeRunEffect(function(t,n,a){if(O(t))Me(t,a);else if(I(t))_e(e,t,u.context,n,c,!1,a);else if(t&&t[X]){var r=Ce[t.type];r(e,t.payload,a,l)}else a(t)});v.cancel=H;var f={meta:c,cancel:function(){f.status===xe&&(f.status=je,v(U))},status:xe},u=Ge(e,f,n,a,c,o,s),l={task:u,digestEffect:d};return s&&(s.cancel=u.cancel),v(),u;function v(e,n){try{var c;n?(c=t.throw(e),Le()):V(e)?(f.status=je,v.cancel(),c=r(t.return)?t.return(U):{done:!0,value:U}):c=W(e)?r(t.return)?t.return():{done:!0}:t.next(e),c.done?(f.status!==je&&(f.status=Se),f.cont(c.value)):d(c.value,a,v)}catch(e){if(f.status===je)throw e;f.status=Re,f.cont(e,!0)}}function d(t,n,a,r){void 0===r&&(r="");var c,o=we();function s(n,r){c||(c=!0,a.cancel=H,e.sagaMonitor&&(r?e.sagaMonitor.effectRejected(o,n):e.sagaMonitor.effectResolved(o,n)),r&&Pe(t),a(n,r))}e.sagaMonitor&&e.sagaMonitor.effectTriggered({effectId:o,parentEffectId:n,label:r,effect:t}),s.cancel=H,a.cancel=(()=>{c||(c=!0,s.cancel(),s.cancel=H,e.sagaMonitor&&e.sagaMonitor.effectCancelled(o))}),i(t,o,s)}}function Be(e,t){for(var{channel:n=ke(),dispatch:a,getState:r,context:c={},sagaMonitor:o,effectMiddlewares:s,onError:i=Y}=e,f=arguments.length,u=Array(f>2?f-2:0),l=2;f>l;l++)u[l-2]=arguments[l];var v,d=t(...u),h=we();if(o&&(o.rootSagaStarted=o.rootSagaStarted||H,o.effectTriggered=o.effectTriggered||H,o.effectResolved=o.effectResolved||H,o.effectRejected=o.effectRejected||H,o.effectCancelled=o.effectCancelled||H,o.actionDispatched=o.actionDispatched||H,o.rootSagaStarted({effectId:h,saga:t,args:u})),s){var g=function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce(function(e,t){return function(){return e(t.apply(void 0,arguments))}})}(...s);v=(e=>(t,n,a)=>{return g(t=>e(t,n,a))(t)})}else v=$;var p={channel:n,dispatch:Z(a),getState:r,sagaMonitor:o,onError:i,finalizeRunEffect:v};return ce(()=>{var e=_e(p,d,c,h,D(t),!0,void 0);return o&&o.effectResolved(h,e),e})}export default function(e){var t,n=void 0===e?{}:e,{context:a={},channel:r=ke(),sagaMonitor:c}=n,o=function(e,t){if(null==e)return{};var n,a,r={},c=Object.keys(e);for(a=0;c.length>a;a++)0>t.indexOf(n=c[a])&&(r[n]=e[n]);return r}(n,["context","channel","sagaMonitor"]);function s(e){var{getState:n,dispatch:s}=e;return t=Be.bind(null,ee({},o,{context:a,channel:r,dispatch:s,getState:n,sagaMonitor:c})),e=>t=>{c&&c.actionDispatched&&c.actionDispatched(t);var n=e(t);return r.put(t),n}}return s.run=function(){return t(...arguments)},s.setContext=(e=>{F(a,e)}),s}export{ge as END,ye as channel,be as eventChannel,pe as isEnd,me as multicastChannel,Be as runSaga,ke as stdChannel};