import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';

export function markControlsAsDirty(controls: AbstractControl[]): void {
  controls.forEach(control => {
    if (control instanceof FormControl) {
      control.markAsDirty({ onlySelf: true });
    } else if (control instanceof FormGroup) {
      markControlsAsDirty(Object.values(control.controls));
    } else if (control instanceof FormArray) {
      markControlsAsDirty(control.controls);
    }
  });
}
