<template>
  <div class="d-flex justify-content-center">
    <div class="col-8">
      <form name="editForm" novalidate @submit.prevent="save()">
        <h2 id="smartbookingApp.modelloLiberatoria.home.createOrEditLabel" data-cy="ModelloLiberatoriaCreateUpdateHeading">
          {{ t$('smartbookingApp.modelloLiberatoria.home.createOrEditLabel') }}
        </h2>
        <div>
          <div class="mb-3" v-if="modelloLiberatoria.id">
            <label for="id">{{ t$('global.field.id') }}</label>
            <input type="text" class="form-control" id="id" name="id" v-model="modelloLiberatoria.id" readonly />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.nome') }}</label>
            <input
              type="text"
              class="form-control"
              name="nome"
              id="modello-liberatoria-nome"
              data-cy="nome"
              :class="{ valid: !v$.nome.$invalid, invalid: v$.nome.$invalid }"
              v-model="v$.nome.$model"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.testo') }}</label>
            <input
              type="text"
              class="form-control"
              name="testo"
              id="modello-liberatoria-testo"
              data-cy="testo"
              :class="{ valid: !v$.testo.$invalid, invalid: v$.testo.$invalid }"
              v-model="v$.testo.$model"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.documento') }}</label>
            <div>
              <div v-if="modelloLiberatoria.documento" class="form-text text-danger clearfix">
                <span class="pull-start">{{ modelloLiberatoria.documentoContentType }}, {{ byteSize(modelloLiberatoria.documento) }}</span>
                <button
                  type="button"
                  @click="
                    modelloLiberatoria.documento = null;
                    modelloLiberatoria.documentoContentType = null;
                  "
                  class="btn btn-secondary btn-xs pull-end"
                >
                  <font-awesome-icon icon="times"></font-awesome-icon>
                </button>
              </div>
              <label for="file_documento" class="btn btn-primary pull-end">{{ t$('entity.action.addblob') }}</label>
              <input
                type="file"
                ref="file_documento"
                id="file_documento"
                style="display: none"
                data-cy="documento"
                @change="setFileData($event, modelloLiberatoria, 'documento', false)"
              />
            </div>
            <input
              type="hidden"
              class="form-control"
              name="documento"
              id="modello-liberatoria-documento"
              data-cy="documento"
              :class="{ valid: !v$.documento.$invalid, invalid: v$.documento.$invalid }"
              v-model="v$.documento.$model"
            />
            <input
              type="hidden"
              class="form-control"
              name="documentoContentType"
              id="modello-liberatoria-documentoContentType"
              v-model="modelloLiberatoria.documentoContentType"
            />
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.validoDal') }}</label>
            <div class="d-flex">
              <input
                id="modello-liberatoria-validoDal"
                data-cy="validoDal"
                type="datetime-local"
                class="form-control"
                name="validoDal"
                :class="{ valid: !v$.validoDal.$invalid, invalid: v$.validoDal.$invalid }"
                :value="convertDateTimeFromServer(v$.validoDal.$model)"
                @change="updateInstantField('validoDal', $event)"
              />
            </div>
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.validoAl') }}</label>
            <div class="d-flex">
              <input
                id="modello-liberatoria-validoAl"
                data-cy="validoAl"
                type="datetime-local"
                class="form-control"
                name="validoAl"
                :class="{ valid: !v$.validoAl.$invalid, invalid: v$.validoAl.$invalid }"
                :value="convertDateTimeFromServer(v$.validoAl.$model)"
                @change="updateInstantField('validoAl', $event)"
              />
            </div>
          </div>
          <div class="mb-3">
            <label class="form-control-label" for="modello-liberatoria">{{ t$('smartbookingApp.modelloLiberatoria.struttura') }}</label>
            <select
              class="form-control"
              id="modello-liberatoria-struttura"
              data-cy="struttura"
              name="struttura"
              v-model="modelloLiberatoria.struttura"
            >
              <option :value="null"></option>
              <option
                :value="
                  modelloLiberatoria.struttura && strutturaOption.id === modelloLiberatoria.struttura.id
                    ? modelloLiberatoria.struttura
                    : strutturaOption
                "
                v-for="strutturaOption in strutturas"
                :key="strutturaOption.id"
              >
                {{ strutturaOption.id }}
              </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="./modello-liberatoria-update.component.ts"></script>
