import {c as createCommonjsModule} from "./common/xstate-dev.cjs-65b37d22.js";
import {x as xstateActors_cjs} from "./common/xstate-actors.cjs-cf331ae7.js";
import {r as raiseF051f097_cjs} from "./common/raise-f051f097.cjs-87f17174.js";
import {S as StateMachineD3e2432b_cjs} from "./common/StateMachine-d3e2432b.cjs-e1749576.js";
import {a as assignF10db67b_cjs} from "./common/assign-f10db67b.cjs-8e67bc08.js";
import {l as log30abbb83_cjs} from "./common/log-30abbb83.cjs-a9773a4d.js";
var xstate_cjs = createCommonjsModule(function(module, exports) {
  Object.defineProperty(exports, "__esModule", {value: true});
  function assertEvent2(event, type) {
    const types = raiseF051f097_cjs.toArray(type);
    const matches = types.some((descriptor) => raiseF051f097_cjs.matchesEventDescriptor(event.type, descriptor));
    if (!matches) {
      const typesText = types.length === 1 ? `type matching "${types[0]}"` : `one of types matching "${types.join('", "')}"`;
      throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
    }
  }
  function createMachine2(config, implementations) {
    return new StateMachineD3e2432b_cjs.StateMachine(config, implementations);
  }
  function createInertActorScope(actorLogic) {
    const self = raiseF051f097_cjs.createActor(actorLogic);
    const inertActorScope = {
      self,
      defer: () => {
      },
      id: "",
      logger: () => {
      },
      sessionId: "",
      stopChild: () => {
      },
      system: self.system,
      emit: () => {
      },
      actionExecutor: () => {
      }
    };
    return inertActorScope;
  }
  function getInitialSnapshot2(actorLogic, ...[input]) {
    const actorScope = createInertActorScope(actorLogic);
    return actorLogic.getInitialSnapshot(actorScope, input);
  }
  function getNextSnapshot2(actorLogic, snapshot, event) {
    const inertActorScope = createInertActorScope(actorLogic);
    inertActorScope.self._snapshot = snapshot;
    return actorLogic.transition(snapshot, event, inertActorScope);
  }
  function setup2({
    schemas,
    actors,
    actions,
    guards,
    delays
  }) {
    return {
      assign: assignF10db67b_cjs.assign,
      sendTo: log30abbb83_cjs.sendTo,
      raise: raiseF051f097_cjs.raise,
      log: log30abbb83_cjs.log,
      cancel: raiseF051f097_cjs.cancel,
      stopChild: raiseF051f097_cjs.stopChild,
      enqueueActions: log30abbb83_cjs.enqueueActions,
      emit: log30abbb83_cjs.emit,
      spawnChild: raiseF051f097_cjs.spawnChild,
      createStateConfig: (config) => config,
      createAction: (fn) => fn,
      createMachine: (config) => createMachine2({
        ...config,
        schemas
      }, {
        actors,
        actions,
        guards,
        delays
      }),
      extend: (extended) => setup2({
        schemas,
        actors,
        actions: {
          ...actions,
          ...extended.actions
        },
        guards: {
          ...guards,
          ...extended.guards
        },
        delays: {
          ...delays,
          ...extended.delays
        }
      })
    };
  }
  class SimulatedClock2 {
    constructor() {
      this.timeouts = new Map();
      this._now = 0;
      this._id = 0;
      this._flushing = false;
      this._flushingInvalidated = false;
    }
    now() {
      return this._now;
    }
    getId() {
      return this._id++;
    }
    setTimeout(fn, timeout) {
      this._flushingInvalidated = this._flushing;
      const id = this.getId();
      this.timeouts.set(id, {
        start: this.now(),
        timeout,
        fn
      });
      return id;
    }
    clearTimeout(id) {
      this._flushingInvalidated = this._flushing;
      this.timeouts.delete(id);
    }
    set(time) {
      if (this._now > time) {
        throw new Error("Unable to travel back in time");
      }
      this._now = time;
      this.flushTimeouts();
    }
    flushTimeouts() {
      if (this._flushing) {
        this._flushingInvalidated = true;
        return;
      }
      this._flushing = true;
      const sorted = [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
        const endA = timeoutA.start + timeoutA.timeout;
        const endB = timeoutB.start + timeoutB.timeout;
        return endB > endA ? -1 : 1;
      });
      for (const [id, timeout] of sorted) {
        if (this._flushingInvalidated) {
          this._flushingInvalidated = false;
          this._flushing = false;
          this.flushTimeouts();
          return;
        }
        if (this.now() - timeout.start >= timeout.timeout) {
          this.timeouts.delete(id);
          timeout.fn.call(null);
        }
      }
      this._flushing = false;
    }
    increment(ms) {
      this._now += ms;
      this.flushTimeouts();
    }
  }
  function toPromise2(actor) {
    return new Promise((resolve, reject) => {
      actor.subscribe({
        complete: () => {
          resolve(actor.getSnapshot().output);
        },
        error: reject
      });
    });
  }
  function transition2(logic, snapshot, event) {
    const executableActions = [];
    const actorScope = createInertActorScope(logic);
    actorScope.actionExecutor = (action) => {
      executableActions.push(action);
    };
    const nextSnapshot = logic.transition(snapshot, event, actorScope);
    return [nextSnapshot, executableActions];
  }
  function initialTransition2(logic, ...[input]) {
    const executableActions = [];
    const actorScope = createInertActorScope(logic);
    actorScope.actionExecutor = (action) => {
      executableActions.push(action);
    };
    const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
    return [nextSnapshot, executableActions];
  }
  function getMicrosteps2(machine, snapshot, event) {
    const actorScope = createInertActorScope(machine);
    const {
      microsteps
    } = raiseF051f097_cjs.macrostep(snapshot, event, actorScope, []);
    return microsteps;
  }
  function getInitialMicrosteps2(machine, ...[input]) {
    const actorScope = createInertActorScope(machine);
    const initEvent = raiseF051f097_cjs.createInitEvent(input);
    const internalQueue = [];
    const preInitialSnapshot = machine._getPreInitialState(actorScope, initEvent, internalQueue);
    const first = raiseF051f097_cjs.initialMicrostep(machine.root, preInitialSnapshot, actorScope, initEvent, internalQueue);
    const {
      microsteps
    } = raiseF051f097_cjs.macrostep(first[0], initEvent, actorScope, internalQueue);
    return [first, ...microsteps];
  }
  function getNextTransitions2(state) {
    const potentialTransitions = [];
    const atomicStates = state._nodes.filter(raiseF051f097_cjs.isAtomicStateNode);
    const visited = new Set();
    for (const stateNode of atomicStates) {
      for (const s of [stateNode].concat(raiseF051f097_cjs.getProperAncestors(stateNode, void 0))) {
        if (visited.has(s.id)) {
          continue;
        }
        visited.add(s.id);
        for (const [, transitions] of s.transitions) {
          potentialTransitions.push(...transitions);
        }
        if (s.always) {
          potentialTransitions.push(...s.always);
        }
      }
    }
    return potentialTransitions;
  }
  const defaultWaitForOptions = {
    timeout: Infinity
  };
  function waitFor2(actorRef, predicate, options) {
    const resolvedOptions = {
      ...defaultWaitForOptions,
      ...options
    };
    return new Promise((res, rej) => {
      const {
        signal
      } = resolvedOptions;
      if (signal == null ? void 0 : signal.aborted) {
        rej(signal.reason);
        return;
      }
      let done = false;
      const handle = resolvedOptions.timeout === Infinity ? void 0 : setTimeout(() => {
        dispose();
        rej(new Error(`Timeout of ${resolvedOptions.timeout} ms exceeded`));
      }, resolvedOptions.timeout);
      const dispose = () => {
        clearTimeout(handle);
        done = true;
        sub == null ? void 0 : sub.unsubscribe();
        if (abortListener) {
          signal.removeEventListener("abort", abortListener);
        }
      };
      function checkEmitted(emitted) {
        if (predicate(emitted)) {
          dispose();
          res(emitted);
        }
      }
      let abortListener;
      let sub;
      checkEmitted(actorRef.getSnapshot());
      if (done) {
        return;
      }
      if (signal) {
        abortListener = () => {
          dispose();
          rej(signal.reason);
        };
        signal.addEventListener("abort", abortListener);
      }
      sub = actorRef.subscribe({
        next: checkEmitted,
        error: (err) => {
          dispose();
          rej(err);
        },
        complete: () => {
          dispose();
          rej(new Error(`Actor terminated without satisfying predicate`));
        }
      });
      if (done) {
        sub.unsubscribe();
      }
    });
  }
  exports.createEmptyActor = xstateActors_cjs.createEmptyActor;
  exports.fromCallback = xstateActors_cjs.fromCallback;
  exports.fromEventObservable = xstateActors_cjs.fromEventObservable;
  exports.fromObservable = xstateActors_cjs.fromObservable;
  exports.fromPromise = xstateActors_cjs.fromPromise;
  exports.fromTransition = xstateActors_cjs.fromTransition;
  exports.Actor = raiseF051f097_cjs.Actor;
  exports.__unsafe_getAllOwnEventDescriptors = raiseF051f097_cjs.getAllOwnEventDescriptors;
  exports.and = raiseF051f097_cjs.and;
  exports.cancel = raiseF051f097_cjs.cancel;
  exports.createActor = raiseF051f097_cjs.createActor;
  exports.getStateNodes = raiseF051f097_cjs.getStateNodes;
  exports.interpret = raiseF051f097_cjs.interpret;
  exports.isMachineSnapshot = raiseF051f097_cjs.isMachineSnapshot;
  exports.matchesState = raiseF051f097_cjs.matchesState;
  exports.not = raiseF051f097_cjs.not;
  exports.or = raiseF051f097_cjs.or;
  exports.pathToStateValue = raiseF051f097_cjs.pathToStateValue;
  exports.raise = raiseF051f097_cjs.raise;
  exports.spawnChild = raiseF051f097_cjs.spawnChild;
  exports.stateIn = raiseF051f097_cjs.stateIn;
  exports.stop = raiseF051f097_cjs.stop;
  exports.stopChild = raiseF051f097_cjs.stopChild;
  exports.toObserver = raiseF051f097_cjs.toObserver;
  exports.StateMachine = StateMachineD3e2432b_cjs.StateMachine;
  exports.StateNode = StateMachineD3e2432b_cjs.StateNode;
  exports.assign = assignF10db67b_cjs.assign;
  exports.SpecialTargets = log30abbb83_cjs.SpecialTargets;
  exports.emit = log30abbb83_cjs.emit;
  exports.enqueueActions = log30abbb83_cjs.enqueueActions;
  exports.forwardTo = log30abbb83_cjs.forwardTo;
  exports.log = log30abbb83_cjs.log;
  exports.sendParent = log30abbb83_cjs.sendParent;
  exports.sendTo = log30abbb83_cjs.sendTo;
  exports.SimulatedClock = SimulatedClock2;
  exports.assertEvent = assertEvent2;
  exports.createMachine = createMachine2;
  exports.getInitialMicrosteps = getInitialMicrosteps2;
  exports.getInitialSnapshot = getInitialSnapshot2;
  exports.getMicrosteps = getMicrosteps2;
  exports.getNextSnapshot = getNextSnapshot2;
  exports.getNextTransitions = getNextTransitions2;
  exports.initialTransition = initialTransition2;
  exports.setup = setup2;
  exports.toPromise = toPromise2;
  exports.transition = transition2;
  exports.waitFor = waitFor2;
});
var Actor = xstate_cjs.Actor;
var SimulatedClock = xstate_cjs.SimulatedClock;
var SpecialTargets = xstate_cjs.SpecialTargets;
var StateMachine = xstate_cjs.StateMachine;
var StateNode = xstate_cjs.StateNode;
var __unsafe_getAllOwnEventDescriptors = xstate_cjs.__unsafe_getAllOwnEventDescriptors;
var and = xstate_cjs.and;
var assertEvent = xstate_cjs.assertEvent;
var assign = xstate_cjs.assign;
var cancel = xstate_cjs.cancel;
var createActor = xstate_cjs.createActor;
var createEmptyActor = xstate_cjs.createEmptyActor;
var createMachine = xstate_cjs.createMachine;
var emit = xstate_cjs.emit;
var enqueueActions = xstate_cjs.enqueueActions;
var forwardTo = xstate_cjs.forwardTo;
var fromCallback = xstate_cjs.fromCallback;
var fromEventObservable = xstate_cjs.fromEventObservable;
var fromObservable = xstate_cjs.fromObservable;
var fromPromise = xstate_cjs.fromPromise;
var fromTransition = xstate_cjs.fromTransition;
var getInitialMicrosteps = xstate_cjs.getInitialMicrosteps;
var getInitialSnapshot = xstate_cjs.getInitialSnapshot;
var getMicrosteps = xstate_cjs.getMicrosteps;
var getNextSnapshot = xstate_cjs.getNextSnapshot;
var getNextTransitions = xstate_cjs.getNextTransitions;
var getStateNodes = xstate_cjs.getStateNodes;
var initialTransition = xstate_cjs.initialTransition;
var interpret = xstate_cjs.interpret;
var isMachineSnapshot = xstate_cjs.isMachineSnapshot;
var log = xstate_cjs.log;
var matchesState = xstate_cjs.matchesState;
var not = xstate_cjs.not;
var or = xstate_cjs.or;
var pathToStateValue = xstate_cjs.pathToStateValue;
var raise = xstate_cjs.raise;
var sendParent = xstate_cjs.sendParent;
var sendTo = xstate_cjs.sendTo;
var setup = xstate_cjs.setup;
var spawnChild = xstate_cjs.spawnChild;
var stateIn = xstate_cjs.stateIn;
var stop = xstate_cjs.stop;
var stopChild = xstate_cjs.stopChild;
var toObserver = xstate_cjs.toObserver;
var toPromise = xstate_cjs.toPromise;
var transition = xstate_cjs.transition;
var waitFor = xstate_cjs.waitFor;
export {Actor, SimulatedClock, SpecialTargets, StateMachine, StateNode, __unsafe_getAllOwnEventDescriptors, and, assertEvent, assign, cancel, createActor, createEmptyActor, createMachine, emit, enqueueActions, forwardTo, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition, getInitialMicrosteps, getInitialSnapshot, getMicrosteps, getNextSnapshot, getNextTransitions, getStateNodes, initialTransition, interpret, isMachineSnapshot, log, matchesState, not, or, pathToStateValue, raise, sendParent, sendTo, setup, spawnChild, stateIn, stop, stopChild, toObserver, toPromise, transition, waitFor};
export default null;
