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

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

  <ng-template #clinicalTrialPopover>
    <cvc-clinical-trial-popover
      [clinicalTrialId]="clinicalTrial.id"
      (contentRendered)="updatePopoverPosition()"></cvc-clinical-trial-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]="'ClinicalTrial' | entityColor"
    nzType="civic-clinicaltrial"></i>
  {{ clinicalTrial.nctId }}
</ng-template>
