import { setup } from "xstate";

export const settingsMachine = setup({
  types: {
    events: {} as
      | { type: "OPEN_SETTINGS" }
      | { type: "OPEN_FAQ" }
      | { type: "OPEN_ACCOUNT" }
      | { type: "OPEN_SUPPORT" }
      | { type: "OPEN_TRANSACTIONS_HISTORY" }
      | { type: "OPEN_LANGUAGE" }
      | { type: "CLOSE" }
      | { type: "BACK" },
  },
}).createMachine({
  id: "settings",
  initial: "closed",
  states: {
    closed: {
      on: {
        OPEN_SETTINGS: { target: "settings" },
      },
    },
    settings: {
      on: {
        CLOSE: { target: "closed" },
        OPEN_FAQ: { target: "faq" },
        OPEN_ACCOUNT: { target: "account" },
        OPEN_SUPPORT: { target: "support" },
        OPEN_TRANSACTIONS_HISTORY: { target: "transactionsHistory" },
        OPEN_LANGUAGE: { target: "language" },
      },
    },
    faq: {
      on: {
        CLOSE: { target: "closed" },
        BACK: { target: "settings" },
      },
    },
    account: {
      on: {
        CLOSE: { target: "closed" },
        BACK: { target: "settings" },
      },
    },
    support: {
      on: {
        CLOSE: { target: "closed" },
        BACK: { target: "settings" },
      },
    },
    transactionsHistory: {
      on: {
        CLOSE: { target: "closed" },
        BACK: { target: "settings" },
      },
    },
    language: {
      on: {
        CLOSE: { target: "closed" },
        BACK: { target: "settings" },
      },
    },
  },
});
