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); }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Icon from '../../Icon';
import DatePicker from './DatePicker';
import MarkdownLabel from '../MarkdownLabel';

class DatePickerField extends Component {
  constructor(props) {
    super(props);
    this.ref = /*#__PURE__*/React.createRef();
  }

  render() {
    const {
      input,
      meta: {
        error,
        invalid,
        touched
      },
      label,
      placeholder,
      parameters,
      fieldLabel,
      className,
      hidden
    } = this.props;
    const formFieldClasses = cx(className, 'form-field-date-picker', {
      'form-field-date-picker--has-error': invalid && touched
    });
    const anyLabel = fieldLabel || label;
    return /*#__PURE__*/React.createElement("div", {
      className: "form-field-container",
      hidden: hidden,
      ref: this.ref
    }, anyLabel && /*#__PURE__*/React.createElement(MarkdownLabel, {
      label: anyLabel
    }), /*#__PURE__*/React.createElement("div", {
      className: formFieldClasses,
      name: input.name
    }, /*#__PURE__*/React.createElement(DatePicker, _extends({
      parameters: parameters // eslint-disable-next-line react/jsx-props-no-spreading

    }, input, {
      onChange: input.onBlur,
      parentRef: this.ref,
      placeholder: placeholder
    })), invalid && touched && /*#__PURE__*/React.createElement("div", {
      className: "form-field-date-picker__error"
    }, /*#__PURE__*/React.createElement("div", {
      className: "form-field-date-picker__error-message"
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "warning"
    }), error))));
  }

}

DatePickerField.propTypes = {
  parameters: PropTypes.object,
  input: PropTypes.object.isRequired,
  meta: PropTypes.object,
  label: PropTypes.string,
  placeholder: PropTypes.string,
  fieldLabel: PropTypes.string,
  className: PropTypes.string,
  hidden: PropTypes.bool
};
DatePickerField.defaultProps = {
  parameters: {},
  meta: {},
  label: null,
  placeholder: null,
  fieldLabel: null,
  className: null,
  hidden: null
};
export default DatePickerField;