'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Input = _styledComponents2.default.input.withConfig({
  displayName: 'TextInput__Input'
})(['color: ', ';background: ', ';letter-spacing: 0.02em;line-height: ', ';font-size: ', ';font-family: ', ';transition: all 0.2s ease;outline: none;width: 100%;padding: ', ';display: block;border: ', ';&:focus {box-shadow: inset 0 -5px 0 ', ';border: 1px solid ', ';}&:focus + div {opacity: 1;}&:disabled {background: ', ';border: 1px solid ', ';opacity: 0.5;}', ''], function (_ref) {
  var theme = _ref.theme;
  return theme.colors.black;
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.colors.white;
}, function (_ref3) {
  var theme = _ref3.theme;
  return theme.input.lineHeight;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.input.fontSize;
}, function (_ref5) {
  var theme = _ref5.theme;
  return theme.input.fontFamily;
}, function (_ref6) {
  var theme = _ref6.theme;
  return theme.padding.medium;
}, function (_ref7) {
  var theme = _ref7.theme;
  return theme.input.border;
}, function (_ref8) {
  var theme = _ref8.theme;
  return theme.colors.primaryLight;
}, function (_ref9) {
  var theme = _ref9.theme;
  return theme.colors.border;
}, function (_ref10) {
  var theme = _ref10.theme;
  return theme.colors.disabled;
}, function (_ref11) {
  var theme = _ref11.theme;
  return theme.colors.border;
}, function (_ref12) {
  var visited = _ref12.visited,
      theme = _ref12.theme;
  return visited ? (0, _styledComponents.css)(['&:invalid {box-shadow: inset 0 -5px 0 ', ';}'], theme.colors.errorBackgroundLight) : '';
});

var TextInput = function (_React$Component) {
  _inherits(TextInput, _React$Component);

  function TextInput(props) {
    _classCallCheck(this, TextInput);

    var _this = _possibleConstructorReturn(this, (TextInput.__proto__ || Object.getPrototypeOf(TextInput)).call(this, props));

    _this.onBlur = function (event) {
      _this.setState({ visited: true });
      if (_this.props.onBlur) {
        _this.props.onBlur(event);
      }
    };

    _this.state = { visited: false };
    return _this;
  }

  _createClass(TextInput, [{
    key: 'render',
    value: function render() {
      var disabled = this.props.disabled;
      var visited = this.state.visited;

      return _react2.default.createElement(Input, _extends({}, this.props, { onBlur: this.onBlur, visited: visited }));
    }
  }]);

  return TextInput;
}(_react2.default.Component);

TextInput.propTypes = {
  value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]),
  onChange: _propTypes2.default.func,
  onBlur: _propTypes2.default.func,
  disabled: _propTypes2.default.bool,
  required: _propTypes2.default.bool,
  id: _propTypes2.default.string,
  type: _propTypes2.default.string
};
TextInput.defaultProps = {
  disabled: false,
  required: false,
  id: null,
  type: 'text',
  onChange: function onChange() {
    return null;
  },
  onBlur: function onBlur() {
    return null;
  }
};


TextInput.usage = '\n# TextInput\n\nA TextInput without the label or help text.\n';

exports.default = TextInput;