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 { getSumTotal } from "./amount.js";
import { checkHolderIsError, formatValues } from "./utils.js";
import { getIsSubjectRequire, isDayBooking, isEventBooking, isHasDayAppointmentProduct, isNormalProductByDurationSchedule } from "../../info/service2/utils.js";
import { isWalkIn } from "../../utils.js";
import useEngineContext from "../../../../hooks/useEngineContext.js";
import NoteModal from "../../../../plus/noteModal/index.js";
import { useShopDiscountModule } from "../../../ticketBooking/hooks/pisellos/useShopDiscountModule.js";
import { useCustomer } from "../../../ticketBooking/hooks/pisellos/useCustomer.js";
import { closeAllPaymentResultToasts } from "../../../checkout/components/PaymentResultToast/utils.js";
import { createBookings, editBookings } from "../../info2/serve.js";
import PaymentModal from "../../../checkout/PaymentModal.js";
import { useIsBooking4Shop } from "../../hooks/useIsBooking4Shop.js";
import useScanManager from "../../../ticketBooking/hooks/pisellos/useScanManager.js";
import { formatProducts } from "../../addons/index.js";
import AppointmentProductModal_default from "./AppointmentProductModal/index.js";
import FooterMenus from "./FooterMenus/index.js";
import { createEventBooking, editEventBooking } from "./serve.js";
import { ConfirmHolderModal, showConfirmHolderModal } from "../../utils/confirmHolderModal.js";
import SubTotal from "../../../subTotal/index.js";
import dayjs from "dayjs";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Button, ConfigProvider, Dropdown, Modal, Skeleton, Space, message } from "antd";
import { formatAmount, locales, sendWarningLog } from "@pisell/utils";
import Decimal from "decimal.js";
import { cloneDeep } from "lodash";
import { Iconfont } from "@pisell/materials";
import classNames from "classnames";
import { useDebounceEffect, useDebounceFn, useMemoizedFn } from "ahooks";
import { DownOutlined } from "@ant-design/icons";
import ChevronDown from "@pisell/icon/es/ChevronDown";
import "./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$service5, _state$bookingDetail, _state$bookingDetail2, _state$client2, _state$notes3, _state$bookingDetail14, _state$addons4, _state$notes4, _state$bookingConfig7, _state$client5;
	const { state, buttons, dispatch, source } = props;
	const [showDetail, setShowDetail] = useState(false);
	const [loading, setLoading] = useState(false);
	const [checkoutLoading, setCheckoutLoading] = useState(false);
	const [noteModalOpen, setNoteModalOpen] = useState(false);
	const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false);
	const [paymentModalData, setPaymentModalData] = useState(null);
	const [paymentCallback, setPaymentCallback] = useState(null);
	const [editOrderId, setEditOrderId] = useState(0);
	const [isShowPaymentLink, setIsShowPaymentLink] = useState(false);
	const isBooking4Shop = useIsBooking4Shop(state);
	const appointmentProductRef = useRef(null);
	const { isTerminal, isWebPos, interaction, store, storage, pisellosAllModule, getData, pisellos } = (_context$appHelper = useEngineContext().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const { disableAllScanListeners } = useScanManager();
	const { ScheduleModule } = pisellosAllModule;
	useEffect(() => {
		store === null || store === void 0 || store.dispatch({
			type: "global/_getMetadataMap",
			callback: (data) => {
				console.log(data, "data");
				setIsShowPaymentLink(!!data["payment_collection_link_config_switch"]);
			}
		});
	}, []);
	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);
		}
	}, []);
	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 [modal, contextHolder] = Modal.useModal();
	const { setActiveTab } = state;
	const isTeam = useMemo(() => {
		return storage.get("channel") === "android_team_portal" || storage.get("channel") === "ios_team_portal";
	}, []);
	const actionMap = {
		sale: {
			label: locales.getText("pisell2.text.addons"),
			key: "sale"
		},
		paymentLink: {
			label: locales.getText("pisell2.text.payment-link"),
			key: "payment",
			children: [{
				label: locales.getText("pisell2.text.send-mail"),
				key: "sendMail"
			}, {
				label: locales.getText("pisell2.text.copy-to-clipboard"),
				key: "copy"
			}]
		},
		print: {
			label: "Print",
			key: "print"
		},
		orderDetail: {
			label: locales.getText("pisell2.text.deposit-order-detail"),
			key: "orderDetail"
		},
		refund: {
			label: locales.getText("pisell2.text.refund"),
			key: "refund"
		},
		rebook: {
			label: locales.getText("pisell2.text.rebook"),
			key: "rebook"
		},
		cancelOrder: {
			label: "Cancel order",
			key: "cancelOrder"
		}
	};
	useEffect(() => {
		if (state.bookingDetail) state.action({
			type: "pisell1.registerPlugin",
			data: { pluginList: ["RefundPlugin"] }
		});
	}, [state.bookingDetail]);
	const params = 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 = 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 = 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 = 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 = 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 = useMemo(() => {
		return getSumTotal(state, _objectSpread2({
			isEdit,
			ScheduleModule
		}, getDataFromHost()));
	}, [state, isEdit]);
	useDebounceEffect(() => {
		var _state$service4;
		if (state === null || state === void 0 || (_state$service4 = state.service) === null || _state$service4 === void 0 ? void 0 : _state$service4.addTimeModal) try {
			sendWarningLog({
				title: "加时商品变更",
				content: [{
					key: "params",
					value: JSON.stringify(total)
				}]
			});
		} catch (e) {}
	}, [total, state === null || state === void 0 || (_state$service5 = state.service) === null || _state$service5 === void 0 ? void 0 : _state$service5.addTimeModal], { wait: 300 });
	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 = useMemo(() => {
		return [
			{
				hidden: !state.bookingId,
				key: "custom_orderPaidAmount",
				value: total.orderPaidAmount,
				label: locales.getText("pisell2.text.amount-paid-on-order")
			},
			{
				hidden: !state.bookingId,
				key: "custom_paySurchargeFee",
				value: total.paySurchargeFee,
				label: locales.getText("pisell1.text.payment-fee")
			},
			{
				hidden: !state.bookingId,
				key: "custom_actualPaidAmount",
				value: total.actualPaidAmount,
				label: locales.getText("pisell2.text.amount-actually-paid-by-the-customer")
			},
			{
				hidden: !state.bookingId || !total.totalRefundAmount,
				key: "custom_totalRefundAmount",
				value: total.totalRefundAmount,
				label: 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 = 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: locales.getText("pisell2.subtotal.total")
			},
			{
				hidden: !total.roundingAmount,
				key: "custom_roundingAmount",
				value: total.roundingAmount,
				label: locales.getText("pisell1.text.rounding")
			}
		];
	}, [
		total,
		(_state$bookingDetail2 = state.bookingDetail) === null || _state$bookingDetail2 === void 0 ? void 0 : _state$bookingDetail2.surcharge,
		state.bookingId
	]);
	const isDisabled = 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 = useMemo(() => {
		return total.expectAmount < 0 && state.isBookingTicket2;
	}, [total, state.isBookingTicket2]);
	/**
	* @title: 跳转到 checkout页面
	* @description:
	* @param {any} order_id
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:53
	*/
	const goCheckout = function() {
		var _ref = _asyncToGenerator(function* (order_id, isNewOrder, totalAmount) {
			if (!order_id) return;
			if (isWebPos) {
				state.action({
					type: "pisell1.handleOpenPayment",
					data: {
						order_id,
						total_amount: totalAmount
					},
					callback: (res) => {
						console.log("webpos_pay_result", res);
						if ((res === null || res === void 0 ? void 0 : res.status) === "success") {
							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.status) === "cancel") {
							var _window2;
							(_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.shopApi) === null || _window2 === void 0 || (_window2 = _window2.booking) === null || _window2 === void 0 || _window2.voidBooking(order_id);
						}
					}
				});
				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(_x, _x2, _x3) {
			return _ref.apply(this, arguments);
		};
	}();
	(function() {
		var _ref2 = _asyncToGenerator(function* (res) {
			state.action({
				type: "pisell1.handleOpenPayment",
				data: {
					order_info: res,
					subtotal_info: {
						subTotalList,
						orderTotalList,
						total,
						showDetail
					}
				},
				callback: (res) => {
					console.log("webpos_pay_result", res);
					if ((res === null || res === void 0 ? void 0 : res.status) === "success") {
						var _window3;
						(_window3 = window) === null || _window3 === void 0 || (_window3 = _window3.shopApi) === null || _window3 === void 0 || (_window3 = _window3.bookingTicket) === null || _window3 === void 0 || _window3.clearAllCart();
					} else if ((res === null || res === void 0 ? void 0 : res.status) === "cancel") {
						var _window4;
						(_window4 = window) === null || _window4 === void 0 || (_window4 = _window4.shopApi) === null || _window4 === void 0 || (_window4 = _window4.booking) === null || _window4 === void 0 || _window4.voidBooking(order_id);
					}
				}
			});
		});
		return function goCheckout2(_x4) {
			return _ref2.apply(this, arguments);
		};
	})();
	useDebounceEffect(() => {
		_asyncToGenerator(function* () {
			try {
				console.log("🔄 Footer: OrderTotalList/Total changed, updating PaymentModal data...");
				if (isPaymentModalOpen) {
					const res = yield handleSave({
						type: "checkout",
						messageShow: !(isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()),
						noSubmit: true
					});
					if (!res) return;
					setCheckoutLoading(false);
					const modalData = {
						order_info: res,
						subtotal_info: {
							subTotalList,
							orderTotalList,
							total,
							showDetail
						}
					};
					if (JSON.stringify(modalData) === JSON.stringify(paymentModalData)) return;
					setPaymentModalData(modalData);
				}
			} catch (error) {}
		})();
	}, [
		JSON.stringify(total),
		JSON.stringify(orderTotalList),
		JSON.stringify(subTotalList),
		(_state$client2 = state.client) === null || _state$client2 === void 0 || (_state$client2 = _state$client2.value) === null || _state$client2 === void 0 ? void 0 : _state$client2.id
	]);
	const { run: handleCheckout } = useDebounceFn(function() {
		var _ref3 = _asyncToGenerator(function* () {
			var _state$bookingConfig5;
			if ((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) !== "modal") closeAllPaymentResultToasts();
			const isNewOrder = !state.bookingId;
			if (isEdit) {
				if (isDayBooking(state)) {
					if (handleDaySubmit()) return;
				}
				if (state.isBookingTicket2) {
					const res = yield handleSave({
						type: "checkout",
						messageShow: !(isTerminal === null || isTerminal === void 0 ? void 0 : isTerminal()),
						noSubmit: true
					});
					if (!res) return;
					setPaymentModalData({
						order_info: res,
						subtotal_info: {
							subTotalList: cloneDeep(subTotalList),
							orderTotalList: cloneDeep(orderTotalList),
							total: cloneDeep(total),
							showDetail
						}
					});
					setIsPaymentModalOpen(true);
					setCheckoutLoading(false);
					setPaymentCallback(() => (paymentResult) => {
						console.log("Payment result:", paymentResult);
						setIsPaymentModalOpen(false);
						if ((paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.status) === "success") {
							var _window5;
							console.log("Payment completed successfully");
							(_window5 = window) === null || _window5 === void 0 || (_window5 = _window5.shopApi) === null || _window5 === void 0 || (_window5 = _window5.bookingTicket) === null || _window5 === void 0 || _window5.clearAllCart();
							setPaymentModalData(null);
							setPaymentCallback(null);
						} else if ((paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.status) === "cancelled") {
							console.log("Payment cancelled");
							if (res === null || res === void 0 ? void 0 : res.order_id) {
								var _window6;
								(_window6 = window) === null || _window6 === void 0 || (_window6 = _window6.shopApi) === null || _window6 === void 0 || (_window6 = _window6.booking) === null || _window6 === void 0 || _window6.voidBooking(res.order_id);
							}
							setPaymentModalData(null);
							setPaymentCallback(null);
						} else {
							console.log("Payment status:", paymentResult === null || paymentResult === void 0 ? void 0 : paymentResult.status);
							setPaymentModalData(null);
							setPaymentCallback(null);
						}
					});
				} 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 _ref3.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 _ref4 = _asyncToGenerator(function* () {
			try {
				let _list = [...state.addons.value];
				yield state.apis.saveAddonsByOrderId({
					products: formatProducts(_list),
					shop_discount: state.bookingDetail.shop_discount,
					shop_discount_reason: state.bookingDetail.shop_discount_reason
				});
				message.success(locales.getText("pisell2.text.addons") + locales.getText("pisell2.text.updated"));
			} catch (err) {
				console.log("state.bookingId && state.addons.edit", err);
			}
		});
		return function handleSaveAddons() {
			return _ref4.apply(this, arguments);
		};
	}();
	const getApis = () => {
		if (isBooking4Shop || state.renderType === "dayBooking") return {
			editBooking: editBookings,
			createBooking: 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 = isHasDayAppointmentProduct(state);
		if (_isHasDayProducts) {
			var _appointmentProductRe;
			appointmentProductRef === null || appointmentProductRef === void 0 || (_appointmentProductRe = appointmentProductRef.current) === null || _appointmentProductRe === void 0 || _appointmentProductRe.open();
		}
		return _isHasDayProducts;
	};
	/**
	* 是否只有定金支付
	*/
	const isOnlyDeposit = 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 = useMemo(() => {
		let str = "";
		if (isOnlyDeposit) return str;
		if (total.dueAmount < 0) str = `${locales.getText("pisell1.text.refund-customer")}: ${formatAmount(total.dueAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		return str;
	}, [
		state,
		total,
		isOnlyDeposit
	]);
	/**
	* @title: 保存info
	* @description:
	* @param {object} param1
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:54
	*/
	const handleSave = function() {
		var _ref5 = _asyncToGenerator(function* ({ type, messageShow = true, noSubmit = false }) {
			var _state$bookingConfig6, _state$service$value2, _state$client3;
			if ((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") closeAllPaymentResultToasts();
			if (isDayBooking(state)) {
				if (handleDaySubmit()) return;
			}
			const hasUnspecifiedHolderProduct = (_state$service$value2 = state.service.value) === null || _state$service$value2 === void 0 ? void 0 : _state$service$value2.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) && !isNormalProductByDurationSchedule(item);
			});
			if (!isWalkIn((_state$client3 = state.client) === null || _state$client3 === void 0 || (_state$client3 = _state$client3.value) === null || _state$client3 === void 0 ? void 0 : _state$client3.id) && getIsSubjectRequire(state) && hasUnspecifiedHolderProduct) yield showConfirmHolderModal(state, dispatch);
			if (isBooking4Shop && getIsSubjectRequire(state) && 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" ? editEventBooking : editBooking;
			const createApi = state.renderType === "eventBooking" ? 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, _window7;
				let callbackData = null;
				let values = formatValues(_objectSpread2(_objectSpread2({}, state), saveOtherValue));
				values.product_tax_fee = total.tax || 0;
				if (noSubmit) return values;
				const checkout = pisellos.getModule("checkout");
				if (editOrderId) {
					const subtotal_info = {
						subTotalList: cloneDeep(subTotalList),
						orderTotalList: cloneDeep(orderTotalList),
						total: 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);
					}
					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;
				sendWarningLog({
					title: "saveBooking",
					content: [
						{
							key: "下单前数据",
							value: JSON.stringify(values)
						},
						{
							key: "日期",
							value: dayjs().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((_window7 = window) === null || _window7 === void 0 ? void 0 : _window7.shopApi, (key, value) => {
								if (typeof value === "function") return "function";
								return value;
							})
						}
					]
				});
				if (addonsEdit) yield handleSaveAddons();
				if (infoEdit) {
					callbackData = yield api(values, state.bookingId || editOrderId);
					if (messageShow) message.success(locales.getText(state.bookingId ? "pisell2.text.appointment-updated" : "pisell2.text.created-successfully"));
				}
				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) message.error(err === null || err === void 0 ? void 0 : err.message);
				clearTimeout(loadingTimer);
				_setLoading(false);
			}
		});
		return function handleSave(_x5) {
			return _ref5.apply(this, arguments);
		};
	}();
	/**
	* @title: 将预约状态修改为已完成
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:57
	*/
	const onSelect = function() {
		var _ref6 = _asyncToGenerator(function* (e) {
			const status = "completed";
			dispatch({
				type: "setStatus",
				payload: status
			});
			yield state.apis.editBookingStatus({ appointment_status: status });
			message.success(locales.getText("pisell1.text.edit-status-success"));
			state === null || state === void 0 || state.callback({ order_id: state.bookingId });
		});
		return function onSelect(_x6) {
			return _ref6.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 = 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 = 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.createElement(ConfigProvider, { theme: { token: { colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009" } } }, /* @__PURE__ */ React.createElement(Button, {
			className: classNames("pisell-lowcode__booking-footer-buttons-item", { ["pisell-lowcode__booking-footer-buttons-item-primary"]: buttonType === "primary" }),
			type: "primary",
			loading: checkoutLoading,
			onClick: () => {
				handleCheckout();
			},
			disabled: isDisabled || isDisabledCheckOutForNegativeOrder || arrearsText !== ""
		}, locales.getText("pisell2.text.checkout")));
	}, [
		isEdit,
		checkoutLoading,
		isDisabled,
		state,
		source,
		arrearsText
	]);
	const handleMenuClick = function() {
		var _ref7 = _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(_x7) {
			return _ref7.apply(this, arguments);
		};
	}();
	const handleRebook = () => {
		var _state$onRebook;
		(_state$onRebook = state.onRebook) === null || _state$onRebook === void 0 || _state$onRebook.call(state);
	};
	const handleSale = () => {
		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) {
			modal.warning({
				okText: locales.getText("pisell2.text.ok"),
				content: locales.getText("pisell2.text.terminal-edit-message")
			});
			return;
		}
		setActiveTab === null || setActiveTab === void 0 || setActiveTab("addons");
	};
	const handlePrint = () => {};
	const handleOrderDetail = () => {
		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 = useMemo(() => {
		const items = [{
			label: locales.getText("pisell2.text.send-mail"),
			key: "sendMail"
		}, {
			label: locales.getText("pisell2.text.copy-to-clipboard"),
			key: "copy"
		}];
		return /* @__PURE__ */ React.createElement(Dropdown, { menu: {
			items,
			onClick: handleMenuClick
		} }, /* @__PURE__ */ React.createElement(Button, { className: "pisell-lowcode__booking-footer-buttons-item" }, /* @__PURE__ */ React.createElement(Space, null, locales.getText("pisell2.text.payment-link"), /* @__PURE__ */ React.createElement(DownOutlined, null))));
	}, [handleMenuClick]);
	/**
	* @title: 保存按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 16:58
	*/
	const saveButton = useMemo(() => {
		let buttonType = "default";
		if (transaction_habit_selection.type === "service_now_pay_later") buttonType = "primary";
		return /* @__PURE__ */ React.createElement(ConfigProvider, { theme: { token: { colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009" } } }, /* @__PURE__ */ React.createElement(Button, {
			className: classNames("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
		}, 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 = useMemo(() => {
		return /* @__PURE__ */ React.createElement(Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "primary",
			onClick: onSelect,
			disabled: state.appointment_status === "completed"
		}, 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 = useMemo(() => {
		return /* @__PURE__ */ React.createElement(Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			onClick: handleRebook
		}, 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 = useMemo(() => {
		return /* @__PURE__ */ React.createElement(Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "default",
			onClick: handleRefund
		}, 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 = useMemo(() => {
		return /* @__PURE__ */ React.createElement(ConfigProvider, { theme: { token: { colorPrimary: "#f04438" } } }, /* @__PURE__ */ React.createElement(Button, {
			className: "pisell-lowcode__booking-footer-buttons-item",
			type: "primary",
			onClick: handleClearAll
		}, locales.getText("pisell2.booking.info.text.clear-all")));
	}, []);
	const hasOrderNote = 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: useMemo(() => {
			return /* @__PURE__ */ React.createElement(ConfigProvider, { theme: { token: { colorPrimary: "#0d7fa9" } } }, /* @__PURE__ */ React.createElement(Button, {
				className: "pisell-lowcode__booking-footer-buttons-item note-button",
				type: "primary",
				onClick: handleNote
			}, locales.getText("pisell2.ticket-booking.note"), hasOrderNote && /* @__PURE__ */ React.createElement("span", { className: "note-indicator" }, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-info-circle2" }))));
		}, [hasOrderNote])
	};
	const isShowClearAll = 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 = 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 = useMemo(() => {
		const isEvent = 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 = 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 && !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 = useMemo(() => {
		let str = "";
		if (isOnlyDeposit) {
			var _state$bookingDetail15;
			return `${locales.getText("pisell2.text.deposit-paid")} ${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.totalRefundAmount > 0) return `${locales.getText("pisell2.text.refunded-amount")}: ${formatAmount(total.totalRefundAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		if (total.notPaidAmount <= 0 && state.bookingId) str = `${locales.getText("pisell1.text.fully-paid")}: ${formatAmount(total.sumTotalAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")}`;
		if (total.notPaidAmount > 0 || !state.bookingId) str = `${locales.getText("pisell2.text.to-pay")}: ${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
	]);
	/**
	* @title: 是否显示footer loading
	* @description:  避免数据未获取完时页面闪动
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:03
	*/
	const showFooter = 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 { selectCustomer } = useCustomer({ changeCustomerToGlobalState: useMemoizedFn((value) => {
		var _state$client4, _state$service6;
		const beforeValue = state === null || state === void 0 || (_state$client4 = state.client) === null || _state$client4 === void 0 ? void 0 : _state$client4.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$service6 = state.service) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.value) === null || _state$service6 === void 0 ? void 0 : _state$service6.length) dispatch({
			type: "setService",
			payload: { value: state.service.value.map((item) => _objectSpread2(_objectSpread2({}, item), {}, { _extend: _objectSpread2(_objectSpread2({}, item._extend), {}, { holder_id: [] }) })) }
		});
	}) });
	const shopDiscount = useShopDiscountModule();
	const { clearAllScanListenersTaskQueue } = useScanManager();
	const handleClearAllAndReset = () => {
		var _state$setIntervalTim, _shopDiscount$clear;
		clearAllScanListenersTaskQueue();
		state === null || state === void 0 || (_state$setIntervalTim = state.setIntervalTime) === null || _state$setIntervalTim === void 0 || _state$setIntervalTim.call(state, true);
		dispatch({
			type: "setService",
			payload: { value: [] }
		});
		dispatch({
			type: "setAddons",
			payload: { value: [] }
		});
		selectCustomer(null);
		dispatch({
			type: "setDate",
			payload: {
				value: dayjs(),
				end_date: dayjs().add(1, "days")
			}
		});
		dispatch({
			type: "setPet",
			payload: {
				holders: [],
				value: {}
			}
		});
		dispatch({
			type: "setNotes",
			payload: {
				value: "",
				orderNote: ""
			}
		});
		shopDiscount === null || shopDiscount === void 0 || (_shopDiscount$clear = shopDiscount.clear) === null || _shopDiscount$clear === void 0 || _shopDiscount$clear.call(shopDiscount);
		setEditOrderId(0);
	};
	const setEditCartMode = (order_id, payData, closeModal = false) => {
		setEditOrderId(order_id);
		if (closeModal) setIsPaymentModalOpen(false);
		dispatch({
			type: "setService",
			payload: { value: state.service.value.map((item) => _objectSpread2(_objectSpread2({}, item), {}, {
				edit: true,
				booking_id: "0",
				discount_list: item.discount_list.map((d) => _objectSpread2(_objectSpread2({}, d), {}, { id: d.discount.resource_id }))
			})) }
		});
		dispatch({
			type: "setPaymentPaid",
			payload: { value: {
				paidAmount: payData.paidAmount,
				paidAmountWithoutSurcharge: payData.paidAmountWithoutSurcharge
			} }
		});
		shopDiscount.loadPrepareConfig({
			customerId: state.client.value.id,
			action: "create",
			with_good_pass: 1,
			with_discount_card: 1
		});
	};
	return /* @__PURE__ */ React.createElement(Skeleton, {
		title: false,
		round: true,
		loading: showFooter,
		active: true
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-footer-total" }, /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-footer-left" }, /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-footer-left-total" }, totalText), /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-footer-left-arrears" }, arrearsText)), /* @__PURE__ */ React.createElement("span", {
		className: "pisell-lowcode__booking-footer-right",
		onClick: () => {
			setShowDetail(!showDetail);
		}
	}, locales.getText("pisell2.text.details"), " ", /* @__PURE__ */ React.createElement(ChevronDown, { className: classNames("pisell-lowcode__booking-footer-right-icon", { "pisell-lowcode__booking-footer-right-icon-show": showDetail }) }))), /* @__PURE__ */ React.createElement("div", { className: classNames("pisell-lowcode__booking-footer-total-detail", { "pisell-lowcode__booking-footer-total-detail-show": showDetail }) }, /* @__PURE__ */ React.createElement("div", { className: "order-total-item-border" }), /* @__PURE__ */ React.createElement(SubTotal, {
		mode: "column1",
		list: subTotalList,
		style: { padding: `0` }
	}), /* @__PURE__ */ React.createElement("div", { className: state.bookingId ? "order-total-item-border" : "" }), !!state.bookingId && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SubTotal, {
		mode: "column1",
		list: orderTotalList,
		style: { padding: ` 0 0 16px` }
	}))), !(state === null || state === void 0 ? void 0 : state.disableEventBookingEdit) && /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-footer-buttons" }, /* @__PURE__ */ React.createElement(FooterMenus, {
		items: moreButton,
		state,
		dispatch,
		source,
		menuChange
	}), _buttons.length ? React.Children.toArray(_buttons) : state.bookingId && isShowPaymentLink ? paymentLinkButton : null), 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.createElement("div", {
		className: "pisell-lowcode__booking-footer-buttons",
		style: { marginTop: 12 }
	}, state.appointment_status !== "cancelled" && !state.isBookingCreatePage && !isDayBooking(state) ? /* @__PURE__ */ React.createElement(Button, {
		onClick: () => handleSale(),
		size: "large",
		className: "pisell-lowcode__booking-footer-buttons-item"
	}, actionMap.sale.label) : null, isTeam ? null : /* @__PURE__ */ React.createElement(Button, {
		onClick: () => handleOrderDetail(),
		size: "large",
		className: "pisell-lowcode__booking-footer-buttons-item"
	}, actionMap.orderDetail.label)) : null, contextHolder, /* @__PURE__ */ React.createElement(AppointmentProductModal_default, { ref: appointmentProductRef }), noteModalOpen && /* @__PURE__ */ React.createElement(NoteModal, {
		open: noteModalOpen,
		title: 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
	}), isPaymentModalOpen && /* @__PURE__ */ React.createElement(PaymentModal, {
		open: true,
		editOrderId,
		data: paymentModalData,
		callback: paymentCallback || void 0,
		setEditCartMode,
		paymentResultDisplayMode: 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,
		shopDiscount: state.shop_discount,
		client: (_state$client5 = state.client) === null || _state$client5 === void 0 ? void 0 : _state$client5.value,
		currentTotalPrice: total.productAmount,
		onChangeShopDiscount: (discount) => {
			dispatch({
				type: "setState",
				payload: { shop_discount: new Decimal(discount || 0).toDecimalPlaces(2, Decimal.ROUND_DOWN).toString() }
			});
		},
		onChangeOrderNote: handleNoteConfirm,
		onDeleteOrderNote: handleNoteDelete,
		onClose: (reset) => {
			setIsPaymentModalOpen(false);
			setPaymentModalData(null);
			setPaymentCallback(null);
			setEditOrderId(0);
			dispatch({
				type: "setPaymentPaid",
				payload: { value: {} }
			});
			if (reset) setTimeout(() => {
				handleClearAllAndReset();
			}, 0);
		}
	}), /* @__PURE__ */ React.createElement(ConfirmHolderModal, null));
};
//#endregion
export { Footer as default };
