<p-table
  [value]="comments" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start"
  [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" dataKey="id"
  [lazy]="true" (onLazyLoad)="loadLazy($event)" [lazyLoadOnInit]="false" [selectionPageOnly]="true"
  [showCurrentPageReport]="true" [currentPageReportTemplate]="getPaginationTemplate()"
  [expandedRowKeys]="expandedRows" [(selection)]="selectedRows"
>
  <ng-template pTemplate="caption">
    <div class="caption">
      <div>
        <my-action-dropdown
          *ngIf="isInSelectionMode()" i18n-label label="Batch actions" theme="orange"
          [actions]="bulkActions" [entry]="selectedRows"
        >
        </my-action-dropdown>
      </div>

      <div class="ms-auto right-form">
        <my-advanced-input-filter [filters]="inputFilters" (search)="onSearch($event)"></my-advanced-input-filter>

        <my-button i18n-label label="Refresh" icon="refresh" (click)="reloadData()"></my-button>
      </div>
    </div>
  </ng-template>

  <ng-template pTemplate="header">
    <tr>
      <th scope="col" style="width: 40px;">
        <p-tableHeaderCheckbox ariaLabel="Select all rows" i18n-ariaLabel></p-tableHeaderCheckbox>
      </th>
      <th scope="col" style="width: 40px;">
        <span i18n class="visually-hidden">More information</span>
      </th>
      <th scope="col" style="width: 150px;">
        <span i18n class="visually-hidden">Actions</span>
      </th>
      <th scope="col" i18n>Account</th>
      <th scope="col" i18n>Video</th>
      <th scope="col" i18n>Comment</th>
      <th scope="col" i18n>Auto tags</th>
      <th scope="col" style="width: 150px;" i18n [ngbTooltip]="sortTooltip" container="body" pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th>
    </tr>
  </ng-template>

  <ng-template pTemplate="body" let-videoComment let-expanded="expanded">
    <tr [pSelectableRow]="videoComment">

      <td class="checkbox-cell">
        <p-tableCheckbox [value]="videoComment" ariaLabel="Select this row" i18n-ariaLabel></p-tableCheckbox>
      </td>

      <td class="expand-cell">
        <my-table-expander-icon [pRowToggler]="videoComment" i18n-tooltip tooltip="See full comment" [expanded]="expanded"></my-table-expander-icon>
      </td>

      <td class="action-cell">
        <my-action-dropdown
          [ngClass]="{ 'show': expanded }" placement="bottom-right" container="body"
          i18n-label label="Actions" [actions]="videoCommentActions" [entry]="videoComment"
        ></my-action-dropdown>
      </td>

      <td>
        <a [href]="videoComment.account.localUrl" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer">
          <div class="chip two-lines">
            <my-actor-avatar [actor]="videoComment.account" actorType="account" size="32"></my-actor-avatar>
          <div>
              {{ videoComment.account.displayName }}
              <span>{{ videoComment.by }}</span>
            </div>
          </div>
        </a>
      </td>

      <td class="video">
        <em i18n>Commented video</em>

        <a [href]="videoComment.localUrl" target="_blank" rel="noopener noreferrer">{{ videoComment.video.name }}</a>
      </td>

      <td class="c-hand comment-content-cell" [pRowToggler]="videoComment">
        <span *ngIf="videoComment.heldForReview" class="pt-badge badge-red float-start me-2" i18n>Pending review</span>

        <div class="comment-html">
          <div [innerHTML]="videoComment.textHtml"></div>
        </div>
      </td>

      <td>
        @for (tag of videoComment.automaticTags; track tag) {
          <a
            i18n-title title="Only display comments with this tag"
            class="pt-badge badge-secondary me-1"
            [routerLink]="[ '.' ]" [queryParams]="{ 'search': buildSearchAutoTag(tag) }"
          >{{ tag }}</a>
        }
      </td>

      <td class="c-hand" [pRowToggler]="videoComment">{{ videoComment.createdAt | date: 'short' }}</td>
    </tr>
  </ng-template>

  <ng-template pTemplate="rowexpansion" let-videoComment>
    <tr>
      <td class="expand-cell" myAutoColspan>
        <div [innerHTML]="videoComment.textHtml"></div>
      </td>
    </tr>
  </ng-template>

  <ng-template pTemplate="emptymessage">
    <tr>
      <td myAutoColspan>
        <div class="no-results">
          <ng-container *ngIf="search" i18n>No comments found matching current filters.</ng-container>
          <ng-container *ngIf="!search" i18n>No comments found.</ng-container>
        </div>
      </td>
    </tr>
  </ng-template>
</p-table>

