import React from 'react';
import DocumentFilledIcon from '@atlaskit/icon/core/migration/file--document-filled';
import { isConfluenceGenerator } from '@atlaskit/link-extractors';
import BlogIcon from '../../../common/ui/icons/blog-icon';
import PresentationIcon from '../../../common/ui/icons/chart-bar-icon';
import FileIcon from '../../../common/ui/icons/file-icon';
import SpreadsheetIcon from '../../../common/ui/icons/list-bullet-icon';
import LiveDocumentIcon from '../../../common/ui/icons/live-document-icon';
import DocumentIcon from '../../../common/ui/icons/page-icon';
import { getIconForFileType } from '../../../utils';
import { prioritiseIcon } from './prioritiseIcon';
/**
 * Extracts an icon for a document pbject
 *
 * @param type - The type of the document.
 * @param opts - The options for extracting the icon.
 * @returns The React node representing the extracted icon, or `undefined` if no icon is found.
 */
export var extractIconFromDocument = function extractIconFromDocument(type, opts) {
  var iconFromType = documentTypeToIcon(type, opts);
  var iconFromFileFormat = documentFileFormatToIcon(opts);
  var iconFromProvider = opts.provider && opts.provider.icon;
  return prioritiseIcon({
    fileFormatIcon: iconFromFileFormat,
    documentTypeIcon: iconFromType,
    urlIcon: opts.icon,
    providerIcon: iconFromProvider
  });
};
var documentFileFormatToIcon = function documentFileFormatToIcon(opts) {
  if (opts.fileFormat) {
    return getIconForFileType(opts.fileFormat);
  }
};
var documentTypeToIcon = function documentTypeToIcon(type, opts) {
  switch (type) {
    case 'schema:BlogPosting':
      return /*#__PURE__*/React.createElement(BlogIcon, {
        label: opts.showIconLabel ? opts.title || 'blog' : '',
        testId: "blog-icon"
      });
    case 'schema:DigitalDocument':
      return digitalDocumentToIcon(opts);
    case 'schema:TextDigitalDocument':
      return /*#__PURE__*/React.createElement(DocumentIcon, {
        label: opts.showIconLabel ? opts.title || 'document' : '',
        testId: "document-icon"
      });
    case 'schema:PresentationDigitalDocument':
      return /*#__PURE__*/React.createElement(PresentationIcon, {
        label: opts.showIconLabel ? opts.title || 'presentation' : '',
        testId: "presentation-icon"
      });
    case 'schema:SpreadsheetDigitalDocument':
      return /*#__PURE__*/React.createElement(SpreadsheetIcon, {
        label: opts.showIconLabel ? opts.title || 'spreadsheet' : '',
        testId: "spreadsheet-icon"
      });
    case 'atlassian:Template':
      return /*#__PURE__*/React.createElement(DocumentFilledIcon, {
        color: "currentColor",
        label: opts.showIconLabel ? opts.title || 'template' : '',
        testId: "document-filled-icon"
      });
    case 'atlassian:UndefinedLink':
      return /*#__PURE__*/React.createElement(DocumentIcon, {
        label: opts.showIconLabel ? opts.title || 'undefinedLink' : '',
        testId: "document-icon"
      });
  }
};

/**
 * Enables providers to represent `schema:DigitalDocument` in a manner which
 * aligns with their customers when representing provider-specific types, which
 * do not apply across multiple providers.
 * @example Confluence digital documents represent 'live documents', specific to Confluence.
 * @remark This mechanism will be superseded by backend-driven icon URLs as part
 * of go/j/MODES-5864. Do not add more!
 */
var digitalDocumentToIcon = function digitalDocumentToIcon(opts) {
  var _opts$provider;
  if ((_opts$provider = opts.provider) !== null && _opts$provider !== void 0 && _opts$provider.id && isConfluenceGenerator(opts.provider.id)) {
    return /*#__PURE__*/React.createElement(LiveDocumentIcon, {
      label: "live-doc",
      testId: "live-doc-icon"
    });
  } else {
    return /*#__PURE__*/React.createElement(FileIcon, {
      label: opts.showIconLabel ? opts.title || 'file' : '',
      testId: "file-icon"
    });
  }
};