import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import Loadable from 'react-loadable';
import { ConfluenceIcon, JiraIcon } from '@atlaskit/logo';
import { fg } from '@atlaskit/platform-feature-flags';
import BlogIcon from '../../../../../common/ui/icons/blog-icon';
import LiveDocumentIcon from '../../../../../common/ui/icons/live-document-icon';
import DocumentIcon from '../../../../../common/ui/icons/page-icon';
import { IconType, SmartLinkSize } from '../../../../../constants';
import { getLazyIcons, isIconSizeLarge } from '../../../../../utils';
const getIconImportFn = (icon, size) => {
  const item = getLazyIcons()[icon];
  if (isIconSizeLarge(size) && item !== null && item !== void 0 && item.large) {
    return item.large;
  }
  return item === null || item === void 0 ? void 0 : item.default;
};
const importIcon = importFn => {
  return Loadable({
    loader: () => importFn().then(module => module.default),
    loading: () => null
  }); // Because we're using dynamic loading here, TS will not be able to infer the type.
};
const AtlaskitIcon = ({
  icon,
  label,
  testId,
  size = SmartLinkSize.Medium
}) => {
  // Check for synchonously loaded icons first for SSR purposes
  switch (icon) {
    case IconType.Document:
      return /*#__PURE__*/React.createElement(DocumentIcon, {
        label: label !== null && label !== void 0 ? label : 'document',
        testId: testId,
        size: size
      });
    case IconType.Blog:
      return /*#__PURE__*/React.createElement(BlogIcon, {
        label: label !== null && label !== void 0 ? label : 'blog',
        testId: testId,
        size: size
      });
    case IconType.LiveDocument:
      return /*#__PURE__*/React.createElement(LiveDocumentIcon, {
        label: label !== null && label !== void 0 ? label : 'live-doc',
        testId: testId,
        size: size
      });
  }
  const importFn = getIconImportFn(icon, size);
  if (!importFn) {
    return null;
  }
  const ImportedIcon = importIcon(importFn);
  switch (icon) {
    case IconType.Confluence:
      return /*#__PURE__*/React.createElement(ConfluenceIcon, _extends({
        appearance: "brand",
        testId: testId,
        size: size === SmartLinkSize.Large || size === SmartLinkSize.XLarge ? 'small' : 'xxsmall'
      }, fg('navx-1895-new-logo-design') ? {
        shouldUseNewLogoDesign: true
      } : undefined));
    case IconType.Jira:
      return /*#__PURE__*/React.createElement(JiraIcon, _extends({
        appearance: "brand",
        testId: testId,
        size: size === SmartLinkSize.Large || size === SmartLinkSize.XLarge ? 'small' : 'xxsmall'
      }, fg('navx-1895-new-logo-design') ? {
        shouldUseNewLogoDesign: true
      } : undefined));
    case IconType.Error:
    case IconType.Forbidden:
      return /*#__PURE__*/React.createElement(ImportedIcon, {
        label: label,
        testId: testId,
        LEGACY_size: size === SmartLinkSize.Large || size === SmartLinkSize.XLarge ? 'medium' : 'small',
        color: "var(--ds-icon-danger, #C9372C)"
      });
    default:
      return /*#__PURE__*/React.createElement(ImportedIcon, {
        label: label,
        testId: testId,
        LEGACY_size: size === SmartLinkSize.Large || size === SmartLinkSize.XLarge ? 'medium' : 'small',
        size: size
      });
  }
};
export default AtlaskitIcon;