<div class="header">
  <div class="peertube-select-container">
    <select [(ngModel)]="logType" (ngModelChange)="refresh()" class="form-control">
      <option *ngFor="let logTypeChoice of logTypeChoices" [value]="logTypeChoice.id">{{ logTypeChoice.label }}</option>
    </select>
  </div>

  <ng-select
    [(ngModel)]="startDate"
    (ngModelChange)="refresh()"
    [clearable]="false"
    [searchable]="false"
  >
    <ng-option *ngFor="let time of timeChoices" [value]="time.id">
      {{ time.label }} ({{ time.id | date: time.dateFormat }} - <span i18n>now</span>)
    </ng-option>
  </ng-select>

  <ng-select
    [(ngModel)]="level"
    (ngModelChange)="refresh()"
    [clearable]="false"
    [searchable]="false"
    *ngIf="!isAuditLog()"
  >
    <ng-option *ngFor="let levelChoice of levelChoices" [value]="levelChoice.id">
      <ng-container *ngIf="levelChoice.id === 'debug'"><span style="font-size:80%;color:lightgray;vertical-align:text-top;">&#11044;</span> {{ levelChoice.label }}</ng-container>
      <ng-container *ngIf="levelChoice.id === 'info'"><span style="font-size:80%;color:lightskyblue;vertical-align:text-top;">&#11044;</span> {{ levelChoice.label }}</ng-container>
      <ng-container *ngIf="levelChoice.id === 'warn'"><span style="font-size:80%;color:orange;vertical-align:text-top;">&#11044;</span> {{ levelChoice.label }}</ng-container>
      <ng-container *ngIf="levelChoice.id === 'error'"><span style="font-size:80%;color:red;vertical-align:text-top;">&#11044;</span> {{ levelChoice.label }}</ng-container>
    </ng-option>
  </ng-select>

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

<div class="logs">
  <div *ngIf="loading" i18n>Loading...</div>

  <div #logsElement>
    <div *ngFor="let log of logs" class="log-row" [ngClass]="{ error: log.level === 'error', warn: log.level === 'warn' }">
      <span class="log-level">{{ log.level }}</span>

      <span class="log-date">[{{ log.localeDate }}]</span>

      <strong class="log-by" *ngIf="log.by" i18n>By {{ log.by }} -></strong>
      <strong class="log-domain-action" *ngIf="log.domain">{{ log.domain }} -> {{ log.action }}</strong>

      {{ log.message }}

      <pre>{{ log.meta }}</pre>
    </div>
  </div>
</div>
