const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../../../../pro/priceKeyboard/components/paymentKeyboard/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/components/checkout/components/PaymentOptionsModule/PaymentMethodItem.tsx
const PaymentMethodItem = ({ method, amountSymbol, customAmount, disabled = false, onClick, getText, size = "default" }) => {
	const [isKeyboardVisible, setIsKeyboardVisible] = (0, react.useState)(false);
	const calculateSurcharge = (method) => {
		if (!(method === null || method === void 0 ? void 0 : method.is_surcharge)) return 0;
		const baseAmount = Number(customAmount) || 0;
		if (Number(method.percentage)) return baseAmount * Number(method.percentage) + Number(method.fixed || 0);
		return Number(method.fixed || 0);
	};
	const handleRightButtonClick = (e) => {
		if (!isEftpos) return;
		e.preventDefault();
		if (disabled || !onClick) return;
		onClick(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, method), {}, { surcharge: String((0, _pisell_utils.formatAmount)(calculateSurcharge(method), 2, amountSymbol)) }));
	};
	const renderPaymentIcon = (method) => {
		if (method.code === "EFTPOS") return /* @__PURE__ */ react.default.createElement("div", {
			className: (0, classnames.default)("payment-options-module-icon-container"),
			style: { background: "#FE8279" }
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: "pisell2-credit",
			style: {
				fontSize: "26px",
				color: "#ffffff"
			}
		}));
		switch (String(method.type)) {
			case "credit-card":
			case "eftpos": return /* @__PURE__ */ react.default.createElement("div", {
				className: (0, classnames.default)("payment-options-module-icon-container"),
				style: { background: "#FE8279" }
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-credit",
				style: {
					fontSize: "26px",
					color: "#ffffff"
				}
			}));
			default: return /* @__PURE__ */ react.default.createElement("div", {
				className: (0, classnames.default)("payment-options-module-icon-container"),
				style: { background: "#D277E4" }
			}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-custom",
				style: {
					fontSize: "26px",
					color: "#ffffff"
				}
			}));
		}
	};
	const isEftpos = method.code === "EFTPOS" || method.type === "eftpos";
	const showKeyboard = () => {
		if (isEftpos) return;
		setIsKeyboardVisible(true);
	};
	const renderLeftContent = () => /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-payment-method-left") }, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-icon-container") }, renderPaymentIcon(method)), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-payment-info") }, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-payment-info-inner") }, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-payment-name") }, method.name), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-payment-info-inner-surcharge") }, !!(method === null || method === void 0 ? void 0 : method.is_surcharge) && calculateSurcharge(method) !== 0 && /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-surcharge-text") }, (getText === null || getText === void 0 ? void 0 : getText("pisell2.payment-options.surcharge-label", "Surcharge")) || "Surcharge", ":", (0, _pisell_utils.formatAmount)(calculateSurcharge(method), 2, amountSymbol)), false))));
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("button", {
		className: (0, classnames.default)("payment-options-module-payment-method-item", {
			"payment-options-module-pointer": !disabled,
			"payment-options-module-disabled": disabled
		}),
		style: { height: size === "large" ? "82px" : "62px" },
		onClick: showKeyboard,
		type: "button",
		disabled
	}, renderLeftContent(), /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("payment-options-module-payment-method-right"),
		onClick: handleRightButtonClick
	}, isEftpos ? /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		className: (0, classnames.default)("payment-options-module-pay-button"),
		disabled
	}, getText === null || getText === void 0 ? void 0 : getText("pay", "Pay")) : /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-selection-button") }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-a-arrow-circle-right2",
		style: {
			fontSize: "30px",
			color: disabled ? "#D0D5DD" : "#7F56DA"
		}
	})))), /* @__PURE__ */ react.default.createElement(require_index.default, {
		containerProps: {
			renderType: "modal",
			open: isKeyboardVisible,
			onCancel: () => setIsKeyboardVisible(false)
		},
		paymentOriginalValue: String(customAmount || 0),
		paymentDefaultValue: String(customAmount || 0),
		enableExceedMaxAmount: !isEftpos,
		payment: { enable: true },
		surcharge: { enable: !!(method === null || method === void 0 ? void 0 : method.is_surcharge) && calculateSurcharge(method) !== 0 },
		surchargeDefaultValue: {
			percent: method.percentage ? String(Number(method.percentage) * 100) : "",
			fixed: method.fixed ? String(method.fixed) : ""
		},
		selectType: "dark",
		onChange: (value) => {
			console.log(value);
		},
		onPay: (args) => {
			console.log(args);
			setIsKeyboardVisible(false);
			if (onClick) {
				var _args$surcharge, _args$surcharge2;
				onClick(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, method), {}, {
					fixed: Number(((_args$surcharge = args.surcharge) === null || _args$surcharge === void 0 ? void 0 : _args$surcharge.fixed) || 0),
					percentage: ((_args$surcharge2 = args.surcharge) === null || _args$surcharge2 === void 0 ? void 0 : _args$surcharge2.percent) ? Number(args.surcharge.percent) / 100 : 0,
					totalAmount: String((0, _pisell_utils.formatAmount)(args.amount, 2))
				}));
			}
		}
	}));
};
//#endregion
exports.default = PaymentMethodItem;
