const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_context = require("../../context.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
//#region src/components/venueBooking/components/Header/index.tsx
/**
* venueBooking 步骤导航头部
* 展示三步流程进度条（选场地 → 附加商品 → 结账），支持点击跳转已完成步骤
*/
function Header() {
	var _viewModel$addonProdu2;
	const { currentStep, canNext, viewModel, goToStep, prevStep } = require_context.useVenueBookingContext();
	const [popupOpen, setPopupOpen] = (0, react.useState)(false);
	const [confirmOpen, setConfirmOpen] = (0, react.useState)(false);
	const cardRef = (0, react.useRef)(null);
	/**
	* 步骤配置：当 addonProductList 为空时跳过 addons 步骤，自动重排序号。
	* - 有附加商品：select-venue → addons → checkout（3 步）
	* - 无附加商品：select-venue → checkout（2 步）
	*/
	const STEP_ITEMS = (0, react.useMemo)(() => {
		var _viewModel$addonProdu;
		return [
			{
				key: "select-venue",
				titleKey: "pisell2.venue.step.select"
			},
			...(((_viewModel$addonProdu = viewModel.addonProductList) === null || _viewModel$addonProdu === void 0 ? void 0 : _viewModel$addonProdu.length) || 0) > 0 ? [{
				key: "addons",
				titleKey: "pisell2.venue.step.addons"
			}] : [],
			{
				key: "checkout",
				titleKey: "pisell2.venue.step.checkout"
			}
		].map((item, idx) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { n: idx + 1 }));
	}, [(_viewModel$addonProdu2 = viewModel.addonProductList) === null || _viewModel$addonProdu2 === void 0 ? void 0 : _viewModel$addonProdu2.length]);
	const currentStepIndex = STEP_ITEMS.findIndex((item) => item.key === currentStep);
	const currentStepItem = STEP_ITEMS[currentStepIndex] || STEP_ITEMS[0];
	/** 是否处于第一步:第一步时返回箭头视为退出预订 */
	const isFirstStep = currentStepIndex <= 0;
	/** 返回上一步:首步时弹出离开确认,后续步骤直接回退 */
	function handleBack() {
		if (isFirstStep) {
			setConfirmOpen(true);
			return;
		}
		prevStep();
	}
	/** 判断某步骤是否可点击跳转 */
	function isClickable(targetStep) {
		if (targetStep.key === "select-venue") return true;
		if (targetStep.key === "addons") return canNext;
		return false;
	}
	/** 获取步骤状态：done / active / pending */
	function getStepStatus(item) {
		const itemIndex = STEP_ITEMS.findIndex((s) => s.key === item.key);
		if (itemIndex < currentStepIndex) return "done";
		if (itemIndex === currentStepIndex) return "active";
		return "pending";
	}
	/** 步骤 1 完成时的对勾徽章 */
	function getBadge(item) {
		const status = getStepStatus(item);
		if (item.key === "select-venue" && canNext && status === "done") return /* @__PURE__ */ react.default.createElement("span", {
			className: "ml-1 inline-flex h-5 w-5 items-center justify-center rounded-full text-[11px] font-bold text-white",
			style: { backgroundColor: "var(--vb-primary)" }
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: "pisell2-check",
			style: { fontSize: 12 }
		}));
		if (item.key === "addons") {
			const addonCount = (viewModel.cartItems || []).filter((c) => !(c === null || c === void 0 ? void 0 : c.start_date) || !(c === null || c === void 0 ? void 0 : c.end_date)).length;
			if (addonCount <= 0) return null;
			return /* @__PURE__ */ react.default.createElement("span", { className: "ml-1 inline-flex min-w-[20px] items-center justify-center rounded-full bg-[#111111] px-1.5 text-[11px] font-bold text-white" }, "+", addonCount);
		}
		return null;
	}
	/** 返回上一页：优先回退历史，无历史时回到首页 */
	function doBackHome() {
		if (typeof window === "undefined") return;
		if (window.history.length > 1) {
			window.history.back();
			return;
		}
		window.location.href = "/";
	}
	/** 可返回的步骤（当前步骤之前且允许跳转） */
	const backSteps = STEP_ITEMS.filter((item) => {
		return STEP_ITEMS.findIndex((s) => s.key === item.key) < currentStepIndex && isClickable(item);
	});
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: cardRef,
		className: "relative bg-white p-3 md:rounded-[24px] md:p-4 ring-1 ring-black/6 shadow-[0_10px_30px_rgba(20,20,20,0.04)]"
	}, /* @__PURE__ */ react.default.createElement(antd.Modal, {
		open: confirmOpen,
		onCancel: () => setConfirmOpen(false),
		title: String(_pisell_utils.locales.getText("pisell2.venue.leave.title") || "Leave booking?"),
		centered: true,
		footer: /* @__PURE__ */ react.default.createElement("div", { style: {
			display: "flex",
			gap: 24
		} }, /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			onClick: () => setConfirmOpen(false),
			style: {
				flex: 1,
				borderRadius: 12,
				border: "none",
				background: "#f4f4f5",
				padding: "12px 0",
				fontSize: 16,
				fontWeight: 600,
				color: "#3f3f46",
				cursor: "pointer"
			}
		}, String(_pisell_utils.locales.getText("pisell2.venue.leave.stay") || "Stay")), /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			onClick: () => {
				setConfirmOpen(false);
				doBackHome();
			},
			style: {
				flex: 1,
				borderRadius: 12,
				border: "none",
				background: "var(--vb-primary, #ea1018)",
				padding: "12px 0",
				fontSize: 16,
				fontWeight: 700,
				color: "#fff",
				cursor: "pointer"
			}
		}, String(_pisell_utils.locales.getText("pisell2.venue.leave.confirm") || "Leave")))
	}, /* @__PURE__ */ react.default.createElement("p", { className: "text-sm text-zinc-500" }, String(_pisell_utils.locales.getText("pisell2.venue.leave.desc") || "Your selections will be lost if you leave now."))), popupOpen && backSteps.length > 0 ? /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: "fixed inset-0 z-40 md:hidden",
		onClick: () => setPopupOpen(false)
	}), /* @__PURE__ */ react.default.createElement("div", { className: "absolute left-4 right-4 top-full z-50 mt-2 overflow-hidden rounded-2xl bg-white shadow-[0_8px_30px_rgba(20,20,20,0.12)] ring-1 ring-black/6 md:hidden" }, backSteps.map((item, idx) => /* @__PURE__ */ react.default.createElement("button", {
		key: item.key,
		type: "button",
		onClick: () => {
			goToStep(item.key);
			setPopupOpen(false);
		},
		className: `flex w-full items-center gap-3 px-4 py-3 text-left transition hover:bg-zinc-50 active:bg-zinc-100 ${idx > 0 ? "border-t border-zinc-100" : ""}`
	}, /* @__PURE__ */ react.default.createElement("div", { className: "flex h-8 min-w-[62px] shrink-0 items-center justify-center rounded-full bg-zinc-100 px-2.5 text-xs font-bold text-zinc-700" }, item.n, "/", STEP_ITEMS.length), /* @__PURE__ */ react.default.createElement("div", { className: "flex items-center text-sm font-semibold text-zinc-800" }, /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText(item.titleKey) || "-"), getBadge(item)))))) : null, /* @__PURE__ */ react.default.createElement("div", { className: "flex items-center gap-3" }, !isFirstStep ? /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		"aria-label": "Back",
		onClick: handleBack,
		className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-zinc-50 text-zinc-700 ring-1 ring-black/10 transition hover:bg-zinc-100"
	}, /* @__PURE__ */ react.default.createElement("svg", {
		viewBox: "0 0 24 24",
		className: "h-5 w-5",
		fill: "none",
		stroke: "currentColor",
		strokeWidth: "2.5",
		strokeLinecap: "round",
		strokeLinejoin: "round"
	}, /* @__PURE__ */ react.default.createElement("path", { d: "M15 18l-6-6 6-6" }))) : null, /* @__PURE__ */ react.default.createElement("div", { className: "min-w-0 flex-1" }, /* @__PURE__ */ react.default.createElement("div", {
		className: `md:hidden ${backSteps.length > 0 ? "cursor-pointer" : ""}`,
		onClick: () => {
			if (backSteps.length > 0) setPopupOpen((v) => !v);
		}
	}, /* @__PURE__ */ react.default.createElement("div", { className: "flex items-center gap-3" }, /* @__PURE__ */ react.default.createElement("div", {
		className: "flex h-8 min-w-[62px] items-center justify-center rounded-full px-2.5 text-xs font-bold md:h-10 md:min-w-[74px] md:text-sm",
		style: {
			backgroundColor: "var(--vb-primary-light)",
			color: "var(--vb-primary)"
		}
	}, currentStepIndex + 1, "/", STEP_ITEMS.length), /* @__PURE__ */ react.default.createElement("div", { className: "min-w-0 flex-1 text-lg font-extrabold text-zinc-900 md:text-xl" }, _pisell_utils.locales.getText(currentStepItem.titleKey) || "-"), backSteps.length > 0 ? /* @__PURE__ */ react.default.createElement("svg", {
		viewBox: "0 0 24 24",
		className: `h-5 w-5 shrink-0 text-zinc-400 transition-transform ${popupOpen ? "rotate-180" : ""}`,
		fill: "none",
		stroke: "currentColor",
		strokeWidth: "2"
	}, /* @__PURE__ */ react.default.createElement("path", {
		d: "M6 9l6 6 6-6",
		strokeLinecap: "round",
		strokeLinejoin: "round"
	})) : null)), /* @__PURE__ */ react.default.createElement("div", { className: "hidden items-center gap-3 md:flex" }, STEP_ITEMS.map((item, index) => {
		const status = getStepStatus(item);
		const clickable = isClickable(item);
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, { key: item.n }, /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			onClick: () => {
				if (clickable) goToStep(item.key);
			},
			className: `flex items-center gap-3 rounded-full px-3 py-2 transition ${status === "done" ? "bg-zinc-50" : status !== "active" ? "bg-zinc-50/80" : ""} ${clickable ? "cursor-pointer hover:bg-zinc-100" : "cursor-default"}`,
			style: status === "active" ? { backgroundColor: "var(--vb-primary-light)" } : void 0
		}, /* @__PURE__ */ react.default.createElement("div", {
			className: `flex h-8 w-8 items-center justify-center rounded-full text-sm font-bold ${status === "done" ? "bg-[#111] text-white" : status === "active" ? "text-white" : "bg-white text-zinc-400 ring-1 ring-black/8"}`,
			style: status === "active" ? { backgroundColor: "var(--vb-primary)" } : void 0
		}, status === "done" ? /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: "pisell2-check",
			style: { fontSize: 15 }
		}) : item.n), /* @__PURE__ */ react.default.createElement("div", { className: `flex items-center text-sm font-semibold ${status === "active" ? "text-zinc-900" : status === "done" ? "text-zinc-700" : "text-zinc-400"}` }, /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText(item.titleKey) || "-"), getBadge(item))), index < STEP_ITEMS.length - 1 ? /* @__PURE__ */ react.default.createElement("div", { className: "relative h-px flex-1 overflow-hidden rounded-full bg-zinc-200" }, /* @__PURE__ */ react.default.createElement("div", {
			className: `absolute left-0 top-0 h-full ${status === "done" ? "w-full bg-[#111]" : status === "active" ? "w-1/2" : "w-0"}`,
			style: status === "active" ? { backgroundColor: "var(--vb-primary)" } : void 0
		})) : null);
	}))), /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		"aria-label": "Close",
		onClick: setConfirmOpen.bind(null, true),
		className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-zinc-50 text-zinc-700 ring-1 ring-black/10 transition hover:bg-zinc-100"
	}, /* @__PURE__ */ react.default.createElement("svg", {
		viewBox: "0 0 24 24",
		className: "h-5 w-5",
		fill: "none",
		stroke: "currentColor",
		strokeWidth: "2.5",
		strokeLinecap: "round",
		strokeLinejoin: "round"
	}, /* @__PURE__ */ react.default.createElement("path", { d: "M18 6 6 18" }), /* @__PURE__ */ react.default.createElement("path", { d: "M6 6l12 12" })))));
}
//#endregion
exports.default = Header;
