const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_hooks = require("../../hooks.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let decimal_js = require("decimal.js");
decimal_js = require_runtime.__toESM(decimal_js);
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/components/pay/toB/components/ConfirmedPayment/index.tsx
const ConfirmedPayment = (props) => {
	const { data, onVoidPayment } = props;
	const symbol = require_hooks.useSymbol();
	const getTotalAmount = (item) => {
		const amount = new decimal_js.default((item === null || item === void 0 ? void 0 : item.amount) || 0);
		const surcharge = getSurcharge(item);
		return amount.add(surcharge).toFixed(2).toString();
	};
	const getSurcharge = (item) => {
		var _item$service_charge, _item$service_charge2;
		const amount = new decimal_js.default((item === null || item === void 0 ? void 0 : item.amount) || 0);
		let surcharge = new decimal_js.default(0);
		if (item === null || item === void 0 || (_item$service_charge = item.service_charge) === null || _item$service_charge === void 0 ? void 0 : _item$service_charge.percentage) surcharge = amount.mul(item.service_charge.percentage);
		if (item === null || item === void 0 || (_item$service_charge2 = item.service_charge) === null || _item$service_charge2 === void 0 ? void 0 : _item$service_charge2.amount) surcharge = surcharge.add(item.service_charge.amount);
		return surcharge.toFixed(2).toString();
	};
	const handleVoidPayment = (paymentItem) => {
		onVoidPayment === null || onVoidPayment === void 0 || onVoidPayment(paymentItem);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment" }, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-title" }, _pisell_utils.locales.getText("tobPay.text.confirmed.payment")), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-list" }, data.map((item) => {
		const totalAmount = getTotalAmount(item);
		const surcharge = getSurcharge(item);
		const canVoid = item.isSynced !== true;
		return /* @__PURE__ */ react.default.createElement("div", {
			key: item.uuid,
			className: "tob-pay-confirmed-payment-item"
		}, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-item-left" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: "icona-zu6491",
			style: {
				marginTop: "-2px",
				fontSize: "24px",
				color: "var(--theme-color)"
			}
		}), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-item-left-content" }, /* @__PURE__ */ react.default.createElement("span", { className: "tob-pay-confirmed-payment-item-name" }, item.name), item.created_at && /* @__PURE__ */ react.default.createElement("span", { className: "tob-pay-confirmed-payment-item-time" }, item.created_at))), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-item-right" }, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-confirmed-payment-item-right-info" }, /* @__PURE__ */ react.default.createElement("span", { className: "tob-pay-confirmed-payment-item-amount" }, symbol, totalAmount), Number(surcharge) > 0 && /* @__PURE__ */ react.default.createElement("span", { className: "tob-pay-confirmed-payment-item-surcharge" }, _pisell_utils.locales.getText("tobPay.text.payment.with.surcharge"), ":", " ", symbol, surcharge)), canVoid && /* @__PURE__ */ react.default.createElement(antd.Button, { onClick: () => handleVoidPayment(item) }, "Void")));
	})));
};
//#endregion
exports.default = ConfirmedPayment;
