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, { memo, useRef } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import uuid from 'uuid';
import MarkdownLabel from './MarkdownLabel';

const Checkbox = props => {
  const {
    label,
    className,
    input,
    disabled,
    fieldLabel,
    ...rest
  } = props;
  const id = useRef(uuid());
  const componentClasses = cx('form-field-checkbox', className, {
    'form-field-checkbox--disabled': disabled
  });
  return /*#__PURE__*/React.createElement("label", {
    className: componentClasses,
    htmlFor: id.current
  }, /*#__PURE__*/React.createElement("input", _extends({
    className: "form-field-checkbox__input",
    id: id.current // input.checked is only provided by redux form if type="checkbox" or type="radio" is
    // provided to <Field />, so for the case that it isn't we can rely on the more reliable
    // input.value
    ,
    checked: !!input.value // eslint-disable-next-line react/jsx-props-no-spreading

  }, input, rest, {
    type: "checkbox"
  })), /*#__PURE__*/React.createElement("div", {
    className: "form-field-checkbox__checkbox"
  }), label && /*#__PURE__*/React.createElement(MarkdownLabel, {
    inline: true,
    label: label,
    className: "form-field-inline-label"
  }));
};

Checkbox.propTypes = {
  label: PropTypes.node,
  fieldLabel: PropTypes.string,
  className: PropTypes.string,
  disabled: PropTypes.bool,
  input: PropTypes.object.isRequired
};
Checkbox.defaultProps = {
  className: '',
  label: null,
  fieldLabel: null,
  disabled: false
};

const areEqual = (prevProps, nextProps) => {
  const {
    input: {
      value: prevValue
    },
    ...prevRest
  } = prevProps;
  const {
    input: {
      value: nextValue
    },
    ...nextRest
  } = nextProps;
  return prevValue === nextValue && prevRest === nextRest;
};

export default /*#__PURE__*/memo(Checkbox, areEqual);