<template>
  <div>
    <h2 id="page-heading" data-cy="StrutturaHeading">
      <span id="struttura">{{ t$('smartbookingApp.struttura.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.struttura.home.refreshListLabel') }}</span>
        </button>
        <router-link :to="{ name: 'StrutturaCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-struttura"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span>{{ t$('smartbookingApp.struttura.home.createLabel') }}</span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && strutturas?.length === 0">
      <span>{{ t$('smartbookingApp.struttura.home.notFound') }}</span>
    </div>
    <div class="table-responsive" v-if="strutturas?.length > 0">
      <table class="table table-striped" aria-describedby="strutturas">
        <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('nome')">
              <span>{{ t$('smartbookingApp.struttura.nome') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'nome'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('descrizione')">
              <span>{{ t$('smartbookingApp.struttura.descrizione') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'descrizione'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('indirizzo')">
              <span>{{ t$('smartbookingApp.struttura.indirizzo') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'indirizzo'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('capienzaMax')">
              <span>{{ t$('smartbookingApp.struttura.capienzaMax') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'capienzaMax'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('attiva')">
              <span>{{ t$('smartbookingApp.struttura.attiva') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'attiva'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('fotoUrl')">
              <span>{{ t$('smartbookingApp.struttura.fotoUrl') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'fotoUrl'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('createdAt')">
              <span>{{ t$('smartbookingApp.struttura.createdAt') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'createdAt'"></jhi-sort-indicator>
            </th>
            <th scope="col" @click="changeOrder('updatedAt')">
              <span>{{ t$('smartbookingApp.struttura.updatedAt') }}</span>
              <jhi-sort-indicator :current-order="propOrder" :reverse="reverse" :field-name="'updatedAt'"></jhi-sort-indicator>
            </th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="struttura in strutturas" :key="struttura.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'StrutturaView', params: { strutturaId: struttura.id } }">{{ struttura.id }}</router-link>
            </td>
            <td>{{ struttura.nome }}</td>
            <td>{{ struttura.descrizione }}</td>
            <td>{{ struttura.indirizzo }}</td>
            <td>{{ struttura.capienzaMax }}</td>
            <td>{{ struttura.attiva }}</td>
            <td>{{ struttura.fotoUrl }}</td>
            <td>{{ formatDateShort(struttura.createdAt) || '' }}</td>
            <td>{{ formatDateShort(struttura.updatedAt) || '' }}</td>
            <td class="text-end">
              <div class="btn-group">
                <router-link
                  :to="{ name: 'StrutturaDisponibilitaConfig', params: { strutturaId: struttura.id } }"
                  class="btn btn-info btn-sm"
                  data-cy="entityConfigButton"
                >
                  <font-awesome-icon icon="clock"></font-awesome-icon>
                  <span class="d-none d-md-inline">{{ t$('smartbookingApp.struttura.configDisponibilita') }}</span>
                </router-link>
                <router-link
                  :to="{ name: 'StrutturaView', params: { strutturaId: struttura.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: 'StrutturaEdit', params: { strutturaId: struttura.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(struttura)"
                  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.struttura.delete.question" data-cy="strutturaDeleteDialogHeading">{{ t$('entity.delete.title') }}</span>
      </template>
      <div class="modal-body">
        <p id="jhi-delete-struttura-heading">{{ t$('smartbookingApp.struttura.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-struttura"
            data-cy="entityConfirmDeleteButton"
            @click="removeStruttura"
          >
            {{ t$('entity.action.delete') }}
          </button>
        </div>
      </template>
    </b-modal>
    <div v-show="strutturas?.length > 0">
      <div class="d-flex justify-content-center">
        <jhi-item-count :page="page" :total="queryCount" :items-per-page="itemsPerPage"></jhi-item-count>
      </div>
      <div class="d-flex justify-content-center">
        <b-pagination size="md" :total-rows="totalItems" v-model="page" :per-page="itemsPerPage"></b-pagination>
      </div>
    </div>
  </div>
</template>

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