import { createMachine as l } from "valtio-fsm";
import { logger as n } from "../logger.js";
import { guardStates as _ } from "./guards/index.js";
import { initialContext as s } from "./context.js";
const t = l(
  "initial_dry",
  {
    // 1. Wallet not connected
    initial_dry: {
      transitions: ["initial_wallet", "input_valid_dry"]
    },
    // 2. Wallet connected
    initial_wallet: {
      transitions: [
        "initial_dry",
        "input_valid_internal",
        "input_valid_external",
        "input_valid_dry"
      ]
    },
    // 3. Wallet not connected and user inputs are valid
    input_valid_dry: {
      transitions: [
        "initial_dry",
        "initial_wallet",
        "quote_success_dry",
        "input_valid_internal",
        "input_valid_external"
      ]
    },
    // 4. Wallet connected and user inputs are valid for Intents swap
    input_valid_internal: {
      transitions: [
        "initial_dry",
        "initial_wallet",
        "quote_success_internal",
        "transfer_success",
        "input_valid_dry"
      ]
    },
    // 5. Wallet connected and user inputs are valid for external swap
    input_valid_external: {
      transitions: [
        "initial_dry",
        "initial_wallet",
        "quote_success_external",
        "transfer_success",
        "input_valid_dry"
      ]
    },
    // 6. Wallet not connected and dry quote fetched
    quote_success_dry: {
      transitions: [
        "initial_dry",
        "input_valid_dry",
        "initial_wallet",
        "input_valid_external",
        "input_valid_internal"
      ]
    },
    // 7. Wallet connected and real quote fetched
    quote_success_internal: {
      transitions: [
        "initial_dry",
        "initial_wallet",
        "input_valid_internal",
        "input_valid_external",
        "transfer_success",
        "input_valid_dry"
      ]
    },
    quote_success_external: {
      transitions: [
        "initial_dry",
        "initial_wallet",
        "input_valid_internal",
        "input_valid_external",
        "transfer_success",
        "input_valid_dry"
      ]
    },
    // 8. Transfer is made
    transfer_success: {
      transitions: ["initial_dry", "initial_wallet"]
    }
  },
  s
), p = (i, { onMoved: r } = {}) => {
  if (t.current === i)
    return;
  if (!t.canMoveTo(i)) {
    n.error(
      `[WIDGET] Invalid logical transition request with moveTo (from ${t.current} to ${i})`
    );
    return;
  }
  if (!_(t.context, [i])) {
    n.error(
      `[WIDGET] Invalid context state for transition request with moveTo (from ${t.current} to ${i})`
    );
    return;
  }
  const { current: a, context: e } = t.moveTo(i);
  a === i && (e.state = i, r?.(i));
};
export {
  t as machine,
  p as moveTo
};
//# sourceMappingURL=machine.js.map
