import { Component, inject } from '@angular/core';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatDialogClose } from '@angular/material/dialog';
import { CircleButtonComponent, HasScrollbarDirective, IconButtonComponent, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui';
import { TranslateModule } from '@ngx-translate/core';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
import { ResizeAnnotationData, ResizeAnnotationResult } from '../../../utils/dialog-types';

@Component({
    templateUrl: './resize-annotation-dialog.component.html',
    standalone: true,
    imports: [ReactiveFormsModule, TranslateModule, HasScrollbarDirective, IconButtonComponent, CircleButtonComponent, MatDialogClose],
})
export class ResizeAnnotationDialogComponent extends IqserDialogComponent<
    ResizeAnnotationDialogComponent,
    ResizeAnnotationData,
    ResizeAnnotationResult
> {
    readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId);
    readonly iconButtonTypes = IconButtonTypes;
    readonly dictionaries = inject(DictionariesMapService).get(this.#dossier.dossierTemplateId);
    readonly entity = this.dictionaries.find(d => d.type === this.data.redaction.type);
    readonly form = inject(FormBuilder).group({
        comment: [null],
    });

    constructor() {
        super();
    }

    save() {
        const formValue = this.form.getRawValue();

        this.close({
            comment: formValue.comment,
            updateDictionary: this.entity?.hasDictionary,
            addToAllDossiers: this.entity?.hasDictionary,
        });
    }
}
