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/Init/index.tsx
var Init_exports = {};
__export(Init_exports, {
  InitContext: () => InitContext,
  InitProvider: () => InitProvider,
  useInit: () => useInit
});
module.exports = __toCommonJS(Init_exports);
var import_react = __toESM(require("react"));
var import_SalesModel = require("../../../businessModel/SalesModel");
var import_serve = require("./serve");
var import_ahooks = require("ahooks");
var import_Step = __toESM(require("../Step"));
var import_Cart = __toESM(require("../Cart"));
var import_Checkout = __toESM(require("../Checkout"));
var import_Holder = __toESM(require("../Holder"));
var import_Event = __toESM(require("../Event"));
var import_Resource = __toESM(require("../Resource"));
var import_Summary = __toESM(require("../Summary"));
var import_Customer = require("../Customer");
var InitContext = (0, import_react.createContext)(
  void 0
);
var InitProvider = ({ children }) => {
  const { data, setData, hooks, getCurrentData, getSessionStorage } = (0, import_SalesModel.useSales)();
  const { appUtils } = (0, import_Customer.useCustomer)();
  const { useCustomInit } = hooks;
  const customInit = useCustomInit();
  const initData = (0, import_react.useMemo)(() => {
    return data.initData || {};
  }, [data]);
  const init = () => {
    const storageData = getSessionStorage();
    setData({
      initData: import_Step.default.defaultState,
      stepData: import_Step.default.defaultState,
      cartData: import_Cart.default.defaultState,
      checkoutData: import_Checkout.default.defaultState,
      holderData: import_Holder.default.defaultState,
      eventData: import_Event.default.defaultState,
      resourceData: import_Resource.default.defaultState,
      summaryData: import_Summary.default.defaultState,
      ...storageData || {}
    });
  };
  const setInitData = (newInitData) => {
    setData({
      initData: { ...data.initData, ...newInitData }
    });
  };
  const resetInitPartData = () => {
    var _a;
    setData({
      ...getCurrentData() || {},
      cartData: import_Cart.default.defaultState,
      checkoutData: import_Checkout.default.defaultState,
      holderData: import_Holder.default.defaultState,
      eventData: import_Event.default.defaultState,
      summaryData: import_Summary.default.defaultState,
      resourceData: {
        resourceList: (_a = getCurrentData().resourceData) == null ? void 0 : _a.resourceList,
        currentResourceItem: null
      }
    });
  };
  (0, import_react.useEffect)(() => {
    init();
  }, []);
  const getBoardSetting = (0, import_ahooks.useRequest)(import_serve.getBoardSettingApi, {
    manual: true,
    onSuccess: (res) => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
      setInitData({
        boardSetting: res == null ? void 0 : res.data,
        form_id: (_d = (_c = (_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.config) == null ? void 0 : _b.resource) == null ? void 0 : _c.booking_event_v2_resource) == null ? void 0 : _d.form_id,
        shop_id: (_e = res == null ? void 0 : res.data) == null ? void 0 : _e.shop_id,
        shop: (_i = (_h = (_g = (_f = appUtils.getStore()) == null ? void 0 : _f.getState()) == null ? void 0 : _g.core) == null ? void 0 : _h.core) == null ? void 0 : _i.shop,
        scheduleDisplayType: (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.config) == null ? void 0 : _k.product_display_setting) == null ? void 0 : _l.booking_event_v2_schedule_display_format) == null ? void 0 : _m.value
      });
    }
  });
  const contextValue = {
    initData,
    getBoardSetting,
    resetInitPartData
  };
  return /* @__PURE__ */ import_react.default.createElement(InitContext.Provider, { value: contextValue }, children);
};
var useInit = () => {
  const context = import_react.default.useContext(InitContext);
  if (!context) {
    throw new Error("useInit must be used within a InitProvider");
  }
  return context;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  InitContext,
  InitProvider,
  useInit
});
