"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SelectField = exports.ChoiceInput = exports.TextField = exports.FieldContent = exports.Field = exports.FormGroup = exports.Form = exports.Legend = exports.Label = exports.TextArea = exports.Input = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Select = _interopRequireDefault(require("./Select"));

require("./Form.css");

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

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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

  return _react.default.createElement("input", _extends({
    type: type || 'text',
    className: "form-control ".concat(className || '')
  }, otherProps));
};

exports.Input = Input;
Input.propTypes = {
  className: _propTypes.default.string,
  type: _propTypes.default.string
};

var TextArea = function TextArea(_ref2) {
  var className = _ref2.className,
      otherProps = _objectWithoutProperties(_ref2, ["className"]);

  return _react.default.createElement("textarea", _extends({
    className: "form-control ".concat(className || '')
  }, otherProps));
};

exports.TextArea = TextArea;

var Label = function Label(_ref3) {
  var children = _ref3.children,
      className = _ref3.className,
      required = _ref3.required,
      vertical = _ref3.vertical,
      fontWeight = _ref3.fontWeight,
      otherProps = _objectWithoutProperties(_ref3, ["children", "className", "required", "vertical", "fontWeight"]);

  return _react.default.createElement("label", _extends({
    className: "form-label control-label form-label-".concat(vertical ? 'vertical' : 'horizontal', " ").concat(fontWeight ? "vs-label-font-".concat(fontWeight) : '', " ").concat(className || '')
  }, otherProps), children, required && _react.default.createElement("span", {
    className: "form-group-required-sign"
  }, "*"));
};

exports.Label = Label;
Label.propTypes = {
  className: _propTypes.default.string,
  required: _propTypes.default.bool
};

var Legend = function Legend(_ref4) {
  var children = _ref4.children,
      otherProps = _objectWithoutProperties(_ref4, ["children"]);

  return _react.default.createElement("legend", otherProps, children);
};

exports.Legend = Legend;

