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 from "../../hooks/useEngineContext.js";
import CompensatedPisellContainer from "../../pro/compensatedPisellContainer/index.js";
import withResponsive from "../../responsive/withResponsive.js";
import useLogger from "../../hooks/useLogger.js";
import { request } from "../../utils/index.js";
import { getBookingDetail } from "./serve.js";
import locales_default from "./locales.js";
import ticketBooking_default, { ticketBookingInitialState } from "./index.js";
import { getPicoCodingOpenData } from "../../plus/pisellReservation/serve/formResourcePage.js";
import { formatBookingDetail } from "./utils/edit.js";
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { Modal, Skeleton } from "antd";
import { locales } from "@pisell/utils";
import { Iconfont, useToast } from "@pisell/materials";
import "./dialog.less";
//#region src/components/ticketBooking/dialog.tsx
/**
* 把 preloaded editData 中"会变"的字段（bookingConfigParams + editModeInitialState）
* 局部 dispatch 到 TicketBooking 的 miniRedux store。
*
* 注意：这里**只做浅 merge**，不重置 store 的其它字段（如资源缓存、列表数据等）。
* 残留的购物车 / UI 状态由关闭时的 `shopApi.bookingTicket.clearAllCart()` 负责清理，
* 这样既能切换 placeholder/detail，又能保留商品列表等需要复用的缓存数据。
*
* @example
* dispatchEditDataToStore(storeRef.current, nextEditData);
*/
function dispatchEditDataToStore(store, editData) {
	if (!store) return;
	const ems = editData.editModeInitialState || {};
	store.setState(_objectSpread2({ bookingConfigParams: editData.bookingConfigParams }, ems));
}
/**
* 关闭弹窗时调用全局 `shopApi.bookingTicket.clearAllCart()`，
* 清空当前购物车以及相关业务态，下一次打开新的 placeholder 时不会与上一次串数据。
*
* 仅在 preloaded 模式下需要：非 preloaded 模式因为 destroyOnClose 会卸载整棵子树，
* miniRedux 随 TicketBooking 一起销毁，无需额外清理。
*
* @example
* tryClearCartOnClose();
*/
function tryClearCartOnClose() {
	if (typeof window === "undefined") return;
	try {
		var _window;
		const api = (_window = window) === null || _window === void 0 || (_window = _window.shopApi) === null || _window === void 0 || (_window = _window.bookingTicket) === null || _window === void 0 ? void 0 : _window.clearAllCart;
		if (typeof api === "function") api();
	} catch (e) {}
}
/**
* 全局调试日志：把 dialog 内部关键状态推到 window 上，便于宿主复制给开发排查问题。
* 数组上限 200 条，循环覆盖，避免内存增长。
*
* @example
* // 浏览器控制台
* copy(window.__pisellEditBookingDebug)
*/
function pushDebugLog(label, data) {
	if (typeof window === "undefined") return;
	const w = window;
	if (!Array.isArray(w.__pisellEditBookingDebug)) w.__pisellEditBookingDebug = [];
	if (w.__pisellEditBookingDebug.length > 200) w.__pisellEditBookingDebug.shift();
	w.__pisellEditBookingDebug.push({
		ts: Date.now(),
		label,
		data
	});
}
const getPicodingMenuData = function() {
	var _ref = _asyncToGenerator(function* (context, business_code) {
		var _context$appHelper, _context$appHelper$ge, _context$appHelper2, _context$appHelper2$g;
		const res = yield getPicoCodingOpenData({
			shop_id: context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getData) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper, "shop_id"),
			data: {
				scope: "board",
				section_code: [
					"reservation",
					"fulfillment",
					"menu"
				],
				target: `${business_code}+pos`
			}
		}, {
			prefix: false,
			headers: { "Tenant-Id": context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$g = _context$appHelper2.getData) === null || _context$appHelper2$g === void 0 ? void 0 : _context$appHelper2$g.call(_context$appHelper2, "tenant_id") }
		});
		return (res === null || res === void 0 ? void 0 : res.data) || {};
	});
	return function getPicodingMenuData(_x, _x2) {
		return _ref.apply(this, arguments);
	};
}();
/**
* TicketBooking dialog wrapper，支持编辑模式和新建模式。
*
* - 编辑模式：传入 order_id，拉取详情后渲染 TicketBooking。
* - 新建模式：传入 createModeConfig（含预填充 modalState），跳过 API 直接渲染。
*
* 两种模式互斥，优先判断 order_id。
*/
function TicketBookingDialog(props) {
	var _preloadedEditData$ed, _preloadedEditData$ed2, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _context$appHelper$ut4, _context$appHelper3;
	let { open, order_id, onClose, callback, rulesHooks, createModeConfig, variant } = props;
	const { preloaded, preloadedEditData, onEditDataReady } = props;
	const context = useEngineContext();
	if (!preloaded && !order_id && !createModeConfig) {
		var _context$engine;
		const engineProps = ((_context$engine = context.engine) === null || _context$engine === void 0 ? void 0 : _context$engine.props) || {};
		order_id = engineProps.order_id;
		open = engineProps.open;
		callback = engineProps.callback;
		rulesHooks = engineProps.rulesHooks;
	}
	const [title, setTitle] = useState("");
	const { productExtensionType } = ticketBookingInitialState;
	const Toast = useToast();
	pushDebugLog("dialog.render", {
		open,
		order_id,
		preloaded,
		hasPreloadedEditData: !!preloadedEditData,
		preloadedIsEditMode: (_preloadedEditData$ed = preloadedEditData === null || preloadedEditData === void 0 || (_preloadedEditData$ed2 = preloadedEditData.editModeInitialState) === null || _preloadedEditData$ed2 === void 0 ? void 0 : _preloadedEditData$ed2.isEditTicketMode) !== null && _preloadedEditData$ed !== void 0 ? _preloadedEditData$ed : null,
		hasCreateModeConfig: !!createModeConfig
	});
	/**
	* TicketBooking 内部 miniRedux store 的引用，dialog 通过它在 edit 模式下
	* **不重 mount TicketBooking** 的前提下，把详情接口的 modalState/bookingDetail/paymentPaid
	* 局部 dispatch 进去（避免商品列表跟随 Skeleton 抖动）。
	*/
	const storeRef = useRef(null);
	/**
	* editData 为 null 时表示数据未就绪，TicketBooking 不渲染（Modal 内显示 Skeleton）。
	*
	* 注意：preloaded 模式下也用 null 初始化——若初始就用一份空 base 的 editData，
	* TicketBooking 会被提前 mount，后续 setEditData 切换到真实数据时 store 重建，
	* 但 miniRedux 的 useStore 用 useRef 缓存 state，store 变化不会自动同步到 stateRef，
	* 导致购物车看不到详情/initialModalState 的数据。
	* 通过让 editData 在每次切换前先变成 null（或外层 key 变化），强制 TicketBooking 完整重建。
	*/
	const [editData, setEditData] = useState(preloaded && preloadedEditData ? preloadedEditData : null);
	const [editDataVersion, setEditDataVersion] = useState(0);
	/**
	* 提交一份新的 editData，并递增重建版本号。
	* 用于 new 模式 / 切换 order_id / 强制重建场景。
	*/
	const commitEditData = useCallback((next) => {
		var _next$editModeInitial;
		pushDebugLog("dialog.commitEditData", {
			hasNext: !!next,
			isEditMode: next ? !!((_next$editModeInitial = next.editModeInitialState) === null || _next$editModeInitial === void 0 ? void 0 : _next$editModeInitial.isEditTicketMode) : null
		});
		setEditData(next);
		setEditDataVersion((v) => v + 1);
	}, []);
	/**
	* Render 阶段同步切换：preloaded 模式下，外部传入新的 `preloadedEditData` 引用时分两种处理：
	*
	* 1) **light swap**（仅「编辑占位 → 编辑占位」等同模式微调）：局部 dispatch，不重 mount。
	*
	* 2) **commit 路径**（首次 / 新建 / 编辑↔新建互切）：setEditData + editDataVersion++，
	*    强制 TicketBooking 完整重 mount。关闭时 clearAllCart 会清空 modalState.service，
	*    新建若走 light swap 购物车无法从 initialModalState 恢复（miniRedux stateRef 缓存问题）。
	*
	* React 允许 render 时 setState 触发 immediate re-render，靠引用相等保护避免无限循环。
	*/
	const lastPreloadedRef = useRef(preloadedEditData);
	const pendingDispatchRef = useRef(null);
	if (preloaded && preloadedEditData && preloadedEditData !== lastPreloadedRef.current) {
		var _preloadedEditData$ed3, _prevPreloaded$editMo;
		const prevPreloaded = lastPreloadedRef.current;
		const nextIsEditMode = !!((_preloadedEditData$ed3 = preloadedEditData.editModeInitialState) === null || _preloadedEditData$ed3 === void 0 ? void 0 : _preloadedEditData$ed3.isEditTicketMode);
		const prevIsEditMode = !!(prevPreloaded === null || prevPreloaded === void 0 || (_prevPreloaded$editMo = prevPreloaded.editModeInitialState) === null || _prevPreloaded$editMo === void 0 ? void 0 : _prevPreloaded$editMo.isEditTicketMode);
		const modeSwitched = prevPreloaded != null && prevIsEditMode !== nextIsEditMode;
		const shouldFullSwap = !storeRef.current || !editData || modeSwitched || !nextIsEditMode;
		lastPreloadedRef.current = preloadedEditData;
		if (shouldFullSwap) {
			pendingDispatchRef.current = null;
			pushDebugLog("dialog.render.swapPreloaded", {
				order_id,
				isEditMode: nextIsEditMode,
				modeSwitched,
				reason: !storeRef.current ? "noStore" : !editData ? "noEditData" : modeSwitched ? "modeSwitched" : "createMode"
			});
			setEditData(preloadedEditData);
			setEditDataVersion((v) => v + 1);
		} else {
			pushDebugLog("dialog.render.lightSwap", {
				order_id,
				isEditMode: nextIsEditMode
			});
			pendingDispatchRef.current = preloadedEditData;
		}
	}
	/**
	* light swap 配套：commit 后把 pendingDispatchRef 中的 editModeInitialState 字段
	* 通过 storeRef.current.setState 局部 dispatch 到 TicketBooking 的 miniRedux store。
	*
	* 仅 preloaded 模式有效；dispatch 后子组件订阅 modalState/bookingDetail 等会自动 forceUpdate。
	*/
	useEffect(() => {
		const pending = pendingDispatchRef.current;
		if (!pending || !storeRef.current) return;
		pendingDispatchRef.current = null;
		const ems = pending.editModeInitialState;
		pushDebugLog("dialog.effect.lightDispatch", {
			isEditMode: !!(ems === null || ems === void 0 ? void 0 : ems.isEditTicketMode),
			hasModalState: !!(ems === null || ems === void 0 ? void 0 : ems.modalState)
		});
		dispatchEditDataToStore(storeRef.current, pending);
	}, [preloadedEditData]);
	const logger = useLogger();
	locales.init(locales_default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getApp) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.locales) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut3 = _context$appHelper$ut2.getLocale) === null || _context$appHelper$ut3 === void 0 ? void 0 : _context$appHelper$ut3.call(_context$appHelper$ut2)) || ((_context$appHelper$ut4 = context.appHelper.utils) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut4.storage) === null || _context$appHelper$ut4 === void 0 ? void 0 : _context$appHelper$ut4.get("umi_locale")) || "en");
	const { interaction, getSymbolic } = ((_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.utils) || {};
	useEffect(() => {
		if (!open) {
			var _interaction$utils, _interaction$utils$po;
			pushDebugLog("dialog.close", { preloaded });
			if (!preloaded) commitEditData(null);
			else tryClearCartOnClose();
			interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$po = _interaction$utils.postMessageToApp) === null || _interaction$utils$po === void 0 || _interaction$utils$po.call(_interaction$utils, {
				module: "cds",
				key: "cartUpdate",
				data: {
					currency_symbol: getSymbolic === null || getSymbolic === void 0 ? void 0 : getSymbolic(),
					total: "0",
					products: [],
					fees: []
				}
			});
		}
	}, [
		open,
		commitEditData,
		preloaded
	]);
	useLayoutEffect(() => {
		request.setRequest(context.appHelper.utils.request);
	}, []);
	useEffect(() => {
		if (!open) return;
		let isMounted = true;
		pushDebugLog("dialog.effect.openBranch", {
			open,
			order_id,
			preloaded,
			hasPreloadedEditData: !!preloadedEditData,
			hasCreateModeConfig: !!createModeConfig
		});
		if (preloaded && !order_id && preloadedEditData) {
			setTitle(props.title || locales.getText("pisell2.ticket-booking.new-booking"));
			return;
		}
		if (!order_id && createModeConfig) {
			var _createModeConfig$bus;
			const mergedModalState = _objectSpread2(_objectSpread2({}, ticketBookingInitialState.modalState), createModeConfig.initialModalState);
			setTitle(props.title || locales.getText("pisell2.ticket-booking.new-booking"));
			commitEditData({
				bookingConfigParams: createModeConfig.bookingConfigParams,
				productDisplayConfig: createModeConfig.productDisplayConfig || "sku-list-a2",
				businessCode: (_createModeConfig$bus = createModeConfig.businessCode) !== null && _createModeConfig$bus !== void 0 ? _createModeConfig$bus : "",
				editModeInitialState: _objectSpread2(_objectSpread2({
					bookingId: 0,
					bookingDetail: null,
					isParallelResourcesBooking: true,
					modalState: mergedModalState,
					open: true,
					isBookingTicket2: true,
					isEditTicketMode: false,
					dialogCallback: (data) => {
						var _interaction$utils2, _interaction$utils2$p;
						callback === null || callback === void 0 || callback(data);
						interaction === null || interaction === void 0 || (_interaction$utils2 = interaction.utils) === null || _interaction$utils2 === void 0 || (_interaction$utils2$p = _interaction$utils2.postMessageToApp) === null || _interaction$utils2$p === void 0 || _interaction$utils2$p.call(_interaction$utils2, {
							module: "cds",
							key: "cartUpdate",
							data: {
								currency_symbol: getSymbolic === null || getSymbolic === void 0 ? void 0 : getSymbolic(),
								total: "0",
								products: [],
								fees: []
							}
						});
					}
				}, Array.isArray(createModeConfig.associated_menu_list_ids) && createModeConfig.associated_menu_list_ids.length > 0 ? { associated_menu_list_ids: createModeConfig.associated_menu_list_ids } : {}), createModeConfig.order_type ? { order_type: createModeConfig.order_type } : {})
			});
			return;
		}
		if (!preloaded) commitEditData(null);
		else pushDebugLog("dialog.edit.keepPlaceholder", {
			order_id,
			hasPlaceholder: !!editData
		});
		function loadBookingDetail() {
			return _loadBookingDetail.apply(this, arguments);
		}
		function _loadBookingDetail() {
			_loadBookingDetail = _asyncToGenerator(function* () {
				var _Toast$loading;
				if (!order_id) return;
				Toast === null || Toast === void 0 || (_Toast$loading = Toast.loading) === null || _Toast$loading === void 0 || _Toast$loading.call(Toast);
				try {
					var _bookingOrigin$bookin, _snapshot$menuAssoci, _bookingConfigParamsM, _bookingConfigParamsM2, _bookingConfigParamsM3, _Toast$close2;
					const bookingOrigin = yield getBookingDetail(order_id);
					console.log("bookingOrigin>>>>");
					console.log(bookingOrigin);
					if (!bookingOrigin.business_code) {
						var _Toast$close;
						Toast === null || Toast === void 0 || (_Toast$close = Toast.close) === null || _Toast$close === void 0 || _Toast$close.call(Toast);
						Modal.error({
							title: locales.getText("pisell2.ticket-booking.business-not-supported.title"),
							content: locales.getText("pisell2.ticket-booking.business-not-supported.content"),
							onOk: () => {
								callback === null || callback === void 0 || callback({ type: "no-support-business" });
							}
						});
						return;
					}
					if (!isMounted) return;
					setTitle(props.title || (bookingOrigin === null || bookingOrigin === void 0 || (_bookingOrigin$bookin = bookingOrigin.bookings) === null || _bookingOrigin$bookin === void 0 ? void 0 : _bookingOrigin$bookin.booking_id) || (bookingOrigin === null || bookingOrigin === void 0 ? void 0 : bookingOrigin.shop_full_order_number));
					const bookingConfigParamsMap = {
						"appointment_booking": {
							productDisplayConfig: "sku-list-a2",
							bookingConfigParams: {
								item_type: "appointment_booking",
								sub_type: "ticket",
								osKey: "edit"
							},
							order_type: "appointment_booking"
						},
						"virtual": {
							productDisplayConfig: "sku-list-a5",
							bookingConfigParams: {
								item_type: "appointment_booking",
								sub_type: "food",
								source_type: "pos",
								osKey: "edit"
							},
							order_type: "virtual"
						},
						"table-order": {
							productDisplayConfig: "sku-list-a5",
							bookingConfigParams: {
								item_type: "appointment_booking",
								sub_type: "food",
								source_type: "pos",
								osKey: "edit"
							},
							order_type: "table-order"
						}
					};
					let menu_ids = [];
					const snapshot = yield getPicodingMenuData(context, bookingOrigin.business_code);
					snapshot === null || snapshot === void 0 || (_snapshot$menuAssoci = snapshot["menu.associated_menus"]) === null || _snapshot$menuAssoci === void 0 || _snapshot$menuAssoci.forEach((item) => {
						menu_ids.push(Number(item.value));
					});
					console.log("menu_ids>>>>", menu_ids, snapshot);
					let bookingConfigParams = (_bookingConfigParamsM = bookingConfigParamsMap[bookingOrigin === null || bookingOrigin === void 0 ? void 0 : bookingOrigin.type]) === null || _bookingConfigParamsM === void 0 ? void 0 : _bookingConfigParamsM.bookingConfigParams;
					let productDisplayConfig = (_bookingConfigParamsM2 = bookingConfigParamsMap[bookingOrigin === null || bookingOrigin === void 0 ? void 0 : bookingOrigin.type]) === null || _bookingConfigParamsM2 === void 0 ? void 0 : _bookingConfigParamsM2.productDisplayConfig;
					let businessCode = bookingOrigin.business_code || "";
					let order_type = (_bookingConfigParamsM3 = bookingConfigParamsMap[bookingOrigin === null || bookingOrigin === void 0 ? void 0 : bookingOrigin.type]) === null || _bookingConfigParamsM3 === void 0 ? void 0 : _bookingConfigParamsM3.order_type;
					const ov = createModeConfig;
					if (ov) {
						if (ov.bookingConfigParams && typeof ov.bookingConfigParams === "object") bookingConfigParams = ov.bookingConfigParams;
						if (ov.productDisplayConfig) productDisplayConfig = ov.productDisplayConfig;
						if (ov.businessCode != null && String(ov.businessCode).trim() !== "") businessCode = String(ov.businessCode).trim();
					}
					const modalState = formatBookingDetail(bookingOrigin, ticketBookingInitialState.modalState);
					modalState.service.value = (modalState.service.value || []).map((item) => _objectSpread2(_objectSpread2({}, item), {}, { edit: true }));
					modalState.service.edit = true;
					const { paidAmount, paidAmountWithoutSurcharge } = getPaidAmounts(bookingOrigin);
					const nextEditData = {
						bookingConfigParams,
						productDisplayConfig,
						businessCode,
						editModeInitialState: _objectSpread2(_objectSpread2({
							bookingId: "",
							bookingDetail: bookingOrigin,
							isParallelResourcesBooking: true,
							modalState,
							paymentPaid: { value: {
								paidAmount,
								paidAmountWithoutSurcharge
							} },
							open: true,
							isBookingTicket2: true,
							isEditTicketMode: true,
							dialogCallback: (data) => {
								var _interaction$utils3, _interaction$utils3$p;
								callback === null || callback === void 0 || callback(data);
								interaction === null || interaction === void 0 || (_interaction$utils3 = interaction.utils) === null || _interaction$utils3 === void 0 || (_interaction$utils3$p = _interaction$utils3.postMessageToApp) === null || _interaction$utils3$p === void 0 || _interaction$utils3$p.call(_interaction$utils3, {
									module: "cds",
									key: "cartUpdate",
									data: {
										currency_symbol: getSymbolic === null || getSymbolic === void 0 ? void 0 : getSymbolic(),
										total: "0",
										products: [],
										fees: []
									}
								});
							}
						}, ov && Array.isArray(ov.associated_menu_list_ids) && ov.associated_menu_list_ids.length > 0 ? { associated_menu_list_ids: ov.associated_menu_list_ids } : (menu_ids === null || menu_ids === void 0 ? void 0 : menu_ids.length) ? { associated_menu_list_ids: menu_ids } : {}), (ov === null || ov === void 0 ? void 0 : ov.order_type) || order_type ? { order_type: (ov === null || ov === void 0 ? void 0 : ov.order_type) || order_type } : {})
					};
					Toast === null || Toast === void 0 || (_Toast$close2 = Toast.close) === null || _Toast$close2 === void 0 || _Toast$close2.call(Toast);
					if (preloaded && storeRef.current) {
						pushDebugLog("dialog.edit.dispatchToStore", {
							order_id,
							hasModalState: !!nextEditData.editModeInitialState.modalState
						});
						dispatchEditDataToStore(storeRef.current, nextEditData);
					} else commitEditData(nextEditData);
					onEditDataReady === null || onEditDataReady === void 0 || onEditDataReady(nextEditData);
				} catch (error) {
					var _logger$addLog;
					console.error("[TicketBookingDialog] getBookingDetail failed", error);
					logger === null || logger === void 0 || (_logger$addLog = logger.addLog) === null || _logger$addLog === void 0 || _logger$addLog.call(logger, {
						metadata: { error: error === null || error === void 0 ? void 0 : error.message },
						title: `TicketBookingDialog-getBookingDetail failed ${order_id}`
					});
					Modal.error({
						title: locales.getText("pisell2.ticket-booking.business-not-supported.title"),
						content: locales.getText("pisell2.ticket-booking.business-not-supported.content"),
						onOk: () => {
							callback === null || callback === void 0 || callback({ type: "no-support-business" });
						}
					});
				}
			});
			return _loadBookingDetail.apply(this, arguments);
		}
		loadBookingDetail();
		return () => {
			isMounted = false;
		};
	}, [
		open,
		order_id,
		createModeConfig,
		preloaded,
		preloadedEditData,
		commitEditData
	]);
	const isPhoneVariant = variant === "phone";
	const handleClose = useCallback(() => {
		var _interaction$utils4, _interaction$utils4$p;
		interaction === null || interaction === void 0 || (_interaction$utils4 = interaction.utils) === null || _interaction$utils4 === void 0 || (_interaction$utils4$p = _interaction$utils4.postMessageToApp) === null || _interaction$utils4$p === void 0 || _interaction$utils4$p.call(_interaction$utils4, {
			module: "cds",
			key: "cartUpdate",
			data: {
				currency_symbol: getSymbolic === null || getSymbolic === void 0 ? void 0 : getSymbolic(),
				total: "0",
				products: [],
				fees: []
			}
		});
		callback === null || callback === void 0 || callback({ type: "close" });
		onClose === null || onClose === void 0 || onClose();
	}, [callback, onClose]);
	const bodyTopSlot = useMemo(() => {
		if (isPhoneVariant) return null;
		return /* @__PURE__ */ React.createElement("div", { className: "ticket-booking-dialog-body-top-slot" }, /* @__PURE__ */ React.createElement("div", { className: "ticket-booking-dialog-body-top-content" }, /* @__PURE__ */ React.createElement("div", {
			className: "ticket-booking-dialog-body-top-title",
			title: String(title || "")
		}, title)), /* @__PURE__ */ React.createElement("button", {
			type: "button",
			className: "ticket-booking-dialog-body-top-close",
			"aria-label": "Close",
			onClick: handleClose
		}, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-x-close" })));
	}, [
		handleClose,
		isPhoneVariant,
		title
	]);
	console.log(editDataVersion, "editDataVersion1234");
	return /* @__PURE__ */ React.createElement(CompensatedPisellContainer, {
		renderType: isPhoneVariant ? "drawer" : "modal",
		showHandlerBar: isPhoneVariant,
		onHandlerBarClick: handleClose,
		props: isPhoneVariant ? {
			open,
			onClose: handleClose,
			placement: "bottom",
			title: void 0,
			width: "100%",
			height: "95%",
			className: "ticket-booking-dialog-drawer-phone",
			rootClassName: "ticket-booking-dialog-drawer-phone-root",
			destroyOnClose: false,
			maskClosable: false,
			footer: null,
			closable: false,
			bodyStyle: {
				padding: 0,
				height: "100%"
			}
		} : {
			open,
			onCancel: handleClose,
			title: null,
			width: "99%",
			className: "ticket-booking-dialog-modal",
			destroyOnClose: false,
			header: false,
			maskClosable: false,
			footer: null,
			closeIcon: null,
			wrapClassName: "ticket-booking-dialog-wrapper",
			size: "large",
			bodyStyle: {
				padding: 0,
				height: "100%"
			}
		}
	}, (() => {
		pushDebugLog("dialog.renderBody", {
			hasEditData: !!editData,
			editDataVersion,
			open
		});
		return null;
	})(), editData ? /* @__PURE__ */ React.createElement(ticketBooking_default, {
		key: editDataVersion,
		isActive: true,
		rulesHooks,
		bookingConfigParams: editData.bookingConfigParams,
		productExtensionType,
		isShowMenuBar: false,
		isShowTimeBar: false,
		isShowFloatButtons: false,
		isEditTicketMode: !!order_id,
		editModeInitialState: editData.editModeInitialState,
		productDisplayConfig: editData.productDisplayConfig,
		businessCode: editData.businessCode,
		bodyTopSlot,
		storeRef
	}) : /* @__PURE__ */ React.createElement(Skeleton, {
		round: true,
		active: true,
		loading: true
	}));
}
/**
* Compute paid amounts with and without surcharge from booking detail.
*/
function getPaidAmounts(bookingOrigin) {
	const paidPayments = ((bookingOrigin === null || bookingOrigin === void 0 ? void 0 : bookingOrigin.payments) || []).filter((item) => (item === null || item === void 0 ? void 0 : item.status) === "paid");
	return {
		paidAmount: paidPayments.reduce((total, item) => {
			return total + Number(item.amount);
		}, 0),
		paidAmountWithoutSurcharge: paidPayments.reduce((total, item) => {
			return total + Number(item.amount) - Number(item.service_fee || 0);
		}, 0)
	};
}
TicketBookingDialog.displayName = "TicketBookingDialog";
var dialog_default = withResponsive(TicketBookingDialog);
//#endregion
export { dialog_default as default };
