var _excluded = ["suffix", "allowClear", "selectInFocus", "prefixCls", "onChange", "onClose"];

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import * as React from 'react';
import { trim } from 'lodash-es';
import classNames from 'classnames';
import { useUpdateEffect } from 'ahooks';
import Input from 'antd/es/input';
import { CloseCircleFilled } from '@ant-design/icons';
var InlineInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var suffix = props.suffix,
      allowClear = props.allowClear,
      selectInFocus = props.selectInFocus,
      customizePrefixCls = props.prefixCls,
      onChange = props.onChange,
      onClose = props.onClose,
      inputProps = _objectWithoutProperties(props, _excluded);

  var inputRef = React.useRef(null);

  var _React$useState = React.useState(props.value || props.defaultValue),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      value = _React$useState2[0],
      setValue = _React$useState2[1];

  var pxxPrefixCls = "".concat(customizePrefixCls, "-input");
  React.useImperativeHandle(ref, function () {
    return inputRef.current;
  });
  useUpdateEffect(function () {
    setValue(props.value);
  }, [props.value]);

  var handleReset = function handleReset() {
    setValue('');
    onChange === null || onChange === void 0 ? void 0 : onChange('');
    onClose === null || onClose === void 0 ? void 0 : onClose();
  };

  var renderClearIcon = function renderClearIcon(prefixCls) {
    var disabled = props.disabled,
        readOnly = props.readOnly;

    if (!allowClear) {
      return null;
    }

    var needClear = !disabled && !readOnly && value;
    var closeClassName = "".concat(prefixCls, "-clear-icon");
    return /*#__PURE__*/React.createElement(CloseCircleFilled, {
      onClick: handleReset,
      className: classNames(_defineProperty({}, "".concat(closeClassName, "-hidden"), !needClear), closeClassName),
      role: "button"
    });
  };

  var renderSuffix = function renderSuffix(prefixCls) {
    if (suffix || allowClear) {
      return /*#__PURE__*/React.createElement(React.Fragment, null, renderClearIcon(prefixCls), suffix);
    }

    return null;
  };

  var handleChange = function handleChange(e) {
    var trimValue = trim(e.target.value);

    var _value = trimValue === '' ? undefined : trimValue;

    setValue(_value);
    onChange === null || onChange === void 0 ? void 0 : onChange(_value);
  };

  return /*#__PURE__*/React.createElement(Input, Object.assign({
    ref: inputRef,
    suffix: renderSuffix(pxxPrefixCls),
    value: value,
    onChange: handleChange,
    prefixCls: pxxPrefixCls
  }, inputProps, {
    onFocus: function onFocus(event) {
      var _inputRef$current, _inputProps$onFocus;

      if (selectInFocus) (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.select();
      (_inputProps$onFocus = inputProps.onFocus) === null || _inputProps$onFocus === void 0 ? void 0 : _inputProps$onFocus.call(inputProps, event);
    }
  }));
});
InlineInput.defaultProps = {
  prefixCls: 'pxx',
  placeholder: '请输入',
  allowClear: true
};
export var Group = function Group(props) {
  return /*#__PURE__*/React.createElement(Input.Group, Object.assign({}, props, {
    prefixCls: "".concat(props.prefixCls, "-input-group")
  }));
};
Group.defaultProps = {
  prefixCls: 'pxx'
};
export var Search = /*#__PURE__*/React.forwardRef(function (props, ref) {
  return /*#__PURE__*/React.createElement(Input.Search, Object.assign({
    ref: ref
  }, props, {
    prefixCls: "".concat(props.prefixCls, "-input-search"),
    inputPrefixCls: "".concat(props.prefixCls, "-input")
  }));
});
Search.defaultProps = {
  prefixCls: 'pxx'
};
export var TextArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
  return /*#__PURE__*/React.createElement(Input.TextArea, Object.assign({
    ref: ref
  }, props, {
    prefixCls: "".concat(props.prefixCls, "-input")
  }));
});
TextArea.defaultProps = {
  prefixCls: 'pxx'
};
export var Password = /*#__PURE__*/React.forwardRef(function (props, ref) {
  return /*#__PURE__*/React.createElement(Input.Password, Object.assign({
    ref: ref
  }, props, {
    prefixCls: "".concat(props.prefixCls, "-input-password"),
    inputPrefixCls: "".concat(props.prefixCls, "-input")
  }));
});
Password.defaultProps = {
  prefixCls: 'pxx'
};
export default InlineInput;