const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_hooks = require("../../hooks.js");
const require_utils = require("../../store/utils.js");
const require_hooks$1 = require("../../store/hooks.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/components/pay/toB/components/Cache/index.tsx
const ToBPayCache = (props) => {
	const { open, title, uuid, expect_amount = "", onCancel, onOk } = props;
	const osPayment = require_hooks$1.useOSPayment();
	const symbol = require_hooks.useSymbol();
	const [inputAmount, setInputAmount] = (0, react.useState)(expect_amount);
	const [payDesc, setPayDesc] = (0, react.useState)("");
	(0, react.useEffect)(() => {
		setInputAmount(expect_amount);
	}, [expect_amount]);
	(0, react.useEffect)(() => {
		osPayment.getRemainingOrderAmountWithInputAsync(inputAmount, uuid).then((res) => {
			if (Number(res) === 0) setPayDesc(_pisell_utils.locales.getText("tobPay.text.cash.modal.no.change.given"));
			if (Number(res) < 0) setPayDesc(_pisell_utils.locales.getText("tobPay.text.cash.modal.amount.pay.change")(`${symbol}${Math.abs(Number(res))}`));
			if (Number(res) > 0) setPayDesc(_pisell_utils.locales.getText("tobPay.text.cash.modal.amount.left.pay.paid")(`${symbol}${res}`));
		});
	}, [inputAmount]);
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		title,
		open,
		onCancel,
		okButtonProps: { disabled: Number(inputAmount) <= 0 },
		okText: _pisell_utils.locales.getText("tobPay.text.cash.modal.ok"),
		onOk: () => {
			onOk(inputAmount);
		},
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache" }, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache-money" }, /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache-text" }, _pisell_utils.locales.getText("tobPay.text.cash.modal.amount.toPay")), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache-num" }, symbol, Number(expect_amount).toFixed(2))), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache-title" }, _pisell_utils.locales.getText("tobPay.text.cash.modal.input.title")), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement(antd.InputNumber, {
		precision: 2,
		value: inputAmount,
		min: 0,
		formatter: require_utils.limitDecimals,
		parser: require_utils.limitDecimals,
		onChange: (event) => {
			if (event !== null && event !== void 0) setInputAmount(event);
			else setInputAmount("0");
		},
		style: { width: "100%" }
	})), /* @__PURE__ */ react.default.createElement("div", { className: "tob-pay-cache-desc" }, payDesc)));
};
//#endregion
exports.default = ToBPayCache;
