<h2 mat-dialog-title>{{ title }}</h2>

<mat-dialog-content [formGroup]="teacherForm">
  <div class="form-grid">

    <mat-form-field appearance="fill">
      <mat-label>Nome</mat-label>
      <input matInput formControlName="first_name" required>
      <mat-error *ngIf="teacherForm.get('first_name')?.hasError('required')">
        Il nome è obbligatorio.
      </mat-error>
    </mat-form-field>

    <mat-form-field appearance="fill">
      <mat-label>Cognome</mat-label>
      <input matInput formControlName="last_name" required>
      <mat-error *ngIf="teacherForm.get('last_name')?.hasError('required')">
        Il cognome è obbligatorio.
      </mat-error>
    </mat-form-field>

    <mat-form-field appearance="fill">
      <mat-label>Email</mat-label>
      <input matInput formControlName="email" type="email">
       <mat-error *ngIf="teacherForm.get('email')?.hasError('email')">
        Inserisci un indirizzo email valido.
      </mat-error>
    </mat-form-field>

    <mat-form-field appearance="fill">
      <mat-label>Telefono</mat-label>
      <input matInput formControlName="phone">
    </mat-form-field>

    <mat-form-field appearance="fill">
      <mat-label>Data di Nascita</mat-label>
      <input matInput [matDatepicker]="dobPicker" formControlName="date_of_birth" readonly> <!-- Ripristinato readonly -->
      <mat-hint>GG/MM/AAAA</mat-hint>
      <mat-datepicker-toggle matSuffix [for]="dobPicker"></mat-datepicker-toggle>
      <mat-datepicker #dobPicker></mat-datepicker>
    </mat-form-field>

    <mat-form-field appearance="fill">
      <mat-label>Data Assunzione</mat-label>
      <input matInput [matDatepicker]="hirePicker" formControlName="hire_date" readonly> <!-- Ripristinato readonly -->
      <mat-hint>GG/MM/AAAA</mat-hint>
      <mat-datepicker-toggle matSuffix [for]="hirePicker"></mat-datepicker-toggle>
      <mat-datepicker #hirePicker></mat-datepicker>
    </mat-form-field>

     <div class="full-width-field"> <!-- Contenitore per checkbox/textarea -->
        <mat-checkbox formControlName="is_active" labelPosition="after">
            Insegnante Attivo
        </mat-checkbox>
     </div>


    <mat-form-field appearance="fill" class="full-width-field">
      <mat-label>Qualifiche/Note</mat-label>
      <textarea matInput formControlName="qualifications" rows="3"></textarea>
    </mat-form-field>

  </div>
</mat-dialog-content>

<mat-dialog-actions align="end">
  <button mat-button (click)="onCancel()">Annulla</button>
  <button mat-raised-button color="primary" (click)="onSave()" [disabled]="!teacherForm.valid"> <!-- Ripristinato controllo validità -->
    {{ isEditMode ? 'Salva Modifiche' : 'Aggiungi' }}
  </button>
</mat-dialog-actions>
