"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.default = exports.TYPE = exports.SIZE = exports.ICON_TAG_TYPE = exports.ICON_COLOR = void 0;

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

var _classnames = _interopRequireDefault(require("classnames"));

var _utils = require("../utils");

var _excluded = ["color", "size", "type", "children", "as", "className", "title", "description"];

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var TYPE = {
  ACADEMIC_CAP: 'academic_cap',
  ACHIEVEMENT: 'achievement',
  ADD_MORE: 'add_more',
  AI: 'ai',
  ALL_QUESTIONS: 'all_questions',
  ANSWER_BUBBLE: 'answer_bubble',
  ANSWER: 'answer',
  ANSWERS: 'answers',
  APPLE: 'apple',
  ARCHIVE_CHECKED: 'archive_checked',
  ARCHIVE: 'archive',
  ARROW_DOUBLE_RIGHT: 'arrow_double_right',
  ARROW_DOWN: 'arrow_down',
  ARROW_LEFT: 'arrow_left',
  ARROW_RIGHT: 'arrow_right',
  ARROW_TOP_RIGHT: 'arrow_top_right',
  ARROW_UP: 'arrow_up',
  ASK_BUBBLE: 'ask_bubble',
  ASK_PARENT_TO_PAY: 'ask_parent_to_pay',
  ATTACHMENT: 'attachment',
  BELL_CHECKED: 'bell_checked',
  BELL_OUTLINED: 'bell_outlined',
  BEST_ANSWER: 'best_answer',
  BLOCK: 'block',
  BOLD: 'bold',
  BRAINLY_OVAL: 'brainly_oval',
  BRAINLY_PARALLELOGRAM: 'brainly_parallelogram',
  BULB_CHECKED: 'bulb_checked',
  BULB_FILLED: 'bulb_filled',
  BULB: 'bulb',
  BULLETED_LIST: 'bulleted_list',
  CALENDAR: 'calendar',
  CAMERA: 'camera',
  CARET_DOWN: 'caret_down',
  CARET_UP: 'caret_up',
  CHAPTER: 'chapter',
  CHECK: 'check',
  CHECK_CIRCLE: 'check_circle',
  CHEVRON_DOUBLE_DOWN: 'chevron_double_down',
  CHEVRON_DOUBLE_RIGHT: 'chevron_double_right',
  CHEVRON_DOWN: 'chevron_down',
  CHEVRON_LEFT: 'chevron_left',
  CHEVRON_RIGHT: 'chevron_right',
  CHEVRON_UP: 'chevron_up',
  CHEVRONS_HORIZONTAL: 'chevrons_horizontal',
  CIRCLE: 'circle',
  CLEAR: 'clear',
  CLIPBOARD: 'clipboard',
  CLIPBOARD_OUTLINED: 'clipboard_outlined',
  CLOSE: 'close',
  COLLAPSE: 'collapse',
  COMMENT_OUTLINED: 'comment_outlined',
  COMMENT: 'comment',
  COUNTER: 'counter',
  CREDIT_CARD: 'credit_card',
  CROP: 'crop',
  CROWN_OUTLINED: 'crown_outlined',
  CROWN: 'crown',
  CUP: 'cup',
  CURSOR_SELECT: 'cursor_select',
  CYRILLIC: 'cyrillic',
  DOCUMENT: 'document',
  DOT: 'dot',
  DRAW: 'draw',
  DRAWING_MODE: 'drawing_mode',
  ENVELOPE: 'envelope',
  EQUATION: 'equation',
  ERASER: 'eraser',
  EUROPEAN: 'european',
  EXCLAMATION_MARK: 'exclamation_mark',
  EXPAND: 'expand',
  FACEBOOK: 'facebook',
  FILTERS: 'filters',
  FORWARD: 'forward',
  FRIEND_ADD: 'friend_add',
  FRIEND_CHECKED: 'friend_checked',
  FRIEND_PENDING: 'friend_pending',
  FRIEND_REMOVE: 'friend_remove',
  FRIENDS: 'friends',
  FULLSCREEN: 'fullscreen',
  FUNNEL: 'funnel',
  GINNY: 'ginny',
  GLOBE: 'globe',
  GOOGLE: 'google',
  GRAPH: 'graph',
  GREEK: 'greek',
  HEADING: 'heading',
  HEART_OUTLINED: 'heart_outlined',
  HEART: 'heart',
  HIGHLIGHT: 'highlight',
  HOME: 'home',
  HOW_TO_SCAN: 'how_to_scan',
  IMAGE_LIBRARY: 'image_library',
  IMAGE: 'image',
  INFLUENCE: 'influence',
  INFO_OUTLINED: 'info_outlined',
  INFO: 'info',
  INSTRAGRAM: 'instagram',
  ITALIC: 'italic',
  KEYBOARD: 'keyboard',
  LESS: 'less',
  LINE: 'line',
  LINK: 'link',
  LINKEDIN: 'linkedin',
  LOCK_WITH_PLAY: 'lock_with_play',
  LOGOUT: 'logout',
  MATH_SCAN: 'math_scan',
  MEDIUM: 'medium',
  MEGAPHONE: 'megaphone',
  MENU: 'menu',
  MESSAGE_NEW: 'message_new',
  MESSAGES: 'messages',
  MIC: 'mic',
  MIC_MUTED: 'mic_muted',
  MINUS_IN_CIRCLE_OUTLIEND: 'minus_in_circle_outlined',
  MONEY_TRANSFER: 'money_transfer',
  MORE: 'more',
  MULTISELECT_CHECKED: 'multiselect_checked',
  MULTISELECT_UNCHECKED: 'multiselect_unchecked',
  NOTIFICATIONS: 'notifications',
  NUMBERED_LIST: 'numbered_list',
  OPEN_IN_NEW_TAB: 'open_in_new_tab',
  OPTIONS: 'options',
  PADLOCK_OPEN: 'padlock_open',
  PADLOCK: 'padlock',
  PAUSE: 'pause',
  PDF: 'pdf',
  PENCIL: 'pencil',
  PI: 'pi',
  PLAY: 'play',
  PLUS: 'plus',
  POINTS: 'points',
  PRINTER: 'printer',
  PROFILE_SETTINGS: 'profile_settings',
  PROFILE_VIEW: 'profile_view',
  PROFILE: 'profile',
  QUESTION_ALT: 'question_alt',
  QUESTION: 'question',
  QUOTE: 'quote',
  RECENT_QUESTIONS_ALT: 'recent_questions_alt',
  RECENT_QUESTIONS: 'recent_questions',
  RECTANGLE: 'rectangle',
  RELOAD: 'reload',
  REPORT_FLAG_OUTLINED: 'report_flag_outlined',
  REPORT_FLAG: 'report_flag',
  ROTATE_90: 'rotate_90',
  ROTATE: 'rotate',
  SEARCH: 'search',
  SEARCH_ADD: 'search_add',
  SEEN: 'seen',
  SEND: 'send',
  SETTINGS: 'settings',
  SHARE: 'share',
  SHIELD: 'shield',
  SIDEBAR_LEFT: 'sidebar_left',
  SIDEBAR_RIGHT: 'sidebar_right',
  SMARTPHONE: 'smartphone',
  SMS: 'sms',
  SPARK: 'spark',
  SPARKS: 'sparks',
  STAR_HALF_OUTLINED: 'star_half_outlined',
  STAR_HALF: 'star_half',
  STAR_OUTLINED: 'star_outlined',
  STAR: 'star',
  SUBTITLE: 'subtitle',
  SUP_SUB: 'sup_sub',
  SYMBOLS: 'symbols',
  TEXTBOOK: 'textbook',
  THUMB_DOWN_OUTLINED: 'thumb_down_outlined',
  THUMB_DOWN: 'thumb_down',
  THUMB_UP_OUTLINED: 'thumb_up_outlined',
  THUMB_UP: 'thumb_up',
  TITLE: 'title',
  TOUGHEST_QUESTIONS_ALT: 'toughest_questions_alt',
  TOUGHEST_QUESTIONS: 'toughest_questions',
  TRASH: 'trash',
  TRIANGLE: 'triangle',
  TWITTER: 'twitter',
  UNDERLINED: 'underlined',
  UNSEEN: 'unseen',
  UPLOAD: 'upload',
  USER_BLOCK: 'user_block',
  VERIFIED: 'verified',
  VIEW_CHECKED: 'view_checked',
  WARNING: 'warning',
  YOUTUBE: 'youtube',
  GIFT: 'gift'
};
exports.TYPE = TYPE;
var ICON_COLOR = {
  ADAPTIVE: 'adaptive',
  'icon-black': 'icon-black',
  'icon-white': 'icon-white',
  'icon-blue-50': 'icon-blue-50',
  'icon-blue-60': 'icon-blue-60',
  'icon-indigo-50': 'icon-indigo-50',
  'icon-indigo-60': 'icon-indigo-60',
  'icon-green-50': 'icon-green-50',
  'icon-green-60': 'icon-green-60',
  'icon-yellow-50': 'icon-yellow-50',
  'icon-yellow-60': 'icon-yellow-60',
  'icon-red-50': 'icon-red-50',
  'icon-red-60': 'icon-red-60',
  'icon-gray-70': 'icon-gray-70',
  'icon-gray-60': 'icon-gray-60',
  'icon-gray-50': 'icon-gray-50',
  'icon-gray-40': 'icon-gray-40'
};
exports.ICON_COLOR = ICON_COLOR;
var ICON_TAG_TYPE = {
  DIV: 'div',
  SPAN: 'span'
};
exports.ICON_TAG_TYPE = ICON_TAG_TYPE;
var SIZE = [16, 24, 32, 40, 56, 80, 104];
exports.SIZE = SIZE;

