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

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