<template>
  <div>
    <h2 id="page-heading" data-cy="DisponibilitaHeading">
      <span id="disponibilita">{{ t$('smartbookingApp.disponibilita.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.disponibilita.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'DisponibilitaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-disponibilita"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.disponibilita.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && disponibilitas?.length === 0">
      <span>{{ t$('smartbookingApp.disponibilita.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="disponibilitas?.length > 0">
      <table class="table table-striped" aria-describedby="disponibilitas">
        <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('giornoSettimana')">
              <span>{{ t$('smartbookingApp.disponibilita.giornoSettimana') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'giornoSettimana'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('dataSpecifica')">
              <span>{{ t$('smartbookingApp.disponibilita.dataSpecifica') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'dataSpecifica'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('oraInizio')">
              <span>{{ t$('smartbookingApp.disponibilita.oraInizio') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'oraInizio'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('oraFine')">
              <span>{{ t$('smartbookingApp.disponibilita.oraFine') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'oraFine'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('orarioInizio')">
              <span>{{ t$('smartbookingApp.disponibilita.orarioInizio') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'orarioInizio'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('orarioFine')">
              <span>{{ t$('smartbookingApp.disponibilita.orarioFine') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'orarioFine'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('tipo')">
              <span>{{ t$('smartbookingApp.disponibilita.tipo') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'tipo'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('note')">
              <span>{{ t$('smartbookingApp.disponibilita.note') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'note'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('struttura.nome')">
              <span>{{ t$('smartbookingApp.disponibilita.struttura') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'struttura.nome'"></jhi-sort-indicator>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="disponibilita in disponibilitas" :key="disponibilita.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'DisponibilitaView', params: { disponibilitaId: disponibilita.id } }">{{
                disponibilita.id
              }}</router-link>
            </td>
            <td>{{ t$('smartbookingApp.GiornoSettimana.' + disponibilita.giornoSettimana) }}</td>
            <td>{{ disponibilita.dataSpecifica }}</td>
            <td>{{ formatDateShort(disponibilita.oraInizio) || '' }}</td>
            <td>{{ formatDateShort(disponibilita.oraFine) || '' }}</td>
            <td>{{ disponibilita.orarioInizio }}</td>
            <td>{{ disponibilita.orarioFine }}</td>
            <td>{{ t$('smartbookingApp.TipoDisponibilita.' + disponibilita.tipo) }}</td>
            <td>{{ disponibilita.note }}</td>
            <td>
              <div v-if="disponibilita.struttura">
                <router-link :to="{ name: 'StrutturaView', params: { strutturaId: disponibilita.struttura.id } }">{{
                  disponibilita.struttura.nome
                }}</router-link>
              </div>
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'DisponibilitaView', params: { disponibilitaId: disponibilita.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: 'DisponibilitaEdit', params: { disponibilitaId: disponibilita.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(disponibilita)"
                  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>
      <span ref="infiniteScrollEl"></span>
    </div>
    <b-modal ref="removeEntity" id="removeEntity">
      <template #title>
        <span id="smartbookingApp.disponibilita.delete.question" data-cy="disponibilitaDeleteDialogHeading">{{
          t$('entity.delete.title')
        }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-disponibilita-heading">{{ t$('smartbookingApp.disponibilita.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-disponibilita"
            data-cy="entityConfirmDeleteButton"
            @click="removeDisponibilita"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
  </div>
</template>

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