var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/eftposPay/store/index.tsx
var store_exports = {};
__export(store_exports, {
  EActionTypes: () => EActionTypes,
  Provider: () => Provider,
  backUpFree: () => backUpFree,
  backUpProduction: () => backUpProduction,
  reducers: () => reducers,
  updateClient: () => updateClient,
  updateComponent: () => updateComponent,
  updateCurrentCustomStemItem: () => updateCurrentCustomStemItem,
  updateCurrentStemItem: () => updateCurrentStemItem,
  updateCustom: () => updateCustom,
  updateDevice: () => updateDevice,
  updateKey: () => updateKey,
  updateNextStep: () => updateNextStep,
  updateState: () => updateState,
  updateStatus: () => updateStatus,
  updateStepKey: () => updateStepKey,
  updateSteps: () => updateSteps,
  useContextData: () => useContextData,
  useDispatch: () => useDispatch
});
module.exports = __toCommonJS(store_exports);
var import_react = __toESM(require("react"));
var import_const = require("../const");
var import_helper = require("../helper");
var import_useThunkReducer = __toESM(require("./useThunkReducer"));
var EActionTypes = /* @__PURE__ */ ((EActionTypes2) => {
  EActionTypes2["UPDATE_INIT"] = "UPDATE_INIT";
  EActionTypes2["UPDATE_CUSTOM"] = "UPDATE_CUSTOM";
  EActionTypes2["UPDATE_KEY"] = "UPDATE_KEY";
  EActionTypes2["UPDATE_STEP_KEY"] = "UPDATE_STEP_KEY";
  EActionTypes2["UPDATE_DEVICE"] = "UPDATE_DEVICE";
  EActionTypes2["UPDATE_NEXT_STEP"] = "UPDATE_NEXT_STEP";
  EActionTypes2["UPDATE_STATUS"] = "UPDATE_STATUS";
  EActionTypes2["UPDATE_TITLE"] = "UPDATE_TITLE";
  EActionTypes2["UPDATE_LOADING"] = "UPDATE_LOADING";
  EActionTypes2["UPDATE_COMPONENT"] = "UPDATE_COMPONENT";
  EActionTypes2["UPDATE_STEPS"] = "UPDATE_STEPS";
  EActionTypes2["UPDATE_STEP_CURRENT_ITEM_CUSTOM"] = "UPDATE_STEP_CURRENT_ITEM_CUSTOM";
  EActionTypes2["UPDATE_STEP_ITEM"] = "UPDATE_STEP_ITEM";
  EActionTypes2["BACKUP_PRODUCTION"] = "BACKUP_PRODUCTION";
  EActionTypes2["BACKUP_FREE"] = "BACKUP_FREE";
  EActionTypes2["UPDATE_CLIENT"] = "UPDATE_CLIENT";
  return EActionTypes2;
})(EActionTypes || {});
var updateKey = (key) => ({
  type: "UPDATE_KEY" /* UPDATE_KEY */,
  payload: {
    key
  }
});
var updateDevice = (payload) => ({
  type: "UPDATE_DEVICE" /* UPDATE_DEVICE */,
  payload
});
var updateStepKey = () => ({
  type: "UPDATE_STEP_KEY" /* UPDATE_STEP_KEY */,
  payload: {}
});
var updateNextStep = (warn) => ({
  type: "UPDATE_NEXT_STEP" /* UPDATE_NEXT_STEP */,
  payload: warn ? { warn } : {}
});
var updateCustom = (payload) => ({
  type: "UPDATE_CUSTOM" /* UPDATE_CUSTOM */,
  payload
});
var updateStatus = (status) => ({
  type: "UPDATE_LOADING" /* UPDATE_LOADING */,
  payload: { status }
});
var updateComponent = (component, render) => ({
  type: "UPDATE_COMPONENT" /* UPDATE_COMPONENT */,
  payload: component ? {
    component,
    type: "unset",
    render: typeof render === "boolean" ? render : false
  } : {
    type: "step",
    render: typeof render === "boolean" ? render : true
  }
});
var updateSteps = (steps) => ({
  type: "UPDATE_STEPS" /* UPDATE_STEPS */,
  payload: { steps }
});
var updateState = (payload) => ({
  type: "UPDATE_INIT" /* UPDATE_INIT */,
  payload
});
var updateCurrentCustomStemItem = (payload) => ({
  type: "UPDATE_STEP_CURRENT_ITEM_CUSTOM" /* UPDATE_STEP_CURRENT_ITEM_CUSTOM */,
  payload
});
var updateCurrentStemItem = (payload) => ({
  type: "UPDATE_STEP_ITEM" /* UPDATE_STEP_ITEM */,
  payload
});
var updateClient = (payload) => ({
  type: "UPDATE_CLIENT" /* UPDATE_CLIENT */,
  payload: {
    client: payload
  }
});
var backUpProduction = (payload) => ({
  type: "BACKUP_PRODUCTION" /* BACKUP_PRODUCTION */,
  payload
});
var backUpFree = (payload) => ({
  type: "BACKUP_FREE" /* BACKUP_FREE */,
  payload: {
    ...payload
  }
});
var initialState = {
  name: "",
  symbol: "",
  amount: "",
  order_id: "",
  mode: import_const.ModeEnum.Pay,
  eftpos: "",
  key: 0,
  step: 0,
  type: import_const.PayRouteEnum.Step,
  title: "",
  net: true,
  component: "",
  status: import_const.StatusEnum.Loading,
  steps: [],
  warn: "",
  render: true
};
var StateContext = (0, import_react.createContext)(void 0);
var DispatchContext = (0, import_react.createContext)(
  void 0
);
function reducers(state, action) {
  switch (action.type) {
    case "UPDATE_INIT" /* UPDATE_INIT */:
      return {
        ...state,
        ...action.payload
      };
    case "UPDATE_NEXT_STEP" /* UPDATE_NEXT_STEP */:
      const currentStep = state.step + 1;
      if (state.step === state.steps.length - 1) {
        state.steps[state.steps.length - 1].status = "success";
        return {
          ...state,
          status: "success",
          steps: [...state.steps]
        };
      }
      state.steps[state.step].status = "success";
      return {
        ...state,
        warn: action.payload.warn || "",
        steps: [...state.steps],
        status: state.steps[currentStep].status,
        step: currentStep
      };
    case "UPDATE_KEY" /* UPDATE_KEY */:
      return {
        ...state,
        ...action.payload
      };
    case "UPDATE_LOADING" /* UPDATE_LOADING */:
      return {
        ...state,
        ...action.payload
      };
    case "UPDATE_COMPONENT" /* UPDATE_COMPONENT */:
      return {
        ...state,
        ...action.payload,
        form: state.component
      };
    case "UPDATE_STEPS" /* UPDATE_STEPS */:
      return {
        ...state,
        ...action.payload
      };
    case "UPDATE_STEP_ITEM" /* UPDATE_STEP_ITEM */:
      state.steps[state.step] = {
        ...state.steps[state.step],
        ...action.payload
      };
      return {
        ...state,
        steps: [...state.steps]
      };
    case "UPDATE_STEP_CURRENT_ITEM_CUSTOM" /* UPDATE_STEP_CURRENT_ITEM_CUSTOM */:
      if (state.steps[state.step].custom) {
        state.steps[state.step].custom = {
          ...state.steps[state.step].custom,
          ...action.payload
        };
      } else {
        state.steps[state.step].custom = {
          ...action.payload
        };
      }
      return {
        ...state,
        steps: [...state.steps]
      };
    case "UPDATE_STEP_KEY" /* UPDATE_STEP_KEY */:
      state.steps[state.step].key = Date.now();
      return {
        ...state,
        steps: [...state.steps]
      };
    case "UPDATE_DEVICE" /* UPDATE_DEVICE */:
      return {
        ...state,
        ...action.payload
      };
    case "UPDATE_CUSTOM" /* UPDATE_CUSTOM */:
      return {
        ...state,
        custom: state.custom ? {
          ...state.custom,
          ...action.payload
        } : { ...action.payload }
        // ,
      };
    case "BACKUP_PRODUCTION" /* BACKUP_PRODUCTION */:
      return {
        ...state,
        backup: (0, import_helper.cloneDeep)(state)
      };
    case "BACKUP_FREE" /* BACKUP_FREE */:
      if (!state.backup) {
        return state;
      }
      const { ...s } = state.backup;
      return {
        ...s,
        ...action.payload
      };
    case "UPDATE_CLIENT" /* UPDATE_CLIENT */:
      return {
        ...state,
        client: action.payload["client"]
      };
    default: {
      throw new Error(`Unhandled action type: ${action.type}`);
    }
  }
}
var Provider = ({
  children,
  state: providerState
}) => {
  const [state, dispatch] = (0, import_useThunkReducer.default)(
    reducers,
    providerState || initialState
  );
  return /* @__PURE__ */ import_react.default.createElement(StateContext.Provider, { value: state }, /* @__PURE__ */ import_react.default.createElement(DispatchContext.Provider, { value: dispatch }, children));
};
function useContextData() {
  const context = (0, import_react.useContext)(StateContext);
  if (context === void 0) {
    throw new Error("useState must be used within a Provider");
  }
  return context;
}
function useDispatch() {
  const context = (0, import_react.useContext)(DispatchContext);
  if (context === void 0) {
    throw new Error("useDispatch must be used within a Provider");
  }
  return context;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  EActionTypes,
  Provider,
  backUpFree,
  backUpProduction,
  reducers,
  updateClient,
  updateComponent,
  updateCurrentCustomStemItem,
  updateCurrentStemItem,
  updateCustom,
  updateDevice,
  updateKey,
  updateNextStep,
  updateState,
  updateStatus,
  updateStepKey,
  updateSteps,
  useContextData,
  useDispatch
});
