"use strict";

exports.__esModule = true;
exports.Input = void 0;

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _reactHookForm = require("react-hook-form");

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

var Input = function Input(_ref) {
  var name = _ref.name,
      placeholder = _ref.placeholder,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'text' : _ref$type,
      _ref$required = _ref.required,
      required = _ref$required === void 0 ? false : _ref$required;

  var _useFormContext = (0, _reactHookForm.useFormContext)(),
      register = _useFormContext.register,
      clearError = _useFormContext.clearError,
      errors = _useFormContext.errors;

  var options = required ? {
    required: "Can't be blank"
  } : {};
  var classes = (0, _classnames.default)('field', errors[name] ? 'error' : '');
  return /*#__PURE__*/_react.default.createElement("div", {
    className: classes
  }, /*#__PURE__*/_react.default.createElement("input", {
    type: type,
    name: name,
    placeholder: placeholder,
    onFocus: function onFocus() {
      return clearError();
    },
    "aria-invalid": errors[name] ? 'true' : 'false',
    ref: register(options)
  }));
};

Input.displayName = 'Input';
var InputDoc;

if (process.env.NODE_ENV !== 'production') {
  // eslint-disable-next-line global-require
  InputDoc = require('./doc').doc(Input);
}

var InputWrapper = InputDoc || Input;
exports.Input = InputWrapper;