<h1 class="d-flex justify-content-between">
  <span class="text-nowrap me-2">
    <my-global-icon iconName="cog" aria-hidden="true"></my-global-icon>
    <ng-container i18n>Runner registration tokens</ng-container>
  </span>

  <div>
    <a routerLink="/admin/system/runners/runners-list" class="peertube-button-link peertube-button-icon grey-button">
      <my-global-icon iconName="codesandbox" aria-hidden="true"></my-global-icon>
      <ng-container i18n>Remote runners</ng-container>
    </a>
  </div>
</h1>

<p-table
  [value]="registrationTokens" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start"
  [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order"
  [lazy]="true" (onLazyLoad)="loadLazy($event)"
  [showCurrentPageReport]="true" [currentPageReportTemplate]="getPaginationTemplate()"
>
  <ng-template pTemplate="header">
    <tr>
      <th scope="col" style="width: 120px;">
        <span i18n class="visually-hidden">Actions</span>
      </th>
      <th scope="col" i18n>Token</th>
      <th scope="col" style="width: 150px;" i18n [ngbTooltip]="sortTooltip" container="body" pSortableColumn="createdAt">Created <p-sortIcon field="createdAt"></p-sortIcon></th>
      <th scope="col" style="width: 160px;" i18n>Associated runners</th>
    </tr>
  </ng-template>

  <ng-template pTemplate="caption">
    <div class="caption">
      <div class="left-buttons">
        <my-button theme="orange" i18n-label label="Generate token" icon="add" (click)="generateToken()"></my-button>
      </div>
    </div>
  </ng-template>

  <ng-template pTemplate="body" let-registrationToken>
    <tr>
      <td class="action-cell">
        <my-action-dropdown
          placement="bottom-right top-right left auto" container="body"
          i18n-label label="Actions" [actions]="actions" [entry]="registrationToken"
        ></my-action-dropdown>
      </td>

      <td>
        {{ registrationToken.registrationToken }}

        <my-copy-button
          [value]="registrationToken.registrationToken" i18n-notification notification="Registration token copied"
          i18n-title title="Copy registration token"
        ></my-copy-button>
      </td>

      <td>{{ registrationToken.createdAt | date: 'short'  }}</td>

      <td>{{ registrationToken.registeredRunnersCount }}</td>
    </tr>
  </ng-template>

  <ng-template pTemplate="emptymessage">
    <tr>
      <td myAutoColspan>
        <div class="no-results">
          <ng-container i18n>No registration token found for remote runners.</ng-container>
        </div>
      </td>
    </tr>
  </ng-template>
</p-table>
