import { extractPersonOwnedBy, extractSmartLinkAri, extractSmartLinkAuthorGroup, extractSmartLinkCreatedBy, extractSmartLinkCreatedOn, extractSmartLinkModifiedBy, extractSmartLinkModifiedOn, extractSmartLinkUrl, extractType } from '@atlaskit/link-extractors';
import { fg } from '@atlaskit/platform-feature-flags';
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 extractProvider from './extract-provider';
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';
const extractFlexibleUiContext = ({
  appearance,
  fireEvent,
  id,
  onClick,
  onAuxClick,
  onContextMenu,
  origin,
  product,
  resolve,
  rovoConfig,
  actionOptions,
  response,
  status,
  aiSummaryConfig,
  isPreviewPanelAvailable,
  openPreviewPanel,
  transformUrl,
  ...props
} = {}) => {
  if (!response) {
    return undefined;
  }
  const data = response.data;
  const meta = response.meta;
  const url = extractSmartLinkUrl(response);
  return {
    actions: extractFlexibleCardActions({
      actionOptions,
      aiSummaryConfig,
      appearance,
      fireEvent,
      id,
      origin,
      product,
      rovoConfig,
      response,
      url: props.url,
      // Use the original URL in edge cases, such as short links for AI summary and copy link actions.
      isPreviewPanelAvailable,
      openPreviewPanel,
      ...(fg('platform_smartlink_xpc_url_wrapping') ? {
        transformUrl
      } : undefined)
    }),
    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, onAuxClick, onContextMenu),
    location: extractLocation(data),
    modifiedBy: extractSmartLinkModifiedBy(response),
    modifiedOn: extractSmartLinkModifiedOn(response),
    preview: extractSmartLinkPreviewImage(response),
    priority: extractPriority(data),
    provider: fg('platform_sl_google_rebrand') ? extractProvider(response) : 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, fg('platform_smartlink_xpc_url_wrapping') ? transformUrl : undefined),
    subscriberCount: extractSubscriberCount(data),
    subTasksProgress: extractSubTasksProgress(data),
    storyPoints: extractStoryPoints(data),
    targetBranch: extractTargetBranch(data),
    userAttributes: extractUserAttributes(data),
    teamMemberCount: extractTeamMemberCount(data),
    url,
    ari: extractSmartLinkAri(response),
    type: extractType(data),
    meta: {
      objectId: extractMetaObjectId(meta),
      resourceType: extractMetaResourceType(meta),
      tenantId: extractMetaTenantId(meta)
    },
    hostName: extractHostName(response)
  };
};
export default extractFlexibleUiContext;