<div class="header-container">
  <button mat-icon-button color="primary" (click)="iniciarTour()">
    <mat-icon>help</mat-icon>
  </button>
  <div class="header-container-title">
    <h2 class="title" joyrideStep="titleStep" text="{{ 'titleStepText' | translate }}">{{ 'manageTasksTitle' | translate }}</h2>
  </div>
  <div class="task-button-row">
    <button class="action-button" (click)="openCreateTaskModal()" joyrideStep="addTaskStep" text="{{ 'addTaskStepText' | translate }}">
      {{ 'addTask' | translate }}
    </button>
  </div>
</div>

<div class="search-container" joyrideStep="searchStep" text="{{ 'searchStepText' | translate }}">
  <mat-form-field appearance="fill" class="search-string">
    <mat-label>{{ 'searchTaskLabel' | translate }}</mat-label>
    <input matInput placeholder="{{ 'searchPlaceholder' | translate }}" [(ngModel)]="filters['name']" (keyup.enter)="search()" />
    <mat-icon matSuffix>search</mat-icon>
    <mat-hint>{{ 'searchHint' | translate }}</mat-hint>
  </mat-form-field>
</div>

<div *ngIf="!loading">
  <table mat-table [dataSource]="tasks" class="mat-elevation-z8" joyrideStep="tableStep" text="{{ 'tableStepText' | translate }}">
    <ng-container matColumnDef="taskid">
      <th mat-header-cell *matHeaderCellDef> {{ 'idColumn' | translate }} </th>
      <td mat-cell *matCellDef="let task"> {{ task.id }} </td>
    </ng-container>

    <ng-container matColumnDef="notes">
      <th mat-header-cell *matHeaderCellDef> {{ 'infoColumn' | translate }} </th>
      <td mat-cell *matCellDef="let task"> {{ task.notes }} </td>
    </ng-container>

    <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef> {{ 'createdByColumn' | translate }} </th>
      <td mat-cell *matCellDef="let task"> {{ task.createdBy }} </td>
    </ng-container>

    <ng-container matColumnDef="scheduledDate">
      <th mat-header-cell *matHeaderCellDef> {{ 'executionDateColumn' | translate }} </th>
      <td mat-cell *matCellDef="let task"> {{ task.dateTime | date:'short' }} </td>
    </ng-container>

    <ng-container matColumnDef="enabled">
      <th mat-header-cell *matHeaderCellDef> {{ 'statusColumn' | translate }} </th>
      <td mat-cell *matCellDef="let task"> {{ task.enabled ? ('enabled' | translate) : ('disabled' | translate) }} </td>
    </ng-container>

    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef style="text-align: center;">{{ 'columnActions' | translate }}</th>
      <td mat-cell *matCellDef="let task" style="text-align: center;" joyrideStep="actionsStep" text="{{ 'actionsStepText' | translate }}">
        <button mat-icon-button color="info" (click)="viewTaskDetails(task)">
          <mat-icon>visibility</mat-icon>
        </button>
        <button mat-icon-button color="primary" (click)="editTask(task)">
          <mat-icon>edit</mat-icon>
        </button>
        <button mat-icon-button color="warn" (click)="deleteTask(task)">
          <mat-icon>delete</mat-icon>
        </button>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>
</div>

<mat-paginator joyrideStep="paginationStep" text="{{ 'paginationStepText' | translate }}"
               [length]="length"
               [pageSize]="itemsPerPage"
               [pageSizeOptions]="pageSizeOptions"
               (page)="onPageChange($event)">
</mat-paginator>
