"use strict";

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

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

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

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

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

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

var _ = require("..");

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

var _styles = _interopRequireDefault(require("../Checkbox/styles"));

var _ControlBox = require("../ControlBox");

var _useVariantColorWarning = require("../hooks/useVariantColorWarning");

var _Text = require("../Text");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __jsx = _react["default"].createElement;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var Radio = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var id = _ref.id,
      name = _ref.name,
      value = _ref.value,
      ariaLabel = _ref['aria-label'],
      ariaLabelledBy = _ref['aria-labelledby'],
      _ref$variantColor = _ref.variantColor,
      variantColor = _ref$variantColor === void 0 ? 'primary' : _ref$variantColor,
      defaultIsChecked = _ref.defaultIsChecked,
      isChecked = _ref.isChecked,
      isFullWidth = _ref.isFullWidth,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'md' : _ref$size,
      isDisabled = _ref.isDisabled,
      isInvalid = _ref.isInvalid,
      onChange = _ref.onChange,
      renderCustomControl = _ref.renderCustomControl,
      onBlur = _ref.onBlur,
      onFocus = _ref.onFocus,
      children = _ref.children,
      rest = (0, _objectWithoutProperties2["default"])(_ref, ["id", "name", "value", "aria-label", "aria-labelledby", "variantColor", "defaultIsChecked", "isChecked", "isFullWidth", "size", "isDisabled", "isInvalid", "onChange", "renderCustomControl", "onBlur", "onFocus", "children"]);
  // Wrong usage of `variantColor` prop is quite common
  // Let's add a warning hook that validates the passed variantColor
  (0, _useVariantColorWarning.useVariantColorWarning)('Radio', variantColor);

  var _useCheckboxStyle = (0, _styles["default"])({
    color: variantColor,
    size: size,
    type: 'radio'
  }),
      rootStyleProps = _useCheckboxStyle.root,
      labelStyleProps = _useCheckboxStyle.label,
      containerStyleProps = _useCheckboxStyle.container;

  return __jsx(_Box.Box, (0, _extends2["default"])({
    as: "label",
    htmlFor: id
  }, containerStyleProps, rest), __jsx(_.VisuallyHidden, {
    as: "input",
    type: "radio",
    "aria-label": ariaLabel,
    "aria-labelledby": ariaLabelledBy,
    id: name,
    ref: ref,
    name: name,
    value: value,
    "aria-invalid": isInvalid,
    defaultChecked: defaultIsChecked,
    onChange: onChange,
    onBlur: onBlur,
    onFocus: onFocus,
    checked: isChecked,
    disabled: isDisabled
  }), renderCustomControl ? renderCustomControl(_objectSpread({
    isChecked: isChecked,
    type: 'radio'
  }, rootStyleProps)) : __jsx(_ControlBox.ControlBox, (0, _extends2["default"])({}, rootStyleProps, {
    type: "radio",
    rounded: "full"
  }), __jsx(_Box.Box, {
    bg: "currentColor",
    as: "span",
    rounded: "full",
    size: "50%"
  })), children && __jsx(_Text.Text, labelStyleProps, children));
});
exports.Radio = Radio;
//# sourceMappingURL=Radio.js.map