<template>
  <div>
    <h2 id="page-heading" data-cy="UtenteAppHeading">
      <span id="utente-app">{{ t$('smartbookingApp.utenteApp.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.utenteApp.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'UtenteAppCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-utente-app"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.utenteApp.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && utenteApps?.length === 0">
      <span>{{ t$('smartbookingApp.utenteApp.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="utenteApps?.length > 0">
      <table class="table table-striped" aria-describedby="utenteApps">
        <thead>
          <tr>
            <th scope="col">
              <span>{{ t$('global.field.id') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.username') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.email') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.telefono') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.ruolo') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.attivo') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.nome') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.cognome') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.luogoNascita') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.dataNascita') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.residente') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.societa') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.sede') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.codfiscale') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.telefonoSoc') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.emailSoc') }}</span>
            </th>
            <th scope="col">
              <span>{{ t$('smartbookingApp.utenteApp.internalUser') }}</span>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="utenteApp in utenteApps" :key="utenteApp.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'UtenteAppView', params: { utenteAppId: utenteApp.id } }">{{ utenteApp.id }}</router-link>
            </td>
            <td>{{ utenteApp.username }}</td>
            <td>{{ utenteApp.email }}</td>
            <td>{{ utenteApp.telefono }}</td>
            <td>{{ t$('smartbookingApp.Ruolo.' + utenteApp.ruolo) }}</td>
            <td>{{ utenteApp.attivo }}</td>
            <td>{{ utenteApp.nome }}</td>
            <td>{{ utenteApp.cognome }}</td>
            <td>{{ utenteApp.luogoNascita }}</td>
            <td>{{ utenteApp.dataNascita }}</td>
            <td>{{ utenteApp.residente }}</td>
            <td>{{ utenteApp.societa }}</td>
            <td>{{ utenteApp.sede }}</td>
            <td>{{ utenteApp.codfiscale }}</td>
            <td>{{ utenteApp.telefonoSoc }}</td>
            <td>{{ utenteApp.emailSoc }}</td>
            <td>
              {{ utenteApp.internalUser ? utenteApp.internalUser.login : '' }}
            </td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'UtenteAppView', params: { utenteAppId: utenteApp.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: 'UtenteAppEdit', params: { utenteAppId: utenteApp.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(utenteApp)"
                  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.utenteApp.delete.question" data-cy="utenteAppDeleteDialogHeading">{{ t$('entity.delete.title') }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-utenteApp-heading">{{ t$('smartbookingApp.utenteApp.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-utenteApp"
            data-cy="entityConfirmDeleteButton"
            @click="removeUtenteApp"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
  </div>
</template>

<script lang="ts" src="./utente-app.component.ts"></script>
