import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import React from 'react';
import { Field } from 'redux-form'; // HOC wrapper around redux-form's Field to alter props
// before they get to the compoonent

var withField = function withField(emptyValidator) {
  return function (component) {
    return function (props) {
      var disabled = props.disabled,
          required = props.required,
          _props$validate = props.validate,
          validate = _props$validate === void 0 ? [] : _props$validate; // attach the validation for required based off input type

      if (required) {
        validate.push(emptyValidator);
      } // do not validate disabled fields


      var fixedValidate = !disabled ? validate : [];

      var fixedProps = _objectSpread({}, props, {
        component: component,
        validate: fixedValidate
      });

      return React.createElement(Field, fixedProps);
    };
  };
};

export default withField;