<div class="d-flex justify-content-center">
  <div class="col-8">
    <form name="editForm" novalidate (ngSubmit)="save()" [formGroup]="editForm">
      <h2
        id="jhi-document-heading"
        data-cy="DocumentCreateUpdateHeading"
        jhiTranslate="resilientApp.document.home.createOrEditLabel"
      >
        Criar ou editar Document
      </h2>

      <div>
        <jhi-alert-error></jhi-alert-error>

        <div class="mb-3">
          <label
            class="form-label"
            for="field_title"
            [ngbTooltip]="'resilientApp.document.help.title' | translate"
            jhiTranslate="resilientApp.document.title"
            >Title</label
          >
          <input type="text" class="form-control" name="title" id="field_title" data-cy="title" formControlName="title" />
          @if (editForm.get('title')!.invalid && (editForm.get('title')!.dirty || editForm.get('title')!.touched)) {
            <div>
              @if (editForm.get('title')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">O campo é obrigatório.</small>
              }
            </div>
          }
        </div>
        <div class="mb-3">
          <label
            class="form-label"
            for="field_description"
            [ngbTooltip]="'resilientApp.document.help.description' | translate"
            jhiTranslate="resilientApp.document.description"
            >Description</label
          >
          <input type="text" class="form-control" name="description" id="field_description" data-cy="description" formControlName="description" />
        </div>
        <div class="mb-3">
          <label
            class="form-label"
            for="field_dataFile"
            [ngbTooltip]="'resilientApp.document.help.dataFile' | translate"
            jhiTranslate="resilientApp.document.dataFile"
            >Data File</label
          >
          <div>
            @if (editForm.get('dataFile')!.value) {
              <div class="form-text text-danger clearfix">
                <a
                  class="pull-start"
                  (click)="openFile(editForm.get('dataFile')!.value!, editForm.get('dataFileContentType')!.value!)"
                  jhiTranslate="entity.action.open"
                  >Abrir</a
                ><br />
                <span class="pull-start"
                  >{{ editForm.get('dataFileContentType')!.value }}, {{ byteSize(editForm.get('dataFile')!.value!) }}</span
                >
                <button
                  type="button"
                  (click)="editForm.patchValue({ dataFile: undefined, dataFileContentType: undefined })"
                  class="btn btn-secondary btn-xs pull-end"
                >
                  <fa-icon icon="times"></fa-icon>
                </button>
              </div>
            }
            <input
              type="file"
              id="file_dataFile"
              data-cy="dataFile"
              (change)="setFileData($event, 'dataFile', false)"
              jhiTranslate="entity.action.addblob"
            />
          </div>
          <input type="hidden" class="form-control" name="dataFile" id="field_dataFile" data-cy="dataFile" formControlName="dataFile" />
          <input
            type="hidden"
            class="form-control"
            name="dataFileContentType"
            id="field_dataFileContentType"
            formControlName="dataFileContentType"
          />
          @if (editForm.get('dataFile')!.invalid && (editForm.get('dataFile')!.dirty || editForm.get('dataFile')!.touched)) {
            <div>
              @if (editForm.get('dataFile')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">O campo é obrigatório.</small>
              }
            </div>
          }
        </div>
      </div>

      <div>
        <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
          <fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancelar</span>
        </button>

        <button
          type="submit"
          id="save-entity"
          data-cy="entityCreateSaveButton"
          [disabled]="editForm.invalid || isSaving"
          class="btn btn-primary"
        >
          <fa-icon icon="save"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Guardar</span>
        </button>
      </div>
    </form>
  </div>
</div>
