import { useModal } from "../../hooks.js";
import { ECupActionType, ECupStatus } from "../../types.js";
import CupActionModal from "../CupActionModal/index.js";
import MoreDropdown from "../MoreDropdown/index.js";
import dayjs from "dayjs";
import React, { useMemo } from "react";
import { locales } from "@pisell/utils";
import { Button, Icon } from "@pisell/materials";
import "./index.less";
//#region src/components/ecocup/components/CupActionList/index.tsx
const CupActionList = (props) => {
	const { maxNum, currentNum, cups, customerData, onClearAll, onRemove, onAction } = props;
	const cupActionModal = useModal("ecocup-cup-action-modal");
	const isOverMax = useMemo(() => {
		return currentNum > maxNum;
	}, [currentNum, maxNum]);
	const handleAction = (type, cup) => {
		cupActionModal.open({
			data: {
				type,
				cupData: cup,
				customerData
			},
			onOk: () => {
				onAction(type, cup);
			}
		});
	};
	return /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list" }, isOverMax && /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-over-max" }, /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.text.ecocup.customer-first-modal.over-max").replace("{{num}}", (currentNum - maxNum).toString())), /* @__PURE__ */ React.createElement("span", { onClick: onClearAll }, locales.getText("pisell2.text.ecocup.button.clear-all"))), /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-cup-list" }, cups.map((cup) => {
		var _cup$rent_shop;
		const isInStock = (cup === null || cup === void 0 ? void 0 : cup.status) === ECupStatus.IN_STOCK;
		return /* @__PURE__ */ React.createElement("div", {
			key: cup.code,
			className: "pisell2-ecocup-cup-action-list-cup",
			style: isInStock ? {
				backgroundColor: "#F6F2FF",
				border: "1px solid #F6F2FF"
			} : { border: "1px solid #D0D5DD" }
		}, /* @__PURE__ */ React.createElement(Icon, {
			type: "RestOutlined",
			size: 24,
			color: "#7F56DA"
		}), /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-cup-info" }, /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-cup-info-top" }, /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.text.ecocup.cup-id")), /* @__PURE__ */ React.createElement("span", null, (cup === null || cup === void 0 ? void 0 : cup.eco_cup_code) || (cup === null || cup === void 0 ? void 0 : cup.code) || "-")), !isInStock && /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-cup-info-bottom" }, /* @__PURE__ */ React.createElement("span", null, (cup === null || cup === void 0 || (_cup$rent_shop = cup.rent_shop) === null || _cup$rent_shop === void 0 ? void 0 : _cup$rent_shop.name) || "-"), /* @__PURE__ */ React.createElement("span", null, (cup === null || cup === void 0 ? void 0 : cup.rent_time) ? dayjs(cup === null || cup === void 0 ? void 0 : cup.rent_time).format("DD/MM/YYYY") : "-"))), isInStock ? /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			icon: /* @__PURE__ */ React.createElement(Icon, {
				type: "pisell2-trash-01",
				size: 24,
				color: "#7F56DA"
			}),
			onClick: () => onRemove(cup),
			className: "pisell2-ecocup-cup-action-list-cup-info-remove"
		}, locales.getText("pisell2.text.ecocup.button.remove")) : /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-list-cup-info-actions" }, /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			onClick: () => handleAction(ECupActionType.RETURN, cup)
		}, "Return"), /* @__PURE__ */ React.createElement(MoreDropdown, {
			locales,
			onClick: (key) => handleAction(key, cup),
			buttonText: locales.getText("pisell2.text.ecocup.button.others")
		})));
	})), (cupActionModal === null || cupActionModal === void 0 ? void 0 : cupActionModal.visible) && /* @__PURE__ */ React.createElement(CupActionModal, cupActionModal === null || cupActionModal === void 0 ? void 0 : cupActionModal.modalProps));
};
//#endregion
export { CupActionList as default };
