<!-- GUIPropertiesViewAndSortCustomizer -->
<div>
  <h2 id="page-heading" data-cy="PeriodHeading">
    <span jhiTranslate="resilientApp.period.home.title">Periods</span>

    <div class="d-flex justify-content-end">
      <button class="btn btn-info me-2" (click)="load()" [disabled]="isLoading">
        <fa-icon icon="sync" [spin]="isLoading"></fa-icon>
        <span jhiTranslate="resilientApp.period.home.refreshListLabel">Refresh list</span>
      </button>

      <button
        id="jh-create-entity"
        data-cy="entityCreateButton"
        class="btn btn-primary jh-create-entity create-period"
        [routerLink]="['/period/new']"
      >
        <fa-icon icon="plus"></fa-icon>
        <span jhiTranslate="resilientApp.period.home.createLabel">Criar novo(a) Period</span>
      </button>
    </div>
  </h2>

  <jhi-alert-error></jhi-alert-error>

  <jhi-alert></jhi-alert>

  @if (periods?.length === 0) {
    <div class="alert alert-warning" id="no-result">
      <span jhiTranslate="resilientApp.period.home.notFound">Nenhum Periods encontrado</span>
    </div>
  }

  @if (periods && periods.length > 0) {
    <div class="table-responsive table-entities" id="entities">
      <table class="table table-striped" aria-describedby="page-heading">
        <thead>
          <tr jhiSort [sortState]="sortState" (sortChange)="navigateToWithComponentValues($event)">
            <th scope="col" jhiSortBy="name">
              <div class="d-flex">
                <span jhiTranslate="resilientApp.period.name">Name</span>

                <fa-icon class="p-1" icon="sort"></fa-icon>
              </div>
            </th>
            <th scope="col" jhiSortBy="description">
              <div class="d-flex">
                <span jhiTranslate="resilientApp.period.description">Description</span>

                <fa-icon class="p-1" icon="sort"></fa-icon>
              </div>
            </th>
            <th scope="col" jhiSortBy="beginDate">
              <div class="d-flex">
                <span jhiTranslate="resilientApp.period.beginDate">Begin Date</span>

                <fa-icon class="p-1" icon="sort"></fa-icon>
              </div>
            </th>
            <th scope="col" jhiSortBy="endDate">
              <div class="d-flex">
                <span jhiTranslate="resilientApp.period.endDate">End Date</span>

                <fa-icon class="p-1" icon="sort"></fa-icon>
              </div>
            </th>
            <th scope="col" jhiSortBy="state">
              <div class="d-flex">
                <span jhiTranslate="resilientApp.period.state">State</span>

                <fa-icon class="p-1" icon="sort"></fa-icon>
              </div>
            </th>

            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          @for (period of periods; track trackId) {
            <tr data-cy="entityTable">
              <td>{{ period.name }}</td>
              <td>{{ period.description }}</td>
              <td>{{ period.beginDate | formatMediumDate }}</td>
              <td>{{ period.endDate | formatMediumDate }}</td>
              <td [jhiTranslate]="'resilientApp.PeriodStatus.' + (period.state ?? 'null')">
                {{ { null: '', CREATED: 'CREATED',OPENED: 'OPENED', CLOSED: 'CLOSED', PROCESSING: 'PROCESSING', ENDED: 'ENDED' }[period.state ?? 'null'] }}
              </td>

              <td class="text-end">
                <div class="btn-group" >
                  <a [routerLink]="['/period', period.id, 'view']" class="btn btn-info btn-sm" data-cy="entityDetailsButton">
                    <fa-icon icon="eye"></fa-icon>
                    <span class="d-none d-md-inline" jhiTranslate="entity.action.view">Visualizar</span>
                  </a>

                  <a [routerLink]="!canUpdate(period) ? null : ['/period', period.id, 'edit']" class="btn btn-primary btn-sm" [class.disabled]="!canUpdate(period)" data-cy="entityEditButton">
                    <fa-icon icon="pencil-alt"></fa-icon>
                    <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Editar</span>
                  </a>

                  <button type="submit" (click)="delete(period)" class="btn btn-danger btn-sm" [class.disabled]="!canDelete(period)" data-cy="entityDeleteButton">
                    <fa-icon icon="times"></fa-icon>
                    <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Eliminar</span>
                  </button>
                </div>
              </td>
            </tr>
          }
        </tbody>
      </table>
    </div>
  }
</div>
