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

var getVariant = function getVariant(_ref) {
  var hasError = _ref.hasError,
      readOnly = _ref.readOnly,
      disabled = _ref.disabled;

  if (hasError) {
    return 'danger';
  }

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

var CheckboxField = /*#__PURE__*/forwardRef(function (_ref2, ref) {
  var label = _ref2.label,
      hasError = _ref2.hasError,
      disabled = _ref2.disabled,
      readOnly = _ref2.readOnly,
      hint = _ref2.hint,
      rest = _objectWithoutProperties(_ref2, ["label", "hasError", "disabled", "readOnly", "hint"]);

  return /*#__PURE__*/React.createElement(Box, {
    ref: ref,
    variant: getVariant({
      hasError: hasError,
      readOnly: readOnly,
      disabled: disabled
    }),
    pb: 2
  }, /*#__PURE__*/React.createElement(Label, {
    alignItems: "center"
  }, /*#__PURE__*/React.createElement(Checkbox, rest), label), hint ? /*#__PURE__*/React.createElement(SuperFieldHint, null, hint) : null);
});
CheckboxField.displayName = 'CheckboxField';
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
};
export default CheckboxField;