const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../../../businessModel/SalesModel/Sales/index.js");
const require_index$1 = require("../Step/index.js");
const require_index$2 = require("../Customer/index.js");
const require_index$3 = require("../Cart/index.js");
const require_index$4 = require("../Checkout/index.js");
const require_serve = require("./serve.js");
const require_index$5 = require("../Holder/index.js");
const require_index$6 = require("../Event/index.js");
const require_index$7 = require("../Resource/index.js");
const require_index$8 = require("../Summary/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
//#region src/components/Sales/Init/index.tsx
const InitContext = (0, react.createContext)(void 0);
const InitProvider = ({ children }) => {
	const { data, setData, hooks, getCurrentData, getSessionStorage } = require_index.useSales();
	const { appUtils } = require_index$2.useCustomer();
	const { useCustomInit } = hooks;
	useCustomInit();
	const initData = (0, react.useMemo)(() => {
		return data.initData || {};
	}, [data]);
	const init = () => {
		const storageData = getSessionStorage();
		setData(require_objectSpread2._objectSpread2({
			initData: require_index$1.default.defaultState,
			stepData: require_index$1.default.defaultState,
			cartData: require_index$3.default.defaultState,
			checkoutData: require_index$4.default.defaultState,
			holderData: require_index$5.default.defaultState,
			eventData: require_index$6.default.defaultState,
			resourceData: require_index$7.default.defaultState,
			summaryData: require_index$8.default.defaultState
		}, storageData || {}));
	};
	const setInitData = (newInitData) => {
		setData({ initData: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, data.initData), newInitData) });
	};
	/**
	* 返回第一步后需要重置部分数据
	*/
	const resetInitPartData = () => {
		var _getCurrentData$resou;
		setData(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, getCurrentData() || {}), {}, {
			cartData: require_index$3.default.defaultState,
			checkoutData: require_index$4.default.defaultState,
			holderData: require_index$5.default.defaultState,
			eventData: require_index$6.default.defaultState,
			summaryData: require_index$8.default.defaultState,
			resourceData: {
				resourceList: (_getCurrentData$resou = getCurrentData().resourceData) === null || _getCurrentData$resou === void 0 ? void 0 : _getCurrentData$resou.resourceList,
				currentResourceItem: null
			}
		}));
	};
	(0, react.useEffect)(() => {
		init();
	}, []);
	const contextValue = {
		initData,
		getBoardSetting: (0, ahooks.useRequest)(require_serve.getBoardSettingApi, {
			manual: true,
			onSuccess: (res) => {
				var _res$data, _res$data2, _appUtils$getStore, _res$data3;
				setInitData({
					boardSetting: res === null || res === void 0 ? void 0 : res.data,
					form_id: res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.config) === null || _res$data === void 0 || (_res$data = _res$data.resource) === null || _res$data === void 0 || (_res$data = _res$data.booking_event_v2_resource) === null || _res$data === void 0 ? void 0 : _res$data.form_id,
					shop_id: res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.shop_id,
					shop: (_appUtils$getStore = appUtils.getStore()) === null || _appUtils$getStore === void 0 || (_appUtils$getStore = _appUtils$getStore.getState()) === null || _appUtils$getStore === void 0 || (_appUtils$getStore = _appUtils$getStore.core) === null || _appUtils$getStore === void 0 || (_appUtils$getStore = _appUtils$getStore.core) === null || _appUtils$getStore === void 0 ? void 0 : _appUtils$getStore.shop,
					scheduleDisplayType: res === null || res === void 0 || (_res$data3 = res.data) === null || _res$data3 === void 0 || (_res$data3 = _res$data3.config) === null || _res$data3 === void 0 || (_res$data3 = _res$data3.product_display_setting) === null || _res$data3 === void 0 || (_res$data3 = _res$data3.booking_event_v2_schedule_display_format) === null || _res$data3 === void 0 ? void 0 : _res$data3.value
				});
			}
		}),
		resetInitPartData
	};
	return /* @__PURE__ */ react.default.createElement(InitContext.Provider, { value: contextValue }, children);
};
/**
* 使用步骤管理的Hook
* @throws {Error} 如果在StepProvider外部使用会抛出错误
* @returns {StepContextType} 步骤管理上下文
*/
const useInit = () => {
	const context = react.default.useContext(InitContext);
	if (!context) throw new Error("useInit must be used within a InitProvider");
	return context;
};
//#endregion
exports.InitProvider = InitProvider;
exports.useInit = useInit;
