function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
import { InputNumber, message, Modal } from "antd";
import "./index.less";
import { formatAmount, locales } from "@pisell/utils";
var EditDepositModal = function EditDepositModal(props, ref) {
  var onChange = props.onChange,
    amountSymbol = props.amountSymbol,
    totalAmount = props.totalAmount;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useState3 = useState("1"),
    _useState4 = _slicedToArray(_useState3, 2),
    depositMode = _useState4[0],
    setDepositMode = _useState4[1];
  var _useState5 = useState(null),
    _useState6 = _slicedToArray(_useState5, 2),
    amount = _useState6[0],
    setAmount = _useState6[1];
  var inputNumberRef = useRef(null);
  var options = [{
    label: "固定金额",
    value: "1"
  }
  // { label: "订单百分比", value: "2" },
  ];
  var onAmountChange = function onAmountChange(value) {
    setAmount(value);
  };
  var amountProps = useMemo(function () {
    if (depositMode === "1") {
      return {
        prefix: amountSymbol
      };
    }
    return {
      min: 0,
      max: 100,
      addonAfter: "%"
    };
  }, [depositMode]);
  var handleOk = function 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"));
    }
    // if (amount > totalAmount) {
    //   return message.error(
    //     locales.getText("pisell2.text.deposit-amount-message2")
    //   );
    // }
    onChange(amount);
    setOpen(false);
  };
  var handleOpenChange = function handleOpenChange(val) {
    setOpen(val);
  };
  useEffect(function () {
    if (open) {
      setTimeout(function () {
        var _inputNumberRef$curre;
        (_inputNumberRef$curre = inputNumberRef.current) === null || _inputNumberRef$curre === void 0 || _inputNumberRef$curre.focus();
      });
    }
  }, [open]);
  useImperativeHandle(ref, function () {
    return {
      handleOpen: function handleOpen(amount) {
        if (amount) {
          setAmount(amount);
        }
        handleOpenChange(true);
      },
      handleClose: function handleClose() {
        return handleOpenChange(false);
      }
    };
  });
  var onCancel = function onCancel() {
    handleOpenChange(false);
    setAmount(null);
  };
  return /*#__PURE__*/React.createElement(Modal, {
    open: 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: 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, _extends({
    ref: inputNumberRef,
    style: {
      width: "100%"
    },
    onChange: onAmountChange,
    value: amount,
    size: "large",
    min: 0,
    precision: 2
  }, amountProps))))));
};
export default /*#__PURE__*/forwardRef(EditDepositModal);