var Ee = Object.defineProperty;
var Oe = (e, t, n) => t in e ? Ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
var X = (e, t, n) => (Oe(e, typeof t != "symbol" ? t + "" : t, n), n);
import { g as It, n as Ht, $ as ke, t as Te } from "./index-c02da01c.js";
var p = function() {
  return p = Object.assign || function(e) {
    for (var t, n = 1, i = arguments.length; n < i; n++) {
      t = arguments[n];
      for (var r in t)
        Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
    }
    return e;
  }, p.apply(this, arguments);
};
function qt(e, t) {
  var n = {};
  for (var i in e)
    Object.prototype.hasOwnProperty.call(e, i) && t.indexOf(i) < 0 && (n[i] = e[i]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var r = 0, i = Object.getOwnPropertySymbols(e); r < i.length; r++)
      t.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, i[r]) && (n[i[r]] = e[i[r]]);
  return n;
}
function E(e) {
  var t = typeof Symbol == "function" && Symbol.iterator, n = t && e[t], i = 0;
  if (n)
    return n.call(e);
  if (e && typeof e.length == "number")
    return { next: function() {
      return e && i >= e.length && (e = void 0), { value: e && e[i++], done: !e };
    } };
  throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function O(e, t) {
  var n = typeof Symbol == "function" && e[Symbol.iterator];
  if (!n)
    return e;
  var i = n.call(e), r, o = [], a;
  try {
    for (; (t === void 0 || t-- > 0) && !(r = i.next()).done; )
      o.push(r.value);
  } catch (s) {
    a = { error: s };
  } finally {
    try {
      r && !r.done && (n = i.return) && n.call(i);
    } finally {
      if (a)
        throw a.error;
    }
  }
  return o;
}
function V(e, t, n) {
  if (n || arguments.length === 2)
    for (var i = 0, r = t.length, o; i < r; i++)
      (o || !(i in t)) && (o || (o = Array.prototype.slice.call(t, 0, i)), o[i] = t[i]);
  return e.concat(o || Array.prototype.slice.call(t));
}
var N;
(function(e) {
  e.Start = "xstate.start", e.Stop = "xstate.stop", e.Raise = "xstate.raise", e.Send = "xstate.send", e.Cancel = "xstate.cancel", e.NullEvent = "", e.Assign = "xstate.assign", e.After = "xstate.after", e.DoneState = "done.state", e.DoneInvoke = "done.invoke", e.Log = "xstate.log", e.Init = "xstate.init", e.Invoke = "xstate.invoke", e.ErrorExecution = "error.execution", e.ErrorCommunication = "error.communication", e.ErrorPlatform = "error.platform", e.ErrorCustom = "xstate.error", e.Update = "xstate.update", e.Pure = "xstate.pure", e.Choose = "xstate.choose";
})(N || (N = {}));
var rt;
(function(e) {
  e.Parent = "#_parent", e.Internal = "#_internal";
})(rt || (rt = {}));
var Mt = N.Start, Ft = N.Stop, yt = N.Raise, jt = N.Send, re = N.Cancel, Ae = N.NullEvent, oe = N.Assign;
N.After;
N.DoneState;
var ae = N.Log, Pe = N.Init, Ct = N.Invoke;
N.ErrorExecution;
var Yt = N.ErrorPlatform, je = N.ErrorCustom, se = N.Update, Ne = N.Choose, Ie = N.Pure, ce = ".", Zt = {}, Rt = "xstate.guard", Le = "", Lt;
function Xt(e, t, n) {
  n === void 0 && (n = ce);
  var i = dt(e, n), r = dt(t, n);
  return j(r) ? j(i) ? r === i : !1 : j(i) ? i in r : Object.keys(i).every(function(o) {
    return o in r ? Xt(i[o], r[o]) : !1;
  });
}
function ue(e) {
  try {
    return j(e) || typeof e == "number" ? "".concat(e) : e.type;
  } catch {
    throw new Error("Events must be strings or objects with a string event.type property.");
  }
}
function Bt(e, t) {
  try {
    return at(e) ? e : e.toString().split(t);
  } catch {
    throw new Error("'".concat(e, "' is not a valid state path."));
  }
}
function Ve(e) {
  return typeof e == "object" && "value" in e && "context" in e && "event" in e && "_event" in e;
}
function dt(e, t) {
  if (Ve(e))
    return e.value;
  if (at(e))
    return kt(e);
  if (typeof e != "string")
    return e;
  var n = Bt(e, t);
  return kt(n);
}
function kt(e) {
  if (e.length === 1)
    return e[0];
  for (var t = {}, n = t, i = 0; i < e.length - 1; i++)
    i === e.length - 2 ? n[e[i]] = e[i + 1] : (n[e[i]] = {}, n = n[e[i]]);
  return t;
}
function ut(e, t) {
  for (var n = {}, i = Object.keys(e), r = 0; r < i.length; r++) {
    var o = i[r];
    n[o] = t(e[o], o, e, r);
  }
  return n;
}
function Kt(e, t, n) {
  var i, r, o = {};
  try {
    for (var a = E(Object.keys(e)), s = a.next(); !s.done; s = a.next()) {
      var c = s.value, u = e[c];
      n(u) && (o[c] = t(u, c, e));
    }
  } catch (h) {
    i = { error: h };
  } finally {
    try {
      s && !s.done && (r = a.return) && r.call(a);
    } finally {
      if (i)
        throw i.error;
    }
  }
  return o;
}
var De = function(e) {
  return function(t) {
    var n, i, r = t;
    try {
      for (var o = E(e), a = o.next(); !a.done; a = o.next()) {
        var s = a.value;
        r = r[s];
      }
    } catch (c) {
      n = { error: c };
    } finally {
      try {
        a && !a.done && (i = o.return) && i.call(o);
      } finally {
        if (n)
          throw n.error;
      }
    }
    return r;
  };
};
function Me(e, t) {
  return function(n) {
    var i, r, o = n;
    try {
      for (var a = E(e), s = a.next(); !s.done; s = a.next()) {
        var c = s.value;
        o = o[t][c];
      }
    } catch (u) {
      i = { error: u };
    } finally {
      try {
        s && !s.done && (r = a.return) && r.call(a);
      } finally {
        if (i)
          throw i.error;
      }
    }
    return o;
  };
}
function bt(e) {
  if (!e)
    return [[]];
  if (j(e))
    return [[e]];
  var t = D(Object.keys(e).map(function(n) {
    var i = e[n];
    return typeof i != "string" && (!i || !Object.keys(i).length) ? [[n]] : bt(e[n]).map(function(r) {
      return [n].concat(r);
    });
  }));
  return t;
}
function D(e) {
  var t;
  return (t = []).concat.apply(t, V([], O(e), !1));
}
function he(e) {
  return at(e) ? e : [e];
}
function U(e) {
  return e === void 0 ? [] : he(e);
}
function Tt(e, t, n) {
  var i, r;
  if (T(e))
    return e(t, n.data);
  var o = {};
  try {
    for (var a = E(Object.keys(e)), s = a.next(); !s.done; s = a.next()) {
      var c = s.value, u = e[c];
      T(u) ? o[c] = u(t, n.data) : o[c] = u;
    }
  } catch (h) {
    i = { error: h };
  } finally {
    try {
      s && !s.done && (r = a.return) && r.call(a);
    } finally {
      if (i)
        throw i.error;
    }
  }
  return o;
}
function Ce(e) {
  return /^(done|error)\./.test(e);
}
function te(e) {
  return !!(e instanceof Promise || e !== null && (T(e) || typeof e == "object") && T(e.then));
}
function Re(e) {
  return e !== null && typeof e == "object" && "transition" in e && typeof e.transition == "function";
}
function Be(e, t) {
  var n, i, r = O([[], []], 2), o = r[0], a = r[1];
  try {
    for (var s = E(e), c = s.next(); !c.done; c = s.next()) {
      var u = c.value;
      t(u) ? o.push(u) : a.push(u);
    }
  } catch (h) {
    n = { error: h };
  } finally {
    try {
      c && !c.done && (i = s.return) && i.call(s);
    } finally {
      if (n)
        throw n.error;
    }
  }
  return [o, a];
}
function le(e, t) {
  return ut(e.states, function(n, i) {
    if (n) {
      var r = (j(t) ? void 0 : t[i]) || (n ? n.current : void 0);
      if (r)
        return { current: r, states: le(n, r) };
    }
  });
}
function $e(e, t) {
  return { current: t, states: le(e, t) };
}
function ee(e, t, n, i) {
  var r = e && n.reduce(function(o, a) {
    var s, c, u = a.assignment, h = { state: i, action: a, _event: t }, f = {};
    if (T(u))
      f = u(o, t.data, h);
    else
      try {
        for (var l = E(Object.keys(u)), d = l.next(); !d.done; d = l.next()) {
          var y = d.value, v = u[y];
          f[y] = T(v) ? v(o, t.data, h) : v;
        }
      } catch (x) {
        s = { error: x };
      } finally {
        try {
          d && !d.done && (c = l.return) && c.call(l);
        } finally {
          if (s)
            throw s.error;
        }
      }
    return Object.assign({}, o, f);
  }, e);
  return r;
}
var ze = function() {
};
function at(e) {
  return Array.isArray(e);
}
function T(e) {
  return typeof e == "function";
}
function j(e) {
  return typeof e == "string";
}
function fe(e, t) {
  if (e)
    return j(e) ? { type: Rt, name: e, predicate: t ? t[e] : void 0 } : T(e) ? { type: Rt, name: e.name, predicate: e } : e;
}
function Je(e) {
  try {
    return "subscribe" in e && T(e.subscribe);
  } catch {
    return !1;
  }
}
var Q = function() {
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
}();
Lt = {}, Lt[Q] = function() {
  return this;
}, Lt[Symbol.observable] = function() {
  return this;
};
function ot(e) {
  return !!e && "__xstatenode" in e;
}
function Ue(e) {
  return !!e && typeof e.send == "function";
}
function Nt(e, t) {
  return j(e) || typeof e == "number" ? p({ type: e }, t) : e;
}
function R(e, t) {
  if (!j(e) && "$$type" in e && e.$$type === "scxml")
    return e;
  var n = Nt(e);
  return p({ name: n.type, data: n, $$type: "scxml", type: "external" }, t);
}
function Z(e, t) {
  var n = he(t).map(function(i) {
    return typeof i > "u" || typeof i == "string" || ot(i) ? { target: i, event: e } : p(p({}, i), { event: e });
  });
  return n;
}
function qe(e) {
  if (!(e === void 0 || e === Le))
    return U(e);
}
function de(e, t, n, i, r) {
  var o = e.options.guards, a = { state: r, cond: t, _event: i };
  if (t.type === Rt)
    return ((o == null ? void 0 : o[t.name]) || t.predicate)(n, i.data, a);
  var s = o == null ? void 0 : o[t.type];
  if (!s)
    throw new Error("Guard '".concat(t.type, "' is not implemented on machine '").concat(e.id, "'."));
  return s(n, i.data, a);
}
function ve(e) {
  return typeof e == "string" ? { type: e } : e;
}
function wt(e, t, n) {
  var i = function() {
  }, r = typeof e == "object", o = r ? e : null;
  return { next: ((r ? e.next : e) || i).bind(o), error: ((r ? e.error : t) || i).bind(o), complete: ((r ? e.complete : n) || i).bind(o) };
}
function mt(e, t) {
  return "".concat(e, ":invocation[").concat(t, "]");
}
function $t(e) {
  return (e.type === yt || e.type === jt && e.to === rt.Internal) && typeof e.delay != "number";
}
var it = R({ type: Pe });
function zt(e, t) {
  return t && t[e] || void 0;
}
function vt(e, t) {
  var n;
  if (j(e) || typeof e == "number") {
    var i = zt(e, t);
    T(i) ? n = { type: e, exec: i } : i ? n = i : n = { type: e, exec: void 0 };
  } else if (T(e))
    n = { type: e.name || e.toString(), exec: e };
  else {
    var i = zt(e.type, t);
    if (T(i))
      n = p(p({}, e), { exec: i });
    else if (i) {
      var r = i.type || e.type;
      n = p(p(p({}, i), e), { type: r });
    } else
      n = e;
  }
  return n;
}
var G = function(e, t) {
  if (!e)
    return [];
  var n = at(e) ? e : [e];
  return n.map(function(i) {
    return vt(i, t);
  });
};
function Qt(e) {
  var t = vt(e);
  return p(p({ id: j(e) ? e : t.id }, t), { type: t.type });
}
function Fe(e, t) {
  return { type: yt, event: typeof e == "function" ? e : Nt(e), delay: t ? t.delay : void 0, id: t == null ? void 0 : t.id };
}
function Xe(e, t, n, i) {
  var r = { _event: n }, o = R(T(e.event) ? e.event(t, n.data, r) : e.event), a;
  if (j(e.delay)) {
    var s = i && i[e.delay];
    a = T(s) ? s(t, n.data, r) : s;
  } else
    a = T(e.delay) ? e.delay(t, n.data, r) : e.delay;
  return p(p({}, e), { type: yt, _event: o, delay: a });
}
function Qe(e, t) {
  return { to: t ? t.to : void 0, type: jt, event: T(e) ? e : Nt(e), delay: t ? t.delay : void 0, id: t && t.id !== void 0 ? t.id : T(e) ? e.name : ue(e) };
}
function Ge(e, t, n, i) {
  var r = { _event: n }, o = R(T(e.event) ? e.event(t, n.data, r) : e.event), a;
  if (j(e.delay)) {
    var s = i && i[e.delay];
    a = T(s) ? s(t, n.data, r) : s;
  } else
    a = T(e.delay) ? e.delay(t, n.data, r) : e.delay;
  var c = T(e.to) ? e.to(t, n.data, r) : e.to;
  return p(p({}, e), { to: c, _event: o, event: o.data, delay: a });
}
var We = function(e, t, n) {
  return p(p({}, e), { value: j(e.expr) ? e.expr : e.expr(t, n.data, { _event: n }) });
}, He = function(e) {
  return { type: re, sendId: e };
};
function Ye(e) {
  var t = Qt(e);
  return { type: N.Start, activity: t, exec: void 0 };
}
function Ze(e) {
  var t = T(e) ? e : Qt(e);
  return { type: N.Stop, activity: t, exec: void 0 };
}
function Ke(e, t, n) {
  var i = T(e.activity) ? e.activity(t, n.data) : e.activity, r = typeof i == "string" ? { id: i } : i, o = { type: N.Stop, activity: r };
  return o;
}
function tn(e, t) {
  var n = t ? "#".concat(t) : "";
  return "".concat(N.After, "(").concat(e, ")").concat(n);
}
function xt(e, t) {
  var n = "".concat(N.DoneState, ".").concat(e), i = { type: n, data: t };
  return i.toString = function() {
    return n;
  }, i;
}
function Et(e, t) {
  var n = "".concat(N.DoneInvoke, ".").concat(e), i = { type: n, data: t };
  return i.toString = function() {
    return n;
  }, i;
}
function ht(e, t) {
  var n = "".concat(N.ErrorPlatform, ".").concat(e), i = { type: n, data: t };
  return i.toString = function() {
    return n;
  }, i;
}
var en = function(e) {
  var t, n, i = [];
  try {
    for (var r = E(e), o = r.next(); !o.done; o = r.next())
      for (var a = o.value, s = 0; s < a.actions.length; ) {
        if (a.actions[s].type === oe) {
          i.push(a.actions[s]), a.actions.splice(s, 1);
          continue;
        }
        s++;
      }
  } catch (c) {
    t = { error: c };
  } finally {
    try {
      o && !o.done && (n = r.return) && n.call(r);
    } finally {
      if (t)
        throw t.error;
    }
  }
  return i;
};
function At(e, t, n, i, r, o, a) {
  a === void 0 && (a = !1);
  var s = a ? [] : en(r), c = s.length ? ee(n, i, s, t) : n, u = a ? [n] : void 0, h = [];
  function f(y, v) {
    var x;
    switch (v.type) {
      case yt: {
        var g = Xe(v, c, i, e.options.delays);
        return o && typeof g.delay == "number" && o(g, c, i), g;
      }
      case jt:
        var m = Ge(v, c, i, e.options.delays);
        return o && m.to !== rt.Internal && (y === "entry" ? h.push(m) : o(m, c, i)), m;
      case ae: {
        var _ = We(v, c, i);
        return o == null || o(_, c, i), _;
      }
      case Ne: {
        var b = v, A = (x = b.conds.find(function(gt) {
          var q = fe(gt.cond, e.options.guards);
          return !q || de(e, q, c, i, o ? void 0 : t);
        })) === null || x === void 0 ? void 0 : x.actions;
        if (!A)
          return [];
        var L = O(At(e, t, c, i, [{ type: y, actions: G(U(A), e.options.actions) }], o, a), 2), k = L[0], I = L[1];
        return c = I, u == null || u.push(c), k;
      }
      case Ie: {
        var A = v.get(c, i.data);
        if (!A)
          return [];
        var w = O(At(e, t, c, i, [{ type: y, actions: G(U(A), e.options.actions) }], o, a), 2), M = w[0], S = w[1];
        return c = S, u == null || u.push(c), M;
      }
      case Ft: {
        var _ = Ke(v, c, i);
        return o == null || o(_, n, i), _;
      }
      case oe: {
        c = ee(c, i, [v], o ? void 0 : t), u == null || u.push(c);
        break;
      }
      default:
        var P = vt(v, e.options.actions), B = P.exec;
        if (o)
          o(P, c, i);
        else if (B && u) {
          var $ = u.length - 1, st = p(p({}, P), { exec: function(gt) {
            for (var q = [], W = 1; W < arguments.length; W++)
              q[W - 1] = arguments[W];
            B.apply(void 0, V([u[$]], O(q), !1));
          } });
          P = st;
        }
        return P;
    }
  }
  function l(y) {
    var v, x, g = [];
    try {
      for (var m = E(y.actions), _ = m.next(); !_.done; _ = m.next()) {
        var b = _.value, A = f(y.type, b);
        A && (g = g.concat(A));
      }
    } catch (L) {
      v = { error: L };
    } finally {
      try {
        _ && !_.done && (x = m.return) && x.call(m);
      } finally {
        if (v)
          throw v.error;
      }
    }
    return h.forEach(function(L) {
      o(L, c, i);
    }), h.length = 0, g;
  }
  var d = D(r.map(l));
  return [d, c];
}
var et = function(e, t) {
  var n = t(e);
  return n;
};
function pe(e) {
  var t;
  return t = { id: e, send: function() {
  }, subscribe: function() {
    return { unsubscribe: function() {
    } };
  }, getSnapshot: function() {
  }, toJSON: function() {
    return { id: e };
  } }, t[Q] = function() {
    return this;
  }, t;
}
function nn(e, t, n, i) {
  var r, o = ve(e.src), a = (r = t == null ? void 0 : t.options.services) === null || r === void 0 ? void 0 : r[o.type], s = e.data ? Tt(e.data, n, i) : void 0, c = a ? ye(a, e.id, s) : pe(e.id);
  return c.meta = e, c;
}
function ye(e, t, n) {
  var i = pe(t);
  if (i.deferred = !0, ot(e)) {
    var r = i.state = et(void 0, function() {
      return (n ? e.withContext(n) : e).initialState;
    });
    i.getSnapshot = function() {
      return r;
    };
  }
  return i;
}
function rn(e) {
  try {
    return typeof e.send == "function";
  } catch {
    return !1;
  }
}
function on(e) {
  return rn(e) && "id" in e;
}
function an(e) {
  var t;
  return p((t = { subscribe: function() {
    return { unsubscribe: function() {
    } };
  }, id: "anonymous", getSnapshot: function() {
  } }, t[Q] = function() {
    return this;
  }, t), e);
}
var Pt = function(e) {
  return e.type === "atomic" || e.type === "final";
};
function ge(e) {
  return Object.keys(e.states).map(function(t) {
    return e.states[t];
  });
}
function pt(e) {
  return ge(e).filter(function(t) {
    return t.type !== "history";
  });
}
function me(e) {
  var t = [e];
  return Pt(e) ? t : t.concat(D(pt(e).map(me)));
}
function lt(e, t) {
  var n, i, r, o, a, s, c, u, h = new Set(e), f = Jt(h), l = new Set(t);
  try {
    for (var d = E(l), y = d.next(); !y.done; y = d.next())
      for (var v = y.value, x = v.parent; x && !l.has(x); )
        l.add(x), x = x.parent;
  } catch (w) {
    n = { error: w };
  } finally {
    try {
      y && !y.done && (i = d.return) && i.call(d);
    } finally {
      if (n)
        throw n.error;
    }
  }
  var g = Jt(l);
  try {
    for (var m = E(l), _ = m.next(); !_.done; _ = m.next()) {
      var v = _.value;
      if (v.type === "compound" && (!g.get(v) || !g.get(v).length))
        f.get(v) ? f.get(v).forEach(function(M) {
          return l.add(M);
        }) : v.initialStateNodes.forEach(function(M) {
          return l.add(M);
        });
      else if (v.type === "parallel")
        try {
          for (var b = (a = void 0, E(pt(v))), A = b.next(); !A.done; A = b.next()) {
            var L = A.value;
            l.has(L) || (l.add(L), f.get(L) ? f.get(L).forEach(function(M) {
              return l.add(M);
            }) : L.initialStateNodes.forEach(function(M) {
              return l.add(M);
            }));
          }
        } catch (M) {
          a = { error: M };
        } finally {
          try {
            A && !A.done && (s = b.return) && s.call(b);
          } finally {
            if (a)
              throw a.error;
          }
        }
    }
  } catch (w) {
    r = { error: w };
  } finally {
    try {
      _ && !_.done && (o = m.return) && o.call(m);
    } finally {
      if (r)
        throw r.error;
    }
  }
  try {
    for (var k = E(l), I = k.next(); !I.done; I = k.next())
      for (var v = I.value, x = v.parent; x && !l.has(x); )
        l.add(x), x = x.parent;
  } catch (w) {
    c = { error: w };
  } finally {
    try {
      I && !I.done && (u = k.return) && u.call(k);
    } finally {
      if (c)
        throw c.error;
    }
  }
  return l;
}
function xe(e, t) {
  var n = t.get(e);
  if (!n)
    return {};
  if (e.type === "compound") {
    var i = n[0];
    if (i) {
      if (Pt(i))
        return i.key;
    } else
      return {};
  }
  var r = {};
  return n.forEach(function(o) {
    r[o.key] = xe(o, t);
  }), r;
}
function Jt(e) {
  var t, n, i = /* @__PURE__ */ new Map();
  try {
    for (var r = E(e), o = r.next(); !o.done; o = r.next()) {
      var a = o.value;
      i.has(a) || i.set(a, []), a.parent && (i.has(a.parent) || i.set(a.parent, []), i.get(a.parent).push(a));
    }
  } catch (s) {
    t = { error: s };
  } finally {
    try {
      o && !o.done && (n = r.return) && n.call(r);
    } finally {
      if (t)
        throw t.error;
    }
  }
  return i;
}
function sn(e, t) {
  var n = lt([e], t);
  return xe(e, Jt(n));
}
function ft(e, t) {
  return Array.isArray(e) ? e.some(function(n) {
    return n === t;
  }) : e instanceof Set ? e.has(t) : !1;
}
function cn(e) {
  return V([], O(new Set(D(V([], O(e.map(function(t) {
    return t.ownEvents;
  })), !1)))), !1);
}
function Ot(e, t) {
  return t.type === "compound" ? pt(t).some(function(n) {
    return n.type === "final" && ft(e, n);
  }) : t.type === "parallel" ? pt(t).every(function(n) {
    return Ot(e, n);
  }) : !1;
}
function un(e) {
  return e === void 0 && (e = []), e.reduce(function(t, n) {
    return n.meta !== void 0 && (t[n.id] = n.meta), t;
  }, {});
}
function ne(e) {
  return new Set(D(e.map(function(t) {
    return t.tags;
  })));
}
function _e(e, t) {
  if (e === t)
    return !0;
  if (e === void 0 || t === void 0)
    return !1;
  if (j(e) || j(t))
    return e === t;
  var n = Object.keys(e), i = Object.keys(t);
  return n.length === i.length && n.every(function(r) {
    return _e(e[r], t[r]);
  });
}
function hn(e) {
  return typeof e != "object" || e === null ? !1 : "value" in e && "_event" in e;
}
function ln(e, t) {
  var n = e.exec, i = p(p({}, e), { exec: n !== void 0 ? function() {
    return n(t.context, t.event, { action: e, state: t, _event: t._event });
  } : void 0 });
  return i;
}
var F = function() {
  function e(t) {
    var n = this, i;
    this.actions = [], this.activities = Zt, this.meta = {}, this.events = [], this.value = t.value, this.context = t.context, this._event = t._event, this._sessionid = t._sessionid, this.event = this._event.data, this.historyValue = t.historyValue, this.history = t.history, this.actions = t.actions || [], this.activities = t.activities || Zt, this.meta = un(t.configuration), this.events = t.events || [], this.matches = this.matches.bind(this), this.toStrings = this.toStrings.bind(this), this.configuration = t.configuration, this.transitions = t.transitions, this.children = t.children, this.done = !!t.done, this.tags = (i = Array.isArray(t.tags) ? new Set(t.tags) : t.tags) !== null && i !== void 0 ? i : /* @__PURE__ */ new Set(), this.machine = t.machine, Object.defineProperty(this, "nextEvents", { get: function() {
      return cn(n.configuration);
    } });
  }
  return e.from = function(t, n) {
    if (t instanceof e)
      return t.context !== n ? new e({ value: t.value, context: n, _event: t._event, _sessionid: null, historyValue: t.historyValue, history: t.history, actions: [], activities: t.activities, meta: {}, events: [], configuration: [], transitions: [], children: {} }) : t;
    var i = it;
    return new e({ value: t, context: n, _event: i, _sessionid: null, historyValue: void 0, history: void 0, actions: [], activities: void 0, meta: void 0, events: [], configuration: [], transitions: [], children: {} });
  }, e.create = function(t) {
    return new e(t);
  }, e.inert = function(t, n) {
    if (t instanceof e) {
      if (!t.actions.length)
        return t;
      var i = it;
      return new e({ value: t.value, context: n, _event: i, _sessionid: null, historyValue: t.historyValue, history: t.history, activities: t.activities, configuration: t.configuration, transitions: [], children: {} });
    }
    return e.from(t, n);
  }, e.prototype.toStrings = function(t, n) {
    var i = this;
    if (t === void 0 && (t = this.value), n === void 0 && (n = "."), j(t))
      return [t];
    var r = Object.keys(t);
    return r.concat.apply(r, V([], O(r.map(function(o) {
      return i.toStrings(t[o], n).map(function(a) {
        return o + n + a;
      });
    })), !1));
  }, e.prototype.toJSON = function() {
    var t = this;
    t.configuration, t.transitions;
    var n = t.tags;
    t.machine;
    var i = qt(t, ["configuration", "transitions", "tags", "machine"]);
    return p(p({}, i), { tags: Array.from(n) });
  }, e.prototype.matches = function(t) {
    return Xt(t, this.value);
  }, e.prototype.hasTag = function(t) {
    return this.tags.has(t);
  }, e.prototype.can = function(t) {
    var n;
    ze(!!this.machine);
    var i = (n = this.machine) === null || n === void 0 ? void 0 : n.getTransitionData(this, t);
    return !!(i != null && i.transitions.length) && i.transitions.some(function(r) {
      return r.target !== void 0 || r.actions.length;
    });
  }, e;
}(), fn = { deferEvents: !1 }, ie = function() {
  function e(t) {
    this.processingEvent = !1, this.queue = [], this.initialized = !1, this.options = p(p({}, fn), t);
  }
  return e.prototype.initialize = function(t) {
    if (this.initialized = !0, t) {
      if (!this.options.deferEvents) {
        this.schedule(t);
        return;
      }
      this.process(t);
    }
    this.flushEvents();
  }, e.prototype.schedule = function(t) {
    if (!this.initialized || this.processingEvent) {
      this.queue.push(t);
      return;
    }
    if (this.queue.length !== 0)
      throw new Error("Event queue should be empty when it is not processing events");
    this.process(t), this.flushEvents();
  }, e.prototype.clear = function() {
    this.queue = [];
  }, e.prototype.flushEvents = function() {
    for (var t = this.queue.shift(); t; )
      this.process(t), t = this.queue.shift();
  }, e.prototype.process = function(t) {
    this.processingEvent = !0;
    try {
      t();
    } catch (n) {
      throw this.clear(), n;
    } finally {
      this.processingEvent = !1;
    }
  }, e;
}(), Vt = /* @__PURE__ */ new Map(), dn = 0, ct = { bookId: function() {
  return "x:".concat(dn++);
}, register: function(e, t) {
  return Vt.set(e, t), e;
}, get: function(e) {
  return Vt.get(e);
}, free: function(e) {
  Vt.delete(e);
} };
function Gt() {
  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 vn() {
  var e = Gt();
  if (e && "__xstate__" in e)
    return e.__xstate__;
}
function pn(e) {
  if (Gt()) {
    var t = vn();
    t && t.register(e);
  }
}
function yn(e, t) {
  t === void 0 && (t = {});
  var n = e.initialState, i = /* @__PURE__ */ new Set(), r = [], o = !1, a = function() {
    if (!o) {
      for (o = !0; r.length > 0; ) {
        var u = r.shift();
        n = e.transition(n, u, c), i.forEach(function(h) {
          return h.next(n);
        });
      }
      o = !1;
    }
  }, s = an({ id: t.id, send: function(u) {
    r.push(u), a();
  }, getSnapshot: function() {
    return n;
  }, subscribe: function(u, h, f) {
    var l = wt(u, h, f);
    return i.add(l), l.next(n), { unsubscribe: function() {
      i.delete(l);
    } };
  } }), c = { parent: t.parent, self: s, id: t.id || "anonymous", observers: i };
  return n = e.start ? e.start(c) : n, s;
}
var gn = { sync: !1, autoForward: !1 }, C;
(function(e) {
  e[e.NotStarted = 0] = "NotStarted", e[e.Running = 1] = "Running", e[e.Stopped = 2] = "Stopped";
})(C || (C = {}));
var mn = function() {
  function e(t, n) {
    n === void 0 && (n = e.defaultOptions);
    var i = this;
    this.machine = t, this.delayedEventsMap = {}, this.listeners = /* @__PURE__ */ new Set(), this.contextListeners = /* @__PURE__ */ new Set(), this.stopListeners = /* @__PURE__ */ new Set(), this.doneListeners = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Set(), this.sendListeners = /* @__PURE__ */ new Set(), this.initialized = !1, this.status = C.NotStarted, this.children = /* @__PURE__ */ new Map(), this.forwardTo = /* @__PURE__ */ new Set(), this._outgoingQueue = [], this.init = this.start, this.send = function(h, f) {
      if (at(h))
        return i.batch(h), i.state;
      var l = R(Nt(h, f));
      if (i.status === C.Stopped)
        return i.state;
      if (i.status !== C.Running && !i.options.deferEvents)
        throw new Error('Event "'.concat(l.name, '" was sent to uninitialized service "').concat(i.machine.id, `". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
Event: `).concat(JSON.stringify(l.data)));
      return i.scheduler.schedule(function() {
        i.forward(l);
        var d = i._nextState(l);
        i.update(d, l);
      }), i._state;
    }, this.sendTo = function(h, f, l) {
      var d = i.parent && (f === rt.Parent || i.parent.id === f), y = d ? i.parent : j(f) ? f === rt.Internal ? i : i.children.get(f) || ct.get(f) : Ue(f) ? f : void 0;
      if (!y) {
        if (!d)
          throw new Error("Unable to send event to child '".concat(f, "' from service '").concat(i.id, "'."));
        return;
      }
      if ("machine" in y) {
        if (i.status !== C.Stopped || i.parent !== y || i.state.done) {
          var v = p(p({}, h), { name: h.name === je ? "".concat(ht(i.id)) : h.name, origin: i.sessionId });
          !l && i.machine.config.predictableActionArguments ? i._outgoingQueue.push([y, v]) : y.send(v);
        }
      } else
        !l && i.machine.config.predictableActionArguments ? i._outgoingQueue.push([y, h.data]) : y.send(h.data);
    }, this._exec = function(h, f, l, d) {
      d === void 0 && (d = i.machine.options.actions);
      var y = h.exec || zt(h.type, d), v = T(y) ? y : y ? y.exec : h.exec;
      if (v)
        try {
          return v(f, l.data, i.machine.config.predictableActionArguments ? { action: h, _event: l } : { action: h, state: i.state, _event: l });
        } catch ($) {
          throw i.parent && i.parent.send({ type: "xstate.error", data: $ }), $;
        }
      switch (h.type) {
        case yt: {
          var x = h;
          i.defer(x);
          break;
        }
        case jt:
          var g = h;
          if (typeof g.delay == "number") {
            i.defer(g);
            return;
          } else
            g.to ? i.sendTo(g._event, g.to, l === it) : i.send(g._event);
          break;
        case re:
          i.cancel(h.sendId);
          break;
        case Mt: {
          if (i.status !== C.Running)
            return;
          var m = h.activity;
          if (!i.machine.config.predictableActionArguments && !i.state.activities[m.id || m.type])
            break;
          if (m.type === N.Invoke) {
            var _ = ve(m.src), b = i.machine.options.services ? i.machine.options.services[_.type] : void 0, A = m.id, L = m.data, k = "autoForward" in m ? m.autoForward : !!m.forward;
            if (!b)
              return;
            var I = L ? Tt(L, f, l) : void 0;
            if (typeof b == "string")
              return;
            var w = T(b) ? b(f, l.data, { data: I, src: _, meta: m.meta }) : b;
            if (!w)
              return;
            var M = void 0;
            ot(w) && (w = I ? w.withContext(I) : w, M = { autoForward: k }), i.spawn(w, A, M);
          } else
            i.spawnActivity(m);
          break;
        }
        case Ft: {
          i.stopChild(h.activity.id);
          break;
        }
        case ae:
          var S = h, P = S.label, B = S.value;
          P ? i.logger(P, B) : i.logger(B);
          break;
      }
    };
    var r = p(p({}, e.defaultOptions), n), o = r.clock, a = r.logger, s = r.parent, c = r.id, u = c !== void 0 ? c : t.id;
    this.id = u, this.logger = a, this.clock = o, this.parent = s, this.options = r, this.scheduler = new ie({ deferEvents: this.options.deferEvents }), this.sessionId = ct.bookId();
  }
  return Object.defineProperty(e.prototype, "initialState", { get: function() {
    var t = this;
    return this._initialState ? this._initialState : et(this, function() {
      return t._initialState = t.machine.initialState, t._initialState;
    });
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "state", { get: function() {
    return this._state;
  }, enumerable: !1, configurable: !0 }), e.prototype.execute = function(t, n) {
    var i, r;
    try {
      for (var o = E(t.actions), a = o.next(); !a.done; a = o.next()) {
        var s = a.value;
        this.exec(s, t, n);
      }
    } catch (c) {
      i = { error: c };
    } finally {
      try {
        a && !a.done && (r = o.return) && r.call(o);
      } finally {
        if (i)
          throw i.error;
      }
    }
  }, e.prototype.update = function(t, n) {
    var i, r, o, a, s, c, u, h, f = this;
    if (t._sessionid = this.sessionId, this._state = t, (!this.machine.config.predictableActionArguments || n === it) && this.options.execute)
      this.execute(this.state);
    else
      for (var l = void 0; l = this._outgoingQueue.shift(); )
        l[0].send(l[1]);
    if (this.children.forEach(function(w) {
      f.state.children[w.id] = w;
    }), this.devTools && this.devTools.send(n.data, t), t.event)
      try {
        for (var d = E(this.eventListeners), y = d.next(); !y.done; y = d.next()) {
          var v = y.value;
          v(t.event);
        }
      } catch (w) {
        i = { error: w };
      } finally {
        try {
          y && !y.done && (r = d.return) && r.call(d);
        } finally {
          if (i)
            throw i.error;
        }
      }
    try {
      for (var x = E(this.listeners), g = x.next(); !g.done; g = x.next()) {
        var v = g.value;
        v(t, t.event);
      }
    } catch (w) {
      o = { error: w };
    } finally {
      try {
        g && !g.done && (a = x.return) && a.call(x);
      } finally {
        if (o)
          throw o.error;
      }
    }
    try {
      for (var m = E(this.contextListeners), _ = m.next(); !_.done; _ = m.next()) {
        var b = _.value;
        b(this.state.context, this.state.history ? this.state.history.context : void 0);
      }
    } catch (w) {
      s = { error: w };
    } finally {
      try {
        _ && !_.done && (c = m.return) && c.call(m);
      } finally {
        if (s)
          throw s.error;
      }
    }
    if (this.state.done) {
      var A = t.configuration.find(function(w) {
        return w.type === "final" && w.parent === f.machine;
      }), L = A && A.doneData ? Tt(A.doneData, t.context, n) : void 0;
      this._doneEvent = Et(this.id, L);
      try {
        for (var k = E(this.doneListeners), I = k.next(); !I.done; I = k.next()) {
          var v = I.value;
          v(this._doneEvent);
        }
      } catch (w) {
        u = { error: w };
      } finally {
        try {
          I && !I.done && (h = k.return) && h.call(k);
        } finally {
          if (u)
            throw u.error;
        }
      }
      this._stop(), this._stopChildren(), ct.free(this.sessionId);
    }
  }, e.prototype.onTransition = function(t) {
    return this.listeners.add(t), this.status === C.Running && t(this.state, this.state.event), this;
  }, e.prototype.subscribe = function(t, n, i) {
    var r = this, o = wt(t, n, i);
    this.listeners.add(o.next), this.status !== C.NotStarted && o.next(this.state);
    var a = function() {
      r.doneListeners.delete(a), r.stopListeners.delete(a), o.complete();
    };
    return this.status === C.Stopped ? o.complete() : (this.onDone(a), this.onStop(a)), { unsubscribe: function() {
      r.listeners.delete(o.next), r.doneListeners.delete(a), r.stopListeners.delete(a);
    } };
  }, e.prototype.onEvent = function(t) {
    return this.eventListeners.add(t), this;
  }, e.prototype.onSend = function(t) {
    return this.sendListeners.add(t), this;
  }, e.prototype.onChange = function(t) {
    return this.contextListeners.add(t), this;
  }, e.prototype.onStop = function(t) {
    return this.stopListeners.add(t), this;
  }, e.prototype.onDone = function(t) {
    return this.status === C.Stopped && this._doneEvent ? t(this._doneEvent) : this.doneListeners.add(t), this;
  }, e.prototype.off = function(t) {
    return this.listeners.delete(t), this.eventListeners.delete(t), this.sendListeners.delete(t), this.stopListeners.delete(t), this.doneListeners.delete(t), this.contextListeners.delete(t), this;
  }, e.prototype.start = function(t) {
    var n = this;
    if (this.status === C.Running)
      return this;
    this.machine._init(), ct.register(this.sessionId, this), this.initialized = !0, this.status = C.Running;
    var i = t === void 0 ? this.initialState : et(this, function() {
      return hn(t) ? n.machine.resolveState(t) : n.machine.resolveState(F.from(t, n.machine.context));
    });
    return this.options.devTools && this.attachDev(), this.scheduler.initialize(function() {
      n.update(i, it);
    }), this;
  }, e.prototype._stopChildren = function() {
    this.children.forEach(function(t) {
      T(t.stop) && t.stop();
    }), this.children.clear();
  }, e.prototype._stop = function() {
    var t, n, i, r, o, a, s, c, u, h;
    try {
      for (var f = E(this.listeners), l = f.next(); !l.done; l = f.next()) {
        var d = l.value;
        this.listeners.delete(d);
      }
    } catch (k) {
      t = { error: k };
    } finally {
      try {
        l && !l.done && (n = f.return) && n.call(f);
      } finally {
        if (t)
          throw t.error;
      }
    }
    try {
      for (var y = E(this.stopListeners), v = y.next(); !v.done; v = y.next()) {
        var d = v.value;
        d(), this.stopListeners.delete(d);
      }
    } catch (k) {
      i = { error: k };
    } finally {
      try {
        v && !v.done && (r = y.return) && r.call(y);
      } finally {
        if (i)
          throw i.error;
      }
    }
    try {
      for (var x = E(this.contextListeners), g = x.next(); !g.done; g = x.next()) {
        var d = g.value;
        this.contextListeners.delete(d);
      }
    } catch (k) {
      o = { error: k };
    } finally {
      try {
        g && !g.done && (a = x.return) && a.call(x);
      } finally {
        if (o)
          throw o.error;
      }
    }
    try {
      for (var m = E(this.doneListeners), _ = m.next(); !_.done; _ = m.next()) {
        var d = _.value;
        this.doneListeners.delete(d);
      }
    } catch (k) {
      s = { error: k };
    } finally {
      try {
        _ && !_.done && (c = m.return) && c.call(m);
      } finally {
        if (s)
          throw s.error;
      }
    }
    if (!this.initialized)
      return this;
    this.initialized = !1, this.status = C.Stopped, this._initialState = void 0;
    try {
      for (var b = E(Object.keys(this.delayedEventsMap)), A = b.next(); !A.done; A = b.next()) {
        var L = A.value;
        this.clock.clearTimeout(this.delayedEventsMap[L]);
      }
    } catch (k) {
      u = { error: k };
    } finally {
      try {
        A && !A.done && (h = b.return) && h.call(b);
      } finally {
        if (u)
          throw u.error;
      }
    }
    this.scheduler.clear(), this.scheduler = new ie({ deferEvents: this.options.deferEvents });
  }, e.prototype.stop = function() {
    var t = this, n = this.scheduler;
    return this._stop(), n.schedule(function() {
      var i = R({ type: "xstate.stop" }), r = et(t, function() {
        var o = D(V([], O(t.state.configuration), !1).sort(function(h, f) {
          return f.order - h.order;
        }).map(function(h) {
          return G(h.onExit, t.machine.options.actions);
        })), a = O(At(t.machine, t.state, t.state.context, i, [{ type: "exit", actions: o }], t.machine.config.predictableActionArguments ? t._exec : void 0, t.machine.config.predictableActionArguments || t.machine.config.preserveActionOrder), 2), s = a[0], c = a[1], u = new F({ value: t.state.value, context: c, _event: i, _sessionid: t.sessionId, historyValue: void 0, history: t.state, actions: s.filter(function(h) {
          return !$t(h);
        }), activities: {}, events: [], configuration: [], transitions: [], children: {}, done: t.state.done, tags: t.state.tags, machine: t.machine });
        return u.changed = !0, u;
      });
      t.update(r, i), t._stopChildren(), ct.free(t.sessionId);
    }), this;
  }, e.prototype.batch = function(t) {
    var n = this;
    if (!(this.status === C.NotStarted && this.options.deferEvents) && this.status !== C.Running)
      throw new Error("".concat(t.length, ' event(s) were sent to uninitialized service "').concat(this.machine.id, '". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));
    if (t.length) {
      var i = !!this.machine.config.predictableActionArguments && this._exec;
      this.scheduler.schedule(function() {
        var r, o, a = n.state, s = !1, c = [], u = function(d) {
          var y = R(d);
          n.forward(y), a = et(n, function() {
            return n.machine.transition(a, y, void 0, i || void 0);
          }), c.push.apply(c, V([], O(n.machine.config.predictableActionArguments ? a.actions : a.actions.map(function(v) {
            return ln(v, a);
          })), !1)), s = s || !!a.changed;
        };
        try {
          for (var h = E(t), f = h.next(); !f.done; f = h.next()) {
            var l = f.value;
            u(l);
          }
        } catch (d) {
          r = { error: d };
        } finally {
          try {
            f && !f.done && (o = h.return) && o.call(h);
          } finally {
            if (r)
              throw r.error;
          }
        }
        a.changed = s, a.actions = c, n.update(a, R(t[t.length - 1]));
      });
    }
  }, e.prototype.sender = function(t) {
    return this.send.bind(this, t);
  }, e.prototype._nextState = function(t, n) {
    var i = this;
    n === void 0 && (n = !!this.machine.config.predictableActionArguments && this._exec);
    var r = R(t);
    if (r.name.indexOf(Yt) === 0 && !this.state.nextEvents.some(function(a) {
      return a.indexOf(Yt) === 0;
    }))
      throw r.data.data;
    var o = et(this, function() {
      return i.machine.transition(i.state, r, void 0, n || void 0);
    });
    return o;
  }, e.prototype.nextState = function(t) {
    return this._nextState(t, !1);
  }, e.prototype.forward = function(t) {
    var n, i;
    try {
      for (var r = E(this.forwardTo), o = r.next(); !o.done; o = r.next()) {
        var a = o.value, s = this.children.get(a);
        if (!s)
          throw new Error("Unable to forward event '".concat(t, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(a, "'."));
        s.send(t);
      }
    } catch (c) {
      n = { error: c };
    } finally {
      try {
        o && !o.done && (i = r.return) && i.call(r);
      } finally {
        if (n)
          throw n.error;
      }
    }
  }, e.prototype.defer = function(t) {
    var n = this, i = this.clock.setTimeout(function() {
      "to" in t && t.to ? n.sendTo(t._event, t.to, !0) : n.send(t._event);
    }, t.delay);
    t.id && (this.delayedEventsMap[t.id] = i);
  }, e.prototype.cancel = function(t) {
    this.clock.clearTimeout(this.delayedEventsMap[t]), delete this.delayedEventsMap[t];
  }, e.prototype.exec = function(t, n, i) {
    i === void 0 && (i = this.machine.options.actions), this._exec(t, n.context, n._event, i);
  }, e.prototype.removeChild = function(t) {
    var n;
    this.children.delete(t), this.forwardTo.delete(t), (n = this.state) === null || n === void 0 || delete n.children[t];
  }, e.prototype.stopChild = function(t) {
    var n = this.children.get(t);
    n && (this.removeChild(t), T(n.stop) && n.stop());
  }, e.prototype.spawn = function(t, n, i) {
    if (this.status !== C.Running)
      return ye(t, n);
    if (te(t))
      return this.spawnPromise(Promise.resolve(t), n);
    if (T(t))
      return this.spawnCallback(t, n);
    if (on(t))
      return this.spawnActor(t, n);
    if (Je(t))
      return this.spawnObservable(t, n);
    if (ot(t))
      return this.spawnMachine(t, p(p({}, i), { id: n }));
    if (Re(t))
      return this.spawnBehavior(t, n);
    throw new Error('Unable to spawn entity "'.concat(n, '" of type "').concat(typeof t, '".'));
  }, e.prototype.spawnMachine = function(t, n) {
    var i = this;
    n === void 0 && (n = {});
    var r = new e(t, p(p({}, this.options), { parent: this, id: n.id || t.id })), o = p(p({}, gn), n);
    o.sync && r.onTransition(function(s) {
      i.send(se, { state: s, id: r.id });
    });
    var a = r;
    return this.children.set(r.id, a), o.autoForward && this.forwardTo.add(r.id), r.onDone(function(s) {
      i.removeChild(r.id), i.send(R(s, { origin: r.id }));
    }).start(), a;
  }, e.prototype.spawnBehavior = function(t, n) {
    var i = yn(t, { id: n, parent: this });
    return this.children.set(n, i), i;
  }, e.prototype.spawnPromise = function(t, n) {
    var i, r = this, o = !1, a;
    t.then(function(c) {
      o || (a = c, r.removeChild(n), r.send(R(Et(n, c), { origin: n })));
    }, function(c) {
      if (!o) {
        r.removeChild(n);
        var u = ht(n, c);
        try {
          r.send(R(u, { origin: n }));
        } catch {
          r.devTools && r.devTools.send(u, r.state), r.machine.strict && r.stop();
        }
      }
    });
    var s = (i = { id: n, send: function() {
    }, subscribe: function(c, u, h) {
      var f = wt(c, u, h), l = !1;
      return t.then(function(d) {
        l || (f.next(d), !l && f.complete());
      }, function(d) {
        l || f.error(d);
      }), { unsubscribe: function() {
        return l = !0;
      } };
    }, stop: function() {
      o = !0;
    }, toJSON: function() {
      return { id: n };
    }, getSnapshot: function() {
      return a;
    } }, i[Q] = function() {
      return this;
    }, i);
    return this.children.set(n, s), s;
  }, e.prototype.spawnCallback = function(t, n) {
    var i, r = this, o = !1, a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c, u = function(l) {
      c = l, s.forEach(function(d) {
        return d(l);
      }), !o && r.send(R(l, { origin: n }));
    }, h;
    try {
      h = t(u, function(l) {
        a.add(l);
      });
    } catch (l) {
      this.send(ht(n, l));
    }
    if (te(h))
      return this.spawnPromise(h, n);
    var f = (i = { id: n, send: function(l) {
      return a.forEach(function(d) {
        return d(l);
      });
    }, subscribe: function(l) {
      var d = wt(l);
      return s.add(d.next), { unsubscribe: function() {
        s.delete(d.next);
      } };
    }, stop: function() {
      o = !0, T(h) && h();
    }, toJSON: function() {
      return { id: n };
    }, getSnapshot: function() {
      return c;
    } }, i[Q] = function() {
      return this;
    }, i);
    return this.children.set(n, f), f;
  }, e.prototype.spawnObservable = function(t, n) {
    var i, r = this, o, a = t.subscribe(function(c) {
      o = c, r.send(R(c, { origin: n }));
    }, function(c) {
      r.removeChild(n), r.send(R(ht(n, c), { origin: n }));
    }, function() {
      r.removeChild(n), r.send(R(Et(n), { origin: n }));
    }), s = (i = { id: n, send: function() {
    }, subscribe: function(c, u, h) {
      return t.subscribe(c, u, h);
    }, stop: function() {
      return a.unsubscribe();
    }, getSnapshot: function() {
      return o;
    }, toJSON: function() {
      return { id: n };
    } }, i[Q] = function() {
      return this;
    }, i);
    return this.children.set(n, s), s;
  }, e.prototype.spawnActor = function(t, n) {
    return this.children.set(n, t), t;
  }, e.prototype.spawnActivity = function(t) {
    var n = this.machine.options && this.machine.options.activities ? this.machine.options.activities[t.type] : void 0;
    if (n) {
      var i = n(this.state.context, t);
      this.spawnEffect(t.id, i);
    }
  }, e.prototype.spawnEffect = function(t, n) {
    var i;
    this.children.set(t, (i = { id: t, send: function() {
    }, subscribe: function() {
      return { unsubscribe: function() {
      } };
    }, stop: n || void 0, getSnapshot: function() {
    }, toJSON: function() {
      return { id: t };
    } }, i[Q] = function() {
      return this;
    }, i));
  }, e.prototype.attachDev = function() {
    var t = Gt();
    if (this.options.devTools && t) {
      if (t.__REDUX_DEVTOOLS_EXTENSION__) {
        var n = typeof this.options.devTools == "object" ? this.options.devTools : void 0;
        this.devTools = t.__REDUX_DEVTOOLS_EXTENSION__.connect(p(p({ name: this.id, autoPause: !0, stateSanitizer: function(i) {
          return { value: i.value, context: i.context, actions: i.actions };
        } }, n), { features: p({ jump: !1, skip: !1 }, n ? n.features : void 0) }), this.machine), this.devTools.init(this.state);
      }
      pn(this);
    }
  }, e.prototype.toJSON = function() {
    return { id: this.id };
  }, e.prototype[Q] = function() {
    return this;
  }, e.prototype.getSnapshot = function() {
    return this.status === C.NotStarted ? this.initialState : this._state;
  }, e.defaultOptions = { execute: !0, deferEvents: !0, clock: { setTimeout: function(t, n) {
    return setTimeout(t, n);
  }, clearTimeout: function(t) {
    return clearTimeout(t);
  } }, logger: console.log.bind(console), devTools: !1 }, e.interpret = Se, e;
}();
function Se(e, t) {
  var n = new mn(e, t);
  return n;
}
function xn(e) {
  if (typeof e == "string") {
    var t = { type: e };
    return t.toString = function() {
      return e;
    }, t;
  }
  return e;
}
function _t(e) {
  return p(p({ type: Ct }, e), { toJSON: function() {
    e.onDone, e.onError;
    var t = qt(e, ["onDone", "onError"]);
    return p(p({}, t), { type: Ct, src: xn(e.src) });
  } });
}
var St = "", Ut = "#", Dt = "*", K = {}, tt = function(e) {
  return e[0] === Ut;
}, _n = function() {
  return { actions: {}, guards: {}, services: {}, activities: {}, delays: {} };
}, Sn = function() {
  function e(t, n, i, r) {
    i === void 0 && (i = "context" in t ? t.context : void 0);
    var o = this, a;
    this.config = t, this._context = i, this.order = -1, this.__xstatenode = !0, this.__cache = { events: void 0, relativeValue: /* @__PURE__ */ new Map(), initialStateValue: void 0, initialState: void 0, on: void 0, transitions: void 0, candidates: {}, delayedTransitions: void 0 }, this.idMap = {}, this.tags = [], this.options = Object.assign(_n(), n), this.parent = r == null ? void 0 : r.parent, this.key = this.config.key || (r == null ? void 0 : r.key) || this.config.id || "(machine)", this.machine = this.parent ? this.parent.machine : this, this.path = this.parent ? this.parent.path.concat(this.key) : [], this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : ce), this.id = this.config.id || V([this.machine.key], O(this.path), !1).join(this.delimiter), this.version = this.parent ? this.parent.version : this.config.version, this.type = this.config.type || (this.config.parallel ? "parallel" : this.config.states && Object.keys(this.config.states).length ? "compound" : this.config.history ? "history" : "atomic"), this.schema = this.parent ? this.machine.schema : (a = this.config.schema) !== null && a !== void 0 ? a : {}, this.description = this.config.description, this.initial = this.config.initial, this.states = this.config.states ? ut(this.config.states, function(u, h) {
      var f, l = new e(u, {}, void 0, { parent: o, key: h });
      return Object.assign(o.idMap, p((f = {}, f[l.id] = l, f), l.idMap)), l;
    }) : K;
    var s = 0;
    function c(u) {
      var h, f;
      u.order = s++;
      try {
        for (var l = E(ge(u)), d = l.next(); !d.done; d = l.next()) {
          var y = d.value;
          c(y);
        }
      } catch (v) {
        h = { error: v };
      } finally {
        try {
          d && !d.done && (f = l.return) && f.call(l);
        } finally {
          if (h)
            throw h.error;
        }
      }
    }
    c(this), this.history = this.config.history === !0 ? "shallow" : this.config.history || !1, this._transient = !!this.config.always || (this.config.on ? Array.isArray(this.config.on) ? this.config.on.some(function(u) {
      var h = u.event;
      return h === St;
    }) : St in this.config.on : !1), this.strict = !!this.config.strict, this.onEntry = U(this.config.entry || this.config.onEntry).map(function(u) {
      return vt(u);
    }), this.onExit = U(this.config.exit || this.config.onExit).map(function(u) {
      return vt(u);
    }), this.meta = this.config.meta, this.doneData = this.type === "final" ? this.config.data : void 0, this.invoke = U(this.config.invoke).map(function(u, h) {
      var f, l;
      if (ot(u)) {
        var d = mt(o.id, h);
        return o.machine.options.services = p((f = {}, f[d] = u, f), o.machine.options.services), _t({ src: d, id: d });
      } else if (j(u.src)) {
        var d = u.id || mt(o.id, h);
        return _t(p(p({}, u), { id: d, src: u.src }));
      } else if (ot(u.src) || T(u.src)) {
        var d = u.id || mt(o.id, h);
        return o.machine.options.services = p((l = {}, l[d] = u.src, l), o.machine.options.services), _t(p(p({ id: d }, u), { src: d }));
      } else {
        var y = u.src;
        return _t(p(p({ id: mt(o.id, h) }, u), { src: y }));
      }
    }), this.activities = U(this.config.activities).concat(this.invoke).map(function(u) {
      return Qt(u);
    }), this.transition = this.transition.bind(this), this.tags = U(this.config.tags);
  }
  return e.prototype._init = function() {
    this.__cache.transitions || me(this).forEach(function(t) {
      return t.on;
    });
  }, e.prototype.withConfig = function(t, n) {
    var i = this.options, r = i.actions, o = i.activities, a = i.guards, s = i.services, c = i.delays;
    return new e(this.config, { actions: p(p({}, r), t.actions), activities: p(p({}, o), t.activities), guards: p(p({}, a), t.guards), services: p(p({}, s), t.services), delays: p(p({}, c), t.delays) }, n ?? this.context);
  }, e.prototype.withContext = function(t) {
    return new e(this.config, this.options, t);
  }, Object.defineProperty(e.prototype, "context", { get: function() {
    return T(this._context) ? this._context() : this._context;
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "definition", { get: function() {
    return { id: this.id, key: this.key, version: this.version, context: this.context, type: this.type, initial: this.initial, history: this.history, states: ut(this.states, function(t) {
      return t.definition;
    }), on: this.on, transitions: this.transitions, entry: this.onEntry, exit: this.onExit, activities: this.activities || [], meta: this.meta, order: this.order || -1, data: this.doneData, invoke: this.invoke, description: this.description, tags: this.tags };
  }, enumerable: !1, configurable: !0 }), e.prototype.toJSON = function() {
    return this.definition;
  }, Object.defineProperty(e.prototype, "on", { get: function() {
    if (this.__cache.on)
      return this.__cache.on;
    var t = this.transitions;
    return this.__cache.on = t.reduce(function(n, i) {
      return n[i.eventType] = n[i.eventType] || [], n[i.eventType].push(i), n;
    }, {});
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "after", { get: function() {
    return this.__cache.delayedTransitions || (this.__cache.delayedTransitions = this.getDelayedTransitions(), this.__cache.delayedTransitions);
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "transitions", { get: function() {
    return this.__cache.transitions || (this.__cache.transitions = this.formatTransitions(), this.__cache.transitions);
  }, enumerable: !1, configurable: !0 }), e.prototype.getCandidates = function(t) {
    if (this.__cache.candidates[t])
      return this.__cache.candidates[t];
    var n = t === St, i = this.transitions.filter(function(r) {
      var o = r.eventType === t;
      return n ? o : o || r.eventType === Dt;
    });
    return this.__cache.candidates[t] = i, i;
  }, e.prototype.getDelayedTransitions = function() {
    var t = this, n = this.config.after;
    if (!n)
      return [];
    var i = function(o, a) {
      var s = T(o) ? "".concat(t.id, ":delay[").concat(a, "]") : o, c = tn(s, t.id);
      return t.onEntry.push(Qe(c, { delay: o })), t.onExit.push(He(c)), c;
    }, r = at(n) ? n.map(function(o, a) {
      var s = i(o.delay, a);
      return p(p({}, o), { event: s });
    }) : D(Object.keys(n).map(function(o, a) {
      var s = n[o], c = j(s) ? { target: s } : s, u = isNaN(+o) ? o : +o, h = i(u, a);
      return U(c).map(function(f) {
        return p(p({}, f), { event: h, delay: u });
      });
    }));
    return r.map(function(o) {
      var a = o.delay;
      return p(p({}, t.formatTransition(o)), { delay: a });
    });
  }, e.prototype.getStateNodes = function(t) {
    var n, i = this;
    if (!t)
      return [];
    var r = t instanceof F ? t.value : dt(t, this.delimiter);
    if (j(r)) {
      var o = this.getStateNode(r).initial;
      return o !== void 0 ? this.getStateNodes((n = {}, n[r] = o, n)) : [this, this.states[r]];
    }
    var a = Object.keys(r), s = [this];
    return s.push.apply(s, V([], O(D(a.map(function(c) {
      return i.getStateNode(c).getStateNodes(r[c]);
    }))), !1)), s;
  }, e.prototype.handles = function(t) {
    var n = ue(t);
    return this.events.includes(n);
  }, e.prototype.resolveState = function(t) {
    var n = t instanceof F ? t : F.create(t), i = Array.from(lt([], this.getStateNodes(n.value)));
    return new F(p(p({}, n), { value: this.resolve(n.value), configuration: i, done: Ot(i, this), tags: ne(i), machine: this.machine }));
  }, e.prototype.transitionLeafNode = function(t, n, i) {
    var r = this.getStateNode(t), o = r.next(n, i);
    return !o || !o.transitions.length ? this.next(n, i) : o;
  }, e.prototype.transitionCompoundNode = function(t, n, i) {
    var r = Object.keys(t), o = this.getStateNode(r[0]), a = o._transition(t[r[0]], n, i);
    return !a || !a.transitions.length ? this.next(n, i) : a;
  }, e.prototype.transitionParallelNode = function(t, n, i) {
    var r, o, a = {};
    try {
      for (var s = E(Object.keys(t)), c = s.next(); !c.done; c = s.next()) {
        var u = c.value, h = t[u];
        if (h) {
          var f = this.getStateNode(u), l = f._transition(h, n, i);
          l && (a[u] = l);
        }
      }
    } catch (g) {
      r = { error: g };
    } finally {
      try {
        c && !c.done && (o = s.return) && o.call(s);
      } finally {
        if (r)
          throw r.error;
      }
    }
    var d = Object.keys(a).map(function(g) {
      return a[g];
    }), y = D(d.map(function(g) {
      return g.transitions;
    })), v = d.some(function(g) {
      return g.transitions.length > 0;
    });
    if (!v)
      return this.next(n, i);
    var x = D(Object.keys(a).map(function(g) {
      return a[g].configuration;
    }));
    return { transitions: y, exitSet: D(d.map(function(g) {
      return g.exitSet;
    })), configuration: x, source: n, actions: D(Object.keys(a).map(function(g) {
      return a[g].actions;
    })) };
  }, e.prototype._transition = function(t, n, i) {
    return j(t) ? this.transitionLeafNode(t, n, i) : Object.keys(t).length === 1 ? this.transitionCompoundNode(t, n, i) : this.transitionParallelNode(t, n, i);
  }, e.prototype.getTransitionData = function(t, n) {
    return this._transition(t.value, t, R(n));
  }, e.prototype.next = function(t, n) {
    var i, r, o = this, a = n.name, s = [], c = [], u;
    try {
      for (var h = E(this.getCandidates(a)), f = h.next(); !f.done; f = h.next()) {
        var l = f.value, d = l.cond, y = l.in, v = t.context, x = y ? j(y) && tt(y) ? t.matches(dt(this.getStateNodeById(y).path, this.delimiter)) : Xt(dt(y, this.delimiter), De(this.path.slice(0, -2))(t.value)) : !0, g = !1;
        try {
          g = !d || de(this.machine, d, v, n, t);
        } catch (b) {
          throw new Error("Unable to evaluate guard '".concat(d.name || d.type, "' in transition for event '").concat(a, "' in state node '").concat(this.id, `':
`).concat(b.message));
        }
        if (g && x) {
          l.target !== void 0 && (c = l.target), s.push.apply(s, V([], O(l.actions), !1)), u = l;
          break;
        }
      }
    } catch (b) {
      i = { error: b };
    } finally {
      try {
        f && !f.done && (r = h.return) && r.call(h);
      } finally {
        if (i)
          throw i.error;
      }
    }
    if (u) {
      if (!c.length)
        return { transitions: [u], exitSet: [], configuration: t.value ? [this] : [], source: t, actions: s };
      var m = D(c.map(function(b) {
        return o.getRelativeStateNodes(b, t.historyValue);
      })), _ = !!u.internal;
      return { transitions: [u], exitSet: _ ? [] : D(c.map(function(b) {
        return o.getPotentiallyReenteringNodes(b);
      })), configuration: m, source: t, actions: s };
    }
  }, e.prototype.getPotentiallyReenteringNodes = function(t) {
    if (this.order < t.order)
      return [this];
    for (var n = [], i = this, r = t; i && i !== r; )
      n.push(i), i = i.parent;
    return i !== r ? [] : (n.push(r), n);
  }, e.prototype.getActions = function(t, n, i, r, o, a, s) {
    var c, u, h, f, l = this, d = a ? lt([], this.getStateNodes(a.value)) : [], y = /* @__PURE__ */ new Set();
    try {
      for (var v = E(Array.from(t).sort(function(S, P) {
        return S.order - P.order;
      })), x = v.next(); !x.done; x = v.next()) {
        var g = x.value;
        (!ft(d, g) || ft(i.exitSet, g) || g.parent && y.has(g.parent)) && y.add(g);
      }
    } catch (S) {
      c = { error: S };
    } finally {
      try {
        x && !x.done && (u = v.return) && u.call(v);
      } finally {
        if (c)
          throw c.error;
      }
    }
    try {
      for (var m = E(d), _ = m.next(); !_.done; _ = m.next()) {
        var g = _.value;
        (!ft(t, g) || ft(i.exitSet, g.parent)) && i.exitSet.push(g);
      }
    } catch (S) {
      h = { error: S };
    } finally {
      try {
        _ && !_.done && (f = m.return) && f.call(m);
      } finally {
        if (h)
          throw h.error;
      }
    }
    i.exitSet.sort(function(S, P) {
      return P.order - S.order;
    });
    var b = Array.from(y).sort(function(S, P) {
      return S.order - P.order;
    }), A = new Set(i.exitSet), L = D(b.map(function(S) {
      var P = [];
      if (S.type !== "final")
        return P;
      var B = S.parent;
      if (!B.parent)
        return P;
      P.push(xt(S.id, S.doneData), xt(B.id, S.doneData ? Tt(S.doneData, r, o) : void 0));
      var $ = B.parent;
      return $.type === "parallel" && pt($).every(function(st) {
        return Ot(i.configuration, st);
      }) && P.push(xt($.id)), P;
    })), k = b.map(function(S) {
      var P = S.onEntry, B = S.activities.map(function($) {
        return Ye($);
      });
      return { type: "entry", actions: G(s ? V(V([], O(P), !1), O(B), !1) : V(V([], O(B), !1), O(P), !1), l.machine.options.actions) };
    }).concat({ type: "state_done", actions: L.map(function(S) {
      return Fe(S);
    }) }), I = Array.from(A).map(function(S) {
      return { type: "exit", actions: G(V(V([], O(S.onExit), !1), O(S.activities.map(function(P) {
        return Ze(P);
      })), !1), l.machine.options.actions) };
    }), w = I.concat({ type: "transition", actions: G(i.actions, this.machine.options.actions) }).concat(k);
    if (n) {
      var M = G(D(V([], O(t), !1).sort(function(S, P) {
        return P.order - S.order;
      }).map(function(S) {
        return S.onExit;
      })), this.machine.options.actions).filter(function(S) {
        return !$t(S);
      });
      return w.concat({ type: "stop", actions: M });
    }
    return w;
  }, e.prototype.transition = function(t, n, i, r) {
    t === void 0 && (t = this.initialState);
    var o = R(n), a;
    if (t instanceof F)
      a = i === void 0 ? t : this.resolveState(F.from(t, i));
    else {
      var s = j(t) ? this.resolve(kt(this.getResolvedPath(t))) : this.resolve(t), c = i ?? this.machine.context;
      a = this.resolveState(F.from(s, c));
    }
    if (this.strict && !this.events.includes(o.name) && !Ce(o.name))
      throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(o.name, "'"));
    var u = this._transition(a.value, a, o) || { transitions: [], configuration: [], exitSet: [], source: a, actions: [] }, h = lt([], this.getStateNodes(a.value)), f = u.configuration.length ? lt(h, u.configuration) : h;
    return u.configuration = V([], O(f), !1), this.resolveTransition(u, a, a.context, r, o);
  }, e.prototype.resolveRaisedTransition = function(t, n, i, r) {
    var o, a = t.actions;
    return t = this.transition(t, n, void 0, r), t._event = i, t.event = i.data, (o = t.actions).unshift.apply(o, V([], O(a), !1)), t;
  }, e.prototype.resolveTransition = function(t, n, i, r, o) {
    var a, s, c, u, h = this;
    o === void 0 && (o = it);
    var f = t.configuration, l = !n || t.transitions.length > 0, d = l ? t.configuration : n ? n.configuration : [], y = Ot(d, this), v = l ? sn(this.machine, f) : void 0, x = n ? n.historyValue ? n.historyValue : t.source ? this.machine.historyValue(n.value) : void 0 : void 0, g = this.getActions(new Set(d), y, t, i, o, n, r), m = n ? p({}, n.activities) : {};
    try {
      for (var _ = E(g), b = _.next(); !b.done; b = _.next()) {
        var A = b.value;
        try {
          for (var L = (c = void 0, E(A.actions)), k = L.next(); !k.done; k = L.next()) {
            var I = k.value;
            I.type === Mt ? m[I.activity.id || I.activity.type] = I : I.type === Ft && (m[I.activity.id || I.activity.type] = !1);
          }
        } catch (J) {
          c = { error: J };
        } finally {
          try {
            k && !k.done && (u = L.return) && u.call(L);
          } finally {
            if (c)
              throw c.error;
          }
        }
      }
    } catch (J) {
      a = { error: J };
    } finally {
      try {
        b && !b.done && (s = _.return) && s.call(_);
      } finally {
        if (a)
          throw a.error;
      }
    }
    var w = O(At(this, n, i, o, g, r, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2), M = w[0], S = w[1], P = O(Be(M, $t), 2), B = P[0], $ = P[1], st = M.filter(function(J) {
      var Y;
      return J.type === Mt && ((Y = J.activity) === null || Y === void 0 ? void 0 : Y.type) === Ct;
    }), gt = st.reduce(function(J, Y) {
      return J[Y.activity.id] = nn(Y.activity, h.machine, S, o), J;
    }, n ? p({}, n.children) : {}), q = new F({ value: v || n.value, context: S, _event: o, _sessionid: n ? n._sessionid : null, historyValue: v ? x ? $e(x, v) : void 0 : n ? n.historyValue : void 0, history: !v || t.source ? n : void 0, actions: v ? $ : [], activities: v ? m : n ? n.activities : {}, events: [], configuration: d, transitions: t.transitions, children: gt, done: y, tags: ne(d), machine: this }), W = i !== S;
    q.changed = o.name === se || W;
    var H = q.history;
    H && delete H.history;
    var Wt = !y && (this._transient || f.some(function(J) {
      return J._transient;
    }));
    if (!l && (!Wt || o.name === St))
      return q;
    var z = q;
    if (!y)
      for (Wt && (z = this.resolveRaisedTransition(z, { type: Ae }, o, r)); B.length; ) {
        var be = B.shift();
        z = this.resolveRaisedTransition(z, be._event, o, r);
      }
    var we = z.changed || (H ? !!z.actions.length || W || typeof H.value != typeof z.value || !_e(z.value, H.value) : void 0);
    return z.changed = we, z.history = H, z;
  }, e.prototype.getStateNode = function(t) {
    if (tt(t))
      return this.machine.getStateNodeById(t);
    if (!this.states)
      throw new Error("Unable to retrieve child state '".concat(t, "' from '").concat(this.id, "'; no child states exist."));
    var n = this.states[t];
    if (!n)
      throw new Error("Child state '".concat(t, "' does not exist on '").concat(this.id, "'"));
    return n;
  }, e.prototype.getStateNodeById = function(t) {
    var n = tt(t) ? t.slice(Ut.length) : t;
    if (n === this.id)
      return this;
    var i = this.machine.idMap[n];
    if (!i)
      throw new Error("Child state node '#".concat(n, "' does not exist on machine '").concat(this.id, "'"));
    return i;
  }, e.prototype.getStateNodeByPath = function(t) {
    if (typeof t == "string" && tt(t))
      try {
        return this.getStateNodeById(t.slice(1));
      } catch {
      }
    for (var n = Bt(t, this.delimiter).slice(), i = this; n.length; ) {
      var r = n.shift();
      if (!r.length)
        break;
      i = i.getStateNode(r);
    }
    return i;
  }, e.prototype.resolve = function(t) {
    var n, i = this;
    if (!t)
      return this.initialStateValue || K;
    switch (this.type) {
      case "parallel":
        return ut(this.initialStateValue, function(o, a) {
          return o ? i.getStateNode(a).resolve(t[a] || o) : K;
        });
      case "compound":
        if (j(t)) {
          var r = this.getStateNode(t);
          return r.type === "parallel" || r.type === "compound" ? (n = {}, n[t] = r.initialStateValue, n) : t;
        }
        return Object.keys(t).length ? ut(t, function(o, a) {
          return o ? i.getStateNode(a).resolve(o) : K;
        }) : this.initialStateValue || {};
      default:
        return t || K;
    }
  }, e.prototype.getResolvedPath = function(t) {
    if (tt(t)) {
      var n = this.machine.idMap[t.slice(Ut.length)];
      if (!n)
        throw new Error("Unable to find state node '".concat(t, "'"));
      return n.path;
    }
    return Bt(t, this.delimiter);
  }, Object.defineProperty(e.prototype, "initialStateValue", { get: function() {
    var t;
    if (this.__cache.initialStateValue)
      return this.__cache.initialStateValue;
    var n;
    if (this.type === "parallel")
      n = Kt(this.states, function(i) {
        return i.initialStateValue || K;
      }, function(i) {
        return i.type !== "history";
      });
    else if (this.initial !== void 0) {
      if (!this.states[this.initial])
        throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
      n = Pt(this.states[this.initial]) ? this.initial : (t = {}, t[this.initial] = this.states[this.initial].initialStateValue, t);
    } else
      n = {};
    return this.__cache.initialStateValue = n, this.__cache.initialStateValue;
  }, enumerable: !1, configurable: !0 }), e.prototype.getInitialState = function(t, n) {
    this._init();
    var i = this.getStateNodes(t);
    return this.resolveTransition({ configuration: i, exitSet: [], transitions: [], source: void 0, actions: [] }, void 0, n ?? this.machine.context, void 0);
  }, Object.defineProperty(e.prototype, "initialState", { get: function() {
    var t = this.initialStateValue;
    if (!t)
      throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
    return this.getInitialState(t);
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "target", { get: function() {
    var t;
    if (this.type === "history") {
      var n = this.config;
      j(n.target) ? t = tt(n.target) ? kt(this.machine.getStateNodeById(n.target).path.slice(this.path.length - 1)) : n.target : t = n.target;
    }
    return t;
  }, enumerable: !1, configurable: !0 }), e.prototype.getRelativeStateNodes = function(t, n, i) {
    return i === void 0 && (i = !0), i ? t.type === "history" ? t.resolveHistory(n) : t.initialStateNodes : [t];
  }, Object.defineProperty(e.prototype, "initialStateNodes", { get: function() {
    var t = this;
    if (Pt(this))
      return [this];
    if (this.type === "compound" && !this.initial)
      return [this];
    var n = bt(this.initialStateValue);
    return D(n.map(function(i) {
      return t.getFromRelativePath(i);
    }));
  }, enumerable: !1, configurable: !0 }), e.prototype.getFromRelativePath = function(t) {
    if (!t.length)
      return [this];
    var n = O(t), i = n[0], r = n.slice(1);
    if (!this.states)
      throw new Error("Cannot retrieve subPath '".concat(i, "' from node with no states"));
    var o = this.getStateNode(i);
    if (o.type === "history")
      return o.resolveHistory();
    if (!this.states[i])
      throw new Error("Child state '".concat(i, "' does not exist on '").concat(this.id, "'"));
    return this.states[i].getFromRelativePath(r);
  }, e.prototype.historyValue = function(t) {
    if (Object.keys(this.states).length)
      return { current: t || this.initialStateValue, states: Kt(this.states, function(n, i) {
        if (!t)
          return n.historyValue();
        var r = j(t) ? void 0 : t[i];
        return n.historyValue(r || n.initialStateValue);
      }, function(n) {
        return !n.history;
      }) };
  }, e.prototype.resolveHistory = function(t) {
    var n = this;
    if (this.type !== "history")
      return [this];
    var i = this.parent;
    if (!t) {
      var r = this.target;
      return r ? D(bt(r).map(function(a) {
        return i.getFromRelativePath(a);
      })) : i.initialStateNodes;
    }
    var o = Me(i.path, "states")(t).current;
    return j(o) ? [i.getStateNode(o)] : D(bt(o).map(function(a) {
      return n.history === "deep" ? i.getFromRelativePath(a) : [i.states[a[0]]];
    }));
  }, Object.defineProperty(e.prototype, "stateIds", { get: function() {
    var t = this, n = D(Object.keys(this.states).map(function(i) {
      return t.states[i].stateIds;
    }));
    return [this.id].concat(n);
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "events", { get: function() {
    var t, n, i, r;
    if (this.__cache.events)
      return this.__cache.events;
    var o = this.states, a = new Set(this.ownEvents);
    if (o)
      try {
        for (var s = E(Object.keys(o)), c = s.next(); !c.done; c = s.next()) {
          var u = c.value, h = o[u];
          if (h.states)
            try {
              for (var f = (i = void 0, E(h.events)), l = f.next(); !l.done; l = f.next()) {
                var d = l.value;
                a.add("".concat(d));
              }
            } catch (y) {
              i = { error: y };
            } finally {
              try {
                l && !l.done && (r = f.return) && r.call(f);
              } finally {
                if (i)
                  throw i.error;
              }
            }
        }
      } catch (y) {
        t = { error: y };
      } finally {
        try {
          c && !c.done && (n = s.return) && n.call(s);
        } finally {
          if (t)
            throw t.error;
        }
      }
    return this.__cache.events = Array.from(a);
  }, enumerable: !1, configurable: !0 }), Object.defineProperty(e.prototype, "ownEvents", { get: function() {
    var t = new Set(this.transitions.filter(function(n) {
      return !(!n.target && !n.actions.length && n.internal);
    }).map(function(n) {
      return n.eventType;
    }));
    return Array.from(t);
  }, enumerable: !1, configurable: !0 }), e.prototype.resolveTarget = function(t) {
    var n = this;
    if (t !== void 0)
      return t.map(function(i) {
        if (!j(i))
          return i;
        var r = i[0] === n.delimiter;
        if (r && !n.parent)
          return n.getStateNodeByPath(i.slice(1));
        var o = r ? n.key + i : i;
        if (n.parent)
          try {
            var a = n.parent.getStateNodeByPath(o);
            return a;
          } catch (s) {
            throw new Error("Invalid transition definition for state node '".concat(n.id, `':
`).concat(s.message));
          }
        else
          return n.getStateNodeByPath(o);
      });
  }, e.prototype.formatTransition = function(t) {
    var n = this, i = qe(t.target), r = "internal" in t ? t.internal : i ? i.some(function(c) {
      return j(c) && c[0] === n.delimiter;
    }) : !0, o = this.machine.options.guards, a = this.resolveTarget(i), s = p(p({}, t), { actions: G(U(t.actions)), cond: fe(t.cond, o), target: a, source: this, internal: r, eventType: t.event, toJSON: function() {
      return p(p({}, s), { target: s.target ? s.target.map(function(c) {
        return "#".concat(c.id);
      }) : void 0, source: "#".concat(n.id) });
    } });
    return s;
  }, e.prototype.formatTransitions = function() {
    var t, n, i = this, r;
    if (!this.config.on)
      r = [];
    else if (Array.isArray(this.config.on))
      r = this.config.on;
    else {
      var o = this.config.on, a = Dt, s = o[a], c = s === void 0 ? [] : s, u = qt(o, [typeof a == "symbol" ? a : a + ""]);
      r = D(Object.keys(u).map(function(m) {
        var _ = Z(m, u[m]);
        return _;
      }).concat(Z(Dt, c)));
    }
    var h = this.config.always ? Z("", this.config.always) : [], f = this.config.onDone ? Z(String(xt(this.id)), this.config.onDone) : [], l = D(this.invoke.map(function(m) {
      var _ = [];
      return m.onDone && _.push.apply(_, V([], O(Z(String(Et(m.id)), m.onDone)), !1)), m.onError && _.push.apply(_, V([], O(Z(String(ht(m.id)), m.onError)), !1)), _;
    })), d = this.after, y = D(V(V(V(V([], O(f), !1), O(l), !1), O(r), !1), O(h), !1).map(function(m) {
      return U(m).map(function(_) {
        return i.formatTransition(_);
      });
    }));
    try {
      for (var v = E(d), x = v.next(); !x.done; x = v.next()) {
        var g = x.value;
        y.push(g);
      }
    } catch (m) {
      t = { error: m };
    } finally {
      try {
        x && !x.done && (n = v.return) && n.call(v);
      } finally {
        if (t)
          throw t.error;
      }
    }
    return y;
  }, e;
}();
function bn(e, t) {
  return new Sn(e, t);
}
var nt = { click: "onClick", mouseenter: "onMouseEnter", mouseleave: "onMouseLeave", complete: "onComplete", after: "onAfter", enter: "onEnter", show: "onShow" };
Object.values(nt);
var wn = Object.keys(nt), kn = class {
  constructor(e, t) {
    X(this, "activeStateId", "");
    X(this, "_service");
    X(this, "_domListeners", /* @__PURE__ */ new Map());
    X(this, "_domElement");
    X(this, "_playerListeners", /* @__PURE__ */ new Map());
    X(this, "_player");
    X(this, "_machineSchemas", /* @__PURE__ */ new Map());
    X(this, "_onShowPrevValue", 0);
    this._player = t, this._machineSchemas = this._transformToXStateSchema(e), this._domElement = t.container;
  }
  start(e) {
    this.stop();
    let t = this._machineSchemas.get(e);
    if (typeof t > "u")
      throw It(`invalid state machine id ${e}`);
    this._service = Se(bn(t)), this._addEventListeners(), this._service.start();
  }
  stop() {
    var e;
    this._removeEventListeners(), (e = this._service) == null || e.stop(), this._player.stop();
  }
  _removeEventListeners() {
    var e;
    this._requiresDomElement();
    for (let [t, n] of this._domListeners)
      t === "visibilityChange" && this._player.stopPlayOnShow(), (e = this._domElement) == null || e.removeEventListener(t, n), this._domListeners.delete(t);
    for (let [t, n] of this._playerListeners)
      this._player.removeEventListener(t, n), this._playerListeners.delete(t);
  }
  _addEventListeners() {
    this._requiresDomElement();
    let e = (n) => {
      this._service.send({ type: n });
    }, t = (n) => {
      function i() {
        e(n);
      }
      return i;
    };
    this._service.subscribe((n) => {
      var i;
      if (typeof n.changed > "u" || n.changed) {
        this._removeEventListeners();
        for (let r of n.nextEvents)
          if (wn.filter((o) => o !== "complete" && o !== "show").includes(r)) {
            let o = t(r);
            this._domListeners.set(r, o), (i = this._domElement) == null || i.addEventListener(r, o, { once: !0 });
          } else if (r === "complete") {
            let o = t(r);
            this._player.addEventListener(r, o), this._playerListeners.set(r, o);
          } else if (r === "show") {
            let o = t(r);
            this._player.addIntersectionObserver({ callbackOnIntersect: (a) => {
              a > 0 && (a !== 100 && this._onShowPrevValue !== a && o(), this._onShowPrevValue = a);
            }, threshold: [] }), this._domListeners.set("visibilityChange", o);
          }
      }
    });
  }
  subscribe(e) {
    throw It(e.toString());
  }
  _transformToXStateSchema(e) {
    var t, n, i;
    let r = /* @__PURE__ */ new Map();
    for (let o of e) {
      let a = {}, s = {};
      if (s.id = o.descriptor.id, typeof o.descriptor.initial < "u" && (s.initial = o.descriptor.initial), typeof o < "u") {
        let c = o.states;
        for (let u in c)
          if (typeof c[u] < "u" && c[u]) {
            let h = c[u], f = h.playbackSettings, l = Object.keys(h).filter((v) => v.startsWith("on")), d = {}, y = {};
            for (let v of l)
              if (typeof h[v] < "u") {
                let x = h[v];
                if (v === nt.after) {
                  let g = x;
                  y[g.ms] = { target: (t = x == null ? void 0 : x.state) != null ? t : "" };
                } else
                  v === nt.enter ? d[Ht(nt, v)] = { target: (n = x == null ? void 0 : x.state) != null ? n : "" } : d[Ht(nt, v)] = { target: (i = x == null ? void 0 : x.state) != null ? i : "" };
              }
            a[u] = { entry: () => {
              !this._player.getAnimationInstance() || h.animationId && h.animationId !== this._player.currentAnimationId ? this._player.play(h.animationId, () => ({ ...ke, ...f })).then(() => {
                this._updatePlaybackSettings(f);
              }).catch((v) => {
                Te(`State machine error: ${v.message}`);
              }) : this._updatePlaybackSettings(f);
            }, exit: () => {
              typeof f.segments < "u" && this._player.resetSegments(!1), typeof f.playOnScroll < "u" && this._player.stopPlayOnScroll();
            }, on: d, after: y, meta: f };
          }
      }
      s.states = a, r.set(s.id, s);
    }
    return r;
  }
  _handlePlaySegments(e) {
    if (typeof e.segments == "string")
      this._player.goToAndPlay(e.segments, !0);
    else {
      let [t, n] = e.segments, i = t;
      t !== 0 && t === n && (i = t - 1), t === 0 && t === n ? this._player.goToAndPlay(t, !0) : this._player.playSegments([i, n], !0);
    }
  }
  _handlePlayOnScroll(e) {
    let t = e.playOnScroll;
    if (e.segments && typeof e.segments != "string") {
      let n = e.segments;
      this._player.playOnScroll({ threshold: t, segments: n });
    } else
      this._player.playOnScroll({ threshold: t });
  }
  _updatePlaybackSettings(e) {
    if (!this._player.getAnimationInstance())
      throw new Error("Unable to update playbackSettings. Animations is not rendered yet.");
    typeof e.autoplay < "u" && (this._player.setAutoplay(e.autoplay), e.autoplay ? this._player.play() : this._player.pause()), typeof e.direction < "u" && this._player.setDirection(e.direction), typeof e.intermission < "u" && this._player.setIntermission(e.intermission), typeof e.loop < "u" && this._player.setLoop(e.loop), typeof e.playMode < "u" && this._player.setMode(e.playMode), typeof e.speed < "u" && this._player.setSpeed(e.speed), typeof e.defaultTheme < "u" && this._player.setDefaultTheme(e.defaultTheme), typeof e.playOnScroll < "u" && this._handlePlayOnScroll(e), e.segments && this._handlePlaySegments(e), e.autoplay || this._player.pause();
  }
  _requiresDomElement() {
    if (!this._domElement)
      throw It("Requires a DOM element to attach events.");
  }
};
/*! Bundled license information:

xstate/es/_virtual/_tslib.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.
  ***************************************************************************** *)
*/
export {
  kn as DotLottieStateMachineManager
};
//# sourceMappingURL=dotlottie-state-machine-manager-7AXSPEV3-C4JS27KT-fb1cc94c.js.map
