const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
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/plus/walletEditor/components/sortableWalletPassTypes/index.tsx
const { Editable } = _pisell_materials.PisellText;
const WALLET_PASS_TYPES = [
	"rechargeable",
	"point",
	"voucher",
	"discount"
];
const DEFAULT_WALLET_PASS_TYPES_CONFIG = [
	{
		type: "rechargeable",
		custom_title: {
			original: "Balance",
			en: "Balance",
			"zh-CN": "余额",
			"zh-HK": "餘額",
			"ja": "残高",
			"pt": "Saldo"
		}
	},
	{
		type: "point",
		custom_title: {
			original: "Points",
			en: "Points",
			"zh-CN": "积分",
			"zh-HK": "積分",
			"ja": "ポイント",
			"pt": "Pontos"
		}
	},
	{
		type: "voucher",
		custom_title: {
			original: "Voucher",
			en: "Voucher",
			"zh-CN": "代金券",
			"zh-HK": "代金券",
			"ja": "クーポン",
			"pt": "Cupom"
		}
	},
	{
		type: "discount",
		custom_title: {
			original: "Discount",
			en: "Discount",
			"zh-CN": "折扣券",
			"zh-HK": "折扣券",
			"ja": "割引カード",
			"pt": "Cartão de desconto"
		}
	}
];
const SortableWalletPassTypes = (props) => {
	const { value = [], onChange, disabled = false, className, style } = props;
	const dataSource = (0, react.useMemo)(() => {
		const result = [];
		const processedTypes = /* @__PURE__ */ new Set();
		value.forEach((item) => {
			if (WALLET_PASS_TYPES.includes(item.type) && !processedTypes.has(item.type)) {
				result.push(item);
				processedTypes.add(item.type);
			}
		});
		DEFAULT_WALLET_PASS_TYPES_CONFIG.forEach((defaultType) => {
			if (!processedTypes.has(defaultType.type)) result.push({
				type: defaultType.type,
				display: 0,
				custom_title: defaultType.custom_title
			});
		});
		return result;
	}, [value]);
	const handleSortChange = (0, react.useCallback)((newList) => {
		if (!onChange || disabled) return;
		onChange(newList);
	}, [onChange, disabled]);
	const handleToggleDisplay = (0, react.useCallback)((index) => {
		if (!onChange || disabled) return;
		const newList = [...dataSource];
		newList[index] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, newList[index]), {}, { display: newList[index].display === 1 ? 0 : 1 });
		onChange(newList);
	}, [
		dataSource,
		onChange,
		disabled
	]);
	const handleTitleChange = (0, react.useCallback)((index, newTitle) => {
		if (!onChange || disabled) return;
		const newList = [...dataSource];
		newList[index] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, newList[index]), {}, { custom_title: typeof newTitle === "string" ? {
			original: newTitle,
			en: newTitle
		} : newTitle });
		onChange(newList);
	}, [
		dataSource,
		onChange,
		disabled
	]);
	const getDisplayTitle = (0, react.useCallback)((item) => {
		const defaultType = DEFAULT_WALLET_PASS_TYPES_CONFIG.find((t) => t.type === item.type);
		return item.custom_title || (defaultType === null || defaultType === void 0 ? void 0 : defaultType.custom_title) || {
			original: item.type,
			en: item.type
		};
	}, []);
	const renderItem = (0, react.useCallback)((item, index) => {
		const displayTitle = getDisplayTitle(item);
		const isVisible = item.display === 1;
		return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("sortable-wallet-pass-item", {
			"sortable-wallet-pass-item-disabled": disabled,
			"sortable-wallet-pass-item-hidden": !isVisible
		}) }, /* @__PURE__ */ react.default.createElement("div", { className: "sortable-wallet-pass-drag-handle" }, /* @__PURE__ */ react.default.createElement(_ant_design_icons.HolderOutlined, {
			className: "drag-dots",
			size: 20
		})), /* @__PURE__ */ react.default.createElement("div", { className: "sortable-wallet-pass-title" }, /* @__PURE__ */ react.default.createElement(Editable, {
			value: displayTitle,
			editable: !disabled && { maxLength: 10 },
			onChange: (newValue) => handleTitleChange(index, newValue)
		})), /* @__PURE__ */ react.default.createElement("div", { className: "sortable-wallet-pass-toggle" }, /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			style: {
				cursor: "pointer",
				border: "none",
				background: "transparent"
			},
			onClick: () => handleToggleDisplay(index)
		}, isVisible ? /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeOutlined, { className: "eye-icon eye-icon-visible" }) : /* @__PURE__ */ react.default.createElement(_ant_design_icons.EyeInvisibleOutlined, { className: "eye-icon eye-icon-hidden" }))));
	}, [
		disabled,
		getDisplayTitle,
		handleTitleChange,
		handleToggleDisplay
	]);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("sortable-wallet-pass-types", className, { "sortable-wallet-pass-types-disabled": disabled }),
		style
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.SortableList, {
		dataSource,
		onChange: handleSortChange,
		rowKey: "type",
		renderItem,
		activationConstraint: { distance: 5 }
	}));
};
//#endregion
exports.DEFAULT_WALLET_PASS_TYPES_CONFIG = DEFAULT_WALLET_PASS_TYPES_CONFIG;
exports.default = SortableWalletPassTypes;
