import { ElementName, MediaPlacement, SmartLinkPosition, SmartLinkSize } from '../../../../constants';
import { extractOwnedBy } from '../../../../extractors/flexible/utils';
import { getExtensionKey } from '../../../../state/helpers';
const baseTopMetadata = [{
  name: ElementName.ModifiedOn
}, {
  name: ElementName.AttachmentCount
}, {
  name: ElementName.SubscriberCount
}, {
  name: ElementName.VoteCount
}, {
  name: ElementName.DueOn
}, {
  name: ElementName.ReadTime
}];
const baseBottomMetaData = [{
  name: ElementName.ReactCount
}, {
  name: ElementName.CommentCount
}, {
  name: ElementName.ViewCount
}, {
  name: ElementName.Priority
}, {
  name: ElementName.SubTasksProgress
}, {
  name: ElementName.ChecklistProgress
}];
export const getSimulatedBetterMetadata = cardDetails => {
  var _getExtensionKey, _data$Type$includes, _data$Type;
  const extensionKey = (_getExtensionKey = getExtensionKey(cardDetails)) !== null && _getExtensionKey !== void 0 ? _getExtensionKey : '';
  const data = cardDetails === null || cardDetails === void 0 ? void 0 : cardDetails.data;
  const defaultTitleMetadata = [{
    name: ElementName.State
  }];
  const defaultTopMetadata = [{
    name: ElementName.AuthorGroup
  }, {
    name: ElementName.CreatedBy
  }, ...baseTopMetadata];
  const defaultBottomMetadata = baseBottomMetaData;
  switch (extensionKey) {
    case 'bitbucket-object-provider':
    case 'native-bitbucket-object-provider':
      const isFile = data['@type'].includes('schema:DigitalDocument');
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: isFile ? [{
          name: ElementName.LatestCommit
        }, {
          name: ElementName.CollaboratorGroup
        }, {
          name: ElementName.ModifiedOn
        }] : defaultTopMetadata,
        bottomMetadata: defaultBottomMetadata
      };
    case 'dragonfruit-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: extractOwnedBy(data) ? [{
          name: ElementName.OwnedByGroup
        }, {
          name: ElementName.OwnedBy
        }, ...baseTopMetadata] : defaultTopMetadata,
        bottomMetadata: [{
          name: ElementName.AppliedToComponentsCount
        }, ...baseBottomMetaData]
      };
    case 'integration-passionfruit-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: extractOwnedBy(data) ? [{
          name: ElementName.OwnedByGroup
        }, {
          name: ElementName.OwnedBy
        }, ...baseTopMetadata] : defaultTopMetadata,
        bottomMetadata: [{
          name: ElementName.AppliedToComponentsCount
        }, ...baseBottomMetaData]
      };
    case 'confluence-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: extractOwnedBy(data) ? [{
          name: ElementName.OwnedByGroup
        }, {
          name: ElementName.OwnedBy
        }, ...baseTopMetadata] : defaultTopMetadata,
        bottomMetadata: defaultBottomMetadata
      };
    case 'jira-object-provider':
      const isJiraTask = (_data$Type$includes = (_data$Type = data['@type']) === null || _data$Type === void 0 ? void 0 : _data$Type.includes('atlassian:Task')) !== null && _data$Type$includes !== void 0 ? _data$Type$includes : false;
      const isJiraPlan = data['atlassian:ownedBy'] ? true : false;
      let topMetadata = [{
        name: ElementName.AuthorGroup
      }, {
        name: ElementName.CreatedBy
      }, {
        name: ElementName.ModifiedOn
      }];
      if (isJiraTask) {
        topMetadata = [{
          name: ElementName.AssignedToGroup
        }, {
          name: ElementName.AssignedTo
        }, {
          name: ElementName.ModifiedOn
        }];
      } else if (isJiraPlan) {
        topMetadata = [{
          name: ElementName.OwnedByGroup
        }, {
          name: ElementName.OwnedBy
        }];
      }
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata,
        bottomMetadata: [{
          name: ElementName.StoryPoints
        }, {
          name: ElementName.Priority
        }, {
          name: ElementName.SubTasksProgress
        }]
      };
    case 'slack-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: [{
          name: ElementName.AuthorGroup
        }, {
          name: ElementName.SentOn
        }],
        bottomMetadata: [{
          name: ElementName.ReactCount
        }, {
          name: ElementName.CommentCount
        }]
      };
    case 'trello-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: [{
          name: ElementName.CollaboratorGroup
        }, ...baseTopMetadata],
        bottomMetadata: defaultBottomMetadata
      };
    case 'legion-object-provider':
    case 'people-object-provider':
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: [{
          name: ElementName.AuthorGroup
        }, {
          name: ElementName.TeamMemberCount
        }, {
          name: ElementName.UserAttributes
        }, ...baseTopMetadata],
        bottomMetadata: defaultBottomMetadata
      };
    default:
      return {
        titleMetadata: defaultTitleMetadata,
        topMetadata: defaultTopMetadata,
        bottomMetadata: defaultBottomMetadata
      };
  }
};
export const FlexibleCardUiOptions = {
  hideElevation: true,
  hideLegacyButton: true,
  removeBlockRestriction: true
};
export const titleBlockOptions = {
  anchorTarget: '_self',
  position: SmartLinkPosition.Center,
  hideRetry: true,
  size: SmartLinkSize.Large
};
export const PreviewBlockOptions = {
  placement: MediaPlacement.Right,
  ignoreContainerPadding: true
};