import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useComponents from "../../../../hooks/useComponents.js";
import DepositModal from "../../../appointmentBooking/deposit/components/PolicyModal/index.js";
import { contextUtils, useScanOrderLogin } from "../../hooks.js";
import { useScanOrderContext } from "../../context.js";
import Header from "../Header/index.js";
import Cart from "../Cart/index.js";
import Footer from "../Footer/index.js";
import Menu$1 from "../Menu/index.js";
import ErrorState from "../ErrorState/index.js";
import ScanOrderInitializing from "../Initializing/index.js";
import Check from "../Check/index.js";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Modal, message } from "antd";
import { isMobile, locales } from "@pisell/utils";
import { Button as Button$1, PisellModal } from "@pisell/materials";
import "./index.less";
//#region src/components/scanOrder/components/Content/index.tsx
/** 从 pisell1.handlePaxModal 的 callback 入参中解析人数（兼容数字、字符串或对象字段） */
function extractEntryPaxNumber(payload) {
	if (payload == null) return null;
	if (typeof payload === "number" && Number.isFinite(payload) && payload >= 1) return Math.floor(payload);
	if (typeof payload === "string") {
		const n = Number(payload);
		if (Number.isFinite(n) && n >= 1) return Math.floor(n);
	}
	if (typeof payload === "object") {
		const o = payload;
		for (const k of [
			"entryPaxNumber",
			"pax",
			"num",
			"count",
			"value"
		]) {
			const v = o[k];
			if (typeof v === "number" && Number.isFinite(v) && v >= 1) return Math.floor(v);
			if (typeof v === "string") {
				const n = Number(v);
				if (Number.isFinite(n) && n >= 1) return Math.floor(n);
			}
		}
	}
	return null;
}
function ReadyState() {
	var _utils$getApp, _formModal$content, _formModal$content2, _formModal$content3, _formModal$content4;
	const { currentStep, prevStep, goToStep, runModuleAction, entryContext, viewModel, refreshViewModel, footerActionText, setFooterActionText, cartValidation, setTableName, entryMode, setEntryMode, submitDisabledTips, setSubmitDisabledTips, scanOrderModule, isCacheHydrated, markGate, isGatePassed, resumeStep, consumeResumeStep } = useScanOrderContext();
	const { isLogin, openLoginModal } = useScanOrderLogin();
	const utils = contextUtils();
	const [FormCard] = useComponents({ components: ["FormCard"] });
	const formModalRef = useRef(null);
	const [formSubmitting, setFormSubmitting] = useState(false);
	const [policyModal, setPolicyModal] = useState({
		open: false,
		content: null
	});
	const [formModal, setFormModal] = useState({
		open: false,
		content: null
	});
	const [pendingFormPayload, setPendingFormPayload] = useState(null);
	/**
	* 商品列表状态：挂在 ReadyState 而不是 Menu 本地，保证从 check 返回 product 时命中缓存、不重发请求
	* （stepRegistry 切换会让 Menu unmount，本地 useState 会丢；ReadyState 在整段会话内不 unmount）
	* - productListLoadedRef：同步判定是否已有有效结果，避免 setState 异步窗口内重复请求
	* - productListPromiseRef：in-flight promise 去重，让并发调用合并成同一次请求
	*/
	const [productList, setProductList] = useState([]);
	const [isProductListLoading, setIsProductListLoading] = useState(false);
	const productListLoadedRef = useRef(false);
	const productListPromiseRef = useRef(null);
	const ensureProductListLoaded = useCallback(_asyncToGenerator(function* () {
		if (productListLoadedRef.current) return;
		if (productListPromiseRef.current) {
			yield productListPromiseRef.current.catch(() => {});
			return;
		}
		const request = _asyncToGenerator(function* () {
			setIsProductListLoading(true);
			try {
				const res = yield runModuleAction("getProductList");
				if (Array.isArray(res)) {
					productListLoadedRef.current = true;
					setProductList(res);
					return;
				}
				Modal.confirm({
					title: res === null || res === void 0 ? void 0 : res.message,
					okText: String(locales.getText("pisell2.event.confirm") || "OK"),
					cancelButtonProps: { style: { display: "none" } },
					maskClosable: false,
					onOk: () => {
						location.replace("/");
					}
				});
			} catch (error) {
				console.warn("[scanOrder] getProductList failed", error);
			} finally {
				setIsProductListLoading(false);
				productListPromiseRef.current = null;
			}
		})();
		productListPromiseRef.current = request;
		yield request;
	}), [runModuleAction]);
	/** checkResourceAvailable 返回 requestEntryPax === 1 时，在协议/表单之后弹人数并写入 scanOrder otherParams */
	const requestEntryPaxRef = useRef(0);
	const requestPaxMinRef = useRef(1);
	const requestPaxMaxRef = useRef(1);
	const tableFormRecordRef = useRef(null);
	/** 本次会话是否曾实际弹出过入口人数弹窗（商品页返回首页前可二次弹窗） */
	const entryPaxModalWasPresentedRef = useRef(false);
	/** 根据当前语言从多语言 name 对象中取值，兜底当前语言 -> original -> 空串 */
	const getLocalizedName = (nameMap) => {
		if (!nameMap) return "";
		const localized = nameMap[locales.getLocale()];
		if (typeof localized === "string" && localized) return localized;
		const original = nameMap.original;
		if (typeof original === "string" && original) return original;
		return "";
	};
	/**
	* 解析可能是纯字符串或多语言对象的文案
	* - 字符串：原样返回
	* - 多语言对象（如 { en, 'zh-CN', original, ... }）：取当前语言，兜底 original
	* - 其它：空串
	*/
	const resolveLocalizedText = (value) => {
		if (value == null) return "";
		if (typeof value === "string") return value;
		if (typeof value !== "object") return String(value);
		return getLocalizedName(value);
	};
	const normalizeFormPayload = (formPayload, partyroomBookingPayload) => {
		var _ref, _ref2, _sourcePayload$id;
		const sourcePayload = formPayload !== null && formPayload !== void 0 ? formPayload : partyroomBookingPayload;
		if (!sourcePayload) return null;
		const rawId = typeof sourcePayload === "number" || typeof sourcePayload === "string" ? sourcePayload : (_ref = (_ref2 = (_sourcePayload$id = sourcePayload === null || sourcePayload === void 0 ? void 0 : sourcePayload.id) !== null && _sourcePayload$id !== void 0 ? _sourcePayload$id : sourcePayload === null || sourcePayload === void 0 ? void 0 : sourcePayload.form_id) !== null && _ref2 !== void 0 ? _ref2 : sourcePayload === null || sourcePayload === void 0 ? void 0 : sourcePayload.resource_form_id) !== null && _ref !== void 0 ? _ref : sourcePayload === null || sourcePayload === void 0 ? void 0 : sourcePayload.partyroom_booking;
		const formId = Number(rawId);
		if (Number.isNaN(formId) || formId <= 0) return null;
		const sourceDetail = typeof sourcePayload === "object" && sourcePayload !== null ? sourcePayload : {};
		return {
			id: formId,
			title: sourceDetail === null || sourceDetail === void 0 ? void 0 : sourceDetail.title,
			defaultValues: (sourceDetail === null || sourceDetail === void 0 ? void 0 : sourceDetail.defaultValues) || {},
			setting: sourceDetail === null || sourceDetail === void 0 ? void 0 : sourceDetail.setting
		};
	};
	const app = utils === null || utils === void 0 || (_utils$getApp = utils.getApp) === null || _utils$getApp === void 0 ? void 0 : _utils$getApp.call(utils);
	/** 回站点首页（与商品步返回兜底一致） */
	const navigateToHome = () => {
		var _app$history, _app$history2;
		if (app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 ? void 0 : _app$history.replace) app.history.replace("/");
		else if (app === null || app === void 0 || (_app$history2 = app.history) === null || _app$history2 === void 0 ? void 0 : _app$history2.push) app.history.push("/");
		else location.replace("/");
	};
	/** 弹出入口人数弹窗，返回有效人数或取消/关闭时为 null */
	const requestEntryPaxModal = () => new Promise((resolve) => {
		var _tableFormRecordRef$c;
		if (typeof (utils === null || utils === void 0 ? void 0 : utils.action) !== "function") {
			resolve(null);
			return;
		}
		utils.action({
			type: "pisell1.handlePaxModal",
			data: {
				tableName: getLocalizedName((_tableFormRecordRef$c = tableFormRecordRef.current) === null || _tableFormRecordRef$c === void 0 ? void 0 : _tableFormRecordRef$c.name),
				requestPaxMin: requestPaxMinRef.current,
				requestPaxMax: requestPaxMaxRef.current
			},
			callback: (result) => {
				resolve(extractEntryPaxNumber(result));
			}
		});
	});
	const handleOrderDetail = (order_id) => {
		var _app$history3, _app$history4;
		const link = `/order/details?id=${order_id}`;
		if (app === null || app === void 0 || (_app$history3 = app.history) === null || _app$history3 === void 0 ? void 0 : _app$history3.replace) app.history.replace(link);
		else if (app === null || app === void 0 || (_app$history4 = app.history) === null || _app$history4 === void 0 ? void 0 : _app$history4.push) app.history.push(link);
		else location.replace(link);
	};
	const handleBack = () => {
		if (currentStep !== "product") {
			prevStep();
			return;
		}
		if (entryMode === "additional_order" && (entryContext === null || entryContext === void 0 ? void 0 : entryContext.order_id)) {
			handleOrderDetail(entryContext.order_id);
			return;
		}
		if (entryPaxModalWasPresentedRef.current) {
			_asyncToGenerator(function* () {
				const pax = yield requestEntryPaxModal();
				if (pax == null) {
					navigateToHome();
					return;
				}
				try {
					yield runModuleAction("setEntryPaxNumber", pax);
					yield refreshViewModel();
				} catch (error) {
					console.warn("[scanOrder] setEntryPaxNumber on back pax confirm failed", error);
				}
			})();
			return;
		}
		navigateToHome();
	};
	const enterProductStep = function() {
		var _ref3 = _asyncToGenerator(function* () {
			try {
				yield runModuleAction("applyItemRulePrefill");
				yield refreshViewModel();
			} catch (error) {
				console.warn("[scanOrder] applyItemRulePrefill failed", error);
			} finally {
				const target = resumeStep === "check" ? "check" : "product";
				if (resumeStep) consumeResumeStep();
				goToStep(target);
			}
		});
		return function enterProductStep() {
			return _ref3.apply(this, arguments);
		};
	}();
	/** 需要时先走人数弹窗与 setOtherParams(entryPaxNumber)，再进入商品步 */
	const runEntryPaxGateThenEnterProduct = function() {
		var _ref4 = _asyncToGenerator(function* () {
			if (entryMode === "additional_order") {
				yield enterProductStep();
				return;
			}
			if (requestEntryPaxRef.current !== 1) {
				yield enterProductStep();
				return;
			}
			if (isGatePassed("paxEntered")) {
				yield enterProductStep();
				return;
			}
			entryPaxModalWasPresentedRef.current = true;
			const pax = yield requestEntryPaxModal();
			if (pax == null) {
				navigateToHome();
				return;
			}
			try {
				yield runModuleAction("setEntryPaxNumber", pax);
				markGate("paxEntered");
			} catch (error) {
				console.warn("[scanOrder] setOtherParams failed", error);
			}
			yield enterProductStep();
		});
		return function runEntryPaxGateThenEnterProduct() {
			return _ref4.apply(this, arguments);
		};
	}();
	const closePolicyAndBack = () => {
		setPolicyModal({
			open: false,
			content: null
		});
		location.replace("/");
	};
	const openFormModal = (payload) => {
		if (!payload) return;
		setFormSubmitting(false);
		setFormModal({
			open: true,
			content: payload
		});
	};
	const closeFormModalAndBack = () => {
		setFormSubmitting(false);
		setFormModal({
			open: false,
			content: null
		});
		setPendingFormPayload(null);
		location.replace("/");
	};
	const handleFormSubmit = (status) => {
		setFormSubmitting(false);
		if (status !== "success") return;
		setFormModal({
			open: false,
			content: null
		});
		setPendingFormPayload(null);
		markGate("formSubmitted");
		runEntryPaxGateThenEnterProduct();
	};
	const handleFormConfirm = () => {
		var _formModalRef$current, _formModalRef$current2;
		if (formSubmitting) return;
		setFormSubmitting(true);
		(_formModalRef$current = formModalRef.current) === null || _formModalRef$current === void 0 || (_formModalRef$current2 = _formModalRef$current.submit) === null || _formModalRef$current2 === void 0 || _formModalRef$current2.call(_formModalRef$current);
	};
	const confirmPolicyAndContinue = () => {
		setPolicyModal({
			open: false,
			content: null
		});
		markGate("policyAccepted");
		if (pendingFormPayload && !isGatePassed("formSubmitted")) {
			openFormModal(pendingFormPayload);
			return;
		}
		runEntryPaxGateThenEnterProduct();
	};
	const depositProtocolRequest = (id) => {
		var _utils$request, _utils$request$get;
		return utils === null || utils === void 0 || (_utils$request = utils.request) === null || _utils$request === void 0 || (_utils$request$get = _utils$request.get) === null || _utils$request$get === void 0 ? void 0 : _utils$request$get.call(_utils$request, `/h5/shop-policy/${id}`, {});
	};
	useEffect(() => {
		const checkResourceAvailable = function() {
			var _ref5 = _asyncToGenerator(function* () {
				const hasOrderId = !!(entryContext === null || entryContext === void 0 ? void 0 : entryContext.order_id);
				const { mode, order_id, errorTips, policy, form, partyroom_booking, requestEntryPax, requestPaxMin, requestPaxMax, table_form_record } = yield runModuleAction("checkResourceAvailable", entryContext === null || entryContext === void 0 ? void 0 : entryContext.resource_id, hasOrderId);
				requestEntryPaxRef.current = Number(requestEntryPax) === 1 ? 1 : 0;
				requestPaxMinRef.current = Number(requestPaxMin) || 1;
				requestPaxMaxRef.current = Number(requestPaxMax) || 1;
				tableFormRecordRef.current = table_form_record || {};
				setTableName(getLocalizedName(table_form_record === null || table_form_record === void 0 ? void 0 : table_form_record.name));
				const normalizedFormPayload = normalizeFormPayload(form, partyroom_booking);
				const isAdditionalOrder = mode === "additional_order" || mode === "additional_order_with_code";
				setEntryMode(isAdditionalOrder ? "additional_order" : "default");
				if (mode === "idle") {
					const normalizedPolicyPayload = typeof policy === "object" && policy !== null ? policy : { id: policy };
					if ((normalizedPolicyPayload === null || normalizedPolicyPayload === void 0 ? void 0 : normalizedPolicyPayload.id) && !isGatePassed("policyAccepted")) {
						setPendingFormPayload(normalizedFormPayload);
						setPolicyModal({
							open: true,
							content: normalizedPolicyPayload
						});
						return;
					}
					if (normalizedFormPayload && !isGatePassed("formSubmitted")) {
						openFormModal(normalizedFormPayload);
						return;
					}
					yield runEntryPaxGateThenEnterProduct();
				} else if (isAdditionalOrder) yield enterProductStep();
				else if (mode === "submit_disabled") {
					setSubmitDisabledTips(resolveLocalizedText(errorTips) || String(locales.getText("pisell2.scan.order.submit.disabled.default") || ""));
					yield enterProductStep();
				} else if (mode === "resource_busy") if (!isLogin) {
					var _scanOrderModule$setU;
					scanOrderModule === null || scanOrderModule === void 0 || (_scanOrderModule$setU = scanOrderModule.setUIState) === null || _scanOrderModule$setU === void 0 || _scanOrderModule$setU.call(scanOrderModule, "pendingStep", currentStep);
					openLoginModal({ callback: (status) => {
						var _scanOrderModule$dele2;
						if (status === "success") {
							var _scanOrderModule$dele;
							scanOrderModule === null || scanOrderModule === void 0 || (_scanOrderModule$dele = scanOrderModule.deleteUIState) === null || _scanOrderModule$dele === void 0 || _scanOrderModule$dele.call(scanOrderModule, "pendingStep");
							handleOrderDetail(order_id);
							return;
						}
						scanOrderModule === null || scanOrderModule === void 0 || (_scanOrderModule$dele2 = scanOrderModule.deleteUIState) === null || _scanOrderModule$dele2 === void 0 || _scanOrderModule$dele2.call(scanOrderModule, "pendingStep");
						location.replace("/");
					} });
				} else handleOrderDetail(order_id);
				else {
					let content = resolveLocalizedText(errorTips);
					if (!content) if (mode === "resource_block") content = String(locales.getText("pisell2.scan.order.resource.status.exception") || "");
					else content = String(locales.getText("pisell2.scan.order.store.status.exception") || "");
					Modal.info({
						title: locales.getText("pisell2.scan.order.step.error"),
						content: resolveLocalizedText(content).trim(),
						okText: String(locales.getText("pisell2.event.confirm") || "OK"),
						maskClosable: false,
						onOk: () => {
							location.replace("/");
						}
					});
				}
			});
			return function checkResourceAvailable() {
				return _ref5.apply(this, arguments);
			};
		}();
		if (!isCacheHydrated) return;
		checkResourceAvailable();
	}, [isCacheHydrated]);
	useEffect(() => {
		window.scrollTo({
			top: 0,
			behavior: "smooth"
		});
	}, [currentStep]);
	useEffect(() => {
		if (currentStep === "product") {
			setFooterActionText((cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.passed) === true ? String(locales.getText("pisell2.event.continue") || "下一步") : String(locales.getText("pisell2.scan.order.action.select.required") || ""));
			return;
		}
		if (currentStep === "check") {
			setFooterActionText(String(locales.getText("pisell2.event.checkout") || ""));
			return;
		}
	}, [currentStep, cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.passed]);
	const stepRegistry = {
		init: /* @__PURE__ */ React.createElement(ScanOrderInitializing, null),
		product: /* @__PURE__ */ React.createElement(Menu$1, {
			onCheckout: () => goToStep("check"),
			productList,
			isProductListLoading,
			onEnsureProductList: ensureProductListLoaded
		}),
		check: /* @__PURE__ */ React.createElement(Check, null),
		error: /* @__PURE__ */ React.createElement(ErrorState, { message: locales.getText("pisell2.scan.order.store.status.exception") })
	};
	const getFirstFailedProductIds = () => {
		const firstFailure = Array.isArray(cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.failures) ? cartValidation.failures[0] : null;
		const targets = Array.isArray(firstFailure === null || firstFailure === void 0 ? void 0 : firstFailure.targets) ? firstFailure.targets : [];
		const ids = [];
		const seen = /* @__PURE__ */ new Set();
		for (const target of targets) {
			const id = Number(target === null || target === void 0 ? void 0 : target.product_id);
			if (Number.isFinite(id) && id > 0 && !seen.has(id)) {
				seen.add(id);
				ids.push(id);
			}
		}
		return ids;
	};
	const scrollAndHighlightProductsByIds = (productIds) => {
		if (!(productIds === null || productIds === void 0 ? void 0 : productIds.length)) return false;
		let scrolled = false;
		let highlighted = false;
		for (const productId of productIds) {
			const failedProductElement = document.querySelector(`[data-product-id="${String(productId)}"]`);
			if (!failedProductElement) continue;
			failedProductElement.classList.remove("highlight-product-item");
			if (!scrolled) {
				failedProductElement.scrollIntoView({
					behavior: "smooth",
					block: "center"
				});
				scrolled = true;
			}
			failedProductElement.offsetWidth;
			failedProductElement.classList.add("highlight-product-item");
			setTimeout(() => {
				failedProductElement.classList.remove("highlight-product-item");
			}, 3e3);
			highlighted = true;
		}
		return highlighted;
	};
	const gotoCheckOrder = function() {
		var _ref6 = _asyncToGenerator(function* () {
			var _otherParams$dineInCo;
			if (submitDisabledTips) {
				message.warning(submitDisabledTips, 2);
				return;
			}
			const firstFailure = Array.isArray(cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.failures) ? cartValidation.failures[0] : null;
			if ((cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.passed) === false) {
				const failedProductIds = getFirstFailedProductIds();
				if (failedProductIds.length) scrollAndHighlightProductsByIds(failedProductIds);
				const failureTips = String((firstFailure === null || firstFailure === void 0 ? void 0 : firstFailure.validationMessage) || "").trim();
				message.warning(failureTips, 2);
				return;
			}
			const otherParams = yield runModuleAction("getOtherParams");
			console.log("otherParams >>>>> ", otherParams);
			const dineInConfig = (_otherParams$dineInCo = otherParams === null || otherParams === void 0 ? void 0 : otherParams.dineInConfig) !== null && _otherParams$dineInCo !== void 0 ? _otherParams$dineInCo : {};
			if (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig["availability.paused"]) {
				var _dineInConfig$availab;
				Modal.info({
					title: String(locales.getText("pisell2.scan.order.step.error") || ""),
					content: (_dineInConfig$availab = dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig["availability.pause_message"]) !== null && _dineInConfig$availab !== void 0 ? _dineInConfig$availab : "",
					okText: String(locales.getText("pisell2.event.confirm") || "OK"),
					onOk: () => {
						location.replace("/");
					}
				});
				return;
			}
			if (!isLogin) {
				var _scanOrderModule$setU2;
				scanOrderModule === null || scanOrderModule === void 0 || (_scanOrderModule$setU2 = scanOrderModule.setUIState) === null || _scanOrderModule$setU2 === void 0 || _scanOrderModule$setU2.call(scanOrderModule, "pendingStep", "check");
				openLoginModal({ callback: (status) => {
					var _scanOrderModule$dele3;
					scanOrderModule === null || scanOrderModule === void 0 || (_scanOrderModule$dele3 = scanOrderModule.deleteUIState) === null || _scanOrderModule$dele3 === void 0 || _scanOrderModule$dele3.call(scanOrderModule, "pendingStep");
					if (status === "success") goToStep("check");
				} });
				return;
			}
			goToStep("check");
		});
		return function gotoCheckOrder() {
			return _ref6.apply(this, arguments);
		};
	}();
	const isMobileView = isMobile();
	const isShowFooter = useMemo(() => {
		if (!isMobileView) return false;
		return currentStep === "product";
	}, [currentStep, isMobileView]);
	const isShowDesktopCart = useMemo(() => {
		if (isMobileView) return false;
		return currentStep === "product";
	}, [currentStep, isMobileView]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Header, {
		currentStep,
		onBack: handleBack
	}), /* @__PURE__ */ React.createElement("div", {
		className: `pisell-scan-order-content-wrap ${isMobileView ? "pisell-scan-order-content-mobile-wrap" : ""}`,
		"data-cart-validation-passed": String(cartValidation === null || cartValidation === void 0 ? void 0 : cartValidation.passed)
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-content-left" }, stepRegistry[currentStep]), isShowDesktopCart ? /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-content-right" }, /* @__PURE__ */ React.createElement(Cart, {
		embedded: true,
		open: true,
		onCancel: () => {},
		onNext: gotoCheckOrder,
		items: (viewModel === null || viewModel === void 0 ? void 0 : viewModel.cartItems) || [],
		summary: (viewModel === null || viewModel === void 0 ? void 0 : viewModel.summary) || {},
		disabled: !!submitDisabledTips
	})) : null), isShowFooter ? /* @__PURE__ */ React.createElement(Footer, {
		cartItems: (viewModel === null || viewModel === void 0 ? void 0 : viewModel.cartItems) || [],
		summary: (viewModel === null || viewModel === void 0 ? void 0 : viewModel.summary) || {},
		actionText: footerActionText,
		onAction: () => gotoCheckOrder(),
		disabled: !!submitDisabledTips
	}) : null, policyModal.open ? /* @__PURE__ */ React.createElement(DepositModal, {
		open: policyModal.open,
		onCancel: closePolicyAndBack,
		onConfirm: confirmPolicyAndContinue,
		item: policyModal.content,
		isHideCheckout: false,
		depositProtocolRequest
	}) : null, formModal.open ? /* @__PURE__ */ React.createElement(PisellModal, {
		open: formModal.open,
		platform: isMobileView ? "h5" : "pc",
		onCancel: closeFormModalAndBack,
		title: ((_formModal$content = formModal.content) === null || _formModal$content === void 0 ? void 0 : _formModal$content.title) || locales.getText("pisell2.appointment.fill-form") || "填写信息",
		mobileModalHeight: "90vh",
		width: isMobileView ? "100%" : 900,
		className: "pisell-scan-order-form-modal",
		footer: /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-form-modal-footer" }, /* @__PURE__ */ React.createElement(Button$1, {
			type: "primary",
			size: "large",
			loading: formSubmitting,
			onClick: handleFormConfirm,
			className: "pisell-scan-order-form-modal-confirm-btn"
		}, String(locales.getText("pisell2.event.confirm") || "Confirm")))
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-form-modal-body" }, FormCard ? /* @__PURE__ */ React.createElement(FormCard, {
		id: ((_formModal$content2 = formModal.content) === null || _formModal$content2 === void 0 ? void 0 : _formModal$content2.id) || 0,
		ref: formModalRef,
		isGetLastData: false,
		setting: ((_formModal$content3 = formModal.content) === null || _formModal$content3 === void 0 ? void 0 : _formModal$content3.setting) || { isHidden: 1 },
		formWrapStyle: { padding: "16px" },
		isV2API: true,
		isShowSkeleton: true,
		onSubmit: (status) => {
			handleFormSubmit(status);
		},
		onFinishFailed: () => {
			setFormSubmitting(false);
		},
		onFormValueChange: () => {},
		defaultValues: ((_formModal$content4 = formModal.content) === null || _formModal$content4 === void 0 ? void 0 : _formModal$content4.defaultValues) || {},
		isClearData: false
	}) : null)) : null);
}
function Content() {
	const { isLoading, errorMessage } = useScanOrderContext();
	if (isLoading) return /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-loading" }, "Loading...");
	if (errorMessage) return /* @__PURE__ */ React.createElement(ErrorState, {
		message: errorMessage,
		onRetry: () => {
			window.location.reload();
		}
	});
	return /* @__PURE__ */ React.createElement(ReadyState, null);
}
//#endregion
export { Content as default };
