"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 = _interopRequireDefault(require("styled-components"));

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

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

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

var Switch =
/*#__PURE__*/
_styledComponents.default.span.withConfig({
  componentId: "fsp9d5-0"
})(["\n  position: absolute;\n  right: 1rem;\n  bottom: 0.5rem;\n  font-family: ", ";\n  font-size: ", ";\n  font-weight: 600;\n  user-select: none;\n\n  &:hover {\n    text-decoration: underline;\n  }\n"], (0, _interpolation.theme)('fontPrimary'), (0, _interpolation.fontSize)('xs'));

var PasswordInput =
/*#__PURE__*/
(0, _styledComponents.default)(_Input.default).withConfig({
  componentId: "fsp9d5-1"
})(["\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)), "handleSwitchClick", 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;
      }

      return React.createElement(Switch, {
        onClick: _this.handleSwitchClick
      }, _this.state.type === 'password' ? React.createElement(_Icons.FarEye, {
        selectable: true,
        size: "20px"
      }) : React.createElement(_Icons.FarEyeSlash, {
        selectable: true,
        size: "20px"
      }));
    });
    _this.state = {
      type: props.type
    };
    return _this;
  }

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

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