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