'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FormGroup = exports.Form = exports.Legend = exports.Label = exports.Input = undefined;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

require('./Form.css');

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var Input = function Input(_ref) {
  var className = _ref.className,
      type = _ref.type,
      otherProps = _objectWithoutProperties(_ref, ['className', 'type']);

  return _react2.default.createElement('input', _extends({
    type: type || 'text',
    className: 'form-control ' + (className || '')
  }, otherProps));
};
exports.Input = Input;
Input.propTypes = {
  className: _propTypes2.default.string,
  type: _propTypes2.default.string
};

var Label = function Label(_ref2) {
  var children = _ref2.children,
      className = _ref2.className,
      required = _ref2.required,
      vertical = _ref2.vertical,
      otherProps = _objectWithoutProperties(_ref2, ['children', 'className', 'required', 'vertical']);

  return _react2.default.createElement(
    'label',
    _extends({ className: 'form-label control-label form-label-' + (vertical ? 'vertical' : 'horizontal') + ' ' + (className || '') }, otherProps),
    children,
    required && _react2.default.createElement(
      'span',
      { className: 'form-group-required-sign' },
      '*'
    )
  );
};
exports.Label = Label;
Label.propTypes = {
  className: _propTypes2.default.string,
  required: _propTypes2.default.bool
};

var Legend = function Legend(_ref3) {
  var children = _ref3.children,
      otherProps = _objectWithoutProperties(_ref3, ['children']);

  return _react2.default.createElement(
    'legend',
    otherProps,
    children
  );
};

exports.Legend = Legend;
var Form = function Form(_ref4) {
  var children = _ref4.children,
      vertical = _ref4.vertical,
      otherProps = _objectWithoutProperties(_ref4, ['children', 'vertical']);

  return _react2.default.createElement(
    'form',
    _extends({ className: vertical ? 'form-vertical' : 'form-horizontal' }, otherProps),
    children
  );
};

exports.Form = Form;
var FormGroup = exports.FormGroup = function FormGroup(_ref5) {
  var children = _ref5.children,
      error = _ref5.error,
      label = _ref5.label,
      required = _ref5.required,
      vertical = _ref5.vertical,
      classes = _ref5.classes;
  return _react2.default.createElement(
    'div',
    { className: 'form-group ' + (classes ? classes : '') + ' ' + (error ? 'has-error' : '') },
    label ? _react2.default.createElement(
      Label,
      { vertical: vertical, className: !vertical ? 'col-sm-3' : '', required: required },
      label
    ) : _react2.default.createElement('div', { className: !vertical ? 'col-sm-3' : '' }),
    _react2.default.createElement(
      'div',
      { className: !vertical ? 'col-sm-5' : '' },
      children
    ),
    _react2.default.createElement(
      'div',
      { className: 'error-container ' + (!vertical ? 'col-xs-4' : '') },
      error && _react2.default.createElement(
        'div',
        { className: 'form-group-error-span' },
        error
      )
    )
  );
};
FormGroup.propTypes = {
  error: _propTypes2.default.node,
  label: _propTypes2.default.node,
  required: _propTypes2.default.bool
};