<template>
  <div>
    <h2 id="page-heading" data-cy="ModelloLiberatoriaHeading">
      <span id="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.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.modelloLiberatoria.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'ModelloLiberatoriaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-modello-liberatoria"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.modelloLiberatoria.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && modelloLiberatorias?.length === 0">
      <span>{{ t$('smartbookingApp.modelloLiberatoria.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="modelloLiberatorias?.length > 0">
      <table class="table table-striped" aria-describedby="modelloLiberatorias">
        <thead>
          <tr>
            <th scope="col">
              <span>{{ t$('global.field.id') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.nome') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.testo') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.documento') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.validoDal') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.validoAl') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.modelloLiberatoria.struttura') }}</span>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="modelloLiberatoria in modelloLiberatorias" :key="modelloLiberatoria.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'ModelloLiberatoriaView', params: { modelloLiberatoriaId: modelloLiberatoria.id } }">{{
                modelloLiberatoria.id
              }}</router-link>
            </td>
            <td>{{ modelloLiberatoria.nome }}</td>
            <td>{{ modelloLiberatoria.testo }}</td>
            <td>{{ modelloLiberatoria.documento }}</td>
            <td>{{ formatDateShort(modelloLiberatoria.validoDal) || '' }}</td>
            <td>{{ formatDateShort(modelloLiberatoria.validoAl) || '' }}</td>
            <td>
              <div v-if="modelloLiberatoria.struttura">
                <router-link :to="{ name: 'StrutturaView', params: { strutturaId: modelloLiberatoria.struttura.id } }">{{
                  modelloLiberatoria.struttura.id
                }}</router-link>
              </div>
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'ModelloLiberatoriaView', params: { modelloLiberatoriaId: modelloLiberatoria.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: 'ModelloLiberatoriaEdit', params: { modelloLiberatoriaId: modelloLiberatoria.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(modelloLiberatoria)"
                  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.modelloLiberatoria.delete.question" data-cy="modelloLiberatoriaDeleteDialogHeading">{{
          t$('entity.delete.title')
        }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-modelloLiberatoria-heading">{{ t$('smartbookingApp.modelloLiberatoria.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-modelloLiberatoria"
            data-cy="entityConfirmDeleteButton"
            @click="removeModelloLiberatoria"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
  </div>
</template>

<script lang="ts" src="./modello-liberatoria.component.ts"></script>
