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_utils = require("../../utils.js");
const require_index = require("../../../eventBooking/components/progressBar/index.js");
const require_context = require("../../context.js");
const require_hooks = require("../../hooks.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/appointmentBooking/components/Header/index.tsx
const Header = () => {
	var _currentStep$step3;
	const { currentStep, appointmentBooking, setTimes, carts, currentStepParams, currentSelectedResources } = require_context.useAppointmentBookingContext();
	const shopDiscount = require_hooks.useShopDiscount();
	const context = require_useEngineContext.default();
	const { stepList, updateStep, removeStep } = require_hooks.useAppointmentBookingStep();
	const { setOtherData, getOtherData } = require_hooks.useAppointmentBookingSetting();
	const { checkProductType } = require_hooks.useAppointmentBookingProduct();
	const utils = require_hooks.contextUtils();
	/**
	* @title: 获取资源名称
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-04-15 21:37
	*/
	const stepName = (0, react.useMemo)(() => {
		var _currentStep$step, _currentStep$step2;
		const key = currentStep === null || currentStep === void 0 || (_currentStep$step = currentStep.step) === null || _currentStep$step === void 0 ? void 0 : _currentStep$step.key;
		if (!key) return "";
		if (key.startsWith("select-resource")) {
			var _currentSelectedResou;
			const currentResource = currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou = currentSelectedResources[0]) === null || _currentSelectedResou === void 0 ? void 0 : _currentSelectedResou.currentSelectedResource;
			const resourceItem = (currentResource === null || currentResource === void 0 ? void 0 : currentResource.resourceItem) || {};
			const name = require_utils.getResourceTitle(appointmentBooking, resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.code, utils, resourceItem);
			return _pisell_utils.locales.getText("pisell2.event.select.category")(name);
		}
		return (currentStep === null || currentStep === void 0 || (_currentStep$step2 = currentStep.step) === null || _currentStep$step2 === void 0 ? void 0 : _currentStep$step2.description) || "";
	}, [currentStep === null || currentStep === void 0 || (_currentStep$step3 = currentStep.step) === null || _currentStep$step3 === void 0 ? void 0 : _currentStep$step3.key, currentSelectedResources]);
	/**
	* @title: 返回
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-18 22:28
	*/
	const handleBack = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			var _currentStep$step4;
			const key = currentStep === null || currentStep === void 0 || (_currentStep$step4 = currentStep.step) === null || _currentStep$step4 === void 0 ? void 0 : _currentStep$step4.key;
			const types = {
				"select-time": "time",
				"select-resource": "resource",
				"fill-form": "relationForms"
			};
			if (types[key]) appointmentBooking.deleteCartItemInfo(types[key]);
			if (key === "select-date") appointmentBooking.clearDateRange();
			if (key === "select-service") {
				appointmentBooking.clearCart();
				if (appointmentBooking.isCartHasDurationProduct()) appointmentBooking.deleteCartItemInfo("time");
			}
			if (key === "select-time") setTimes([]);
			if (key.startsWith("fill-form")) {
				const form_key = "booking_form";
				let booking_form = getOtherData(form_key);
				removeStep(key);
				setOtherData(form_key, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, booking_form), {}, { [key]: {} }));
			}
			appointmentBooking.back();
			const prevStepData = stepList[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) - 1];
			const currentStepData = stepList[currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index];
			if ((currentStepData === null || currentStepData === void 0 ? void 0 : currentStepData.isSkip) || (prevStepData === null || prevStepData === void 0 ? void 0 : prevStepData.isSkip)) {
				const key = (currentStepData === null || currentStepData === void 0 ? void 0 : currentStepData.isSkip) ? currentStepData === null || currentStepData === void 0 ? void 0 : currentStepData.key : prevStepData === null || prevStepData === void 0 ? void 0 : prevStepData.key;
				if (key === "select-resource") appointmentBooking.deleteCartItemInfo("resource");
				updateStep(key, { isSkip: false });
			}
			const isServiceStep = (prevStepData === null || prevStepData === void 0 ? void 0 : prevStepData.key) === "select-service";
			const isResourceStep = (prevStepData === null || prevStepData === void 0 ? void 0 : prevStepData.key) === "select-resource";
			if (isServiceStep || isResourceStep) stepList.forEach((item) => {
				if (item.key.startsWith("select-resource_") || item.key.startsWith("fill-form_")) removeStep(item.key);
			});
		});
		return function handleBack() {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* @title: 关闭页面
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-22 13:43
	*/
	const handleClose = () => {
		var _shopDiscount$destroy, _utils$history;
		appointmentBooking.destroy();
		shopDiscount === null || shopDiscount === void 0 || (_shopDiscount$destroy = shopDiscount.destroy) === null || _shopDiscount$destroy === void 0 || _shopDiscount$destroy.call(shopDiscount);
		const utils = context.appHelper.utils || {};
		utils === null || utils === void 0 || (_utils$history = utils.history) === null || _utils$history === void 0 || _utils$history.replace("/");
	};
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		title: currentStep ? `${_pisell_utils.locales.getText("pisell2.appointment.step")((currentStep === null || currentStep === void 0 ? void 0 : currentStep.index) + 1)}` : "",
		description: stepName,
		showBack: (currentStep === null || currentStep === void 0 ? void 0 : currentStep.index) > 0,
		onBack: () => handleBack(),
		onClose: () => handleClose()
	});
};
//#endregion
exports.default = Header;
