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