import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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) { _defineProperty(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; }
import { extractPersonOwnedBy, extractSmartLinkAri, extractSmartLinkAuthorGroup, extractSmartLinkCreatedBy, extractSmartLinkCreatedOn, extractSmartLinkModifiedBy, extractSmartLinkModifiedOn, extractSmartLinkUrl, extractType } from '@atlaskit/link-extractors';
import { fg } from '@atlaskit/platform-feature-flags';
import { isNewBlockcardUnauthorizedRefreshExperimentEnabled } from '../../utils/experiments';
import { extractSmartLinkSummary } from '../common/primitives/extractSummary';
import { extractFlexibleCardActions } from './actions';
import { extractPersonsUpdatedBy } from './collaboratorGroup';
import extractLinkTitle from './extract-link-title';
import { extractSmartLinkPreviewImage } from './extract-preview';
import extractPriority from './extract-priority';
import extractState from './extract-state';
import { extractSmartLinkIcon } from './icon';
import { extractSmartLinkProviderIcon } from './icon/extract-provider-icon';
import { extractLatestCommit } from './latest-commit';
import { extractAppliedToComponentsCount, extractAssignedTo, extractAttachmentCount, extractChecklistProgress, extractDueOn, extractHostName, extractLocation, extractMetaObjectId, extractMetaResourceType, extractMetaTenantId, extractOwnedBy, extractPersonAssignedToAsArray, extractProgrammingLanguage, extractReadTime, extractSmartLinkCommentCount, extractSmartLinkReactCount, extractSmartLinkSentOn, extractSourceBranch, extractStoryPoints, extractSubscriberCount, extractSubTasksProgress, extractTargetBranch, extractTeamMemberCount, extractUserAttributes, extractViewCount, extractVoteCount } from './utils';
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 = _objectWithoutProperties(_ref, _excluded);
  if (!response) {
    return undefined;
  }
  var data = response.data;
  var meta = response.meta;
  var url = extractSmartLinkUrl(response);
  return _objectSpread({
    actions: extractFlexibleCardActions(_objectSpread(_objectSpread({
      actionOptions: actionOptions,
      aiSummaryConfig: aiSummaryConfig,
      appearance: appearance,
      fireEvent: fireEvent,
      id: id,
      origin: origin
    }, 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: extractAppliedToComponentsCount(data),
    assignedToGroup: extractPersonAssignedToAsArray(data),
    attachmentCount: extractAttachmentCount(data),
    authorGroup: extractSmartLinkAuthorGroup(response),
    ownedByGroup: extractPersonOwnedBy(data),
    collaboratorGroup: extractPersonsUpdatedBy(data),
    commentCount: extractSmartLinkCommentCount(response),
    viewCount: extractViewCount(data),
    reactCount: extractSmartLinkReactCount(response),
    voteCount: extractVoteCount(data),
    checklistProgress: extractChecklistProgress(data),
    createdBy: extractSmartLinkCreatedBy(response),
    ownedBy: extractOwnedBy(data),
    assignedTo: extractAssignedTo(data),
    createdOn: extractSmartLinkCreatedOn(response),
    dueOn: extractDueOn(data),
    latestCommit: extractLatestCommit(data),
    linkIcon: extractSmartLinkIcon(response),
    linkTitle: extractLinkTitle(status, props.url, response, onClick),
    location: extractLocation(data),
    modifiedBy: extractSmartLinkModifiedBy(response),
    modifiedOn: extractSmartLinkModifiedOn(response),
    preview: extractSmartLinkPreviewImage(response),
    priority: extractPriority(data),
    provider: extractSmartLinkProviderIcon(response),
    programmingLanguage: extractProgrammingLanguage(data),
    readTime: extractReadTime(data),
    sentOn: extractSmartLinkSentOn(response),
    snippet: extractSmartLinkSummary(response) || undefined,
    // Explicitly set here to remove an empty string
    sourceBranch: extractSourceBranch(data),
    state: extractState(response, actionOptions, id, appearance, origin, fireEvent, resolve, isPreviewPanelAvailable, openPreviewPanel),
    subscriberCount: extractSubscriberCount(data),
    subTasksProgress: extractSubTasksProgress(data),
    storyPoints: extractStoryPoints(data),
    targetBranch: extractTargetBranch(data),
    userAttributes: extractUserAttributes(data),
    teamMemberCount: extractTeamMemberCount(data),
    url: url,
    ari: extractSmartLinkAri(response),
    type: extractType(data),
    meta: {
      objectId: extractMetaObjectId(meta),
      resourceType: extractMetaResourceType(meta),
      tenantId: extractMetaTenantId(meta)
    }
  }, isNewBlockcardUnauthorizedRefreshExperimentEnabled() && {
    hostName: extractHostName(response)
  });
};
export default extractFlexibleUiContext;