<template>
  <div class="d-flex justify-content-center">
    <div class="col-8">
      <form name="editForm" novalidate @submit.prevent="save()">
        <h2 id="smartbookingApp.auditLog.home.createOrEditLabel" data-cy="AuditLogCreateUpdateHeading">
          {{ t$('smartbookingApp.auditLog.home.createOrEditLabel') }}
        </h2>
        <div>
          <div class="mb-3" v-if="auditLog.id">
            <label for="id">{{ t$('global.field.id') }}</label>
            <input type="text" class="form-control" id="id" name="id" v-model="auditLog.id" readonly />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.entitaTipo') }}</label>
            <select
              class="form-control"
              name="entitaTipo"
              :class="{ valid: !v$.entitaTipo.$invalid, invalid: v$.entitaTipo.$invalid }"
              v-model="v$.entitaTipo.$model"
              id="audit-log-entitaTipo"
              data-cy="entitaTipo"
            >
              <option
                v-for="tipoEntita in tipoEntitaValues"
                :key="tipoEntita"
                :value="tipoEntita"
                :label="t$('smartbookingApp.TipoEntita.' + tipoEntita)"
              >
                {{ tipoEntita }}
              </option>
            </select>
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.entitaId') }}</label>
            <input
              type="number"
              class="form-control"
              name="entitaId"
              id="audit-log-entitaId"
              data-cy="entitaId"
              :class="{ valid: !v$.entitaId.$invalid, invalid: v$.entitaId.$invalid }"
              v-model.number="v$.entitaId.$model"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.azione') }}</label>
            <select
              class="form-control"
              name="azione"
              :class="{ valid: !v$.azione.$invalid, invalid: v$.azione.$invalid }"
              v-model="v$.azione.$model"
              id="audit-log-azione"
              data-cy="azione"
            >
              <option
                v-for="azioneAudit in azioneAuditValues"
                :key="azioneAudit"
                :value="azioneAudit"
                :label="t$('smartbookingApp.AzioneAudit.' + azioneAudit)"
              >
                {{ azioneAudit }}
              </option>
            </select>
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.dettagli') }}</label>
            <input
              type="text"
              class="form-control"
              name="dettagli"
              id="audit-log-dettagli"
              data-cy="dettagli"
              :class="{ valid: !v$.dettagli.$invalid, invalid: v$.dettagli.$invalid }"
              v-model="v$.dettagli.$model"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.ipAddress') }}</label>
            <input
              type="text"
              class="form-control"
              name="ipAddress"
              id="audit-log-ipAddress"
              data-cy="ipAddress"
              :class="{ valid: !v$.ipAddress.$invalid, invalid: v$.ipAddress.$invalid }"
              v-model="v$.ipAddress.$model"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.createdAt') }}</label>
            <div class="d-flex">
              <input
                id="audit-log-createdAt"
                data-cy="createdAt"
                type="datetime-local"
                class="form-control"
                name="createdAt"
                :class="{ valid: !v$.createdAt.$invalid, invalid: v$.createdAt.$invalid }"
                :value="convertDateTimeFromServer(v$.createdAt.$model)"
                @change="updateInstantField('createdAt', $event)"
              />
            </div>
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="audit-log">{{ t$('smartbookingApp.auditLog.utente') }}</label>
            <select class="form-control" id="audit-log-utente" data-cy="utente" name="utente" v-model="auditLog.utente">
              <option :value="null"></option>
              <option
                :value="auditLog.utente && utenteAppOption.id === auditLog.utente.id ? auditLog.utente : utenteAppOption"
                v-for="utenteAppOption in utenteApps"
                :key="utenteAppOption.id"
              >
                {{ utenteAppOption.username }}
              </option>
            </select>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" @click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>{{ t$('entity.action.cancel') }}</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="v$.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>{{ t$('entity.action.save') }}</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./audit-log-update.component.ts"></script>
