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 antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/booking/deposit/EditDepositModal/index.tsx
const EditDepositModal = (props, ref) => {
	const { onChange, amountSymbol, totalAmount } = props;
	const [open, setOpen] = (0, react.useState)(false);
	const [depositMode, setDepositMode] = (0, react.useState)("1");
	const [amount, setAmount] = (0, react.useState)(null);
	const inputNumberRef = (0, react.useRef)(null);
	const onAmountChange = (value) => {
		setAmount(value);
	};
	const amountProps = (0, react.useMemo)(() => {
		if (depositMode === "1") return { prefix: amountSymbol };
		return {
			min: 0,
			max: 100,
			addonAfter: "%"
		};
	}, [depositMode]);
	const handleOk = () => {
		if (amount === 0) return antd.message.error(_pisell_utils.locales.getText("pisell2.text.deposit-amount-message"));
		if (!amount) return antd.message.error(_pisell_utils.locales.getText("pisell2.text.deposit-amount-message3"));
		onChange(amount);
		setOpen(false);
	};
	const handleOpenChange = (val) => {
		setOpen(val);
	};
	(0, react.useEffect)(() => {
		if (open) setTimeout(() => {
			var _inputNumberRef$curre;
			(_inputNumberRef$curre = inputNumberRef.current) === null || _inputNumberRef$curre === void 0 || _inputNumberRef$curre.focus();
		});
	}, [open]);
	(0, react.useImperativeHandle)(ref, () => {
		return {
			handleOpen: (amount) => {
				if (amount) setAmount(amount);
				handleOpenChange(true);
			},
			handleClose: () => handleOpenChange(false)
		};
	});
	const onCancel = () => {
		handleOpenChange(false);
		setAmount(null);
	};
	return /* @__PURE__ */ react.default.createElement(antd.Modal, {
		open,
		width: 400,
		cancelButtonProps: {
			block: true,
			size: "large"
		},
		okButtonProps: {
			block: true,
			size: "large"
		},
		className: "pisell-lowcode__edit-deposit-modal",
		title: _pisell_utils.locales.getText("pisell2.text.deposit-deposit-amount"),
		onCancel,
		onOk: handleOk,
		destroyOnClose: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field-list" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount-title" }, _pisell_utils.locales.getText("pisell2.text.deposit-order-total")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount" }, (0, _pisell_utils.formatAmount)(totalAmount, 2, amountSymbol || "$"))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field-label" }, _pisell_utils.locales.getText("pisell2.text.deposit-deposit-amount")), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement(antd.InputNumber, require_objectSpread2._objectSpread2({
		ref: inputNumberRef,
		style: { width: "100%" },
		onChange: onAmountChange,
		value: amount,
		size: "large",
		min: 0,
		precision: 2
	}, amountProps))))));
};
var EditDepositModal_default = (0, react.forwardRef)(EditDepositModal);
//#endregion
exports.default = EditDepositModal_default;
