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/Sales/Step/index.tsx
var Step_exports = {};
__export(Step_exports, {
  StepContext: () => StepContext,
  StepProvider: () => StepProvider,
  default: () => Step_default,
  steps: () => steps,
  useStep: () => useStep
});
module.exports = __toCommonJS(Step_exports);
var import_react = __toESM(require("react"));
var import_SalesModel = require("../../../businessModel/SalesModel");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var steps = [
  {
    key: "select-category",
    title: "Step 1",
    description: "Select category"
  },
  {
    key: "select-event",
    title: "Step 2",
    description: "Select event"
  },
  {
    key: "confirm-information",
    title: "Step 3",
    description: "Confirm information"
  }
];
var stepMaps = steps.reduce((acc, step) => {
  acc[step.key] = step;
  return acc;
}, {});
var defaultState = {
  currentStep: steps[0].key,
  isAutoOperate: true
};
var StepContext = (0, import_react.createContext)(
  void 0
);
var StepProvider = ({ children }) => {
  const { data, setData } = (0, import_SalesModel.useSales)();
  const context = (0, import_useEngineContext.default)();
  const utils = context.appHelper.utils || {};
  const stepData = (0, import_react.useMemo)(() => {
    return data.stepData || {};
  }, [data]);
  const currentStepData = (0, import_react.useMemo)(() => {
    return stepMaps[stepData.currentStep];
  }, [stepData]);
  const setStepData = (newStepData) => {
    setData({
      stepData: {
        ...data.stepData,
        ...newStepData
      }
    });
  };
  const getNextStep = () => {
    const currentStepIndex = steps.findIndex(
      (step) => step.key === stepData.currentStep
    );
    if (currentStepIndex < steps.length - 1) {
      return steps[currentStepIndex + 1].key;
    }
    return null;
  };
  const getPrevStep = () => {
    const currentStepIndex = steps.findIndex(
      (step) => step.key === stepData.currentStep
    );
    if (currentStepIndex > 0) {
      return steps[currentStepIndex - 1].key;
    }
    return null;
  };
  const nextStep = () => {
    const nextStep2 = getNextStep();
    if (nextStep2) {
      setStepData({
        currentStep: nextStep2,
        isAutoOperate: true
      });
    }
  };
  const prevStep = () => {
    const prevStep2 = getPrevStep();
    if (prevStep2) {
      setStepData({
        currentStep: prevStep2,
        isAutoOperate: false
      });
    } else {
      closePage();
    }
  };
  const toFirstStep = () => {
    setStepData({
      currentStep: steps[0].key
    });
  };
  const closePage = () => {
    var _a;
    (_a = utils == null ? void 0 : utils.history) == null ? void 0 : _a.replace("/");
  };
  const isFirstStep = (0, import_react.useMemo)(() => {
    return (currentStepData == null ? void 0 : currentStepData.key) === steps[0].key;
  }, [currentStepData == null ? void 0 : currentStepData.key]);
  const isLastStep = (0, import_react.useMemo)(() => {
    return (currentStepData == null ? void 0 : currentStepData.key) === steps[steps.length - 1].key;
  }, [currentStepData == null ? void 0 : currentStepData.key]);
  const isTwoStep = (0, import_react.useMemo)(() => {
    return (currentStepData == null ? void 0 : currentStepData.key) === steps[1].key;
  }, [currentStepData == null ? void 0 : currentStepData.key]);
  const changeAutoOperate = (newAutoOperate) => {
    setStepData({
      isAutoOperate: newAutoOperate
    });
  };
  const contextValue = {
    setStepData,
    currentStepData,
    nextStep,
    prevStep,
    closePage,
    toFirstStep,
    isFirstStep,
    isLastStep,
    isTwoStep,
    changeAutoOperate
  };
  return /* @__PURE__ */ import_react.default.createElement(StepContext.Provider, { value: contextValue }, children);
};
var useStep = () => {
  const context = import_react.default.useContext(StepContext);
  if (!context) {
    throw new Error("useStep must be used within a StepProvider");
  }
  return context;
};
var Step_default = {
  defaultState
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  StepContext,
  StepProvider,
  steps,
  useStep
});
