import React from 'react';

// wrapper around fields to display an optional label and help block.
// Handles displaying errors if vlaidation has failed
var FieldWrapper = function FieldWrapper(props) {
  var label = props.label,
      meta = props.meta,
      helpText = props.helpText,
      className = props.className,
      children = props.children,
      required = props.required;
  var touched = meta.touched,
      error = meta.error;
  var statusClass = '';
  var errorMessage = '';

  if (touched && error) {
    statusClass = 'has-error';
    errorMessage = error;
  }

  return React.createElement("div", {
    className: "form-group ".concat(statusClass, " ").concat(className)
  }, label && React.createElement("label", {
    className: "control-label"
  }, required && React.createElement("span", {
    className: "required-label"
  }, "* "), label), children, errorMessage && React.createElement("small", {
    className: "feedback"
  }, errorMessage), helpText && React.createElement("p", {
    className: "help-block"
  }, helpText));
};

FieldWrapper.defaultProps = {
  label: '',
  helpText: '',
  className: '',
  required: false
};
export default FieldWrapper;