import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useEngineContext, { usePisellOS } from "../../hooks/useEngineContext.js";
import { Toast, checkAndGoNext, checkAndMarkCartRenderError, currentAppointmentBoard, currentRenderLists, formatHolder, getCustomer, getFormInsertBeforeKey, processResourceList } from "./utils.js";
import { useAppointmentBookingContext } from "./context.js";
import { scrollToFirstErrorCard } from "./components/Resource/utils.js";
import { useEffect, useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import { usePisellConfig } from "@pisell/materials";
//#region src/components/appointmentBooking/hooks.ts
const useAppointmentBooking = () => {
	return usePisellOS().getModule("appointmentBooking");
};
const useShopDiscount = () => {
	return usePisellOS().getModule("shopDiscount");
};
const contextUtils = () => {
	var _context$appHelper;
	const context = useEngineContext();
	return (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
};
/**
* @title: 监听步骤发生变化
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:11
*/
const useAppointmentBookingStep = () => {
	var _appointmentBooking$s;
	const pisellOS = usePisellOS();
	const { appointmentBooking, setCurrentStep, carts, openPolicy, setLoading, setCurrentSelectedResources, currentStepParams, setIsErrorHolder } = useAppointmentBookingContext();
	const { isRetailTemplate } = useAppointmentBookingSetting();
	const stepList = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$s = appointmentBooking.store) === null || _appointmentBooking$s === void 0 || (_appointmentBooking$s = _appointmentBooking$s.step) === null || _appointmentBooking$s === void 0 || (_appointmentBooking$s = _appointmentBooking$s.store) === null || _appointmentBooking$s === void 0 ? void 0 : _appointmentBooking$s.stepList) || [];
	const { isLogin, openLoginModal } = useAppointmentBookingLogin();
	const { isFormSubject } = useAppointmentBookingSetting();
	const { getHolders, checkAccount } = useAppointmentBookingAccount();
	const utils = contextUtils();
	const getCurrentAndLastStep = () => {
		setCurrentStep(appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getCurrentStep());
	};
	useEffect(() => {
		getCurrentAndLastStep();
		pisellOS.effects.on("appointmentBooking_step:changed", function() {
			var _ref = _asyncToGenerator(function* (res) {
				if (res.path === "currentStep") getCurrentAndLastStep();
			});
			return function(_x) {
				return _ref.apply(this, arguments);
			};
		}());
	}, []);
	const getStepIndex = (type, skipNumber = 0) => {
		const currentStep = appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getCurrentStep();
		const index = (currentStep === null || currentStep === void 0 ? void 0 : currentStep.index) || 1;
		if (type === "next") {
			const nextIndex = index + skipNumber;
			return nextIndex + 1 > stepList.length ? stepList.length - 1 : nextIndex;
		}
		if (type === "prev") {
			const prevIndex = index - skipNumber;
			return prevIndex < 0 ? 0 : prevIndex;
		}
	};
	const removeStep = (key) => {
		return appointmentBooking.removeStep(key);
	};
	const addStep = (props, stepKey) => {
		const { index, key, description } = props;
		return appointmentBooking.addStep({
			index,
			key,
			description
		}, stepKey);
	};
	const updateStep = (key, step) => {
		appointmentBooking.updateStep(key, {
			index: step === null || step === void 0 ? void 0 : step.index,
			key,
			isSkip: (step === null || step === void 0 ? void 0 : step.isSkip) || false
		});
	};
	const nextStep = () => {
		var _nextStep$key;
		let stepList = appointmentBooking.getStepList() || [];
		const currentKey = currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key;
		const currentSelectedResources = appointmentBooking.getOtherData("current_selected_resources");
		if (!isRetailTemplate && currentKey === "select-service") {
			var _appointmentBooking$o, _stepList$find;
			const { bookingProcess } = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o = appointmentBooking.otherParams) === null || _appointmentBooking$o === void 0 ? void 0 : _appointmentBooking$o.productModuleParams) || {};
			const isDateSelectedFirst = bookingProcess === "date_first";
			const hasResourceStep = stepList === null || stepList === void 0 ? void 0 : stepList.find((item) => (item === null || item === void 0 ? void 0 : item.key) === "select-resource");
			const hasSelectGuestStep = stepList === null || stepList === void 0 || (_stepList$find = stepList.find((item) => (item === null || item === void 0 ? void 0 : item.key) === "select-guest")) === null || _stepList$find === void 0 ? void 0 : _stepList$find.key;
			if (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isCartAllNormalProducts()) {
				removeStep("select-resource");
				removeStep("select-time");
				removeStep("fill-form");
				if (!isDateSelectedFirst) removeStep("select-date");
			} else if (!hasResourceStep) {
				let targetKey = hasSelectGuestStep ? hasSelectGuestStep : "select-service";
				if (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isCartHasDurationProduct()) {
					if (!isDateSelectedFirst) {
						appointmentBooking.addStep({
							key: "select-date",
							description: locales.getText("pisell2.appointment.select.date")
						}, targetKey);
						targetKey = "select-date";
					}
					appointmentBooking.addStep({
						key: "select-resource",
						description: locales.getText("pisell2.appointment.select.resource")
					}, targetKey);
					targetKey = "select-resource";
					appointmentBooking.addStep({
						key: "select-time",
						description: locales.getText("pisell2.appointment.select.time")
					}, targetKey);
				} else appointmentBooking.addStep({
					key: "select-resource",
					description: locales.getText("pisell2.appointment.select.resource")
				}, targetKey);
			}
			stepList = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getStepList()) || [];
		}
		let nextStep = stepList[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) + 1];
		if (!isRetailTemplate && (nextStep === null || nextStep === void 0 ? void 0 : nextStep.key) === "select-resource") {
			if (!appointmentBooking.checkResourceListForDate()) return Toast(locales.getText("pisell2.appointment.unuse.date"));
			const capacityResult = appointmentBooking.checkMaxDurationCapacity();
			if (!capacityResult.success) {
				const getMessage = locales.getText("pisell2.appointment.unuse.capacity");
				return Toast(typeof getMessage === "function" ? getMessage(capacityResult.minAvailableCount) : getMessage);
			}
		}
		if (!isRetailTemplate && (currentKey === null || currentKey === void 0 ? void 0 : currentKey.startsWith("select-resource"))) {
			var _currentSelectedResou;
			const { hasError, updatedCartList } = checkAndMarkCartRenderError(currentSelectedResources, appointmentBooking, utils);
			if (hasError) {
				setCurrentSelectedResources(updatedCartList);
				scrollToFirstErrorCard();
				return;
			}
			let preKey = "";
			currentSelectedResources === null || currentSelectedResources === void 0 || currentSelectedResources.forEach((cart) => {
				var _selectedResource$ren, _selectedResource$ren2;
				const selectedResource = cart === null || cart === void 0 ? void 0 : cart.currentSelectedResource;
				const resourceItem = (selectedResource === null || selectedResource === void 0 ? void 0 : selectedResource.resourceItem) || {};
				const formId = selectedResource === null || selectedResource === void 0 || (_selectedResource$ren = selectedResource.renderItem) === null || _selectedResource$ren === void 0 ? void 0 : _selectedResource$ren.resource_form_id;
				const policyId = selectedResource === null || selectedResource === void 0 || (_selectedResource$ren2 = selectedResource.renderItem) === null || _selectedResource$ren2 === void 0 ? void 0 : _selectedResource$ren2.policy_id;
				const formKey = `fill-form_@${resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.form_id}-${resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.code}-${cart === null || cart === void 0 ? void 0 : cart._id}-${formId}-${policyId}`;
				if (formId) {
					const description = locales.getText("pisell2.appointment.fill-form");
					const beforeKey = getFormInsertBeforeKey(currentKey, stepList);
					appointmentBooking.addStep({
						key: formKey,
						description
					}, preKey || beforeKey);
					preKey = formKey;
				} else appointmentBooking.removeStep(formKey);
			});
			stepList = appointmentBooking.getStepList();
			const selectedResource = currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou = currentSelectedResources[0]) === null || _currentSelectedResou === void 0 ? void 0 : _currentSelectedResou.currentSelectedResource;
			if (selectedResource) {
				var _selectedResource$res;
				const originRenderLists = (selectedResource === null || selectedResource === void 0 || (_selectedResource$res = selectedResource.resourceItem) === null || _selectedResource$res === void 0 ? void 0 : _selectedResource$res.originRenderLists) || [];
				const currentResourceIndex = originRenderLists === null || originRenderLists === void 0 ? void 0 : originRenderLists.findIndex((item) => {
					var _selectedResource$ren3;
					return item.id === (selectedResource === null || selectedResource === void 0 || (_selectedResource$ren3 = selectedResource.renderItem) === null || _selectedResource$ren3 === void 0 ? void 0 : _selectedResource$ren3.form_id);
				});
				const nextResource = originRenderLists === null || originRenderLists === void 0 ? void 0 : originRenderLists[currentResourceIndex + 1];
				const resourceKey = `select-resource_@${nextResource === null || nextResource === void 0 ? void 0 : nextResource.form_id}-${nextResource === null || nextResource === void 0 ? void 0 : nextResource.code}`;
				if (nextResource) {
					var _stepList;
					const beforeKey = (_stepList = stepList[stepList.length - 2]) === null || _stepList === void 0 ? void 0 : _stepList.key;
					appointmentBooking.addStep({
						key: resourceKey,
						description: ""
					}, beforeKey);
				} else appointmentBooking.removeStep(resourceKey);
			}
		}
		stepList = appointmentBooking.getStepList();
		nextStep = stepList[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) + 1];
		if ((nextStep === null || nextStep === void 0 || (_nextStep$key = nextStep.key) === null || _nextStep$key === void 0 ? void 0 : _nextStep$key.startsWith("select-resource_")) || (nextStep === null || nextStep === void 0 ? void 0 : nextStep.key) === "confirm-information") {
			var _currentSelectedResou2;
			const selectedResource = (currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou2 = currentSelectedResources[0]) === null || _currentSelectedResou2 === void 0 ? void 0 : _currentSelectedResou2.currentSelectedResource) || {};
			const renderItem = (selectedResource === null || selectedResource === void 0 ? void 0 : selectedResource.renderItem) || {};
			const checkHolder = function() {
				var _ref2 = _asyncToGenerator(function* () {
					setLoading(false);
					if (isRetailTemplate || (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isCartAllNormalProducts())) return appointmentBooking.next();
					let cartLists = carts || [];
					if (!(carts === null || carts === void 0 ? void 0 : carts.length)) cartLists = (yield appointmentBooking.getCart()) || [];
					else cartLists = carts || [];
					const { hasError } = checkAndGoNext(isFormSubject, checkAccount, cartLists.filter((n) => !(appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isTargetCartIdNormalProduct(n._id))));
					setIsErrorHolder(hasError);
					if (hasError) return;
					if (!!(renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id)) openPolicy({ id: renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id }, () => {
						return appointmentBooking.next();
					});
					else return appointmentBooking.next();
				});
				return function checkHolder() {
					return _ref2.apply(this, arguments);
				};
			}();
			const checkLogin = function() {
				var _ref3 = _asyncToGenerator(function* () {
					if (!isLogin) {
						const { pubsub } = utils;
						pubsub.once("pisell1.login.success", (res) => {
							if (res === "success") checkHolder();
							if (res === "close") setLoading(false);
						});
						return openLoginModal({ callback: (status) => {} });
					} else return checkHolder();
				});
				return function checkLogin() {
					return _ref3.apply(this, arguments);
				};
			}();
			if ((nextStep === null || nextStep === void 0 ? void 0 : nextStep.key) !== "confirm-information") {
				if (!(renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id)) return appointmentBooking.next();
				return openPolicy({ id: renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id }, () => {
					const cartItem = carts === null || carts === void 0 ? void 0 : carts[0];
					appointmentBooking.updateCart(_objectSpread2({ _id: cartItem === null || cartItem === void 0 ? void 0 : cartItem._id }, cartItem));
					appointmentBooking.next();
				});
			} else return checkLogin();
		}
		appointmentBooking.next();
	};
	return {
		getStepIndex,
		stepList,
		removeStep,
		addStep,
		updateStep,
		nextStep
	};
};
/**
* @title: 获取商品数据
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:12
*/
const useAppointmentBookingProduct = () => {
	const { appointmentBooking } = useAppointmentBookingContext();
	const { productModuleParams } = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {};
	const { bookingProcess } = productModuleParams || {};
	const getProducts = function() {
		var _ref4 = _asyncToGenerator(function* () {
			if (bookingProcess === "date_first") {
				var _dates$;
				const dates = yield appointmentBooking.getDateRange();
				if (!dates || !dates.length) return;
				const { productModuleParams } = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {};
				return yield appointmentBooking.loadProductByScheduleDate(_objectSpread2({ date: (_dates$ = dates[0]) === null || _dates$ === void 0 ? void 0 : _dates$.date }, productModuleParams));
			}
			const { productModuleParams } = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {};
			return yield appointmentBooking.loadProducts(productModuleParams);
		});
		return function getProducts() {
			return _ref4.apply(this, arguments);
		};
	}();
	return {
		checkProductType: function() {
			var _ref5 = _asyncToGenerator(function* (productId) {
				return yield appointmentBooking.getProductTypeById(productId);
			});
			return function checkProductType(_x2) {
				return _ref5.apply(this, arguments);
			};
		}(),
		getProducts
	};
};
/**
* @title: 更新购物车数据
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:12
*/
const useAppointmentBookingCart = () => {
	var _appointmentBooking$o2;
	const pisellOS = usePisellOS();
	const utils = contextUtils();
	const { appointmentBooking, setCarts, setSummary, setIsAgreeDepositPolicy } = useAppointmentBookingContext();
	const { bookingSubject } = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o2 = appointmentBooking.otherParams) === null || _appointmentBooking$o2 === void 0 ? void 0 : _appointmentBooking$o2.productModuleParams) || {};
	const getCartAndSummary = function() {
		var _ref6 = _asyncToGenerator(function* () {
			var _utils$storage;
			const locale = (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get("umi_locale")) || "en-US";
			const symbol = (utils === null || utils === void 0 ? void 0 : utils.getSymbolic()) || "$";
			const carts = yield appointmentBooking.getCart();
			const accountLists = yield appointmentBooking.getAccounts();
			setCarts((carts === null || carts === void 0 ? void 0 : carts.map((item) => {
				var _item$duration;
				return _objectSpread2(_objectSpread2({}, item), {}, {
					addHolderButtonText: utils === null || utils === void 0 ? void 0 : utils.translation(bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_name),
					format: ["HH:mm", "HH:mm"],
					show_time: true,
					duration_type: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.type) || "minutes",
					locale,
					symbol,
					holders: formatHolder(accountLists),
					allowClearHolder: true,
					allowClearResource: true,
					isMultipleResource: true
				});
			})) || []);
			setSummary((yield appointmentBooking.getSummary()) || {});
			if (!carts.length) setIsAgreeDepositPolicy(false);
		});
		return function getCartAndSummary() {
			return _ref6.apply(this, arguments);
		};
	}();
	useEffect(() => {
		getCartAndSummary();
		pisellOS.effects.on("appointmentBooking_cart:changed", _asyncToGenerator(function* () {
			getCartAndSummary();
		}));
	}, []);
};
/**
* @title: 获取登录状态
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:14
*/
const useAppointmentBookingLogin = () => {
	var _utils$token, _utils$token$get;
	const utils = contextUtils();
	const isLogin = !!(utils === null || utils === void 0 || (_utils$token = utils.token) === null || _utils$token === void 0 || (_utils$token$get = _utils$token.get) === null || _utils$token$get === void 0 ? void 0 : _utils$token$get.call(_utils$token));
	const openLoginModal = (params) => {
		const { callback } = params || {};
		utils.action({
			type: "pisell1.login",
			data: {},
			callback
		});
	};
	return {
		isLogin,
		openLoginModal
	};
};
/**
* @title: 获取账户
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:15
*/
const useAppointmentBookingAccount = () => {
	var _appointmentBooking$o3;
	const utils = contextUtils();
	const pisellOS = usePisellOS();
	const appointmentBooking = useAppointmentBooking();
	const [accountLists, setAccountLists] = useState([]);
	const { bookingSubject } = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o3 = appointmentBooking.otherParams) === null || _appointmentBooking$o3 === void 0 ? void 0 : _appointmentBooking$o3.productModuleParams) || {};
	const form_id = bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_id;
	const getAccountLists = function() {
		var _ref7 = _asyncToGenerator(function* () {
			setAccountLists((yield appointmentBooking.getAccounts()) || []);
		});
		return function getAccountLists() {
			return _ref7.apply(this, arguments);
		};
	}();
	useEffect(() => {
		getAccountLists();
		pisellOS.effects.on("appointmentBooking_accountList:changed", function() {
			var _ref8 = _asyncToGenerator(function* (res) {
				if (res.path === "accounts") getAccountLists();
			});
			return function(_x3) {
				return _ref8.apply(this, arguments);
			};
		}());
	}, []);
	const getHolders = function() {
		var _ref9 = _asyncToGenerator(function* () {
			var _utils$getStore$getSt;
			const shop_id = (_utils$getStore$getSt = utils.getStore().getState()) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.global) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.shop) === null || _utils$getStore$getSt === void 0 ? void 0 : _utils$getStore$getSt.id;
			const customer = getCustomer(utils);
			if (!shop_id || !form_id || !(customer === null || customer === void 0 ? void 0 : customer.id)) return [];
			const params = {
				url: "/form/data/v1",
				query: {
					customer_id: customer === null || customer === void 0 ? void 0 : customer.id,
					form_id,
					shop_id
				}
			};
			const data = yield appointmentBooking.fetchHolderAccountsAsync(params);
			return (data === null || data === void 0 ? void 0 : data.map((item) => {
				return {
					id: item === null || item === void 0 ? void 0 : item.form_record_id,
					label: item === null || item === void 0 ? void 0 : item.main_field
				};
			})) || [];
		});
		return function getHolders() {
			return _ref9.apply(this, arguments);
		};
	}();
	const addAccount = function() {
		var _ref10 = _asyncToGenerator(function* (val, type) {
			const customer = getCustomer(utils);
			return yield appointmentBooking.addAccount(val, {
				type,
				customerId: customer === null || customer === void 0 ? void 0 : customer.id
			});
		});
		return function addAccount(_x4, _x5) {
			return _ref10.apply(this, arguments);
		};
	}();
	const checkAccount = (type) => {
		return appointmentBooking.checkBeforeSubmitOrder(type);
	};
	return {
		accountLists,
		getHolders,
		form_id,
		addAccount,
		checkAccount
	};
};
/**
* @title: 获取资源数据
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-15 11:29
*/
const useAppointmentBookingResource = () => {
	const { appointmentBooking, setResources, setTimes } = useAppointmentBookingContext();
	const { resourceSort } = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {};
	const getResourceList = () => {
		const { resources: processedResources, resourceCodes } = processResourceList(appointmentBooking.getResourcesList(), resourceSort);
		setResources(processedResources || []);
		return {
			resources: processedResources,
			resourceCodes
		};
	};
	return {
		getResourceTimeSlot: function() {
			var _ref11 = _asyncToGenerator(function* (index) {
				const { resourceCodes } = getResourceList();
				const code = resourceCodes === null || resourceCodes === void 0 ? void 0 : resourceCodes[index || 0];
				setTimes((yield appointmentBooking.getTimeSlotByAllResources(code)) || []);
			});
			return function getResourceTimeSlot(_x6) {
				return _ref11.apply(this, arguments);
			};
		}(),
		getResourceList
	};
};
/**
* @title: 是否跳过资源选择步骤
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-21 11:47
*/
const useIsSkipResourceStep = () => {
	const { currentStepParams } = useAppointmentBookingContext();
	const { getResourceList } = useAppointmentBookingResource();
	const { isFormSubject } = useAppointmentBookingSetting();
	const appointmentBooking = useAppointmentBooking();
	const { nextStep } = useAppointmentBookingStep();
	return { checkSkipResourceStep: function() {
		var _ref12 = _asyncToGenerator(function* () {
			try {
				const { resources } = getResourceList();
				const accountLists = yield appointmentBooking.getAccounts();
				const { isSystem, isSkip, form_code } = currentAppointmentBoard(currentStepParams.key, resources, appointmentBooking);
				if (isSystem) {
					nextStep();
					return true;
				}
				if ((accountLists === null || accountLists === void 0 ? void 0 : accountLists.length) === 1 || isFormSubject) {
					const renderLists = currentRenderLists(resources, form_code);
					let _isSkip = false;
					if ((renderLists === null || renderLists === void 0 ? void 0 : renderLists.length) === 1) _isSkip = isSkip || false;
					else _isSkip = false;
					if (_isSkip) {
						nextStep();
						return true;
					}
					return _isSkip;
				} else return false;
			} catch (error) {
				return false;
			}
		});
		return function checkSkipResourceStep() {
			return _ref12.apply(this, arguments);
		};
	}() };
};
/**
* @title: 获取预约配置
* @description:
* @return {*}
* @Author: WangHan
* @Date: 2025-04-24 18:15
*/
const useAppointmentBookingSetting = () => {
	var _appointmentBooking$o4, _appointmentBooking$o5, _appointmentBooking$o6;
	const utils = contextUtils();
	const { appointmentBooking } = useAppointmentBookingContext();
	const { bookingProcess, bookingSubject, customPageId, channel } = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o4 = appointmentBooking.otherParams) === null || _appointmentBooking$o4 === void 0 ? void 0 : _appointmentBooking$o4.productModuleParams) || {};
	const setOtherData = (key, val) => {
		return appointmentBooking.setOtherData(key, val);
	};
	const getOtherData = (key) => {
		return appointmentBooking.getOtherData(key);
	};
	const formName = useMemo(() => {
		return utils === null || utils === void 0 ? void 0 : utils.translation(bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_name);
	}, [bookingSubject]);
	return {
		isDateSelectedFirst: bookingProcess === "date_first",
		isFormSubject: (bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.type) === "form",
		isRetailTemplate: (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o5 = appointmentBooking.otherParams) === null || _appointmentBooking$o5 === void 0 ? void 0 : _appointmentBooking$o5.isRetailTemplate) || false,
		customPageId,
		channel,
		bookingSubject,
		setOtherData,
		getOtherData,
		formName,
		bookingSetting: (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o6 = appointmentBooking.otherParams) === null || _appointmentBooking$o6 === void 0 ? void 0 : _appointmentBooking$o6.bookingSetting) || {}
	};
};
const useConfig = () => {
	const config = usePisellConfig();
	const platform = (config === null || config === void 0 ? void 0 : config.platform) || "h5";
	return {
		platform,
		isMobile: platform === "h5"
	};
};
//#endregion
export { contextUtils, useAppointmentBooking, useAppointmentBookingAccount, useAppointmentBookingCart, useAppointmentBookingLogin, useAppointmentBookingProduct, useAppointmentBookingResource, useAppointmentBookingSetting, useAppointmentBookingStep, useConfig, useIsSkipResourceStep, useShopDiscount };
