"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extractInlineProps = void 0;
var _linkExtractors = require("@atlaskit/link-extractors");
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)) {
    var provider = (0, _linkExtractors.extractEntityProvider)(response);
    if (provider) {
      return provider.icon;
    }
    // We don't need this for design entities,
    // but we can add it back when we support more entities
    // it requires extractInlineIcon to be moved to the smart link extractor package.
    // see: https://product-fabric.atlassian.net/browse/EDM-12375
    // return extractSmartLinkIcon(response);
  }
  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)
  };
};