<template>
  <div>
    <h2 id="page-heading" data-cy="ConfermaHeading">
      <span id="conferma">{{ t$('smartbookingApp.conferma.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.conferma.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'ConfermaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-conferma"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.conferma.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && confermas?.length === 0">
      <span>{{ t$('smartbookingApp.conferma.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="confermas?.length > 0">
      <table class="table table-striped" aria-describedby="confermas">
        <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('motivoConferma')">
              <span>{{ t$('smartbookingApp.conferma.motivoConferma') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'motivoConferma'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('codice')">
              <span>{{ t$('smartbookingApp.conferma.codice') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'codice'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('tipoConferma')">
              <span>{{ t$('smartbookingApp.conferma.tipoConferma') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'tipoConferma'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('confermataDa.username')">
              <span>{{ t$('smartbookingApp.conferma.confermataDa') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'confermataDa.username'"></jhi-sort-indicator>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="conferma in confermas" :key="conferma.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'ConfermaView', params: { confermaId: conferma.id } }">{{ conferma.id }}</router-link>
            </td>
            <td>{{ conferma.motivoConferma }}</td>
            <td>{{ t$('smartbookingApp.TipoConferma.' + conferma.tipoConferma) }}</td>
            <td>
              <div v-if="conferma.confermataDa">
                <router-link :to="{ name: 'UtenteAppView', params: { utenteAppId: conferma.confermataDa.id } }">{{
                  conferma.confermataDa.username
                }}</router-link>
              </div>
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'ConfermaView', params: { confermaId: conferma.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: 'ConfermaEdit', params: { confermaId: conferma.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(conferma)"
                  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.conferma.delete.question" data-cy="confermaDeleteDialogHeading">{{ t$('entity.delete.title') }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-conferma-heading">{{ t$('smartbookingApp.conferma.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-conferma"
            data-cy="entityConfirmDeleteButton"
            @click="removeConferma"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
    <div v-show="confermas?.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="./conferma.component.ts"></script>
