import { ChangeDetectorRef, inject } from '@angular/core';
export class FormGenericComponent {
    constructor(formGroupDirective) {
        this.formGroupDirective = formGroupDirective;
        this.onChange = () => { };
        this.onTouched = () => { };
        this.changeDetectorRef = inject(ChangeDetectorRef);
    }
    hasErrors(formControl) {
        return (formControl && /*!formControl.pristine &&*/ formControl.touched && !!formControl.errors);
    }
    get formControl() {
        return this.formGroupDirective && this.formGroupDirective.form.get(this.formControlName);
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    triggerChange(value) {
        if (value && this.formControl)
            this.formControl.markAsDirty();
        this.onChange(value);
    }
    triggerTouched() {
        this.onTouched();
    }
    triggerMarkCheck() {
        this.changeDetectorRef.markForCheck();
    }
    triggerChangeDetection() {
        this.changeDetectorRef.detectChanges();
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS1nZW5lcmljLmFic3RyYWN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvY2lyY2xldG9uZS9zcmMvbGliL3NlcnZpY2VzL2Zvcm0tZ2VuZXJpYy5hYnN0cmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRzFELE1BQU0sT0FBZ0Isb0JBQW9CO0lBUXhDLFlBQXNCLGtCQUFzQztRQUF0Qyx1QkFBa0IsR0FBbEIsa0JBQWtCLENBQW9CO1FBUHBELGFBQVEsR0FBeUIsR0FBRyxFQUFFLEdBQUUsQ0FBQyxDQUFDO1FBQzFDLGNBQVMsR0FBZSxHQUFHLEVBQUUsR0FBRSxDQUFDLENBQUM7UUFFeEIsc0JBQWlCLEdBQUcsTUFBTSxDQUFDLGlCQUFpQixDQUFDLENBQUM7SUFJQSxDQUFD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