import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import Label from '../Label';
import Checkbox from '../Checkbox';
import Box from '../Box';
import SuperFieldHint from '../SuperFieldHint';

const getVariant = ({
  hasError,
  readOnly,
  disabled
}) => {
  if (hasError) {
    return 'danger';
  }

  if (disabled || readOnly) {
    return 'disabled';
  }
};

const CheckboxField = (_ref) => {
  let {
    label,
    hasError,
    disabled,
    readOnly,
    hint
  } = _ref,
      rest = _objectWithoutProperties(_ref, ["label", "hasError", "disabled", "readOnly", "hint"]);

  return /*#__PURE__*/React.createElement(Box, {
    variant: getVariant({
      hasError,
      readOnly,
      disabled
    }),
    pb: 2
  }, /*#__PURE__*/React.createElement(Label, {
    alignItems: "center"
  }, /*#__PURE__*/React.createElement(Checkbox, rest), label), hint ? /*#__PURE__*/React.createElement(SuperFieldHint, null, hint) : null);
};

process.env.NODE_ENV !== "production" ? CheckboxField.propTypes = {
  /** Disabled state */
  disabled: PropTypes.bool,

  /** Error state */
  hasError: PropTypes.bool,

  /** Hint itext */
  hint: PropTypes.node,

  /** Label for Checkbox  */
  label: PropTypes.node,

  /** Called when `onChange` event is triggered. */
  onChange: PropTypes.func,

  /** Read-only state */
  readOnly: PropTypes.bool,

  /** Current value of checkbox. */
  value: PropTypes.any
} : void 0;
export default CheckboxField;