const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_index = require("../PaymentMethods/WalletPass/index.js");
const require_index$1 = require("./components/WalletAvailable/index.js");
const require_index$2 = require("./components/WalletUseList/index.js");
const require_index$3 = require("./components/WalletBestValueFound/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/components/pay/toC/WalletPassBlock/index.tsx
const _excluded = [
	"className",
	"payGroup",
	"onWalletPassChange",
	"customer_id",
	"walletSetting"
];
const WalletPassBlock = (props, ref) => {
	var _payGroup$walletPass, _payGroup$walletPass4, _payGroup$walletPass5, _payGroup$walletPass6, _payGroup$walletPass7;
	const { className, payGroup, onWalletPassChange, customer_id, walletSetting } = props, others = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const walletPassRef = (0, react.useRef)(null);
	const walletAvailableRef = (0, react.useRef)(null);
	const walletBestValueFoundRef = (0, react.useRef)(null);
	const [isViewDetail, setIsViewDetail] = (0, react.useState)(false);
	const contentRef = (0, react.useRef)(null);
	const [contentHeight, setContentHeight] = (0, react.useState)(0);
	(0, react.useEffect)(() => {
		if (contentRef.current) {
			const scrollHeight = contentRef.current.scrollHeight;
			setContentHeight(isViewDetail ? scrollHeight : 0);
		}
	}, [isViewDetail, payGroup === null || payGroup === void 0 || (_payGroup$walletPass = payGroup.walletPass) === null || _payGroup$walletPass === void 0 ? void 0 : _payGroup$walletPass.cards]);
	const handleClick = () => {
		var _walletPassRef$curren;
		setIsViewDetail(false);
		(_walletPassRef$curren = walletPassRef.current) === null || _walletPassRef$curren === void 0 || _walletPassRef$curren.init(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, payGroup), {}, { customer_id }));
	};
	const hasNoWalletPassAmount = (0, react.useMemo)(() => {
		var _payGroup$walletPass2, _payGroup$walletPass3;
		return !(payGroup === null || payGroup === void 0 || (_payGroup$walletPass2 = payGroup.walletPass) === null || _payGroup$walletPass2 === void 0 ? void 0 : _payGroup$walletPass2.amount) || (payGroup === null || payGroup === void 0 || (_payGroup$walletPass3 = payGroup.walletPass) === null || _payGroup$walletPass3 === void 0 ? void 0 : _payGroup$walletPass3.amount) == 0;
	}, [payGroup === null || payGroup === void 0 || (_payGroup$walletPass4 = payGroup.walletPass) === null || _payGroup$walletPass4 === void 0 ? void 0 : _payGroup$walletPass4.amount]);
	(0, react.useImperativeHandle)(ref, () => ({ open: () => {
		if (hasNoWalletPassAmount) {
			var _walletAvailableRef$c;
			(_walletAvailableRef$c = walletAvailableRef.current) === null || _walletAvailableRef$c === void 0 || _walletAvailableRef$c.open();
		} else {
			var _walletBestValueFound;
			(_walletBestValueFound = walletBestValueFoundRef.current) === null || _walletBestValueFound === void 0 || _walletBestValueFound.open();
		}
	} }));
	const handleViewDetail = (e) => {
		e.stopPropagation();
		setIsViewDetail(!isViewDetail);
	};
	const handleUnused = () => {
		onWalletPassChange === null || onWalletPassChange === void 0 || onWalletPassChange({
			cards: [],
			amount: 0
		});
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, others), {}, { className: (0, classnames.default)("wallet-pass-wrap", className) }), /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-title" }, _pisell_utils.locales.getText("tocPay.text.howToPay")), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellRow, {
		className: "wallet-pass-card",
		centerContent: /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-title" }, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-title-left" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
			type: "pisell2-a-wallet-021",
			className: "wallet-pass-card-title-left-icon"
		}), walletSetting.name), walletSetting.popup_status === 1 && /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-title-right" }, /* @__PURE__ */ react.default.createElement("span", { className: "wallet-pass-card-title-right-amount" }, "-", /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellText.Amount, { value: payGroup === null || payGroup === void 0 || (_payGroup$walletPass5 = payGroup.walletPass) === null || _payGroup$walletPass5 === void 0 ? void 0 : _payGroup$walletPass5.amount })), /* @__PURE__ */ react.default.createElement(_ant_design_icons.CaretRightOutlined, { className: "wallet-pass-card-title-right-icon" }))), walletSetting.popup_status === 0 && /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-desc-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-desc" }, hasNoWalletPassAmount ? _pisell_utils.locales.getText("tocPay.text.hasNoWalletPassAmount") : _pisell_utils.locales.getText("tocPay.text.bestValueFound")), !hasNoWalletPassAmount && /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-total-savings" }, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-total-savings-title" }, /* @__PURE__ */ react.default.createElement("span", { className: "wallet-pass-card-total-savings-title-left" }, _pisell_utils.locales.getText("tocPay.text.totalSavings"), ":", /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellText.Amount, { value: payGroup === null || payGroup === void 0 || (_payGroup$walletPass6 = payGroup.walletPass) === null || _payGroup$walletPass6 === void 0 ? void 0 : _payGroup$walletPass6.amount })), /* @__PURE__ */ react.default.createElement("span", {
			className: "wallet-pass-card-total-savings-title-right",
			onClick: handleViewDetail
		}, _pisell_utils.locales.getText("tocPay.text.viewDetail"), /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, {
			type: "pisell2-chevron-down",
			className: (0, classnames.default)("wallet-pass-card-total-savings-title-right-icon", { "is-rotate": isViewDetail })
		}))), /* @__PURE__ */ react.default.createElement("div", {
			ref: contentRef,
			className: "wallet-pass-card-total-savings-desc",
			style: { height: contentHeight }
		}, /* @__PURE__ */ react.default.createElement(require_index$2.default, { walletPass: (payGroup === null || payGroup === void 0 || (_payGroup$walletPass7 = payGroup.walletPass) === null || _payGroup$walletPass7 === void 0 ? void 0 : _payGroup$walletPass7.cards) || [] })))), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			size: "large",
			className: "wallet-pass-card-to-use",
			type: "primary",
			block: true,
			rightIcon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-arrow-right",
				className: "wallet-pass-card-icon"
			})
		}, _pisell_utils.locales.getText(hasNoWalletPassAmount ? "tocPay.text.useWalletPass" : "tocPay.text.editWalletPass")(walletSetting.name)))),
		padding: 16,
		gap: 4,
		onClick: handleClick
	}), ((payGroup === null || payGroup === void 0 ? void 0 : payGroup.wait_amount) || 0) == 0 && /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-complete-title" }, _pisell_utils.locales.getText("tocPay.text.walletPassCompleteTitle")), /* @__PURE__ */ react.default.createElement("div", { className: "wallet-pass-card-complete-no-extre-pay" }, _pisell_utils.locales.getText("tocPay.text.walletPassNoExtraPay")))), /* @__PURE__ */ react.default.createElement(require_index.default, {
		ref: walletPassRef,
		walletSetting,
		onWalletPassChange,
		walletPass: payGroup === null || payGroup === void 0 ? void 0 : payGroup.walletPass,
		orderDetail: payGroup === null || payGroup === void 0 ? void 0 : payGroup.orderDetail,
		total_amount: payGroup === null || payGroup === void 0 ? void 0 : payGroup.total_amount
	}), /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		ref: walletAvailableRef,
		walletSetting,
		payGroup,
		onOk: handleClick
	}), /* @__PURE__ */ react.default.createElement(require_index$3.default, {
		ref: walletBestValueFoundRef,
		walletSetting,
		payGroup,
		onEdit: handleClick,
		onUnused: handleUnused
	}));
};
var WalletPassBlock_default = (0, react.forwardRef)(WalletPassBlock);
//#endregion
exports.default = WalletPassBlock_default;
