import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { ECupActionType } from "../../types.js";
import CupInfoCard from "../CupInfoCard/index.js";
import CustomerCard from "../CustomerCard/index.js";
import { useCupAction } from "./hooks.js";
import React, { useMemo } from "react";
import { locales } from "@pisell/utils";
import { Icon, PisellModal, PisellToast } from "@pisell/materials";
import "./index.less";
//#region src/components/ecocup/components/CupActionModal/index.tsx
const CupActionModal = (props) => {
	var _cupData$rent_shop;
	const { visible, onCancel, onOk, data } = props;
	const { type, cupData } = data || {};
	const cupAction = useCupAction();
	const style = useMemo(() => {
		if ((data === null || data === void 0 ? void 0 : data.type) === ECupActionType.MISSING || (data === null || data === void 0 ? void 0 : data.type) === ECupActionType.BROKEN) return {
			backgroundColor: "#FEE4E2",
			color: "#F04438"
		};
		return {
			backgroundColor: "#F6F2FF",
			color: "#7F56DA"
		};
	}, [data === null || data === void 0 ? void 0 : data.type]);
	const _onCancel = () => {
		if (cupAction === null || cupAction === void 0 ? void 0 : cupAction.loading) return;
		onCancel === null || onCancel === void 0 || onCancel();
	};
	const _onOk = () => {
		if (cupAction === null || cupAction === void 0 ? void 0 : cupAction.loading) return;
		cupAction.run((cupData === null || cupData === void 0 ? void 0 : cupData.eco_cup_id) || (cupData === null || cupData === void 0 ? void 0 : cupData.id), type).then((res) => {
			if (res) {
				PisellToast({ content: locales.getText(`pisell2.text.ecocup.toast.success-${type}`) });
				onOk === null || onOk === void 0 || onOk(cupData);
			}
		});
	};
	return /* @__PURE__ */ React.createElement(PisellModal, {
		open: visible,
		headerDivider: false,
		title: locales.getText(`pisell2.text.ecocup.cup-action-modal.title-${data === null || data === void 0 ? void 0 : data.type}`),
		onCancel: _onCancel,
		onOk: _onOk,
		okText: locales.getText(`pisell2.text.ecocup.button.mark-as-${data === null || data === void 0 ? void 0 : data.type}`),
		cancelText: locales.getText("pisell2.text.ecocup.button.cancel"),
		okButtonProps: { loading: cupAction === null || cupAction === void 0 ? void 0 : cupAction.loading },
		width: 580,
		destroyOnClose: true,
		wrapClassName: "pisell2-ecocup-cup-action-modal"
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-modal-content" }, /* @__PURE__ */ React.createElement("div", {
		className: "pisell2-ecocup-cup-action-modal-content-cup",
		style: _objectSpread2({}, style)
	}, /* @__PURE__ */ React.createElement(Icon, {
		type: "RestOutlined",
		size: 24
	}), /* @__PURE__ */ React.createElement("span", { style: { color: (data === null || data === void 0 ? void 0 : data.type) === ECupActionType.RETURN ? "#667085" : "#F04438" } }, locales.getText("pisell2.text.ecocup.cup-action-modal.cup-id")), /* @__PURE__ */ React.createElement("span", null, (cupData === null || cupData === void 0 ? void 0 : cupData.eco_cup_code) || (cupData === null || cupData === void 0 ? void 0 : cupData.code) || "")), /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-modal-info" }, /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-modal-info-left" }, /* @__PURE__ */ React.createElement(CupInfoCard, {
		type: "rentInfo",
		data: {
			shop: cupData === null || cupData === void 0 || (_cupData$rent_shop = cupData.rent_shop) === null || _cupData$rent_shop === void 0 ? void 0 : _cupData$rent_shop.name,
			time: cupData === null || cupData === void 0 ? void 0 : cupData.rent_time
		}
	})), /* @__PURE__ */ React.createElement("div", { className: "pisell2-ecocup-cup-action-modal-info-right" }, /* @__PURE__ */ React.createElement(CustomerCard, data === null || data === void 0 ? void 0 : data.customerData)))));
};
//#endregion
export { CupActionModal as default };
