"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Label = _interopRequireDefault(require("../Label"));

var _Checkbox = _interopRequireDefault(require("../Checkbox"));

var _Box = _interopRequireDefault(require("../Box"));

var _SuperFieldHint = _interopRequireDefault(require("../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__*/(0, _react.forwardRef)(function (_ref2, ref) {
  var label = _ref2.label,
      hasError = _ref2.hasError,
      disabled = _ref2.disabled,
      readOnly = _ref2.readOnly,
      hint = _ref2.hint,
      rest = (0, _objectWithoutProperties2["default"])(_ref2, ["label", "hasError", "disabled", "readOnly", "hint"]);
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], {
    ref: ref,
    variant: getVariant({
      hasError: hasError,
      readOnly: readOnly,
      disabled: disabled
    }),
    pb: 2
  }, /*#__PURE__*/_react["default"].createElement(_Label["default"], {
    alignItems: "center"
  }, /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], rest), label), hint ? /*#__PURE__*/_react["default"].createElement(_SuperFieldHint["default"], null, hint) : null);
});
CheckboxField.displayName = 'CheckboxField';
CheckboxField.propTypes = {
  /** Disabled state */
  disabled: _propTypes["default"].bool,

  /** Error state */
  hasError: _propTypes["default"].bool,

  /** Hint itext */
  hint: _propTypes["default"].node,

  /** Label for Checkbox  */
  label: _propTypes["default"].node,

  /** Called when `onChange` event is triggered. */
  onChange: _propTypes["default"].func,

  /** Read-only state */
  readOnly: _propTypes["default"].bool,

  /** Current value of checkbox. */
  value: _propTypes["default"].any
};
var _default = CheckboxField;
exports["default"] = _default;