import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["onChange", "forwardedRef"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { forwardRef, PureComponent } from 'react';
import PropTypes from 'prop-types';
import SingleLineInputBase from './SingleLineInputBase';

var Input = /*#__PURE__*/function (_PureComponent) {
  _inherits(Input, _PureComponent);

  var _super = _createSuper(Input);

  function Input() {
    var _this;

    _classCallCheck(this, Input);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "state", {
      value: ''
    });

    return _this;
  }

  _createClass(Input, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          _onChange = _this$props.onChange,
          forwardedRef = _this$props.forwardedRef,
          others = _objectWithoutProperties(_this$props, _excluded);

      return /*#__PURE__*/React.createElement(SingleLineInputBase, _extends({
        ref: forwardedRef,
        value: this.state.value,
        onChange: function onChange(event) {
          _this2.setState({
            value: event.currentTarget.value
          });

          _onChange && _onChange(event, event.currentTarget.value);
        }
      }, others));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      if (nextProps.value !== undefined) {
        var newValue = nextProps.value || '';

        if (newValue !== prevState.value) {
          return {
            value: newValue
          };
        }
      }

      return null;
    }
  }]);

  return Input;
}(PureComponent);

Input.defaultProps = {
  type: 'text'
};
/** @type {React.ComponentType<any>} */

var ForwardedInput = /*#__PURE__*/forwardRef(function (props, ref) {
  return /*#__PURE__*/React.createElement(Input, _extends({}, props, {
    forwardedRef: ref
  }));
});
ForwardedInput.displayName = 'Input';
export default ForwardedInput;