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_utils = require("./utils.js");
const require_amount = require("./amount.js");
const require_utils$1 = require("../../info/service2/utils.js");
const require_utils$2 = require("../../utils.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../../pro/compensatedPisellContainer/index.js");
const require_withResponsive = require("../../../../responsive/withResponsive.js");
const require_index$1 = require("../../../../plus/noteModal/index.js");
const require_IsActiveContext = require("../../../ticketBooking/context/IsActiveContext.js");
const require_useActiveExecute = require("../../../ticketBooking/hooks/pisellos/useActiveExecute.js");
const require_utils$3 = require("../../../checkout/components/PaymentResultToast/utils.js");
const require_useIsBooking4Shop = require("../../hooks/useIsBooking4Shop.js");
const require_useLogger = require("../../../../hooks/useLogger.js");
const require_useCustomer = require("../../../ticketBooking/hooks/pisellos/useCustomer.js");
const require_useShopDiscountModule = require("../../../ticketBooking/hooks/pisellos/useShopDiscountModule.js");
const require_useScanManager = require("../../../ticketBooking/hooks/pisellos/useScanManager.js");
const require_useRuntime = require("../../../ticketBooking/hooks/useRuntime.js");
const require_index$2 = require("../../addons/index.js");
const require_serve = require("../../info2/serve.js");
const require_index$3 = require("./AppointmentProductModal/index.js");
const require_index$4 = require("./FooterMenus/index.js");
const require_serve$1 = require("./serve.js");
const require_confirmHolderModal = require("../../utils/confirmHolderModal.js");
const require_printer = require("../../../../hooks/printer.js");
const require_index$5 = require("../../../ticketBooking/components/ticketBooking/index.js");
const require_serve$2 = require("../../editBookingModal/serve.js");
const require_index$6 = require("../../../subTotal/index.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let lodash = require("lodash");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let _ant_design_icons = require("@ant-design/icons");
let _pisell_icon_es_ChevronDown = require("@pisell/icon/es/ChevronDown");
_pisell_icon_es_ChevronDown = require_runtime.__toESM(_pisell_icon_es_ChevronDown);
require("@pisell/icon");
require("./index.less");
//#region src/components/booking/components/footer/index.tsx
/**
* @title: 底部
* @description:
* @param {any} props
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-01-30 16:51
*/
const Footer = (props) => {
	var _context$appHelper, _state$paymentPaid2, _state$bookingConfig2, _state$bookingConfig4, _state$addons2, _state$bookingDetail, _state$bookingDetail2, _context$appHelper3, _context$appHelper3$g, _state$notes3, _state$bookingDetail14, _state$bookingDetail19, _state$addons4, _state$bookingDetail21, _state$notes4;
	const { state, buttons, dispatch, source, variant } = props;
	const isPhoneVariant = variant === "phone";
	const [showDetail, setShowDetail] = (0, react.useState)(false);
	const [loading, setLoading] = (0, react.useState)(false);
	const [checkoutLoading, setCheckoutLoading] = (0, react.useState)(false);
	const [noteModalOpen, setNoteModalOpen] = (0, react.useState)(false);
	const [terminalWarningOpen, setTerminalWarningOpen] = (0, react.useState)(false);
	const logger = require_useLogger.default();
	const [editOrderId, setEditOrderId] = (0, react.useState)(0);
	const [isShowPaymentLink, setIsShowPaymentLink] = (0, react.useState)(false);
	const isBooking4Shop = require_useIsBooking4Shop.useIsBooking4Shop(state);
	const appointmentProductRef = (0, react.useRef)(null);
	const context = require_useEngineContext.default();
	const { isTerminal, isWebPos, interaction, store, storage, pisellosAllModule, getData, pisellos } = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const { disableAllScanListeners } = require_useScanManager.default();
	const { ScheduleModule } = pisellosAllModule;
	const { isSecondaryScreen } = (require_useRuntime.useRuntime === null || require_useRuntime.useRuntime === void 0 ? void 0 : require_useRuntime.useRuntime()) || { isSecondaryScreen: false };
	(0, react.useEffect)(() => {
		store === null || store === void 0 || store.dispatch({
			type: "global/_getMetadataMap",
			callback: (data) => {
				console.log(data, "data");
				setIsShowPaymentLink(!!data["payment_collection_link_config_switch"]);
			}
		});
		const paymentCollectionLinkConfigSwitch = getData("payment_collection_link_config_switch");
		if (paymentCollectionLinkConfigSwitch !== void 0) setIsShowPaymentLink(!!paymentCollectionLinkConfigSwitch);
	}, []);
	(0, react.useEffect)(() => {
		try {
			const is_price_include_tax = getData("is_price_include_tax");
			const tax_rate = getData("tax_rate") || "10";
			const tax_title = getData("tax_title") || "GST";
			const surcharge_list = getData("surcharge_list");
			const schedule_list = getData("schedule_list");
			let scheduleById = {};
			if (Array.isArray(schedule_list)) for (let item of schedule_list) scheduleById[item.id] = item;
			dispatch({
				type: "setState",
				payload: {
					is_price_include_tax,
					tax_rate,
					tax_title,
					surcharge_list,
					schedule_list,
					scheduleById
				}
			});
		} catch (error) {
			console.error(error);
		}
	}, []);
	(0, react.useEffect)(() => {
		var _state$service, _state$service2, _state$paymentPaid;
		if ((((_state$service = state.service) === null || _state$service === void 0 || (_state$service = _state$service.value) === null || _state$service === void 0 ? void 0 : _state$service.length) === 0 || !((_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.value)) && !((_state$paymentPaid = state.paymentPaid) === null || _state$paymentPaid === void 0 || (_state$paymentPaid = _state$paymentPaid.value) === null || _state$paymentPaid === void 0 ? void 0 : _state$paymentPaid.paidAmount)) setEditOrderId(0);
	}, [state.service.value, (_state$paymentPaid2 = state.paymentPaid) === null || _state$paymentPaid2 === void 0 ? void 0 : _state$paymentPaid2.value]);
	const { executeIfActive } = require_useActiveExecute.useActiveExecute();
	const { nativePrint } = require_printer.default();
	(0, _pisell_materials.useToast)();
	(0, react.useEffect)(() => {
		window._setEditOrderMode = function() {
			var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (order_id) {
				let bookingOrigin = yield require_serve$2._getBookingDetail(order_id);
				let booking = require_index$5._formatBookingDetail(bookingOrigin, {});
				changeCustomerToGlobalState(booking.client.value);
				dispatch({
					type: "setService",
					payload: { value: booking.service.value }
				});
				setEditOrderId(order_id);
				dispatch({
					type: "setPaymentPaid",
					payload: { value: {
						paidAmount: bookingOrigin.payments.reduce((total, item) => {
							return total + Number(item.amount);
						}, 0),
						paidAmountWithoutSurcharge: bookingOrigin.payments.reduce((total, item) => {
							var _item$service_charge;
							return total + Number(item.amount) - Number(((_item$service_charge = item.service_charge) === null || _item$service_charge === void 0 ? void 0 : _item$service_charge.amount) || 0);
						}, 0)
					} }
				});
				shopDiscount.loadPrepareConfig({
					customerId: booking.client.value.id,
					action: "create",
					with_good_pass: 1,
					with_discount_card: 1
				});
			});
			return function(_x) {
				return _ref3.apply(this, arguments);
			};
		}();
	}, []);
	const { setActiveTab } = state;
	const isTeam = (0, react.useMemo)(() => {
		return storage.get("channel") === "android_team_portal" || storage.get("channel") === "ios_team_portal";
	}, []);
	const actionMap = {
		sale: {
			label: _pisell_utils.locales.getText("pisell2.text.addons"),
			key: "sale"
		},
		paymentLink: {
			label: _pisell_utils.locales.getText("pisell2.text.payment-link"),
			key: "payment",
			children: [{
				label: _pisell_utils.locales.getText("pisell2.text.send-mail"),
				key: "sendMail"
			}, {
				label: _pisell_utils.locales.getText("pisell2.text.copy-to-clipboard"),
				key: "copy"
			}]
		},
		print: {
			label: "Print",
			key: "print"
		},
		orderDetail: {
			label: _pisell_utils.locales.getText("pisell2.text.deposit-order-detail"),
			key: "orderDetail"
		},
		refund: {
			label: _pisell_utils.locales.getText("pisell2.text.refund"),
			key: "refund"
		},
		rebook: {
			label: _pisell_utils.locales.getText("pisell2.text.rebook"),
			key: "rebook"
		},
		cancelOrder: {
			label: "Cancel order",
			key: "cancelOrder"
		}
	};
	(0, react.useEffect)(() => {
		if (state.bookingDetail) state.action({
			type: "pisell1.registerPlugin",
			data: { pluginList: ["RefundPlugin"] }
		});
	}, [state.bookingDetail]);
	const params = (0, react.useMemo)(() => {
		var _state$bookingConfig;
		return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_subject) || {};
	}, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.basic) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.appointment_subject]);
	const transaction_habit_selection = (0, react.useMemo)(() => {
		var _state$bookingConfig3;
		return (state === null || state === void 0 || (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.config) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.information_tab) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.transaction_habit_selection) || {
			type: "service_now_pay_later",
			button_rows: 1
		};
	}, [state === null || state === void 0 || (_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.config) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.information_tab]);
	const addonsEdit = (0, react.useMemo)(() => {
		var _state$addons;
		if ((_state$addons = state.addons) === null || _state$addons === void 0 ? void 0 : _state$addons.edit) return true;
		return false;
	}, [(_state$addons2 = state.addons) === null || _state$addons2 === void 0 ? void 0 : _state$addons2.edit]);
	const infoEdit = (0, react.useMemo)(() => {
		var _state$client, _state$date, _state$pet, _state$service3, _state$notes, _state$contacts, _state$contacts_info;
		if (!state.bookingId) return true;
		if ((_state$client = state.client) === null || _state$client === void 0 ? void 0 : _state$client.edit) return true;
		if ((_state$date = state.date) === null || _state$date === void 0 ? void 0 : _state$date.edit) return true;
		if ((_state$pet = state.pet) === null || _state$pet === void 0 ? void 0 : _state$pet.edit) return true;
		if ((_state$service3 = state.service) === null || _state$service3 === void 0 ? void 0 : _state$service3.edit) return true;
		if ((_state$notes = state.notes) === null || _state$notes === void 0 ? void 0 : _state$notes.edit) return true;
		if ((_state$contacts = state.contacts) === null || _state$contacts === void 0 ? void 0 : _state$contacts.edit) return true;
		if ((_state$contacts_info = state.contacts_info) === null || _state$contacts_info === void 0 ? void 0 : _state$contacts_info.edit) return true;
		return false;
	}, [state]);
	const isEdit = (0, react.useMemo)(() => {
		return infoEdit || addonsEdit;
	}, [infoEdit, addonsEdit]);
	const getDataFromHost = () => {
		try {
			const is_price_include_tax = getData("is_price_include_tax");
			const tax_rate = getData("tax_rate") || "10";
			const tax_title = getData("tax_title") || "GST";
			const surcharge_list = getData("surcharge_list");
			const schedule_list = getData("schedule_list");
			let scheduleById = {};
			if (Array.isArray(schedule_list)) for (let item of schedule_list) scheduleById[item.id] = item;
			return {
				is_price_include_tax,
				tax_rate,
				tax_title,
				surcharge_list,
				schedule_list,
				scheduleById
			};
		} catch (error) {
			console.error(error);
			return {};
		}
	};
	const total = (0, react.useMemo)(() => {
		return require_amount.getSumTotal(state, require_objectSpread2._objectSpread2({
			isEdit,
			ScheduleModule
		}, getDataFromHost()));
	}, [state, isEdit]);
	(0, react.useEffect)(() => {
		window.dispatchEvent(new CustomEvent("onOriginExpectAmountWithoutDiscountChange", { detail: { originExpectAmountWithoutDiscount: total === null || total === void 0 ? void 0 : total.originExpectAmountWithoutDiscount } }));
	}, [total === null || total === void 0 ? void 0 : total.originExpectAmountWithoutDiscount]);
	const orderTotalList = (0, react.useMemo)(() => {
		return [
			{
				hidden: !state.bookingId,
				key: "custom_orderPaidAmount",
				value: total.orderPaidAmount,
				label: _pisell_utils.locales.getText("pisell2.text.amount-paid-on-order")
			},
			{
				hidden: !state.bookingId,
				key: "custom_paySurchargeFee",
				value: total.paySurchargeFee,
				label: _pisell_utils.locales.getText("pisell1.text.payment-fee")
			},
			{
				hidden: !state.bookingId,
				key: "custom_actualPaidAmount",
				value: total.actualPaidAmount,
				label: _pisell_utils.locales.getText("pisell2.text.amount-actually-paid-by-the-customer")
			},
			{
				hidden: !state.bookingId || !total.totalRefundAmount,
				key: "custom_totalRefundAmount",
				value: total.totalRefundAmount,
				label: _pisell_utils.locales.getText("pisell2.text.refunded-amount")
			}
		];
	}, [
		total,
		(_state$bookingDetail = state.bookingDetail) === null || _state$bookingDetail === void 0 ? void 0 : _state$bookingDetail.surcharge,
		state.bookingId
	]);
	const subTotalList = (0, react.useMemo)(() => {
		return [
			{
				key: "sub_total",
				value: total.productAmount
			},
			...total.surcharge || [],
			{
				key: "tax",
				value: total.tax,
				tax: total.taxInfo
			},
			{
				key: "discount",
				value: total.shopDiscount
			},
			{
				key: "expect_amount",
				value: total.expectAmount,
				label: _pisell_utils.locales.getText("pisell2.subtotal.total")
			},
			{
				hidden: !total.roundingAmount,
				key: "custom_roundingAmount",
				value: total.roundingAmount,
				label: _pisell_utils.locales.getText("pisell1.text.rounding")
			}
		];
	}, [
		total,
		(_state$bookingDetail2 = state.bookingDetail) === null || _state$bookingDetail2 === void 0 ? void 0 : _state$bookingDetail2.surcharge,
		state.bookingId
	]);
	const isDisabled = (0, react.useMemo)(() => {
		var _state$service$value;
		if (!state.client.value) return true;
		if (!((_state$service$value = state.service.value) === null || _state$service$value === void 0 ? void 0 : _state$service$value.length)) return true;
		if (!state.date.value) return true;
		return false;
	}, [state, params]);
	const isDisabledCheckOutForNegativeOrder = (0, react.useMemo)(() => {
		return total.expectAmount < 0 && state.isBookingTicket2;
	}, [total, state.isBookingTicket2]);
	const isDisabledCheckOutForEditTicketMode = (0, react.useMemo)(() => {
		console.log("isDisabledCheckOutForEditTicketMode", total);
		return total.notPaidAmount <= 0 && state.isEditTicketMode;
	}, [total, state.isEditTicketMode]);
	/**
	* @title: 跳转到 checkout页面
	* @description:
	* @param {any} order_id
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:53
	*/
	const goCheckout = function() {
		var _ref4 = require_asyncToGenerator._asyncToGenerator(function* (order_id, isNewOrder, totalAmount) {
			if (!order_id) return;
			if (isWebPos) {
				state.action({
					type: "pisell1.handleOpenPayment",
					data: { order: { id: order_id } },
					callback: (res) => {
						var _res$data;
						if (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.isCallbackFromToast) return;
						state === null || state === void 0 || state.callback({}, "save");
					}
				});
				return;
			}
			/** terminal中打开原生checkout模块 */
			if (isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()) {
				var _interaction$utils, _interaction$utils$po;
				disableAllScanListeners();
				return 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 ? void 0 : _interaction$utils$po.call(_interaction$utils, {
					module: "booking",
					key: "booking_checkout",
					data: {
						order_id,
						callbackType: "pisell2",
						newOrder: isNewOrder
					}
				});
			}
			state.action({
				type: "pisell1.handlePayment",
				data: { orderId: order_id },
				callback: () => {
					state === null || state === void 0 || state.callback();
				}
			});
		});
		return function goCheckout(_x2, _x3, _x4) {
			return _ref4.apply(this, arguments);
		};
	}();
	const goCheckout2 = function() {
		var _ref5 = require_asyncToGenerator._asyncToGenerator(function* (savedOrder) {
			var _state$bookingConfig5;
			state.action({
				type: "pisell1.handleOpenPayment",
				data: {
					order_id: (savedOrder === null || savedOrder === void 0 ? void 0 : savedOrder.order_id) || state.bookingId,
					paymentResultDisplayMode: state === null || state === void 0 || (_state$bookingConfig5 = state.bookingConfig) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.config) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.payment_setting) === null || _state$bookingConfig5 === void 0 ? void 0 : _state$bookingConfig5.payment_result_display_mode,
					config: {
						showHeaderCenter: true,
						showHeaderRightButton: !state.isEditTicketMode
					}
				},
				callback: (res) => {
					console.log("webpos_pay_result", res);
					if (res === null || res === void 0 ? void 0 : res.reset) {
						var _window;
						(_window = window) === null || _window === void 0 || (_window = _window.shopApi) === null || _window === void 0 || (_window = _window.bookingTicket) === null || _window === void 0 || _window.clearAllCart();
					} else if ((res === null || res === void 0 ? void 0 : res.data.source) === "back" && (!(savedOrder === null || savedOrder === void 0 ? void 0 : savedOrder.order_id) || state.bookingId)) {
						var _window2;
						(_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.shopApi) === null || _window2 === void 0 || (_window2 = _window2.booking) === null || _window2 === void 0 || _window2.voidBooking((savedOrder === null || savedOrder === void 0 ? void 0 : savedOrder.order_id) || state.bookingId);
					}
				}
			});
		});
		return function goCheckout2(_x5) {
			return _ref5.apply(this, arguments);
		};
	}();
	const { run: handleCheckout } = (0, ahooks.useDebounceFn)(function() {
		var _ref6 = require_asyncToGenerator._asyncToGenerator(function* () {
			var _state$bookingConfig6;
			const isToastMode = (state === null || state === void 0 || (_state$bookingConfig6 = state.bookingConfig) === null || _state$bookingConfig6 === void 0 || (_state$bookingConfig6 = _state$bookingConfig6.config) === null || _state$bookingConfig6 === void 0 || (_state$bookingConfig6 = _state$bookingConfig6.payment_setting) === null || _state$bookingConfig6 === void 0 ? void 0 : _state$bookingConfig6.payment_result_display_mode) !== "modal";
			if (isToastMode) require_utils$3.closeAllPaymentResultToasts();
			logger.addLog({
				title: "Footer: handleCheckoutInternal 调用",
				metadata: { isToastMode }
			});
			const isNewOrder = !state.bookingId;
			if (isEdit) {
				if (require_utils$1.isDayBooking(state)) {
					if (handleDaySubmit()) return;
				}
				if (state.isBookingTicket2) {
					const res = yield handleSave({
						type: "checkout",
						messageShow: !(isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()),
						noSubmit: false
					});
					if (!res) return;
					goCheckout2(res);
				} else {
					const res = yield handleSave({
						type: "checkout",
						messageShow: !(isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal())
					});
					console.log(res);
					goCheckout((res === null || res === void 0 ? void 0 : res.order_id) || state.bookingId, isNewOrder);
				}
				return;
			}
			return goCheckout(state.bookingId, isNewOrder);
		});
		return function handleCheckoutInternal() {
			return _ref6.apply(this, arguments);
		};
	}(), {
		wait: 500,
		leading: true,
		trailing: false
	});
	/**
	* @title: 保存额外商品
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:54
	*/
	const handleSaveAddons = function() {
		var _ref7 = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				let _list = [...state.addons.value];
				yield state.apis.saveAddonsByOrderId({
					products: require_index$2.formatProducts(_list),
					shop_discount: state.bookingDetail.shop_discount,
					shop_discount_reason: state.bookingDetail.shop_discount_reason
				});
				antd.message.success(_pisell_utils.locales.getText("pisell2.text.addons") + _pisell_utils.locales.getText("pisell2.text.updated"));
			} catch (err) {
				console.log("state.bookingId && state.addons.edit", err);
			}
		});
		return function handleSaveAddons() {
			return _ref7.apply(this, arguments);
		};
	}();
	const getApis = () => {
		if (isBooking4Shop || state.renderType === "dayBooking") return {
			editBooking: require_serve.editBookings,
			createBooking: require_serve.createBookings
		};
		return {
			editBooking: state.apis.editBooking,
			createBooking: state.apis.createBooking
		};
	};
	/**
	* @title: 跨日预约提交之前的验证
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-12 16:18
	*/
	const handleDaySubmit = () => {
		const _isHasDayProducts = require_utils$1.isHasDayAppointmentProduct(state);
		if (_isHasDayProducts) {
			var _appointmentProductRe;
			appointmentProductRef === null || appointmentProductRef === void 0 || (_appointmentProductRe = appointmentProductRef.current) === null || _appointmentProductRe === void 0 || _appointmentProductRe.open();
		}
		return _isHasDayProducts;
	};
	/**
	* 是否只有定金支付
	*/
	const isOnlyDeposit = (0, react.useMemo)(() => {
		var _state$bookingDetail3, _state$bookingDetail4, _state$bookingDetail5;
		if ((state === null || state === void 0 || (_state$bookingDetail3 = state.bookingDetail) === null || _state$bookingDetail3 === void 0 ? void 0 : _state$bookingDetail3.deposit_payment_time) && (state === null || state === void 0 || (_state$bookingDetail4 = state.bookingDetail) === null || _state$bookingDetail4 === void 0 || (_state$bookingDetail4 = _state$bookingDetail4.payment_types) === null || _state$bookingDetail4 === void 0 || (_state$bookingDetail5 = _state$bookingDetail4.every) === null || _state$bookingDetail5 === void 0 ? void 0 : _state$bookingDetail5.call(_state$bookingDetail4, (item) => item === "deposit"))) return true;
		return false;
	}, [state === null || state === void 0 ? void 0 : state.bookingDetail]);
	/**
	* @title: 欠款文案
	* @description: 商家欠用户钱
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:01
	*/
	const arrearsText = (0, react.useMemo)(() => {
		let str = "";
		if (isOnlyDeposit) return str;
		if (total.dueAmount < 0) str = `${_pisell_utils.locales.getText("pisell1.text.refund-customer")}: ${(0, _pisell_utils.formatAmount)(total.dueAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		return str;
	}, [
		state,
		total,
		isOnlyDeposit
	]);
	const mainApp = context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 || (_context$appHelper3$g = _context$appHelper3.getApp) === null || _context$appHelper3$g === void 0 ? void 0 : _context$appHelper3$g.call(_context$appHelper3);
	/**
	* @title: 保存info
	* @description:
	* @param {object} param1
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:54
	*/
	const handleSave = function() {
		var _ref8 = require_asyncToGenerator._asyncToGenerator(function* ({ type, messageShow = true, noSubmit = false }) {
			var _state$bookingConfig7, _state$service$value2, _state$client2;
			logger.addLog({
				title: "Footer: handleSave 调用",
				metadata: {
					type,
					noSubmit
				}
			});
			if (state.isEditTicketMode) window.isPaymentModalPluginOpen = true;
			else window.isPaymentModalPluginOpen = false;
			if ((state === null || state === void 0 || (_state$bookingConfig7 = state.bookingConfig) === null || _state$bookingConfig7 === void 0 || (_state$bookingConfig7 = _state$bookingConfig7.config) === null || _state$bookingConfig7 === void 0 || (_state$bookingConfig7 = _state$bookingConfig7.payment_setting) === null || _state$bookingConfig7 === void 0 ? void 0 : _state$bookingConfig7.payment_result_display_mode) !== "modal") require_utils$3.closeAllPaymentResultToasts();
			if (require_utils$1.isDayBooking(state)) {
				if (handleDaySubmit()) return;
			}
			const products = (_state$service$value2 = state.service.value) === null || _state$service$value2 === void 0 ? void 0 : _state$service$value2.filter((item) => !(item === null || item === void 0 ? void 0 : item._giftInfo));
			const hasUnspecifiedHolderProduct = products === null || products === void 0 ? void 0 : products.some((item) => {
				var _item$_extend, _item$_extend2;
				return (!((_item$_extend = item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.holder_id) || ((_item$_extend2 = item._extend) === null || _item$_extend2 === void 0 || (_item$_extend2 = _item$_extend2.holder_id) === null || _item$_extend2 === void 0 ? void 0 : _item$_extend2.length) === 0) && !require_utils$1.isNormalProductByDurationSchedule(item);
			});
			if (!require_utils$2.isWalkIn((_state$client2 = state.client) === null || _state$client2 === void 0 || (_state$client2 = _state$client2.value) === null || _state$client2 === void 0 ? void 0 : _state$client2.id) && require_utils$1.getIsSubjectRequire(state) && hasUnspecifiedHolderProduct) yield require_confirmHolderModal.showConfirmHolderModal(state, dispatch);
			if (isBooking4Shop && require_utils$1.getIsSubjectRequire(state) && require_utils.checkHolderIsError(state)) return;
			let _setLoading = type === "checkout" ? setCheckoutLoading : setLoading;
			_setLoading(true);
			const loadingTimer = setTimeout(() => {
				_setLoading(false);
			}, 2e4);
			const { createBooking, editBooking } = getApis();
			const editApi = state.renderType === "eventBooking" ? require_serve$1.editEventBooking : editBooking;
			const createApi = state.renderType === "eventBooking" ? require_serve$1.createEventBooking : createBooking;
			let saveOtherValue = {};
			if (type === "save") {
				var _state$onSave;
				saveOtherValue = (yield state === null || state === void 0 || (_state$onSave = state.onSave) === null || _state$onSave === void 0 ? void 0 : _state$onSave.call(state, state.client)) || {};
			}
			try {
				var _store$getState, _window3;
				let callbackData = (state === null || state === void 0 ? void 0 : state.bookingId) ? { order_id: state === null || state === void 0 ? void 0 : state.bookingId } : null;
				const mergedForFormat = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), saveOtherValue);
				if (state.order_type) mergedForFormat.order_type = state.order_type;
				let values = require_utils.formatValues(mergedForFormat);
				values.product_tax_fee = total.tax || 0;
				if (noSubmit) return values;
				const checkout = pisellos.getModule("checkout");
				if (editOrderId) {
					const subtotal_info = {
						subTotalList: (0, lodash.cloneDeep)(subTotalList),
						orderTotalList: (0, lodash.cloneDeep)(orderTotalList),
						total: (0, lodash.cloneDeep)(total),
						showDetail
					};
					yield checkout.updateLocalOrderAsync({
						orderId: editOrderId,
						orderData: values,
						cartSummary: subtotal_info.subTotalList,
						autoPayment: true,
						totalInfo: subtotal_info
					});
					const res = yield checkout.manualSyncOrderAsync();
					if (res.success) {
						state === null || state === void 0 || state.callback(res, type);
						_setLoading(false);
					}
					if (state.isEditTicketMode) {
						var _state$dialogCallback;
						state === null || state === void 0 || (_state$dialogCallback = state.dialogCallback) === null || _state$dialogCallback === void 0 || _state$dialogCallback.call(state, {
							type: "save",
							data: callbackData || values
						});
					}
					setEditOrderId(0);
					return;
				}
				if (type === "save" && !state.bookingId) {
					const isNeedDeposit = checkout.checkIsNeedDepositAsync(values.bookings, values.relation_products);
					if (isNeedDeposit === null || isNeedDeposit === void 0 ? void 0 : isNeedDeposit.hasDeposit) {
						values.is_deposit = 1;
						values.deposit_amount = isNeedDeposit === null || isNeedDeposit === void 0 ? void 0 : isNeedDeposit.total;
					}
				}
				let api = state.bookingId ? editApi : createApi;
				(0, _pisell_utils.sendWarningLog)({
					title: "saveBooking",
					content: [
						{
							key: "下单前数据",
							value: JSON.stringify(values)
						},
						{
							key: "日期",
							value: (0, dayjs.default)().format("YYYY-MM-DD HH:mm")
						},
						{
							key: "店铺id",
							value: store === null || store === void 0 || (_store$getState = store.getState) === null || _store$getState === void 0 || (_store$getState = _store$getState.call(store)) === null || _store$getState === void 0 || (_store$getState = _store$getState.global) === null || _store$getState === void 0 || (_store$getState = _store$getState.globalConfig) === null || _store$getState === void 0 ? void 0 : _store$getState.id
						},
						{
							key: "shopApi",
							value: JSON.stringify((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.shopApi, (key, value) => {
								if (typeof value === "function") return "function";
								return value;
							})
						}
					]
				});
				if (addonsEdit) yield handleSaveAddons();
				console.log("mainApp>>>>>", mainApp);
				const autoPrintReceiptPrinters = mainApp.storage.getStorage("autoPrintAfterSave");
				const isAutoPrintAfterSaveEnabled = autoPrintReceiptPrinters === true || autoPrintReceiptPrinters === "true";
				logger === null || logger === void 0 || logger.addLog({
					type: "info",
					title: "handleSave_autoPrintReceiptPrinters",
					metadata: {
						autoPrintReceiptPrinters,
						isAutoPrintAfterSaveEnabled
					}
				});
				if (isAutoPrintAfterSaveEnabled) values.small_ticket_data_flag = 1;
				if (infoEdit) {
					callbackData = yield api(values, state.bookingId || editOrderId);
					callbackData = require_objectSpread2._objectSpread2({ order_id: state.bookingId || editOrderId }, callbackData || {});
					if (messageShow) antd.message.success(_pisell_utils.locales.getText(state.bookingId ? "pisell2.text.appointment-updated" : "pisell2.text.created-successfully"));
				}
				if (!state.bookingId && type === "save" && isAutoPrintAfterSaveEnabled && callbackData) {
					logger === null || logger === void 0 || logger.addLog({
						type: "info",
						title: "检测到保存订单需要自动打印小票",
						metadata: {}
					});
					nativePrint({
						type: "99",
						data: {
							order_id: callbackData.order_id,
							machine_code_print_info: (callbackData === null || callbackData === void 0 ? void 0 : callbackData.machine_code_print_info) || {},
							small_ticket_data: (callbackData === null || callbackData === void 0 ? void 0 : callbackData.small_ticket_data) || {},
							machine_code_print_info_v2: (callbackData === null || callbackData === void 0 ? void 0 : callbackData.machine_code_print_info_v2) || {}
						}
					}, (res) => {
						console.log("handleSave_autoPrintReceipt_res>>>>", res);
						logger === null || logger === void 0 || logger.addLog({
							type: "info",
							title: "handleSave_autoPrintReceipt_res",
							metadata: { res }
						});
					});
				}
				state === null || state === void 0 || state.callback(callbackData, type);
				clearTimeout(loadingTimer);
				_setLoading(false);
				return callbackData || values;
			} catch (err) {
				console.log(err);
				if ((err === null || err === void 0 ? void 0 : err.code) === 70101) antd.message.error(err === null || err === void 0 ? void 0 : err.message);
				clearTimeout(loadingTimer);
				_setLoading(false);
			}
		});
		return function handleSave(_x6) {
			return _ref8.apply(this, arguments);
		};
	}();
	/**
	* @title: 将预约状态修改为已完成
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:57
	*/
	const onSelect = function() {
		var _ref9 = require_asyncToGenerator._asyncToGenerator(function* (e) {
			const status = "completed";
			dispatch({
				type: "setStatus",
				payload: status
			});
			yield state.apis.editBookingStatus({ appointment_status: status });
			antd.message.success(_pisell_utils.locales.getText("pisell1.text.edit-status-success"));
			state === null || state === void 0 || state.callback({ order_id: state.bookingId });
		});
		return function onSelect(_x7) {
			return _ref9.apply(this, arguments);
		};
	}();
	/**
	* @title: 退款
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:57
	*/
	const handleRefund = () => {
		if (isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()) {
			var _interaction$utils2, _interaction$utils2$p;
			return 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 ? void 0 : _interaction$utils2$p.call(_interaction$utils2, {
				module: "booking",
				key: "booking_refund",
				data: { order_id: state.bookingId },
				origin: "/booking"
			});
		}
		state.action({
			type: "pisell1.handleRefund",
			data: { orderId: state.bookingId },
			callback: () => {
				state === null || state === void 0 || state.callback({ order_id: state.bookingId });
			}
		});
	};
	const paymentRefundedStatus = (0, react.useMemo)(() => {
		var _state$bookingDetail6;
		return ["partially_refunded", "refunded"].includes(state === null || state === void 0 || (_state$bookingDetail6 = state.bookingDetail) === null || _state$bookingDetail6 === void 0 ? void 0 : _state$bookingDetail6.payment_status);
	}, [state === null || state === void 0 ? void 0 : state.bookingDetail]);
	/**
	* @title: checkout按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:57
	*/
	const checkoutButton = (0, react.useMemo)(() => {
		let buttonType = "primary";
		if (transaction_habit_selection.type === "service_now_pay_later") buttonType = "default";
		if (source === "payment") buttonType = "primary";
		if (!isEdit) buttonType = "primary";
		return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme: { token: { colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009" } } }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: (0, classnames.default)("pisell-lowcode__booking-footer-buttons-item", { ["pisell-lowcode__booking-footer-buttons-item-primary"]: buttonType === "primary" }),
			type: "primary",
			loading: checkoutLoading,
			onClick: () => {
				handleCheckout();
			},
			disabled: isDisabled || isDisabledCheckOutForNegativeOrder || isDisabledCheckOutForEditTicketMode || arrearsText !== ""
		}, _pisell_utils.locales.getText("pisell2.text.checkout")));
	}, [
		isEdit,
		checkoutLoading,
		isDisabled,
		state,
		source,
		arrearsText
	]);
	const handleMenuClick = function() {
		var _ref10 = require_asyncToGenerator._asyncToGenerator(function* (e) {
			let id = state.bookingId;
			let customer = state.bookingDetail.customer;
			if (isEdit) {
				const res = yield handleSave({
					type: "checkout",
					messageShow: false
				});
				id = (res === null || res === void 0 ? void 0 : res.order_id) || state.bookingId;
				customer = (res === null || res === void 0 ? void 0 : res.customer_id) ? { id: res === null || res === void 0 ? void 0 : res.customer_id } : state.bookingDetail.customer;
			}
			if (e.key === "sendMail") {
				var _state$bookingDetail7, _state$bookingDetail8;
				console.log(e);
				state.action({
					type: "pisell1.sendPayLinkEmail",
					data: {
						id,
						is_deposit: state.bookingDetail.is_deposit || Number((_state$bookingDetail7 = state.bookingDetail) === null || _state$bookingDetail7 === void 0 ? void 0 : _state$bookingDetail7.deposit_amount),
						deposit_payment_time: state.bookingDetail.deposit_payment_time,
						customer,
						contacts: (_state$bookingDetail8 = state.bookingDetail) === null || _state$bookingDetail8 === void 0 ? void 0 : _state$bookingDetail8.contacts
					},
					callback: () => {}
				});
			}
			if (e.key === "copy") state.action({
				type: "pisell1.genClientPayLink",
				data: { id },
				callback: () => {}
			});
		});
		return function handleMenuClick(_x8) {
			return _ref10.apply(this, arguments);
		};
	}();
	const handleRebook = () => {
		var _state$onRebook;
		(_state$onRebook = state.onRebook) === null || _state$onRebook === void 0 || _state$onRebook.call(state);
	};
	const handleSale = () => {
		if (isWebPos) return state.action({
			type: "pisell1.handleOpenEditBooking",
			data: { order_id: state.bookingId },
			callback: (res) => {
				var _window4;
				(_window4 = window) === null || _window4 === void 0 || (_window4 = _window4.shopApi) === null || _window4 === void 0 || (_window4 = _window4.booking) === null || _window4 === void 0 || _window4.refreshBookingDetail();
			}
		});
		if (isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()) {
			var _interaction$utils3, _interaction$utils3$p;
			return 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 ? void 0 : _interaction$utils3$p.call(_interaction$utils3, {
				module: "booking",
				key: "edit_order",
				data: { order_id: state.bookingId }
			});
		}
		if (state.channelDisabledEdit) {
			setTerminalWarningOpen(true);
			return;
		}
		setActiveTab === null || setActiveTab === void 0 || setActiveTab("addons");
	};
	const handlePrint = () => {};
	const handleOrderDetail = () => {
		if (isWebPos) return state.action({
			type: "pisell1.handleOpenEditBooking",
			data: { order_id: state.bookingId },
			callback: (res) => {
				var _window5;
				(_window5 = window) === null || _window5 === void 0 || (_window5 = _window5.shopApi) === null || _window5 === void 0 || (_window5 = _window5.booking) === null || _window5 === void 0 || _window5.refreshBookingDetail();
			}
		});
		if (isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()) return interaction.utils.postMessageToApp({
			module: "booking",
			key: "view_order",
			data: { order_id: state.bookingId },
			origin: "/booking"
		});
		state.action({
			type: "pisell1.goOrderDetail",
			data: { orderId: state.bookingId },
			callback: () => {
				state === null || state === void 0 || state.callback();
			}
		});
	};
	const handleCancel = () => {};
	const paymentLinkButton = (0, react.useMemo)(() => {
		const items = [{
			label: _pisell_utils.locales.getText("pisell2.text.send-mail"),
			key: "sendMail"
		}, {
			label: _pisell_utils.locales.getText("pisell2.text.copy-to-clipboard"),
			key: "copy"
		}];
		return /* @__PURE__ */ react.default.createElement(antd.Dropdown, { menu: {
			items,
			onClick: handleMenuClick
		} }, /* @__PURE__ */ react.default.createElement(antd.Button, { className: "pisell-lowcode__booking-footer-buttons-item" }, /* @__PURE__ */ react.default.createElement(antd.Space, null, _pisell_utils.locales.getText("pisell2.text.payment-link"), /* @__PURE__ */ react.default.createElement(_ant_design_icons.DownOutlined, null))));
	}, [handleMenuClick]);
	/**
	* @title: 保存按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const saveButton = (0, react.useMemo)(() => {
		let buttonType = "default";
		if (transaction_habit_selection.type === "service_now_pay_later") buttonType = "primary";
		return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme: { token: { colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009" } } }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: (0, classnames.default)("pisell-lowcode__booking-footer-buttons-item", { ["pisell-lowcode__booking-footer-buttons-item-primary"]: buttonType === "primary" }),
			type: "primary",
			onClick: () => {
				handleSave({ type: "save" });
			},
			disabled: isDisabled || !isEdit,
			loading
		}, _pisell_utils.locales.getText("pisell2.text.save")));
	}, [
		loading,
		isDisabled,
		isEdit,
		infoEdit,
		addonsEdit,
		state
	]);
	const handleNote = () => {
		setNoteModalOpen(true);
	};
	const handleNoteConfirm = (noteValue) => {
		dispatch({
			type: "setNotes",
			payload: {
				orderNote: noteValue,
				edit: true
			}
		});
		setNoteModalOpen(false);
	};
	const handleNoteDelete = () => {
		dispatch({
			type: "setNotes",
			payload: {
				orderNote: "",
				edit: true
			}
		});
		setNoteModalOpen(false);
	};
	const handleNoteCancel = () => {
		setNoteModalOpen(false);
	};
	/**
	* @title: 完成按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const completeButton = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "primary",
			onClick: onSelect,
			disabled: state.appointment_status === "completed"
		}, _pisell_utils.locales.getText("pisell2.text.status.completed"));
	}, [state.appointment_status]);
	/**
	* @title: Rebook按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const rebookButton = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			onClick: handleRebook
		}, _pisell_utils.locales.getText("pisell2.text.rebook"));
	}, [state === null || state === void 0 ? void 0 : state.onRebook]);
	/**
	* @title: 退款按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const refundButton = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "default",
			onClick: handleRefund
		}, _pisell_utils.locales.getText("pisell2.text.refund"));
	}, []);
	const handleClearAll = () => {
		var _state$clearAllValue;
		state === null || state === void 0 || (_state$clearAllValue = state.clearAllValue) === null || _state$clearAllValue === void 0 || _state$clearAllValue.call(state);
	};
	/**
	* @title: 清空按钮
	* @description:
	* @return: *
	* @Author: shengjie.zuo
	* @Date: 2024-10-26 10:52:01
	*/
	const clearAllButton = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme: { token: { colorPrimary: "#f04438" } } }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "primary",
			onClick: handleClearAll
		}, _pisell_utils.locales.getText("pisell2.booking.info.text.clear-all")));
	}, []);
	const hasOrderNote = (0, react.useMemo)(() => {
		var _state$notes2;
		return ((state === null || state === void 0 || (_state$notes2 = state.notes) === null || _state$notes2 === void 0 ? void 0 : _state$notes2.orderNote) || "").trim().length > 0;
	}, [state === null || state === void 0 || (_state$notes3 = state.notes) === null || _state$notes3 === void 0 ? void 0 : _state$notes3.orderNote]);
	let buttonMap = {
		checkout: checkoutButton,
		save: saveButton,
		complete: completeButton,
		refund: refundButton,
		paymentLink: paymentLinkButton,
		rebook: rebookButton,
		clearAll: clearAllButton,
		note: (0, react.useMemo)(() => {
			return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme: { token: { colorPrimary: "#0d7fa9" } } }, /* @__PURE__ */ react.default.createElement(antd.Button, {
				className: "pisell-lowcode__booking-footer-buttons-item note-button",
				type: "primary",
				onClick: handleNote
			}, _pisell_utils.locales.getText("pisell2.ticket-booking.note"), hasOrderNote && /* @__PURE__ */ react.default.createElement("span", { className: "note-indicator" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-info-circle2" }))));
		}, [hasOrderNote])
	};
	const isShowClearAll = (0, react.useMemo)(() => {
		if (!state.bookingId) return true;
	}, [state.bookingId]);
	/**
	* @title: 是否可以checkout
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const isCheckout = (0, react.useMemo)(() => {
		var _state$bookingDetail9, _state$bookingDetail10, _state$bookingDetail11;
		if (!state.bookingId || ((_state$bookingDetail9 = state.bookingDetail) === null || _state$bookingDetail9 === void 0 || (_state$bookingDetail9 = _state$bookingDetail9.bookings) === null || _state$bookingDetail9 === void 0 ? void 0 : _state$bookingDetail9.appointment_status) !== "cancelled" && [
			"unfulfilled",
			"unpaid",
			"payment_processing"
		].includes((state === null || state === void 0 || (_state$bookingDetail10 = state.bookingDetail) === null || _state$bookingDetail10 === void 0 ? void 0 : _state$bookingDetail10.payment_status) === "partially_paid" ? "unpaid" : state === null || state === void 0 || (_state$bookingDetail11 = state.bookingDetail) === null || _state$bookingDetail11 === void 0 ? void 0 : _state$bookingDetail11.payment_status) && !state.disabledEdit) return true;
		else {
			if (total.notPaidAmount > 0) return true;
			return false;
		}
	}, [state.bookingDetail, total.notPaidAmount]);
	const _buttons = (0, react.useMemo)(() => {
		const isEvent = require_utils$1.isEventBooking(state);
		if (state.appointment_status === "cancelled") return [buttonMap.rebook];
		if (paymentRefundedStatus) {
			if (isEvent) return [""];
			return [buttonMap.rebook];
		}
		if (source === "addons") {
			let arr = [];
			arr = [...buttons];
			if (isEdit) arr.push(buttonMap.save);
			return arr;
		}
		if (source === "payment") {
			let arr = [];
			if (state.bookingId && isShowPaymentLink) arr.push(buttonMap.paymentLink);
			if (!isTeam) {
				if (total.paidAmount > 0) arr.push(buttonMap.refund);
				if (isCheckout) arr.push(buttonMap.checkout);
			}
			return arr;
		}
		if (source === "info") {
			let arr = [];
			if (state.isBookingTicket2) arr.push(buttonMap.note);
			if (isCheckout) {
				if (!isTeam) arr.push(buttonMap.checkout);
			} else if (!isEdit) arr.push(buttonMap.complete);
			if (isEdit) arr.push(buttonMap.save);
			return arr;
		}
		if (source === "addTime") {
			let arr = [];
			arr = [...buttons];
			return arr;
		}
		return [];
	}, [
		buttons,
		total,
		isEdit,
		checkoutLoading,
		isDisabled,
		source,
		buttonMap,
		loading,
		isCheckout,
		state,
		isTeam,
		isShowClearAll
	]);
	const moreButton = (0, react.useMemo)(() => {
		var _state$bookingDetail12;
		let arr = [];
		if (!state.bookingId) return [];
		if (source !== "info") return [];
		if (state.renderType === "eventBooking") return [];
		if ((state === null || state === void 0 || (_state$bookingDetail12 = state.bookingDetail) === null || _state$bookingDetail12 === void 0 ? void 0 : _state$bookingDetail12.payment_status) === "refunded") return [];
		if (_buttons.length !== 0) {
			var _state$bookingDetail13;
			if (state.bookingId && isShowPaymentLink && (state === null || state === void 0 || (_state$bookingDetail13 = state.bookingDetail) === null || _state$bookingDetail13 === void 0 ? void 0 : _state$bookingDetail13.payment_status) !== "partially_refunded") arr.push(actionMap.paymentLink);
		}
		if (transaction_habit_selection.button_rows == 1) {
			if (state.appointment_status !== "cancelled") {
				if (!state.disabledEdit && !state.isBookingCreatePage && !require_utils$1.isDayBooking(state)) arr.push(actionMap.sale);
			}
		}
		if (!isTeam) {
			if (transaction_habit_selection.button_rows == 1) arr.push(actionMap.orderDetail);
			if (total.paidAmount > 0) arr.push(actionMap.refund);
		}
		if (state.appointment_status !== "cancelled") arr.push(actionMap.rebook);
		return arr;
	}, [
		state,
		total,
		isShowPaymentLink,
		source,
		_buttons.length,
		state === null || state === void 0 || (_state$bookingDetail14 = state.bookingDetail) === null || _state$bookingDetail14 === void 0 ? void 0 : _state$bookingDetail14.payment_status
	]);
	/**
	* @title: 总计文案
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:00
	*/
	const totalText = (0, react.useMemo)(() => {
		var _state$bookingDetail16, _state$bookingDetail17;
		let str = "";
		if (total.totalRefundAmount > 0) return `${_pisell_utils.locales.getText("pisell2.text.refunded-amount")}: ${(0, _pisell_utils.formatAmount)(total.totalRefundAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		if (isOnlyDeposit) {
			var _state$bookingDetail15;
			return `${_pisell_utils.locales.getText("pisell2.text.deposit-paid")} ${(0, _pisell_utils.formatAmount)(state === null || state === void 0 || (_state$bookingDetail15 = state.bookingDetail) === null || _state$bookingDetail15 === void 0 ? void 0 : _state$bookingDetail15.deposit_paid_amount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")} ${total.duration ? `(${total.duration})` : ""}`;
		}
		if (total.notPaidAmount <= 0 && (state.bookingId || ((_state$bookingDetail16 = state.bookingDetail) === null || _state$bookingDetail16 === void 0 ? void 0 : _state$bookingDetail16.id))) str = `${_pisell_utils.locales.getText("pisell1.text.fully-paid")}: ${(0, _pisell_utils.formatAmount)(total.sumTotalAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		if (total.notPaidAmount > 0 || !state.bookingId && !((_state$bookingDetail17 = state.bookingDetail) === null || _state$bookingDetail17 === void 0 ? void 0 : _state$bookingDetail17.id)) {
			var _state$bookingDetail18;
			if (total.dueAmount < 0 && ((_state$bookingDetail18 = state.bookingDetail) === null || _state$bookingDetail18 === void 0 ? void 0 : _state$bookingDetail18.id)) str = `${_pisell_utils.locales.getText("pisell1.text.fully-paid")}: ${(0, _pisell_utils.formatAmount)(total.sumTotalAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
			else str = `${_pisell_utils.locales.getText("pisell2.text.to-pay")}: ${(0, _pisell_utils.formatAmount)(total.notPaidAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		}
		if (total.duration) str = str + ` (${total.duration})`;
		return str;
	}, [
		state,
		total,
		state.bookingId,
		isOnlyDeposit,
		(_state$bookingDetail19 = state.bookingDetail) === null || _state$bookingDetail19 === void 0 ? void 0 : _state$bookingDetail19.id
	]);
	/**
	* @title: 是否显示footer loading
	* @description:  避免数据未获取完时页面闪动
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:03
	*/
	const showFooter = (0, react.useMemo)(() => {
		if (state.bookingId) {
			var _state$addons3;
			if (!state.bookingDetail) return true;
			if (!((_state$addons3 = state.addons) === null || _state$addons3 === void 0 ? void 0 : _state$addons3.load) && state.renderType !== "eventBooking" && !state.isBookingCreatePage) return true;
		}
		return false;
	}, [
		state.bookingId,
		state.bookingDetail,
		(_state$addons4 = state.addons) === null || _state$addons4 === void 0 ? void 0 : _state$addons4.load,
		state.renderType
	]);
	const menuChange = (e) => {
		console.log("e.key", e.key);
		switch (e.key) {
			case "sendMail":
				handleMenuClick(e);
				break;
			case "copy":
				handleMenuClick(e);
				break;
			case "rebook":
				handleRebook();
				break;
			case "sale":
				handleSale();
				break;
			case "print":
				handlePrint();
				break;
			case "orderDetail":
				handleOrderDetail();
				break;
			case "refund":
				handleRefund();
				break;
			case "cancelOrder":
				handleCancel();
				break;
			default: break;
		}
	};
	const changeCustomerToGlobalState = (0, ahooks.useMemoizedFn)((value, options) => {
		var _state$client3, _state$service4;
		debugger;
		const beforeValue = state === null || state === void 0 || (_state$client3 = state.client) === null || _state$client3 === void 0 ? void 0 : _state$client3.value;
		dispatch({
			type: "setClient",
			payload: {
				value,
				edit: true
			}
		});
		if ((beforeValue === null || beforeValue === void 0 ? void 0 : beforeValue.id) === (value === null || value === void 0 ? void 0 : value.id)) return;
		if ((state === null || state === void 0 || (_state$service4 = state.service) === null || _state$service4 === void 0 || (_state$service4 = _state$service4.value) === null || _state$service4 === void 0 ? void 0 : _state$service4.length) && !(options === null || options === void 0 ? void 0 : options.reset)) dispatch({
			type: "setService",
			payload: { value: state.service.value.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { _extend: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item._extend), {}, { holder_id: [] }) })) }
		});
	});
	const { selectCustomer } = require_useCustomer.useCustomer({ changeCustomerToGlobalState });
	const shopDiscount = require_useShopDiscountModule.useShopDiscountModule();
	const { clearAllScanListenersTaskQueue } = require_useScanManager.default();
	const [existPayment, setExistPayment] = (0, react.useState)([]);
	/**
	* 初始化编辑模式下的 payment 还原流程
	*/
	(0, react.useEffect)(() => {
		function loadEditModePayments() {
			return _loadEditModePayments.apply(this, arguments);
		}
		function _loadEditModePayments() {
			_loadEditModePayments = require_asyncToGenerator._asyncToGenerator(function* () {
				var _state$bookingDetail20, _state$bookingDetail$;
				if (!state.isEditTicketMode) return;
				if (!((_state$bookingDetail20 = state.bookingDetail) === null || _state$bookingDetail20 === void 0 ? void 0 : _state$bookingDetail20.id)) return;
				setEditOrderId(state.bookingDetail.id);
				const paymentMethodList = yield (yield pisellos.getModule("checkout")).getPaymentMethodsAsync();
				const onlineStorePaymentCodeList = [
					"WXPAY",
					"WECHAT",
					"ALIPAY",
					"APPLE_PAY",
					"CREDIT_CARD_3DS",
					"CREDIT_CARD_TOKEN",
					"GOOGLE_PAY",
					"GOOGLE_PAY_3DS",
					"CREDIT_CARD"
				];
				setExistPayment((_state$bookingDetail$ = state.bookingDetail.payments) === null || _state$bookingDetail$ === void 0 || (_state$bookingDetail$ = _state$bookingDetail$.filter((item) => item.status === "paid")) === null || _state$bookingDetail$ === void 0 ? void 0 : _state$bookingDetail$.map((item) => {
					var _item$metadata;
					let paymentMethod = paymentMethodList.find((method) => method.code === item.payment_method);
					if (!paymentMethod && onlineStorePaymentCodeList.includes(item.payment_method)) paymentMethod = {
						id: "",
						name: item.payment_method,
						code: item.payment_method,
						type: item.payment_method
					};
					return {
						uuid: (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_payment_number) || item.pay_number,
						custom_payment_id: paymentMethod.id,
						order_payment_id: item.id,
						name: paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.name,
						code: item.payment_method,
						type: paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.type,
						amount: item.origin_amount,
						rounding_amount: item.rounding_amount,
						status: "active",
						order_payment_type: item.type,
						metadata: item.metadata,
						voucher_id: item.voucher_id,
						service_charge: item.service_charge && typeof item.service_charge === "object" && !Array.isArray(item.service_charge) ? item.service_charge : {},
						created_at: item.created_at,
						updated_at: item.updated_at,
						service_fee: item.service_fee
					};
				}));
			});
			return _loadEditModePayments.apply(this, arguments);
		}
		loadEditModePayments();
	}, [state.isEditTicketMode, state === null || state === void 0 || (_state$bookingDetail21 = state.bookingDetail) === null || _state$bookingDetail21 === void 0 ? void 0 : _state$bookingDetail21.id]);
	const isActive = require_IsActiveContext.useIsActive();
	return /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		title: false,
		round: true,
		loading: showFooter,
		active: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-footer-total" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left-total" }, totalText), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left-arrears" }, arrearsText)), /* @__PURE__ */ react.default.createElement("span", {
		className: "pisell-lowcode__booking-footer-right",
		onClick: () => {
			setShowDetail(!showDetail);
		}
	}, _pisell_utils.locales.getText("pisell2.text.details"), " ", /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ChevronDown.default, { className: (0, classnames.default)("pisell-lowcode__booking-footer-right-icon", { "pisell-lowcode__booking-footer-right-icon-show": showDetail || isSecondaryScreen }) }))), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-lowcode__booking-footer-total-detail", { "pisell-lowcode__booking-footer-total-detail-show": showDetail || isSecondaryScreen }) }, /* @__PURE__ */ react.default.createElement("div", { className: "order-total-item-border" }), /* @__PURE__ */ react.default.createElement(require_index$6.default, {
		mode: "column1",
		list: subTotalList,
		style: { padding: `0` }
	}), /* @__PURE__ */ react.default.createElement("div", { className: state.bookingId ? "order-total-item-border" : "" }), !!state.bookingId && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index$6.default, {
		mode: "column1",
		list: orderTotalList,
		style: { padding: ` 0 0 16px` }
	}))), !isSecondaryScreen && !(state === null || state === void 0 ? void 0 : state.disableEventBookingEdit) && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-footer-buttons" }, /* @__PURE__ */ react.default.createElement(require_index$4.default, {
		items: moreButton,
		state,
		dispatch,
		source,
		menuChange
	}), _buttons.length ? _buttons : state.bookingId && isShowPaymentLink ? paymentLinkButton : null), !isSecondaryScreen && source === "info" && state.bookingId && !state.disabledEdit && (transaction_habit_selection === null || transaction_habit_selection === void 0 ? void 0 : transaction_habit_selection.button_rows) == 2 ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__booking-footer-buttons",
		style: { marginTop: 12 }
	}, state.appointment_status !== "cancelled" && !state.isBookingCreatePage && !require_utils$1.isDayBooking(state) ? /* @__PURE__ */ react.default.createElement(antd.Button, {
		onClick: () => handleSale(),
		size: "large",
		className: "pisell-lowcode__booking-footer-buttons-item"
	}, actionMap.sale.label) : null, isTeam ? null : /* @__PURE__ */ react.default.createElement(antd.Button, {
		onClick: () => handleOrderDetail(),
		size: "large",
		className: "pisell-lowcode__booking-footer-buttons-item"
	}, actionMap.orderDetail.label)) : null, /* @__PURE__ */ react.default.createElement(require_index.default, {
		renderType: isPhoneVariant ? "drawer" : "modal",
		props: isPhoneVariant ? {
			open: terminalWarningOpen,
			placement: "bottom",
			width: "100%",
			height: "auto",
			title: null,
			onClose: () => setTerminalWarningOpen(false),
			footer: /* @__PURE__ */ react.default.createElement(antd.Button, {
				block: true,
				type: "primary",
				onClick: () => setTerminalWarningOpen(false)
			}, _pisell_utils.locales.getText("pisell2.text.ok"))
		} : {
			open: terminalWarningOpen,
			title: null,
			onCancel: () => setTerminalWarningOpen(false),
			footer: /* @__PURE__ */ react.default.createElement("div", { style: {
				display: "flex",
				justifyContent: "flex-end"
			} }, /* @__PURE__ */ react.default.createElement(antd.Button, {
				type: "primary",
				onClick: () => setTerminalWarningOpen(false)
			}, _pisell_utils.locales.getText("pisell2.text.ok")))
		}
	}, _pisell_utils.locales.getText("pisell2.text.terminal-edit-message")), /* @__PURE__ */ react.default.createElement(require_index$3.default, { ref: appointmentProductRef }), noteModalOpen && /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		open: noteModalOpen,
		title: _pisell_utils.locales.getText("pisell2.text.add-order-notes"),
		value: ((_state$notes4 = state.notes) === null || _state$notes4 === void 0 ? void 0 : _state$notes4.orderNote) || "",
		onConfirm: handleNoteConfirm,
		onDelete: handleNoteDelete,
		onCancel: handleNoteCancel
	}), isActive && /* @__PURE__ */ react.default.createElement(require_confirmHolderModal.ConfirmHolderModal, null));
};
Footer.displayName = "BookingFooter";
var footer_default = require_withResponsive.default(Footer);
//#endregion
exports.default = footer_default;
