var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/booking/deposit/EditDepositModal/index.tsx
var EditDepositModal_exports = {};
__export(EditDepositModal_exports, {
  default: () => EditDepositModal_default
});
module.exports = __toCommonJS(EditDepositModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_index = require("./index.less");
var import_utils = require("@pisell/utils");
var EditDepositModal = (props, ref) => {
  const { onChange, amountSymbol, totalAmount } = props;
  const [open, setOpen] = (0, import_react.useState)(false);
  const [depositMode, setDepositMode] = (0, import_react.useState)("1");
  const [amount, setAmount] = (0, import_react.useState)(null);
  const inputNumberRef = (0, import_react.useRef)(null);
  const options = [
    { label: "固定金额", value: "1" }
    // { label: "订单百分比", value: "2" },
  ];
  const onAmountChange = (value) => {
    setAmount(value);
  };
  const amountProps = (0, import_react.useMemo)(() => {
    if (depositMode === "1") {
      return {
        prefix: amountSymbol
      };
    }
    return {
      min: 0,
      max: 100,
      addonAfter: "%"
    };
  }, [depositMode]);
  const handleOk = () => {
    if (amount === 0) {
      return import_antd.message.error(
        import_utils.locales.getText("pisell2.text.deposit-amount-message")
      );
    }
    if (!amount) {
      return import_antd.message.error(
        import_utils.locales.getText("pisell2.text.deposit-amount-message3")
      );
    }
    onChange(amount);
    setOpen(false);
  };
  const handleOpenChange = (val) => {
    setOpen(val);
  };
  (0, import_react.useEffect)(() => {
    if (open) {
      setTimeout(() => {
        var _a;
        (_a = inputNumberRef.current) == null ? void 0 : _a.focus();
      });
    }
  }, [open]);
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      handleOpen: (amount2) => {
        if (amount2) {
          setAmount(amount2);
        }
        handleOpenChange(true);
      },
      handleClose: () => handleOpenChange(false)
    };
  });
  const onCancel = () => {
    handleOpenChange(false);
    setAmount(null);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Modal,
    {
      open,
      width: 400,
      cancelButtonProps: { block: true, size: "large" },
      okButtonProps: { block: true, size: "large" },
      className: "pisell-lowcode__edit-deposit-modal",
      title: import_utils.locales.getText("pisell2.text.deposit-deposit-amount"),
      onCancel,
      onOk: handleOk,
      destroyOnClose: true
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field-list" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount-title" }, import_utils.locales.getText("pisell2.text.deposit-order-total")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-order-amount" }, (0, import_utils.formatAmount)(totalAmount, 2, amountSymbol || "$"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__edit-deposit-modal-field-label" }, import_utils.locales.getText("pisell2.text.deposit-deposit-amount")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        ref: inputNumberRef,
        style: { width: "100%" },
        onChange: onAmountChange,
        value: amount,
        size: "large",
        min: 0,
        precision: 2,
        ...amountProps
      }
    ))))
  );
};
var EditDepositModal_default = (0, import_react.forwardRef)(EditDepositModal);
