<template>
  <div>
    <h2 id="page-heading" data-cy="LiberatoriaHeading">
      <span id="liberatoria">{{ t$('smartbookingApp.liberatoria.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.liberatoria.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'LiberatoriaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-liberatoria"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.liberatoria.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && liberatorias?.length === 0">
      <span>{{ t$('smartbookingApp.liberatoria.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="liberatorias?.length > 0">
      <table class="table table-striped" aria-describedby="liberatorias">
        <thead>
          <tr>
            <th scope="col">
              <span>{{ t$('global.field.id') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.liberatoria.accettata') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.liberatoria.utente') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.liberatoria.modelloLiberatoria') }}</span>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="liberatoria in liberatorias" :key="liberatoria.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'LiberatoriaView', params: { liberatoriaId: liberatoria.id } }">{{ liberatoria.id }}</router-link>
            </td>
            <td>{{ formatDateShort(liberatoria.accettata) || '' }}</td>
            <td>
              <div v-if="liberatoria.utente">
                <router-link :to="{ name: 'UtenteAppView', params: { utenteAppId: liberatoria.utente.id } }">{{
                  liberatoria.utente.username
                }}</router-link>
              </div>
            </td>
            <td>
              <div v-if="liberatoria.modelloLiberatoria">
                <router-link
                  :to="{ name: 'ModelloLiberatoriaView', params: { modelloLiberatoriaId: liberatoria.modelloLiberatoria.id } }"
                  >{{ liberatoria.modelloLiberatoria.id }}</router-link
                >
              </div>
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'LiberatoriaView', params: { liberatoriaId: liberatoria.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: 'LiberatoriaEdit', params: { liberatoriaId: liberatoria.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(liberatoria)"
                  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.liberatoria.delete.question" data-cy="liberatoriaDeleteDialogHeading">{{
          t$('entity.delete.title')
        }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-liberatoria-heading">{{ t$('smartbookingApp.liberatoria.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-liberatoria"
            data-cy="entityConfirmDeleteButton"
            @click="removeLiberatoria"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
  </div>
</template>

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