"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

var _Logo = _interopRequireDefault(require("../../../logo/Logo"));

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

var _Flex = _interopRequireDefault(require("../../../flex/Flex"));

var _Icon = _interopRequireDefault(require("../../../icons/Icon"));

var _Headline = _interopRequireDefault(require("../../../text/Headline"));

var _useRadioContext2 = _interopRequireDefault(require("../useRadioContext"));

var _Radio = _interopRequireDefault(require("../Radio"));

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

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

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var LOGO = {
  plus: 'brainly-plus',
  tutor: 'brainly-tutoring'
};

var CustomRadioComponent = function CustomRadioComponent(_ref) {
  var value = _ref.value,
      type = _ref.type,
      benefits = _ref.benefits;

  var _useRadioContext = (0, _useRadioContext2.default)(),
      selectedValue = _useRadioContext.selectedValue,
      setSelectedValue = _useRadioContext.setSelectedValue,
      lastFocusedValue = _useRadioContext.lastFocusedValue;

  var labelId = "label-".concat(value);
  var descriptionId = "description-".concat(value);
  var title = benefits.title,
      items = benefits.items;

  var Benefit = function Benefit(_ref2) {
    var item = _ref2.item;
    return /*#__PURE__*/React.createElement(_Flex.default, {
      marginBottom: "m",
      as: "li"
    }, /*#__PURE__*/React.createElement(_Flex.default, {
      alignItems: "center",
      justifyContent: "center"
    }, /*#__PURE__*/React.createElement(_Icon.default, {
      type: "check",
      color: "icon-gray-70",
      size: 16,
      style: {
        marginRight: '8px'
      }
    }), /*#__PURE__*/React.createElement(_Text.default, {
      size: "medium"
    }, item)));
  };

  var borderColor = lastFocusedValue === value ? 'var(--blue-40)' : value === selectedValue ? 'var(--black)' : 'var(--gray-30)';
  return /*#__PURE__*/React.createElement("div", {
    onClick: function onClick(e) {
      setSelectedValue(e, value);
    },
    style: {
      width: '50%',
      position: 'relative',
      border: '2px solid black',
      borderColor: borderColor,
      borderRadius: '8px',
      padding: '24px',
      marginRight: '10px'
    }
  }, /*#__PURE__*/React.createElement(_Radio.default, {
    value: value,
    "aria-labelledby": labelId,
    "aria-describedby": descriptionId,
    style: {
      position: 'absolute',
      top: '0',
      right: '0',
      '--radioColor': value === selectedValue ? 'var(--black)' : 'var(--gray-30)'
    }
  }), /*#__PURE__*/React.createElement(_Flex.default, {
    alignItems: "center"
  }, /*#__PURE__*/React.createElement(_Logo.default, {
    type: LOGO[type],
    style: {
      width: '42px',
      height: 'auto'
    }
  }), /*#__PURE__*/React.createElement(_Text.default, {
    id: labelId,
    as: "label",
    weight: "bold",
    transform: "capitalize",
    style: {
      marginLeft: '8px'
    }
  }, "Brainly ", value)), /*#__PURE__*/React.createElement(_Flex.default, {
    as: "ul",
    direction: "column",
    alignItems: "flex-start",
    style: {
      padding: '0'
    }
  }, /*#__PURE__*/React.createElement(_Headline.default, {
    align: "to-left",
    extraBold: true,
    style: {
      marginBottom: '16px'
    }
  }, title), _toConsumableArray(items).map(function (item, index) {
    return /*#__PURE__*/React.createElement(Benefit, {
      key: index,
      item: item
    });
  })));
};

exports.CustomRadioComponent = CustomRadioComponent;