<ng-container *ngIf="linked; else unlinked">
  <a [routerLink]="molecularProfile.link">
    <ng-template [ngTemplateOutlet]="tag"></ng-template>
  </a>
</ng-container>

<ng-template #tag>
  <nz-tag
    *ngIf="enablePopover; else noPopover"
    [ngClass]="{ deprecated: molecularProfile.deprecated }"
    nz-popover
    [nzPopoverMouseEnterDelay]="0.5"
    [nzPopoverPlacement]="popoverPlacement"
    [nzPopoverContent]="enablePopover ? popoverContent : undefined">
    <ng-template [ngTemplateOutlet]="tagContent"></ng-template>
  </nz-tag>
  <ng-template #popoverContent>
    <cvc-molecular-profile-popover
      [molecularProfileId]="molecularProfile.id"
      (contentRendered)="updatePopoverPosition()">
    </cvc-molecular-profile-popover>
  </ng-template>
</ng-template>

<ng-template #noPopover>
  <nz-tag [ngClass]="{ deprecated: molecularProfile.deprecated }">
    <ng-template [ngTemplateOutlet]="tagContent"></ng-template>
  </nz-tag>
</ng-template>

<ng-template #unlinked>
  <ng-template [ngTemplateOutlet]="tag"></ng-template>
</ng-template>

<ng-template #tagContent>
  <cvc-icon-badges
    [flagged]="molecularProfile.flagged"
    [entityColor]="iconColor">
    <i
      nz-icon
      nzType="civic-molecularprofile"
      nzTheme="twotone"
      [nzTwotoneColor]="'MolecularProfile' | entityColor"></i>
  </cvc-icon-badges>
  <!-- molecular profile name length mean: 12; mode: 5 (825); max: 68 -->
  <ng-container *ngIf="truncateLongName; else fullName">
    {{ molecularProfile.name! | truncate: truncationLength }}
  </ng-container>
  <ng-template #fullName>
    {{ molecularProfile.name }}
  </ng-template>
</ng-template>
