<template>
  <div>
    <h2 id="page-heading" data-cy="NotificaHeading">
      <span id="notifica">{{ t$('smartbookingApp.notifica.home.title') }}</span>
      <div class="d-flex justify-content-end">
        <button class="btn btn-info me-2" @click="handleSyncList" :disabled="isFetching">
          <font-awesome-icon icon="sync" :spin="isFetching"></font-awesome-icon>
          <span>{{ t$('smartbookingApp.notifica.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'NotificaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-notifica"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.notifica.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && notificas?.length === 0">
      <span>{{ t$('smartbookingApp.notifica.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="notificas?.length > 0">
      <table class="table table-striped" aria-describedby="notificas">
        <thead>
          <tr>
            <th scope="col" @click="changeOrder('id')">
              <span>{{ t$('global.field.id') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'id'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('tipoCanale')">
              <span>{{ t$('smartbookingApp.notifica.tipoCanale') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'tipoCanale'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('tipoEvento')">
              <span>{{ t$('smartbookingApp.notifica.tipoEvento') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'tipoEvento'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('messaggio')">
              <span>{{ t$('smartbookingApp.notifica.messaggio') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'messaggio'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('inviata')">
              <span>{{ t$('smartbookingApp.notifica.inviata') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'inviata'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('inviataAt')">
              <span>{{ t$('smartbookingApp.notifica.inviataAt') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'inviataAt'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('errore')">
              <span>{{ t$('smartbookingApp.notifica.errore') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'errore'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('createdAt')">
              <span>{{ t$('smartbookingApp.notifica.createdAt') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'createdAt'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('conferma.id')">
              <span>{{ t$('smartbookingApp.notifica.conferma') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'conferma.id'"></jhi-sort-indicator>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="notifica in notificas" :key="notifica.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'NotificaView', params: { notificaId: notifica.id } }">{{ notifica.id }}</router-link>
            </td>
            <td>{{ t$('smartbookingApp.TipoCanaleNotifica.' + notifica.tipoCanale) }}</td>
            <td>{{ t$('smartbookingApp.TipoEventoNotifica.' + notifica.tipoEvento) }}</td>
            <td>{{ notifica.messaggio }}</td>
            <td>{{ notifica.inviata }}</td>
            <td>{{ formatDateShort(notifica.inviataAt) || '' }}</td>
            <td>{{ notifica.errore }}</td>
            <td>{{ formatDateShort(notifica.createdAt) || '' }}</td>
            <td>
              <div v-if="notifica.conferma">
                <router-link :to="{ name: 'ConfermaView', params: { confermaId: notifica.conferma.id } }">{{
                  notifica.conferma.id
                }}</router-link>
              </div>
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'NotificaView', params: { notificaId: notifica.id } }"
                  class="btn btn-info btn-sm details"
                  data-cy="entityDetailsButton"
                >
                  <font-awesome-icon icon="eye"></font-awesome-icon>
                  <span class="d-none d-md-inline">{{ t$('entity.action.view') }}</span>
                </router-link>
                <router-link
                  :to="{ name: 'NotificaEdit', params: { notificaId: notifica.id } }"
                  class="btn btn-primary btn-sm edit"
                  data-cy="entityEditButton"
                >
                  <font-awesome-icon icon="pencil-alt"></font-awesome-icon>
                  <span class="d-none d-md-inline">{{ t$('entity.action.edit') }}</span>
                </router-link>
                <b-button
                  @click="prepareRemove(notifica)"
                  variant="danger"
                  class="btn btn-sm"
                  data-cy="entityDeleteButton"
                  v-b-modal.removeEntity
                >
                  <font-awesome-icon icon="times"></font-awesome-icon>
                  <span class="d-none d-md-inline">{{ t$('entity.action.delete') }}</span>
                </b-button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <b-modal ref="removeEntity" id="removeEntity">
      <template #title>
        <span id="smartbookingApp.notifica.delete.question" data-cy="notificaDeleteDialogHeading">{{ t$('entity.delete.title') }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-notifica-heading">{{ t$('smartbookingApp.notifica.delete.question', { id: removeId }) }}</p>
      </div>
      <template #footer>
        <div>
          <button type="button" class="btn btn-secondary" @click="closeDialog()">{{ t$('entity.action.cancel') }}</button>
          <button
            type="button"
            class="btn btn-primary"
            id="jhi-confirm-delete-notifica"
            data-cy="entityConfirmDeleteButton"
            @click="removeNotifica"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
    <div v-show="notificas?.length > 0">
      <div class="d-flex justify-content-center">
        <jhi-item-count :page="page" :total="queryCount" :items-per-page="itemsPerPage"></jhi-item-count>
      </div>
      <div class="d-flex justify-content-center">
        <b-pagination size="md" :total-rows="totalItems" v-model="page" :per-page="itemsPerPage"></b-pagination>
      </div>
    </div>
  </div>
</template>

<script lang="ts" src="./notifica.component.ts"></script>
