"use strict";

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _randomstring = _interopRequireDefault(require("randomstring"));

var _typography = require("../../../mixins/typography");

var _branding = require("../../../mixins/branding");

var _primitives = require("../../../primitives");

var _radioOption = require("../../icon/radio-option");

var _focus = require("../../../mixins/focus");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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); }

var RadioButtonContainer = (0, _styledComponents["default"])(_primitives.Box).withConfig({
  displayName: "RadioButtonContainer",
  componentId: "sc-1grcdji-0"
})(["cursor:pointer;position:relative;", " &:focus-within{box-shadow:", ",", " ", ";}border-radius:", ";"], (0, _focus.getBaseFocusState)({
  hoverTransition: false,
  activeTransition: false
}), _focus.focusedBoxShadow, _focus.focusedBorderShadow, _focus.focusedBorderColor, _focus.focusedBorderRadius);
var StyledRadioOption = (0, _styledComponents["default"])(_radioOption.RadioOption).withConfig({
  displayName: "StyledRadioOption",
  componentId: "sc-1grcdji-1"
})(["margin-left:-", ";"], function (_ref) {
  var theme = _ref.theme;
  return theme.spacing.s1;
});

var Label = _styledComponents["default"].label.withConfig({
  displayName: "Label",
  componentId: "sc-1grcdji-2"
})(["color:", ";cursor:pointer;font-size:", ";font-family:", ";display:flex;align-items:center;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;margin-top:9px;margin-bottom:11px;z-index:-1;"], (0, _branding.getPaletteColor)('greyscale-black'), _typography.getFontSize, _typography.getFontFamily);

var InvisibleInput = _styledComponents["default"].input.withConfig({
  displayName: "InvisibleInput",
  componentId: "sc-1grcdji-3"
})(["height:0;width:0;margin:0;padding:0;opacity:0;"]);

var Wrapper = (0, _styledComponents["default"])(_primitives.Box).withConfig({
  displayName: "Wrapper",
  componentId: "sc-1grcdji-4"
})(["transform:scale(1);"]);

var RadioButton = function RadioButton(_ref2) {
  var id = _ref2.id,
      text = _ref2.text,
      selected = _ref2.selected,
      onClick = _ref2.onClick,
      name = _ref2.name,
      spacing = _ref2.spacing,
      grow = _ref2.grow,
      shrink = _ref2.shrink,
      basis = _ref2.basis,
      className = _ref2.className,
      dataQa = _ref2['data-qa'],
      dataCy = _ref2['data-cy'];

  var onClickWithEvent = function onClickWithEvent(_e) {
    return onClick(id);
  };

  var randomIdentifier = "".concat(_randomstring["default"].generate({
    length: 5,
    charset: 'alphabetic'
  }), "-").concat(id);
  var label = text != null ? /*#__PURE__*/_react["default"].createElement(Label, {
    face: "sans",
    fontSize: "f1",
    htmlFor: randomIdentifier
  }, text) : null;
  return /*#__PURE__*/_react["default"].createElement(Wrapper, _extends({
    spacing: spacing
  }, {
    grow: grow,
    shrink: shrink,
    basis: basis
  }, {
    className: className,
    "data-cy": dataCy,
    "data-qa": dataQa,
    id: id
  }), /*#__PURE__*/_react["default"].createElement(RadioButtonContainer, {
    stacked: "row",
    align: "center",
    onClick: onClickWithEvent
  }, /*#__PURE__*/_react["default"].createElement(InvisibleInput, {
    id: randomIdentifier,
    readOnly: true,
    type: "radio",
    checked: selected,
    name: name
  }), /*#__PURE__*/_react["default"].createElement(StyledRadioOption, {
    checked: selected
  }), label));
};

exports.RadioButton = RadioButton;
RadioButton.displayName = 'RadioButton';