"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var React = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireWildcard(require("styled-components"));

var _interpolation = require("../../Tools/interpolation");

var _Input = require("./Input");

var _Icons = require("../Icons");

//  strict
var iconCss =
/*#__PURE__*/
(0, _styledComponents.css)(["\n  position: absolute;\n  right: 1rem;\n  bottom: calc(1.35rem - 8px);\n  user-select: none;\n  fill: ", ";\n\n  &:hover {\n    fill: ", ";\n  }\n"], (0, _interpolation.theme)('inputColor'), (0, _interpolation.theme)('inputColor'));
var Eye =
/*#__PURE__*/
(0, _styledComponents.default)(_Icons.FarEye).withConfig({
  componentId: "fsp9d5-0"
})(["\n  ", ";\n"], iconCss);
var EyeSlash =
/*#__PURE__*/
(0, _styledComponents.default)(_Icons.FarEyeSlash).withConfig({
  componentId: "fsp9d5-1"
})(["\n  ", ";\n"], iconCss);
var PasswordInput =
/*#__PURE__*/
(0, _styledComponents.default)(_Input.Input).withConfig({
  componentId: "fsp9d5-2"
})(["\n  input {\n    padding-right: 3rem;\n  }\n"]);

var Password =
/*#__PURE__*/
function (_React$Component) {
  (0, _inherits2.default)(Password, _React$Component);

  function Password(_props) {
    var _this;

    (0, _classCallCheck2.default)(this, Password);
    _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Password).call(this, _props));
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), "handleIconClick", function () {
      _this.state.type === 'password' ? _this.setState({
        type: 'text'
      }) : _this.setState({
        type: 'password'
      });
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), "renderToggle", function (disabled) {
      if (disabled === true) {
        return null;
      }

      var props = {
        onClick: _this.handleIconClick,
        selectable: true,
        size: '16px'
      };
      return _this.state.type === 'password' ? React.createElement(EyeSlash, props) : React.createElement(Eye, props);
    });
    _this.state = {
      type: _props.type
    };
    return _this;
  }

  (0, _createClass2.default)(Password, [{
    key: "render",
    value: function render() {
      var type = this.state.type;
      var _this$props = this.props,
          ref = _this$props.forwardRef,
          renderSuffix = _this$props.renderSuffix;
      return React.createElement(PasswordInput, (0, _extends2.default)({}, this.props, {
        ref: ref,
        renderSuffix: renderSuffix || this.renderToggle,
        type: type
      }));
    }
  }]);
  return Password;
}(React.Component);

(0, _defineProperty2.default)(Password, "defaultProps", (0, _objectSpread2.default)({}, _Input.Input.defaultProps, {
  type: 'password'
}));
Password.propTypes = process.env.NODE_ENV !== "production" ? _Input.Input.propTypes : {};

var PasswordWithRef = function PasswordWithRef(props, ref) {
  return React.createElement(Password, (0, _extends2.default)({}, props, {
    forwardRef: ref
  }));
};

var _default = React.forwardRef(PasswordWithRef);

exports.default = _default;