const require_runtime = require("../../../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../../../hooks/useEngineContext.js");
const require_index = require("../../../../../shoppingCart/index.js");
const require_index$1 = require("../../../../../Sales/Step/index.js");
const require_index$2 = require("../../../../../Sales/Cart/index.js");
const require_index$3 = require("../../../../../Sales/Holder/index.js");
const require_index$4 = require("../../../../../Sales/Summary/index.js");
const require_SelectHolderModal = require("../../SelectHolderModal.js");
const require_index$5 = require("../ContinueButton/index.js");
const require_index$6 = require("../../../../../subTotal/index.js");
const require_index$7 = require("../Deposit/index.js");
const require_index$8 = require("../../../Voucher/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/eventBooking/components/Provider/Cart/Item/index.tsx
const CartItem = () => {
	var _context$appHelper, _cartData$cartItems2;
	const { open, holderData, selectedHolderIds } = require_index$3.useHolder();
	const { deleteCartItem, deleteCartItemByHolder, cartData, addNoteToCartItem } = require_index$2.useCart();
	const { taxTitle, taxRate, totalTaxFee, isPriceIncludeTax, total, deposit, subtotal, surcharge } = require_index$4.useSummary();
	const { isLastStep } = require_index$1.useStep();
	const context = require_useEngineContext.default();
	const { translation } = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const handleClickCard = (e, type, key) => {
		if (type === "note") return addNoteToCartItem(e);
		if (type === "delete") return deleteCartItem(e);
		if (type === "delete_holders") return deleteCartItemByHolder(key);
	};
	/**
	* @description: 是否显示定金
	* @param {*} useMemo
	* @return {*}
	*/
	const showDeposit = (0, react.useMemo)(() => {
		var _cartData$cartItems;
		return (cartData === null || cartData === void 0 || (_cartData$cartItems = cartData.cartItems) === null || _cartData$cartItems === void 0 ? void 0 : _cartData$cartItems.length) > 0 && (deposit === null || deposit === void 0 ? void 0 : deposit.hasDeposit);
	}, [cartData === null || cartData === void 0 || (_cartData$cartItems2 = cartData.cartItems) === null || _cartData$cartItems2 === void 0 ? void 0 : _cartData$cartItems2.length, deposit === null || deposit === void 0 ? void 0 : deposit.hasDeposit]);
	/**
	* @description: 结算列表数据
	* @param {*} useMemo
	* @return {*}
	*/
	const subTotalList = (0, react.useMemo)(() => {
		const surchargeList = ((surcharge === null || surcharge === void 0 ? void 0 : surcharge.surchargeList) || []).map((d, index) => {
			return {
				key: `custom_surcharge_${index}`,
				label: translation(d === null || d === void 0 ? void 0 : d.name),
				value: d.amount
			};
		});
		return [
			{
				key: "deposit",
				value: deposit === null || deposit === void 0 ? void 0 : deposit.total,
				label: _pisell_utils.locales.getText("pisell2.appointment.deposit"),
				hidden: !showDeposit
			},
			{
				key: "sub_total",
				value: subtotal
			},
			...surchargeList,
			{
				key: "tax",
				value: totalTaxFee,
				hidden: Number(totalTaxFee) <= 0,
				tax: {
					rate: taxRate,
					is_price_include_tax: isPriceIncludeTax,
					title: taxTitle
				}
			},
			{
				key: "custom_total",
				value: total,
				label: _pisell_utils.locales.getText("pisell2.event.total"),
				bold: !showDeposit
			}
		];
	}, [
		total,
		subtotal,
		surcharge === null || surcharge === void 0 ? void 0 : surcharge.surchargeList,
		deposit === null || deposit === void 0 ? void 0 : deposit.total,
		taxRate,
		isPriceIncludeTax,
		totalTaxFee,
		taxTitle,
		showDeposit
	]);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: `cart-item-wrap ${(0, _pisell_utils.isMobile)() ? "cart-mobile-item-wrap" : ""}` }, /* @__PURE__ */ react.default.createElement("div", { className: "content" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		productParams: {
			products: (cartData === null || cartData === void 0 ? void 0 : cartData.cartItems) || [],
			hideAddBtn: false,
			holders: (holderData === null || holderData === void 0 ? void 0 : holderData.selectedHolderItems) || [],
			disabledEdit: isLastStep
		},
		collapseParams: {
			activeKey: selectedHolderIds,
			ghost: true
		},
		platform: "h5",
		emptyText: _pisell_utils.locales.getText("pisell2.event.empty.service"),
		isOpenGroup: !!(selectedHolderIds === null || selectedHolderIds === void 0 ? void 0 : selectedHolderIds.length),
		onChange: (e, type, key) => handleClickCard(e, type, key)
	})), /* @__PURE__ */ react.default.createElement("div", { className: "event-footer" }, /* @__PURE__ */ react.default.createElement(require_index$8.default, null), /* @__PURE__ */ react.default.createElement(require_index$6.default, {
		list: subTotalList,
		style: { padding: 0 },
		children: showDeposit ? /* @__PURE__ */ react.default.createElement(require_index$7.default, { showTitle: false }) : null
	}), /* @__PURE__ */ react.default.createElement(require_index$5.default, null))), /* @__PURE__ */ react.default.createElement(require_SelectHolderModal.default, { open }));
};
//#endregion
exports.default = CartItem;
