const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../locales/index.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index$1 = require("../pisellCard/index.js");
const require_index$2 = require("../pisellModal/index.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index$3 = require("../pisellText/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
require("./index.less");
//#region src/components/pisellGoodPassCard/index.tsx
const clsPrefix = "pisell-good-pass-card";
const index = (props) => {
	var _context$appHelper;
	const { translation } = (_context$appHelper = require_useEngineContext.default().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const { dataSource = [], onChange, style = {}, mixedSort } = props;
	const [showModal, setShowModal] = (0, react.useState)(false);
	console.log("pisell good card datasource", dataSource);
	const handleChange = (newValue) => {
		if (onChange) onChange(newValue);
	};
	const handleItemChange = (item, checked) => {
		handleChange({
			id: item.id,
			isSelected: checked
		});
	};
	const renderVoucherContent = (item) => {
		return /* @__PURE__ */ react.default.createElement("span", { className: `voucher-item-content-save` }, require_index.getText("pisell2.text.goodpass.save"), " ", /* @__PURE__ */ react.default.createElement(require_index$3.default.Amount, { value: item.savedAmount }));
	};
	const renderActionElement = (item) => {
		const isChecked = item.isSelected;
		return /* @__PURE__ */ react.default.createElement(antd.Checkbox, {
			disabled: item.isDisabled,
			style: { marginLeft: 8 },
			checked: isChecked,
			onChange: (e) => handleItemChange(item, e.target.checked)
		}, renderVoucherContent(item));
	};
	const renderVoucherItem = (item) => {
		return /* @__PURE__ */ react.default.createElement("div", {
			key: item.id,
			className: `${clsPrefix}-voucher-item`
		}, /* @__PURE__ */ react.default.createElement("div", { className: "item-title" }, translation(item.format_title), item.isEditMode && require_index.getText("pisell2.text.goodpass.last-settlement")), /* @__PURE__ */ react.default.createElement("div", { className: "item-content" }, renderActionElement(item)));
	};
	const renderModal = () => {
		return /* @__PURE__ */ react.default.createElement(require_index$2.default, {
			title: require_index.getText("pisell2.text.goodpass.product-vouchers"),
			footer: null,
			open: showModal,
			onCancel: () => setShowModal(false),
			className: `${clsPrefix}-all-items-modal`
		}, /* @__PURE__ */ react.default.createElement("div", { style: {
			padding: "10px 0",
			display: "flex",
			flexDirection: "column",
			gap: 12
		} }, dataSource.map(renderVoucherItem)));
	};
	const renderMixedMode = () => {
		const sortList = (mixedSort === null || mixedSort === void 0 ? void 0 : mixedSort(dataSource)) || dataSource;
		const list = sortList.length > 3 ? sortList.slice(0, 3) : sortList;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: `${clsPrefix}-header` }, /* @__PURE__ */ react.default.createElement("div", null, require_index.getText("pisell2.text.goodpass.product-vouchers")), /* @__PURE__ */ react.default.createElement(antd.Typography.Text, {
			underline: true,
			onClick: () => setShowModal(true)
		}, require_index.getText("pisell2.text.goodpass.view-more"))), /* @__PURE__ */ react.default.createElement(antd.Divider, { style: { margin: 4 } }), /* @__PURE__ */ react.default.createElement("div", { className: `${clsPrefix}-body` }, list.map(renderVoucherItem)));
	};
	const renderModalMode = () => {
		const sortList = (mixedSort === null || mixedSort === void 0 ? void 0 : mixedSort(dataSource)) || dataSource;
		if (sortList.length === 0) return null;
		return /* @__PURE__ */ react.default.createElement("div", { style: {
			padding: "10px 0",
			display: "flex",
			flexDirection: "column",
			gap: 12
		} }, sortList.map(renderVoucherItem));
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, !props.isInModal ? renderModal() : null, dataSource.length > 0 ? /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		padding: 8,
		borderRadius: 8,
		style: require_objectSpread2._objectSpread2({ width: 378 }, style),
		className: clsPrefix
	}, props.isInModal ? renderModalMode() : renderMixedMode()) : null);
};
//#endregion
exports.default = index;