var Form = function Form(_ref5) {
  var children = _ref5.children,
      vertical = _ref5.vertical,
      otherProps = _objectWithoutProperties(_ref5, ["children", "vertical"]);

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

exports.Form = Form;

var FormGroup = function FormGroup(_ref6) {
  var children = _ref6.children,
      error = _ref6.error,
      label = _ref6.label,
      required = _ref6.required,
      vertical = _ref6.vertical,
      classes = _ref6.classes;
  return _react.default.createElement("div", {
    className: "form-group ".concat(classes ? classes : '', " ").concat(error ? 'has-error' : '')
  }, label ? _react.default.createElement(Label, {
    vertical: vertical,
    className: !vertical ? 'col-sm-3' : '',
    required: required
  }, label) : _react.default.createElement("div", {
    className: !vertical ? 'col-sm-3' : ''
  }), _react.default.createElement("div", {
    className: !vertical ? 'col-sm-5' : ''
  }, children), _react.default.createElement("div", {
    className: "error-container ".concat(!vertical ? 'col-xs-4' : '')
  }, error && _react.default.createElement("div", {
    className: "form-group-error-span"
  }, error)));
};

exports.FormGroup = FormGroup;
FormGroup.propTypes = {
  error: _propTypes.default.node,
  label: _propTypes.default.node,
  required: _propTypes.default.bool
}; // Component that renders a label and error/help message

var Field = function Field(_ref7) {
  var htmlFor = _ref7.htmlFor,
      className = _ref7.className,
      label = _ref7.label,
      error = _ref7.error,
      help = _ref7.help,
      optional = _ref7.optional,
      optionalLabel = _ref7.optionalLabel,
      children = _ref7.children,
      otherProps = _objectWithoutProperties(_ref7, ["htmlFor", "className", "label", "error", "help", "optional", "optionalLabel", "children"]);

  return _react.default.createElement("div", {
    className: "vs-field ".concat(className ? className : '')
  }, _react.default.createElement(Label, _extends({
    htmlFor: htmlFor,
    className: "vs-field-label",
    weight: "bold"
  }, otherProps), label, ' ', _react.default.createElement("span", {
    className: "vs-field-optional"
  }, optional ? "- ".concat(optionalLabel) : null)), children, error ? _react.default.createElement("div", {
    className: "vs-validation-error"
  }, error) : _react.default.createElement("div", {
    className: "vs-field-help"
  }, help));
};

exports.Field = Field;

var FieldContent = function FieldContent(_ref8) {
  var className = _ref8.className,
      children = _ref8.children;
  return _react.default.createElement("div", {
    className: "vs-field-content ".concat(className ? className : '')
  }, children);
}; // Input with label and error/help message


exports.FieldContent = FieldContent;

var TextField = function TextField(_ref9) {
  var id = _ref9.id,
      className = _ref9.className,
      name = _ref9.name,
      value = _ref9.value,
      label = _ref9.label,
      error = _ref9.error,
      help = _ref9.help,
      optional = _ref9.optional,
      optionalLabel = _ref9.optionalLabel,
      otherProps = _objectWithoutProperties(_ref9, ["id", "className", "name", "value", "label", "error", "help", "optional", "optionalLabel"]);

  return _react.default.createElement(Field, _extends({
    htmlFor: id,
    classes: "vs-text-field ".concat(className ? className : ''),
    label: label,
    error: error,
    help: help,
    optional: optional,
    optionalLabel: optionalLabel
  }, otherProps), _react.default.createElement(FieldContent, null, _react.default.createElement(Input, _extends({
    id: id,
    className: error ? 'input-error' : '',
    name: name,
    value: value
  }, otherProps))));
}; // Just radio button and label


exports.TextField = TextField;

var ChoiceInput = function ChoiceInput(_ref10) {
  var id = _ref10.id,
      className = _ref10.className,
      _ref10$type = _ref10.type,
      type = _ref10$type === void 0 ? 'radio' : _ref10$type,
      name = _ref10.name,
      value = _ref10.value,
      label = _ref10.label,
      checked = _ref10.checked,
      style = _ref10.style,
      otherProps = _objectWithoutProperties(_ref10, ["id", "className", "type", "name", "value", "label", "checked", "style"]);

  return _react.default.createElement("div", {
    className: "vs-choice-input ".concat(className ? className : ''),
    style: style
  }, _react.default.createElement(Label, _extends({
    htmlFor: id,
    fontWeight: "normal"
  }, otherProps), _react.default.createElement(Input, _extends({
    id: id,
    type: type,
    name: name,
    value: value,
    checked: checked
  }, otherProps)), label));
};

exports.ChoiceInput = ChoiceInput;

var SelectField = function SelectField(_ref11) {
  var id = _ref11.id,
      name = _ref11.name,
      label = _ref11.label,
      error = _ref11.error,
      help = _ref11.help,
      value = _ref11.value,
      onChange = _ref11.onChange,
      onBlur = _ref11.onBlur,
      noOptionsMessage = _ref11.noOptionsMessage,
      isClearable = _ref11.isClearable,
      isDisabled = _ref11.isDisabled,
      isMulti = _ref11.isMulti,
      isSearchable = _ref11.isSearchable,
      autoFocus = _ref11.autoFocus,
      placeholder = _ref11.placeholder,
      otherProps = _objectWithoutProperties(_ref11, ["id", "name", "label", "error", "help", "value", "onChange", "onBlur", "noOptionsMessage", "isClearable", "isDisabled", "isMulti", "isSearchable", "autoFocus", "placeholder"]);

  return _react.default.createElement(Field, _extends({
    htmlFor: id,
    label: label,
    error: error,
    help: help
  }, otherProps), _react.default.createElement(FieldContent, null, _react.default.createElement(_Select.default, _extends({
    id: id,
    name: name,
    error: error,
    value: value,
    onChange: onChange,
    onBlur: onBlur,
    autoFocus: autoFocus,
    noOptionsMessage: noOptionsMessage,
    isClearable: isClearable,
    isDisabled: isDisabled,
    isMulti: isMulti,
    isSearchable: isSearchable,
    placeholder: placeholder
  }, otherProps))));
};

exports.SelectField = SelectField;