const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_useComponents = require("../../../../hooks/useComponents.js");
const require_utils = require("../../utils.js");
const require_context = require("../../context.js");
const require_utils$1 = require("../Resource/utils.js");
const require_hooks = require("../../hooks.js");
const require_index = require("../../deposit/components/PolicyModal/index.js");
const require_index$1 = require("../Cart/Item/index.js");
const require_index$2 = require("../Header/index.js");
const require_index$3 = require("../Footer/index.js");
const require_index$4 = require("../Services/index.js");
const require_index$5 = require("../Date/index.js");
const require_index$6 = require("../Resource/index.js");
const require_index$7 = require("../TimeSlicing/index.js");
const require_index$8 = require("../Guest/index.js");
const require_index$9 = require("../Form/index.js");
const require_index$10 = require("../ConfirmInformation/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/appointmentBooking/components/Content/index.tsx
const Layout = () => {
	var _useEngineContext$eng, _currentStep$step2, _currentStep$step4, _currentStep$step6, _currentStep$step8;
	const stepRef = (0, react.useRef)();
	const { currentStep, setResourceOtherParams, resourceOtherParams, setIsAgreeDepositPolicy, appointmentBooking, setLoading, policyParams, closePolicy, currentStepParams, setIsErrorHolder } = require_context.useAppointmentBookingContext();
	const { isDateSelectedFirst, isFormSubject, isRetailTemplate } = require_hooks.useAppointmentBookingSetting();
	const { isLogin } = require_hooks.useAppointmentBookingLogin();
	const { getHolders } = require_hooks.useAppointmentBookingAccount();
	const { removeStep } = require_hooks.useAppointmentBookingStep();
	const { shopDiscount } = require_hooks.useShopDiscount();
	const { isMobile } = require_hooks.useConfig();
	const { customPageData } = (_useEngineContext$eng = require_useEngineContext.default().engine) === null || _useEngineContext$eng === void 0 ? void 0 : _useEngineContext$eng.props;
	const [CustomComponent] = require_useComponents.default({ components: ["CustomComponent"] });
	console.log("CustomComponent:", CustomComponent, typeof CustomComponent, CustomComponent === null || CustomComponent === void 0 ? void 0 : CustomComponent.$$typeof);
	require_hooks.useAppointmentBookingCart();
	require_hooks.useAppointmentBookingStep();
	const [params, setParams] = (0, react.useState)({});
	const utils = require_hooks.contextUtils();
	const { pubsub } = require_useEngineContext.default().appHelper.utils;
	(0, react.useEffect)(() => {
		const handleLoginSuccess = function() {
			var _ref = require_asyncToGenerator._asyncToGenerator(function* (res) {
				if (!isFormSubject) {
					var _utils$storage;
					const currentUser = require_utils.formatCustomer(JSON.parse((utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get("customer")) || "{}"));
					const accountLists = yield appointmentBooking.getAccounts();
					const meAccount = accountLists === null || accountLists === void 0 ? void 0 : accountLists.find((d) => !(d === null || d === void 0 ? void 0 : d.isGuest));
					appointmentBooking.setLoginAccount(meAccount === null || meAccount === void 0 ? void 0 : meAccount.id, currentUser);
				} else if (!isRetailTemplate) getHolders();
			});
			return function handleLoginSuccess(_x) {
				return _ref.apply(this, arguments);
			};
		}();
		pubsub.subscribe("pisell1.login.success", handleLoginSuccess);
		return () => {
			pubsub.unsubscribe("pisell1.login.success", handleLoginSuccess);
		};
	}, []);
	(0, react.useEffect)(() => {
		appointmentBooking.removeStep("fill-form");
		return () => {
			var _shopDiscount$destroy;
			setIsAgreeDepositPolicy(false);
			appointmentBooking.destroy();
			shopDiscount === null || shopDiscount === void 0 || (_shopDiscount$destroy = shopDiscount.destroy) === null || _shopDiscount$destroy === void 0 || _shopDiscount$destroy.call(shopDiscount);
		};
	}, []);
	(0, react.useEffect)(() => {
		var _currentStepParams$st;
		if ((currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) < 0) return;
		const resourceStepIndex = currentStepParams === null || currentStepParams === void 0 || (_currentStepParams$st = currentStepParams.stepLists) === null || _currentStepParams$st === void 0 ? void 0 : _currentStepParams$st.findIndex((item) => item.key === "select-resource");
		if ((currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) < resourceStepIndex) appointmentBooking.setOtherData("current_selected_resources", null);
	}, [currentStepParams]);
	(0, react.useEffect)(() => {
		try {
			var _appointmentBooking$o;
			if (!(appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || isRetailTemplate) return;
			const showAddGuest = appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o = appointmentBooking.otherParams) === null || _appointmentBooking$o === void 0 || (_appointmentBooking$o = _appointmentBooking$o.productModuleParams) === null || _appointmentBooking$o === void 0 ? void 0 : _appointmentBooking$o.showAddGuest;
			if (isFormSubject || !showAddGuest) removeStep("select-guest");
			else appointmentBooking.addStep({
				key: "select-guest",
				description: _pisell_utils.locales.getText("pisell2.appointment.add-guests")
			}, "select-service");
		} catch (error) {}
	}, [isFormSubject, isRetailTemplate]);
	(0, react.useEffect)(() => {
		if (isFormSubject && isLogin && !isRetailTemplate) getHolders();
	}, [
		isFormSubject,
		isLogin,
		isRetailTemplate
	]);
	(0, react.useEffect)(() => {
		var _currentStep$step;
		if (!(currentStep === null || currentStep === void 0 ? void 0 : currentStep.step)) return;
		setLoading(false);
		setResourceOtherParams(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resourceOtherParams), {}, { errorList: null }));
		setIsErrorHolder(false);
		window.scrollTo({
			top: 0,
			behavior: "smooth"
		});
		if ((currentStep === null || currentStep === void 0 || (_currentStep$step = currentStep.step) === null || _currentStep$step === void 0 ? void 0 : _currentStep$step.key) === "confirm-information") require_utils$1.scrollToFirstErrorCard(".pisell-lowcode-product-card-error");
	}, [currentStep === null || currentStep === void 0 || (_currentStep$step2 = currentStep.step) === null || _currentStep$step2 === void 0 ? void 0 : _currentStep$step2.key]);
	const components = {
		"select-service": require_index$4.default,
		"select-guest": require_index$8.default,
		"select-date": require_index$5.default,
		"select-time": require_index$7.default,
		"confirm-information": require_index$10.default
	};
	const Com = (0, react.useMemo)(() => {
		var _currentStep$step3;
		const key = currentStep === null || currentStep === void 0 || (_currentStep$step3 = currentStep.step) === null || _currentStep$step3 === void 0 ? void 0 : _currentStep$step3.key;
		if (!key) return null;
		let Com;
		if (key.startsWith("select-resource")) Com = require_index$6.default;
		else if (key.startsWith("fill-form")) Com = require_index$9.default;
		else Com = components[key];
		if (key === "select-service") return /* @__PURE__ */ react.default.createElement(CustomComponent, {
			block: customPageData === null || customPageData === void 0 ? void 0 : customPageData.block,
			customComponents: { product_list: /* @__PURE__ */ react.default.createElement(Com, {
				onChange: setParams,
				params,
				ref: stepRef
			}) }
		});
		else return /* @__PURE__ */ react.default.createElement(Com, {
			onChange: setParams,
			params,
			ref: stepRef
		});
	}, [currentStep === null || currentStep === void 0 || (_currentStep$step4 = currentStep.step) === null || _currentStep$step4 === void 0 ? void 0 : _currentStep$step4.key]);
	const isShowCartCom = (0, react.useMemo)(() => {
		var _currentStep$step5;
		const key = currentStep === null || currentStep === void 0 || (_currentStep$step5 = currentStep.step) === null || _currentStep$step5 === void 0 ? void 0 : _currentStep$step5.key;
		if (isMobile) return null;
		if (isDateSelectedFirst && key === "select-date") return null;
		return /* @__PURE__ */ react.default.createElement("div", { className: "parallel-content-right" }, /* @__PURE__ */ react.default.createElement(require_index$1.default, { onNext: () => {
			var _stepRef$current, _stepRef$current$next;
			return stepRef === null || stepRef === void 0 || (_stepRef$current = stepRef.current) === null || _stepRef$current === void 0 || (_stepRef$current$next = _stepRef$current.next) === null || _stepRef$current$next === void 0 ? void 0 : _stepRef$current$next.call(_stepRef$current);
		} }));
	}, [isDateSelectedFirst, currentStep === null || currentStep === void 0 || (_currentStep$step6 = currentStep.step) === null || _currentStep$step6 === void 0 ? void 0 : _currentStep$step6.key]);
	/**
	* @title: 是否显示底部
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-05-10 17:42
	*/
	const isFooter = (0, react.useMemo)(() => {
		var _currentStep$step7;
		if (!isMobile) return false;
		const key = currentStep === null || currentStep === void 0 || (_currentStep$step7 = currentStep.step) === null || _currentStep$step7 === void 0 ? void 0 : _currentStep$step7.key;
		if (isDateSelectedFirst && key === "select-date") return false;
		return key !== "confirm-information";
	}, [
		isDateSelectedFirst,
		currentStep === null || currentStep === void 0 || (_currentStep$step8 = currentStep.step) === null || _currentStep$step8 === void 0 ? void 0 : _currentStep$step8.key,
		isMobile
	]);
	/**
	* @title: 获取协议方法需要在组件中定义才能传递给子组件，子组件无法获取到context中的方法
	* @description:
	* @param {string} id
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-07-07 10:06
	*/
	const depositProtocolRequest = (id) => {
		var _appointmentBooking$g;
		return appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$g = appointmentBooking.getProtocol) === null || _appointmentBooking$g === void 0 ? void 0 : _appointmentBooking$g.call(appointmentBooking, id);
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, !isRetailTemplate ? /* @__PURE__ */ react.default.createElement(require_index$2.default, null) : null, /* @__PURE__ */ react.default.createElement("div", { className: `parallel-content-wrap ${isMobile ? "parallel-content-mobile-wrap" : ""} ${isRetailTemplate ? "parallel-content-retail-wrap" : ""}` }, /* @__PURE__ */ react.default.createElement("div", { className: "parallel-content-left" }, Com), isShowCartCom), isFooter ? /* @__PURE__ */ react.default.createElement(require_index$3.default, { onNext: () => {
		var _stepRef$current2, _stepRef$current2$nex;
		return stepRef === null || stepRef === void 0 || (_stepRef$current2 = stepRef.current) === null || _stepRef$current2 === void 0 || (_stepRef$current2$nex = _stepRef$current2.next) === null || _stepRef$current2$nex === void 0 ? void 0 : _stepRef$current2$nex.call(_stepRef$current2);
	} }) : null, (policyParams === null || policyParams === void 0 ? void 0 : policyParams.open) ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		key: policyParams === null || policyParams === void 0 ? void 0 : policyParams._ts,
		open: policyParams === null || policyParams === void 0 ? void 0 : policyParams.open,
		onCancel: () => closePolicy(false),
		onConfirm: () => closePolicy(true),
		item: policyParams === null || policyParams === void 0 ? void 0 : policyParams.content,
		onChange: () => setLoading(false),
		isHideCheckout: false,
		depositProtocolRequest
	}) : null);
};
//#endregion
exports.default = Layout;
