<!-- GUIPropertiesViewAndSortCustomizer -->
<div class="d-flex justify-content-center">
  <div class="col-8">
    <form name="editForm" novalidate (ngSubmit)="save()" [formGroup]="editForm">
      <h2
        id="jhi-metadata-property-heading"
        data-cy="MetadataPropertyCreateUpdateHeading"
        jhiTranslate="resilientApp.metadataProperty.home.createOrEditLabel"
      >
        Criar ou editar Metadata Property
      </h2>

      <div>
        <jhi-alert-error></jhi-alert-error>
        <div class="mb-3">
          <label class="form-label" for="field_code" jhiTranslate="resilientApp.metadataProperty.code">Code</label>
          @if (editForm.controls.id.value == null) {
          <input type="text" class="form-control" name="code" id="field_code" data-cy="code" formControlName="code" />
          } @else {
          <input type="text" class="form-control readonly" name="code" id="field_code" data-cy="code" formControlName="code"  [readonly]="true" />
          }

          @if (editForm.get('code')!.invalid && (editForm.get('code')!.dirty || editForm.get('code')!.touched)) {
            <div>
              @if (editForm.get('code')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">O campo é obrigatório.</small>
              }
              @if (editForm.get('code')?.errors?.minlength) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.minlength" [translateValues]="{ min: '3' }"
                  >Este campo deve ter pelo menos 3 caracteres.</small
                >
              }
            </div>
          }
        </div>
        <div class="mb-3">
          <label class="form-label" for="field_name" jhiTranslate="resilientApp.metadataProperty.name">Name</label>
          <input type="text" class="form-control" name="name" id="field_name" data-cy="name" formControlName="name" />
          @if (editForm.get('name')!.invalid && (editForm.get('name')!.dirty || editForm.get('name')!.touched)) {
            <div>
              @if (editForm.get('name')?.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" jhiTranslate="resilientApp.metadataProperty.description">Description</label>
          <input
            type="text"
            class="form-control"
            name="description"
            id="field_description"
            data-cy="description"
            formControlName="description"
          />
        </div>
null        <div class="mb-3">
          <label class="form-label" for="field_mandatory" jhiTranslate="resilientApp.metadataProperty.mandatory">Mandatory</label>
          <input type="checkbox" class="form-check" name="mandatory" id="field_mandatory" data-cy="mandatory" formControlName="mandatory" />
        </div>
        <div class="mb-3">
          <label
            class="form-label"
            for="field_pattern"
            [ngbTooltip]="'resilientApp.metadataProperty.help.pattern' | translate"
            jhiTranslate="resilientApp.metadataProperty.pattern"
            >Pattern</label
          >
          <input type="text" class="form-control" name="pattern" id="field_pattern" data-cy="pattern" formControlName="pattern" />
        </div>

<!-- HIDDEN Properties 
        @if (editForm.controls.id.value !== null) {
          <div class="mb-3">
            <label class="form-label" for="field_id" jhiTranslate="resilientApp.metadataProperty.id">ID</label>
            <input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
          </div>
        }
        <div class="mb-3">
          <label class="form-label" for="field_metadataType" jhiTranslate="resilientApp.metadataProperty.metadataType">Metadata Type</label>
          <select class="form-control" name="metadataType" formControlName="metadataType" id="field_metadataType" data-cy="metadataType">
            <option [ngValue]="null">{{ 'resilientApp.MetadataType.null' | translate }}</option>
            @for (metadataType of metadataTypeValues; track $index) {
              <option [value]="metadataType">{{ 'resilientApp.MetadataType.' + metadataType | translate }}</option>
            }
          </select>
          @if (editForm.get('metadataType')!.invalid && (editForm.get('metadataType')!.dirty || editForm.get('metadataType')!.touched)) {
            <div>
              @if (editForm.get('metadataType')?.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_version"
            [ngbTooltip]="'resilientApp.metadataProperty.help.version' | translate"
            jhiTranslate="resilientApp.metadataProperty.version"
            >Version</label
          >
          <input type="number" class="form-control" name="version" id="field_version" data-cy="version" formControlName="version" />
        </div>
        <div class="mb-3">
          <label for="field_organizationTypes" jhiTranslate="resilientApp.metadataProperty.organizationType">Organization Type</label>
          <select
            class="form-control"
            id="field_organizationTypes"
            data-cy="organizationType"
            multiple
            name="organizationTypes"
            formControlName="organizationTypes"
            [compareWith]="compareOrganizationType"
          >
            @for (organizationTypeOption of organizationTypesSharedCollection; track $index) {
              <option [ngValue]="organizationTypeOption">{{ organizationTypeOption.name }}</option>
            }
          </select>
        </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>
