import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import Loadable from 'react-loadable';
import { fg } from '@atlaskit/platform-feature-flags';
import { themeObjectToString } from '@atlaskit/tokens';
import { IconType, SmartLinkSize } from '../constants';
import extractFileFormatIcon from '../extractors/flexible/icon/extract-file-formatIcon';
export var isSpecialEvent = function isSpecialEvent(evt) {
  return evt.isDefaultPrevented() && (isIframe() || isSpecialKey(evt) || isSpecialClick(evt));
};
export var isIframe = function isIframe() {
  return window.parent !== parent;
};

/**
 * Meta key = cmd on mac, windows key on windows
 * Ctrl key on mac by default triggers a right click instead of left click
 * Ctrl key on Windows has the same behaviour of cmd key of mac (open in new tab)
 * Shift key is also a "special" key because the default behavior of Chromium-based browsers is to open the
 * link in a new window; Arc browser has custom logic to show links in its "peek" window when shift is held.
 *
 * `isSpecialKey` on a mouse event on mac with default behaviour should be equivalent to opening in new tab
 * On Windows it will be equivalent to opening a new tab, unless its the Window key that is held
 * in which case typically only a standard clickthrough will occur, this is likely a small portion of events
 */
export var isSpecialKey = function isSpecialKey(event) {
  return fg('platform-smart-card-shift-key') ? event.metaKey || event.ctrlKey || event.shiftKey : event.metaKey || event.ctrlKey;
};
export var isSpecialClick = function isSpecialClick(event) {
  return event.button === 1;
};
export var getIconForFileType = function getIconForFileType(fileMimeType) {
  if (!fileMimeType) {
    return;
  }
  var icon = getTypeToIconMap(fileMimeType.toLowerCase());
  if (!icon) {
    return;
  }
  var _icon = _slicedToArray(icon, 2),
    label = _icon[0],
    importCb = _icon[1];
  if (!importCb) {
    return;
  }
  var Icon = Loadable({
    loader: function loader() {
      return importCb().then(function (module) {
        return module.default;
      });
    },
    loading: function loading() {
      return null;
    }
  }); // because we're using dynamic loading here, TS will not be able to infer the type

  return /*#__PURE__*/React.createElement(Icon, {
    label: label,
    testId: "document-file-format-icon"
  });
};
// prettier-ignore
export var getLazyIcons = function getLazyIcons() {
  var _ref3;
  return _ref3 = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.Document, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_page-icon" */'../common/ui/icons/page-icon');
    }
  }), IconType.Blog, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBlock" */'../common/ui/icons/blog-icon');
    }
  }), IconType.Audio, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_audio-icon" */'../common/ui/icons/audio-icon');
    }
  }), IconType.Code, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_angle-brackets-icon" */'../common/ui/icons/angle-brackets-icon');
    }
  }), IconType.File, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_file-icon" */'../common/ui/icons/file-icon');
    }
  }), IconType.Folder, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_folder-icon" */'../common/ui/icons/folder-icon');
    }
  }), IconType.Generic, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_file-icon" */'../common/ui/icons/file-icon');
    }
  }), IconType.Image, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_image-icon" */'../common/ui/icons/image-icon');
    }
  }), IconType.Presentation, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_chart-bar-icon" */'../common/ui/icons/chart-bar-icon');
    }
  }), IconType.Spreadsheet, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_list-bullet-icon" */'../common/ui/icons/list-bullet-icon');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.Video, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_video-icon" */'../common/ui/icons/video-icon');
    }
  }), IconType.Project, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphProject" */'@atlaskit/icon/core/migration/people-group');
    }
  }), IconType.Template, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphTemplate" */'@atlaskit/icon/core/migration/file--document-filled');
    }
  }), IconType.Forbidden, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphForbidden" */'@atlaskit/icon/core/migration/lock-locked--lock-filled');
    }
  }), IconType.Default, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphDefault" */'@atlaskit/icon/core/migration/link');
    }
  }), IconType.Error, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphDefault" */'@atlaskit/icon/core/migration/status-error--error');
    }
  }), IconType.Archive, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphArchive" */'@atlaskit/icon-file-type/glyph/archive/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphArchive" */'@atlaskit/icon-file-type/glyph/archive/24');
    }
  }), IconType.Executable, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphExecutable" */'@atlaskit/icon-file-type/glyph/executable/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphExecutable" */'@atlaskit/icon-file-type/glyph/executable/24');
    }
  }), IconType.GIF, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGIF" */'@atlaskit/icon-file-type/glyph/gif/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGIF" */'@atlaskit/icon-file-type/glyph/gif/24');
    }
  }), IconType.GoogleDocs, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleDocs" */'@atlaskit/icon-file-type/glyph/google-doc/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleDocs" */'@atlaskit/icon-file-type/glyph/google-doc/24');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.GoogleForms, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleForms" */'@atlaskit/icon-file-type/glyph/google-form/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleForms" */'@atlaskit/icon-file-type/glyph/google-form/24');
    }
  }), IconType.GoogleSheets, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleSheets" */'@atlaskit/icon-file-type/glyph/google-sheet/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleSheets" */'@atlaskit/icon-file-type/glyph/google-sheet/24');
    }
  }), IconType.GoogleSlides, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleSlides" */'@atlaskit/icon-file-type/glyph/google-slide/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphGoogleSlides" */'@atlaskit/icon-file-type/glyph/google-slide/24');
    }
  }), IconType.MSExcel, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSExcel" */'@atlaskit/icon-file-type/glyph/excel-spreadsheet/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSExcel" */'@atlaskit/icon-file-type/glyph/excel-spreadsheet/24');
    }
  }), IconType.MSPowerpoint, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSPowerpoint" */'@atlaskit/icon-file-type/glyph/powerpoint-presentation/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSPowerpoint" */'@atlaskit/icon-file-type/glyph/powerpoint-presentation/24');
    }
  }), IconType.MSWord, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSWord" */'@atlaskit/icon-file-type/glyph/word-document/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMSWord" */'@atlaskit/icon-file-type/glyph/word-document/24');
    }
  }), IconType.PDF, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPDF" */'@atlaskit/icon-file-type/glyph/pdf-document/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPDF" */'@atlaskit/icon-file-type/glyph/pdf-document/24');
    }
  }), IconType.Sketch, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSketch" */'@atlaskit/icon-file-type/glyph/sketch/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSketch" */'@atlaskit/icon-file-type/glyph/sketch/24');
    }
  }), IconType.Branch, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBranch" */'@atlaskit/icon-object/glyph/branch/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBranch" */'@atlaskit/icon-object/glyph/branch/24');
    }
  }), IconType.Commit, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphCommit" */'@atlaskit/icon-object/glyph/commit/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphCommit" */'@atlaskit/icon-object/glyph/commit/24');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.PullRequest, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPullRequest" */'@atlaskit/icon-object/glyph/pull-request/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPullRequest" */'@atlaskit/icon-object/glyph/pull-request/24');
    }
  }), IconType.Repo, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphRepo" */'@atlaskit/icon-object/glyph/code/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphRepo" */'@atlaskit/icon-object/glyph/code/24');
    }
  }), IconType.Bug, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBug" */'@atlaskit/icon-object/glyph/bug/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBug" */'@atlaskit/icon-object/glyph/bug/24');
    }
  }), IconType.Change, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphChange" */'@atlaskit/icon-object/glyph/changes/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphChange" */'@atlaskit/icon-object/glyph/changes/24');
    }
  }), IconType.Epic, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphEpic" */'@atlaskit/icon-object/glyph/epic/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphEpic" */'@atlaskit/icon-object/glyph/epic/24');
    }
  }), IconType.Incident, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphIncident" */'@atlaskit/icon-object/glyph/incident/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphIncident" */'@atlaskit/icon-object/glyph/incident/24');
    }
  }), IconType.Problem, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphProblem" */'@atlaskit/icon-object/glyph/problem/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphProblem" */'@atlaskit/icon-object/glyph/problem/24');
    }
  }), IconType.ServiceRequest, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphServiceRequest" */'@atlaskit/icon-object/glyph/issue/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphServiceRequest" */'@atlaskit/icon-object/glyph/issue/24');
    }
  }), IconType.Story, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphStory" */'@atlaskit/icon-object/glyph/story/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphStory" */'@atlaskit/icon-object/glyph/story/24');
    }
  }), IconType.SubTask, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSubTask" */'@atlaskit/icon-object/glyph/subtask/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSubTask" */'@atlaskit/icon-object/glyph/subtask/24');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.Task, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphTask" */'@atlaskit/icon-object/glyph/task/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphTask" */'@atlaskit/icon-object/glyph/task/24');
    }
  }), IconType.LiveDocument, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPageLiveDoc" */'@atlaskit/icon-object/glyph/page-live-doc/16');
    },
    large: function large() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphPageLiveDoc" */'@atlaskit/icon-object/glyph/page-live-doc/24');
    }
  }), IconType.Confluence, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphConfluence" */'@atlaskit/logo/confluence-icon').then(function (_ref) {
        var ConfluenceIcon = _ref.ConfluenceIcon;
        return {
          default: ConfluenceIcon
        };
      });
    }
  }), IconType.Jira, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphJira" */'@atlaskit/logo/jira-icon').then(function (_ref2) {
        var JiraIcon = _ref2.JiraIcon;
        return {
          default: JiraIcon
        };
      });
    }
  }), IconType.Attachment, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphAttachment" */'@atlaskit/icon/core/migration/attachment');
    }
  }), IconType.CheckItem, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphAttachment" */'@atlaskit/icon/core/migration/task');
    }
  }), IconType.Component, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphComponent" */'@atlaskit/icon/core/migration/component');
    }
  }), IconType.Comment, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphComment" */'@atlaskit/icon/core/migration/comment');
    }
  }), IconType.View, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphComment" */'@atlaskit/icon/core/migration/eye-open--watch');
    }
  }), IconType.React, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphComment" */'@atlaskit/icon/core/migration/thumbs-up--like');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.Vote, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphComment" */'@atlaskit/icon/core/migration/arrow-up');
    }
  }), IconType.PriorityBlocker, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphBlocker" */'@atlaskit/icon-priority/glyph/priority-blocker');
    }
  }), IconType.PriorityCritical, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphCritical" */'@atlaskit/icon-priority/glyph/priority-critical');
    }
  }), IconType.PriorityHigh, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphHigh" */'@atlaskit/icon-priority/glyph/priority-high');
    }
  }), IconType.PriorityHighest, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphHighest" */'@atlaskit/icon-priority/glyph/priority-highest');
    }
  }), IconType.PriorityLow, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphLow" */'@atlaskit/icon-priority/glyph/priority-low');
    }
  }), IconType.PriorityLowest, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphLowest" */'@atlaskit/icon-priority/glyph/priority-lowest');
    }
  }), IconType.PriorityMajor, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMajor" */'@atlaskit/icon-priority/glyph/priority-major');
    }
  }), IconType.PriorityMedium, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMedium" */'@atlaskit/icon-priority/glyph/priority-medium');
    }
  }), IconType.PriorityMinor, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphMinor" */'@atlaskit/icon-priority/glyph/priority-minor');
    }
  }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref3, IconType.PriorityTrivial, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphTrivial" */'@atlaskit/icon-priority/glyph/priority-trivial');
    }
  }), IconType.PriorityUndefined, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphUndefined" */'@atlaskit/icon/core/migration/question-circle--question');
    }
  }), IconType.ProgrammingLanguage, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphProgrammingLanguage" */'@atlaskit/icon/core/migration/angle-brackets--code');
    }
  }), IconType.Subscriber, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSubscriber" */'@atlaskit/icon/core/migration/people-group--people');
    }
  }), IconType.SubTasksProgress, {
    default: function _default() {
      return import( /* webpackChunkName: "@atlaskit-internal_glyphSubtaskProgress" */'@atlaskit/icon/core/migration/subtasks--subtask');
    }
  });
};
var getTypeToIconMap = function getTypeToIconMap(fileFormat) {
  var _lazyIcons$iconDescri;
  var iconDescriptor = extractFileFormatIcon(fileFormat);
  if (!(iconDescriptor !== null && iconDescriptor !== void 0 && iconDescriptor.icon) || !iconDescriptor.label) {
    return null;
  }
  var lazyIcons = getLazyIcons();
  return [iconDescriptor.label, (_lazyIcons$iconDescri = lazyIcons[iconDescriptor.icon]) === null || _lazyIcons$iconDescri === void 0 ? void 0 : _lazyIcons$iconDescri.default];
};
export var getIframeSandboxAttribute = function getIframeSandboxAttribute(isTrusted) {
  if (isTrusted) {
    return undefined;
  }
  var sandboxPermissions = 'allow-downloads allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-same-origin allow-scripts';
  return sandboxPermissions;
};
export var handleOnClick = function handleOnClick(handler) {
  return function (e) {
    e.preventDefault();
    e.stopPropagation();
    handler();
  };
};
export var isIntersectionObserverSupported = function isIntersectionObserverSupported() {
  return typeof IntersectionObserver !== 'undefined';
};
export var sleep = function sleep(ms) {
  return new Promise(function (resolve) {
    return setTimeout(resolve, ms);
  });
};
var _importWithRetry = /*#__PURE__*/function () {
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(importFn) {
    var retries,
      interval,
      _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          retries = _args.length > 1 && _args[1] !== undefined ? _args[1] : 2;
          interval = _args.length > 2 && _args[2] !== undefined ? _args[2] : 500;
          _context.prev = 2;
          _context.next = 5;
          return importFn();
        case 5:
          return _context.abrupt("return", _context.sent);
        case 8:
          _context.prev = 8;
          _context.t0 = _context["catch"](2);
          if (!(_context.t0.name === 'ChunkLoadError' && retries > 0)) {
            _context.next = 16;
            break;
          }
          _context.next = 13;
          return sleep(interval);
        case 13:
          return _context.abrupt("return", _importWithRetry(importFn, retries - 1, interval));
        case 16:
          throw _context.t0;
        case 17:
        case "end":
          return _context.stop();
      }
    }, _callee, null, [[2, 8]]);
  }));
  return function importWithRetry(_x) {
    return _ref4.apply(this, arguments);
  };
}();
export { _importWithRetry as importWithRetry };
export var downloadUrl = /*#__PURE__*/function () {
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
    var isIE11, isSafari, iframeName, link, iframe;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          if (url) {
            _context2.next = 2;
            break;
          }
          return _context2.abrupt("return");
        case 2:
          isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
          isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
          iframeName = 'media-download-iframe';
          link = document.createElement('a');
          iframe = document.getElementById(iframeName);
          if (!iframe) {
            iframe = document.createElement('iframe');
            iframe.style.display = 'none';
            iframe.id = iframeName;
            iframe.name = iframeName;
            document.body.appendChild(iframe);
          }
          link.href = url;
          link.download = url;
          link.target = isIE11 || isSafari ? '_blank' : iframeName;
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        case 14:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  }));
  return function downloadUrl(_x2) {
    return _ref5.apply(this, arguments);
  };
}();
export var openUrl = /*#__PURE__*/function () {
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(url) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          if (url) {
            _context3.next = 2;
            break;
          }
          return _context3.abrupt("return");
        case 2:
          window.open(url, '_blank', 'noopener=yes');
        case 3:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  }));
  return function openUrl(_x3) {
    return _ref6.apply(this, arguments);
  };
}();

/**
 * Append a theme to the URL if it exists
 * @param previewUrl
 * @param themeState
 */
export var getPreviewUrlWithTheme = function getPreviewUrlWithTheme(previewUrl, themeState) {
  try {
    var url = new URL(previewUrl);
    url.searchParams.append('themeState', themeObjectToString(themeState));
    return url.href;
  } catch (_unused) {
    return previewUrl;
  }
};
export var isIconSizeLarge = function isIconSizeLarge(size) {
  return size && [SmartLinkSize.Large, SmartLinkSize.XLarge].includes(size);
};
export var isProfileType = function isProfileType(type) {
  return !!(type && type.includes('Profile'));
};