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

<ng-template #tag>
  <nz-tag
    nz-popover
    [nzPopoverMouseEnterDelay]="0.5"
    [nzPopoverContent]="enablePopover ? phenotypePopover : undefined"
    [nzPopoverPlacement]="popoverPlacement">
    <ng-template [ngTemplateOutlet]="tagContent"></ng-template>
  </nz-tag>

  <ng-template #phenotypePopover>
    <cvc-phenotype-popover
      [phenotypeId]="phenotype.id"
      (contentRendered)="updatePopoverPosition()">
    </cvc-phenotype-popover>
  </ng-template>
</ng-template>

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

<ng-template #tagContent>
  <i
    nz-icon
    nzTheme="twotone"
    [nzTwotoneColor]="'Phenotype' | entityColor"
    nzType="civic-phenotype"></i>
  {{ phenotype.name }}
</ng-template>
