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, { useState, useImperativeHandle, forwardRef } from 'react';
import { Popover } from 'antd';
// import { NumberKeyboard, VirtualKeyboard } from '@pisell/materials';
import NumberKeyboard from "../numberKeyboard";
import "./index.less";
var NumberKeyboardPopover = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var children = _ref.children,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? '' : _ref$value,
    onChange = _ref.onChange,
    onConfirm = _ref.onConfirm,
    onCancel = _ref.onCancel,
    _ref$allowDecimal = _ref.allowDecimal,
    allowDecimal = _ref$allowDecimal === void 0 ? true : _ref$allowDecimal,
    _ref$decimalPlaces = _ref.decimalPlaces,
    decimalPlaces = _ref$decimalPlaces === void 0 ? 2 : _ref$decimalPlaces,
    _ref$selectType = _ref.selectType,
    selectType = _ref$selectType === void 0 ? 'dark' : _ref$selectType,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$overlayClassName = _ref.overlayClassName,
    overlayClassName = _ref$overlayClassName === void 0 ? '' : _ref$overlayClassName,
    max = _ref.max,
    maxLength = _ref.maxLength;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useState3 = useState(''),
    _useState4 = _slicedToArray(_useState3, 2),
    tempValue = _useState4[0],
    setTempValue = _useState4[1];

  // 暴露给父组件的方法
  useImperativeHandle(ref, function () {
    return {
      open: function open() {
        return setOpen(true);
      },
      close: function close() {
        return setOpen(false);
      },
      isOpen: function isOpen() {
        return open;
      }
    };
  });
  var handleOpenChange = function handleOpenChange(visible) {
    if (disabled) return;
    setOpen(visible);
    if (visible) {
      // 打开时初始化临时值
      setTempValue(value);
    } else {
      // 关闭时调用取消回调
      onCancel === null || onCancel === void 0 || onCancel();
    }
  };
  var handleKeyboardChange = function handleKeyboardChange(newValue) {
    setTempValue(newValue);
    onChange === null || onChange === void 0 || onChange(newValue);
  };
  var handleKeyboardEnter = function handleKeyboardEnter() {
    onConfirm === null || onConfirm === void 0 || onConfirm(tempValue);
    setOpen(false);
  };
  var handleKeyboardCancel = function handleKeyboardCancel() {
    setOpen(false);
    onCancel === null || onCancel === void 0 || onCancel();
  };
  var keyboardContent = /*#__PURE__*/React.createElement("div", {
    className: "number-keyboard-popover-content"
  }, /*#__PURE__*/React.createElement(NumberKeyboard, {
    value: tempValue,
    onChange: handleKeyboardChange,
    onOk: handleKeyboardEnter,
    onDelete: handleKeyboardCancel,
    max: max,
    maxLength: maxLength
  }));
  return /*#__PURE__*/React.createElement(Popover, {
    open: open,
    content: keyboardContent,
    trigger: ['click'],
    overlayInnerStyle: {
      padding: 0
    },
    destroyTooltipOnHide: true,
    arrow: false,
    align: {
      offset: [0, 0]
    },
    overlayClassName: "number-keyboard-popover ".concat(overlayClassName),
    onOpenChange: handleOpenChange,
    disabled: disabled
  }, children);
});
NumberKeyboardPopover.displayName = 'NumberKeyboardPopover';
export default NumberKeyboardPopover;