"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extractInlineProps = void 0;
var _linkExtractors = require("@atlaskit/link-extractors");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _jsonld = require("../../utils/jsonld");
var _icon = require("../common/icon");
var _lozenge = require("../common/lozenge");
var _primitives = require("../common/primitives");
var _titlePrefix = require("../common/title-prefix");
var _constants = require("../constants");
var extractInlineIcon = function extractInlineIcon(jsonLd) {
  var showIconLabel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  var provider = (0, _linkExtractors.extractProvider)(jsonLd);
  if (provider && provider.id) {
    if (provider.id === _constants.CONFLUENCE_GENERATOR_ID || provider.id === _constants.JIRA_GENERATOR_ID) {
      return (0, _icon.extractIcon)(jsonLd, 'type', showIconLabel);
    }
  }
  return (0, _icon.extractIcon)(jsonLd, 'provider', showIconLabel);
};

/**
 * Should be moved to the smart link-extractor when jsonld is deprecated
 */
var extractSmartLinkInlineIcon = function extractSmartLinkInlineIcon(response) {
  var showLabel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  if ((0, _linkExtractors.isEntityPresent)(response)) {
    if ((0, _platformFeatureFlags.fg)('platform_lp_use_entity_icon_url_for_icon')) {
      var entityIcon = (0, _linkExtractors.extractEntityIcon)(response);
      if (entityIcon) {
        return [entityIcon.url, entityIcon.label];
      }
    }
    var provider = (0, _linkExtractors.extractEntityProvider)(response);
    if (provider) {
      return provider.icon;
    }
  }
  return extractInlineIcon((response === null || response === void 0 ? void 0 : response.data) || (0, _jsonld.getEmptyJsonLd)(), showLabel);
};
var extractInlineProps = exports.extractInlineProps = function extractInlineProps(response, renderers, removeTextHighlightingFromTitle) {
  var showLabel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  var jsonLd = (response === null || response === void 0 ? void 0 : response.data) || (0, _jsonld.getEmptyJsonLd)();
  return {
    link: (0, _linkExtractors.extractSmartLinkUrl)(response),
    title: (0, _linkExtractors.extractSmartLinkTitle)(response, removeTextHighlightingFromTitle),
    icon: extractSmartLinkInlineIcon(response, showLabel),
    // As we migrate to support more entities we can incorporate these fields
    lozenge: (0, _lozenge.extractLozenge)(jsonLd),
    titleTextColor: (0, _primitives.extractTitleTextColor)(jsonLd),
    titlePrefix: (0, _titlePrefix.extractTitlePrefix)(jsonLd, renderers, 'inline'),
    type: (0, _linkExtractors.extractType)(jsonLd)
  };
};