function generateIdSuffix(type) {
  return "".concat(type, "-").concat((0, _utils.generateId)());
}

var Icon = function Icon(_ref) {
  var _classNames;

  var _ref$color = _ref.color,
      color = _ref$color === void 0 ? ICON_COLOR['icon-white'] : _ref$color,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 24 : _ref$size,
      type = _ref.type,
      children = _ref.children,
      _ref$as = _ref.as,
      as = _ref$as === void 0 ? 'div' : _ref$as,
      className = _ref.className,
      title = _ref.title,
      description = _ref.description,
      props = _objectWithoutProperties(_ref, _excluded);

  var iconClass = (0, _classnames.default)('sg-icon', (_classNames = {}, _defineProperty(_classNames, "sg-icon--".concat(String(color)), color), _defineProperty(_classNames, "sg-icon--x".concat(String(size)), size), _classNames), className);
  var iconType = "#icon-".concat(type);
  var Tag = as;
  var idSuffix = generateIdSuffix(type);
  var titleId = "title-".concat(idSuffix);
  var defaultTitle = String(type).replace(/_/g, ' ');
  var descId = "desc-".concat(idSuffix);
  var labelledBy = description ? "".concat(titleId, " ").concat(descId) : titleId;
  var ariaLabel = type ? undefined : [title, description].filter(Boolean).join(', '); // suppressHydrationWarning is used until 'useId' hook is available

  return /*#__PURE__*/React.createElement(Tag, _extends({}, props, {
    className: iconClass,
    "aria-label": ariaLabel
  }), type ? /*#__PURE__*/React.createElement("svg", {
    className: "sg-icon__svg",
    role: "img",
    "aria-labelledby": labelledBy,
    focusable: "false" // @ts-expect-error
    ,
    suppressHydrationWarning: true
  }, /*#__PURE__*/React.createElement("text", {
    id: titleId,
    visibility: "hidden"
    /* @ts-expect-error */
    ,
    suppressHydrationWarning: true
  }, title || defaultTitle), description && /*#__PURE__*/React.createElement("desc", {
    id: descId
  }, description), /*#__PURE__*/React.createElement("use", {
    xlinkHref: iconType,
    "aria-hidden": "true"
  })) : children);
};

var _default = Icon;
exports.default = _default;