<ng-container *ngIf="linked; else unlinked">
  <a routerLink="/users/{{ user.id }}">
    <ng-template [ngTemplateOutlet]="tag"></ng-template>
  </a>
</ng-container>

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

  <ng-template #userPopover>
    <cvc-user-popover
      [userId]="user.id"
      (contentRendered)="updatePopoverPosition()"></cvc-user-popover>
  </ng-template>
</ng-template>

<ng-template #noPopover>
  <nz-tag>
    <ng-template [ngTemplateOutlet]="tagContent"></ng-template>
  </nz-tag>
</ng-template>

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

<ng-template #tagContent>
  <i
    nz-icon
    [nzType]="icon"
    nzTheme="twotone"
    [nzTwotoneColor]="user.role | titlecase | entityColor"></i>
  {{ user.displayName }}
</ng-template>
