@if (task) {
  <nsi-two-columns-configuration-item
    itemTitle="tasks-automation.execution.ongoing.title"
    description="tasks-automation.execution.ongoing.description"
    noTopBorder>
    @if (task.enabled) {
      <pa-button
        aspect="basic"
        (click)="enable(false)">
        {{ 'tasks-automation.execution.ongoing.disable' | translate }}
      </pa-button>
    } @else {
      <pa-button (click)="enable(true)">
        {{ 'tasks-automation.execution.ongoing.automate' | translate }}
      </pa-button>
    }
  </nsi-two-columns-configuration-item>

  <nsi-two-columns-configuration-item
    itemTitle="tasks-automation.execution.batch.title"
    description="tasks-automation.execution.batch.description">
    <pa-button
      [disabled]="runningTask | async"
      (click)="runTask()">
      {{ 'tasks-automation.execution.batch.run' | translate }}
    </pa-button>
    @if (((batchTasks | async) || []).length > 0) {
      <div class="executions">
        <div class="title-s">{{ 'tasks-automation.execution.batch.executions' | translate }}</div>
        <pa-table
          border
          columns="1fr 160px 120px 50px">
          @for (task of batchTasks | async; track task; let i = $index; let count = $count) {
            <pa-table-row>
              <pa-table-cell>
                <span class="body-m">
                  {{ 'tasks-automation.execution.batch.execution' | translate: { num: count - i } }}
                </span>
              </pa-table-cell>
              <pa-table-cell>
                <span class="body-m">
                  <pa-datetime
                    [datetime]="task.creationDate"
                    dateOnly></pa-datetime>
                </span>
              </pa-table-cell>
              <pa-table-cell>
                <span class="body-m">
                  {{ 'tasks-automation.status.' + task.status | translate }}
                </span>
              </pa-table-cell>
              <pa-table-cell-menu>
                <pa-button
                  aspect="basic"
                  icon="more-vertical"
                  size="small"
                  [disabled]="task.status !== 'progress' && task.status !== 'stopped'"
                  [paPopup]="cellMenu"></pa-button>
                <pa-dropdown #cellMenu>
                  @if (task.status === 'stopped') {
                    <pa-option (selectOption)="restartTask(task.id)">
                      {{ 'tasks-automation.actions.restart' | translate }}
                    </pa-option>
                  }
                  @if (task.status === 'progress') {
                    <pa-option (selectOption)="stopTask(task.id)">
                      {{ 'tasks-automation.actions.stop' | translate }}
                    </pa-option>
                  }
                </pa-dropdown>
              </pa-table-cell-menu>
            </pa-table-row>
          }
        </pa-table>
      </div>
    }
  </nsi-two-columns-configuration-item>
}
