"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _linkExtractors = require("@atlaskit/link-extractors");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _experiments = require("../../utils/experiments");
var _extractSummary = require("../common/primitives/extractSummary");
var _actions = require("./actions");
var _collaboratorGroup = require("./collaboratorGroup");
var _extractLinkTitle = _interopRequireDefault(require("./extract-link-title"));
var _extractPreview = require("./extract-preview");
var _extractPriority = _interopRequireDefault(require("./extract-priority"));
var _extractState = _interopRequireDefault(require("./extract-state"));
var _icon = require("./icon");
var _extractProviderIcon = require("./icon/extract-provider-icon");
var _latestCommit = require("./latest-commit");
var _utils = require("./utils");
var _excluded = ["appearance", "fireEvent", "id", "onClick", "origin", "product", "resolve", "rovoConfig", "actionOptions", "response", "status", "aiSummaryConfig", "isPreviewPanelAvailable", "openPreviewPanel"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var extractFlexibleUiContext = function extractFlexibleUiContext() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var appearance = _ref.appearance,
    fireEvent = _ref.fireEvent,
    id = _ref.id,
    onClick = _ref.onClick,
    origin = _ref.origin,
    product = _ref.product,
    resolve = _ref.resolve,
    rovoConfig = _ref.rovoConfig,
    actionOptions = _ref.actionOptions,
    response = _ref.response,
    status = _ref.status,
    aiSummaryConfig = _ref.aiSummaryConfig,
    isPreviewPanelAvailable = _ref.isPreviewPanelAvailable,
    openPreviewPanel = _ref.openPreviewPanel,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  if (!response) {
    return undefined;
  }
  var data = response.data;
  var meta = response.meta;
  var url = (0, _linkExtractors.extractSmartLinkUrl)(response);
  return _objectSpread({
    actions: (0, _actions.extractFlexibleCardActions)(_objectSpread(_objectSpread({
      actionOptions: actionOptions,
      aiSummaryConfig: aiSummaryConfig,
      appearance: appearance,
      fireEvent: fireEvent,
      id: id,
      origin: origin
    }, (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_action_kill_switch') ? {
      product: product,
      rovoConfig: rovoConfig
    } : undefined), {}, {
      response: response,
      url: props.url,
      // Use the original URL in edge cases, such as short links for AI summary and copy link actions.
      isPreviewPanelAvailable: isPreviewPanelAvailable,
      openPreviewPanel: openPreviewPanel
    })),
    appliedToComponentsCount: (0, _utils.extractAppliedToComponentsCount)(data),
    assignedToGroup: (0, _utils.extractPersonAssignedToAsArray)(data),
    attachmentCount: (0, _utils.extractAttachmentCount)(data),
    authorGroup: (0, _linkExtractors.extractSmartLinkAuthorGroup)(response),
    ownedByGroup: (0, _linkExtractors.extractPersonOwnedBy)(data),
    collaboratorGroup: (0, _collaboratorGroup.extractPersonsUpdatedBy)(data),
    commentCount: (0, _utils.extractSmartLinkCommentCount)(response),
    viewCount: (0, _utils.extractViewCount)(data),
    reactCount: (0, _utils.extractSmartLinkReactCount)(response),
    voteCount: (0, _utils.extractVoteCount)(data),
    checklistProgress: (0, _utils.extractChecklistProgress)(data),
    createdBy: (0, _linkExtractors.extractSmartLinkCreatedBy)(response),
    ownedBy: (0, _utils.extractOwnedBy)(data),
    assignedTo: (0, _utils.extractAssignedTo)(data),
    createdOn: (0, _linkExtractors.extractSmartLinkCreatedOn)(response),
    dueOn: (0, _utils.extractDueOn)(data),
    latestCommit: (0, _latestCommit.extractLatestCommit)(data),
    linkIcon: (0, _icon.extractSmartLinkIcon)(response),
    linkTitle: (0, _extractLinkTitle.default)(status, props.url, response, onClick),
    location: (0, _utils.extractLocation)(data),
    modifiedBy: (0, _linkExtractors.extractSmartLinkModifiedBy)(response),
    modifiedOn: (0, _linkExtractors.extractSmartLinkModifiedOn)(response),
    preview: (0, _extractPreview.extractSmartLinkPreviewImage)(response),
    priority: (0, _extractPriority.default)(data),
    provider: (0, _extractProviderIcon.extractSmartLinkProviderIcon)(response),
    programmingLanguage: (0, _utils.extractProgrammingLanguage)(data),
    readTime: (0, _utils.extractReadTime)(data),
    sentOn: (0, _utils.extractSmartLinkSentOn)(response),
    snippet: (0, _extractSummary.extractSmartLinkSummary)(response) || undefined,
    // Explicitly set here to remove an empty string
    sourceBranch: (0, _utils.extractSourceBranch)(data),
    state: (0, _extractState.default)(response, actionOptions, id, appearance, origin, fireEvent, resolve, isPreviewPanelAvailable, openPreviewPanel),
    subscriberCount: (0, _utils.extractSubscriberCount)(data),
    subTasksProgress: (0, _utils.extractSubTasksProgress)(data),
    storyPoints: (0, _utils.extractStoryPoints)(data),
    targetBranch: (0, _utils.extractTargetBranch)(data),
    userAttributes: (0, _utils.extractUserAttributes)(data),
    teamMemberCount: (0, _utils.extractTeamMemberCount)(data),
    url: url,
    ari: (0, _linkExtractors.extractSmartLinkAri)(response),
    type: (0, _linkExtractors.extractType)(data),
    meta: {
      objectId: (0, _utils.extractMetaObjectId)(meta),
      resourceType: (0, _utils.extractMetaResourceType)(meta),
      tenantId: (0, _utils.extractMetaTenantId)(meta)
    }
  }, (0, _experiments.isNewBlockcardUnauthorizedRefreshExperimentEnabled)() && {
    hostName: (0, _utils.extractHostName)(response)
  });
};
var _default = exports.default = extractFlexibleUiContext;