import { Component, Inject, OnInit } from '@angular/core';
import { Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { imageCategoriesTranslations } from '@translations/image-categories-translations';
import { Dossier, ImageCategory } from '@red/domain';
import { BaseDialogComponent } from '@iqser/common-ui';

@Component({
    templateUrl: './recategorize-image-dialog.component.html',
})
export class RecategorizeImageDialogComponent extends BaseDialogComponent implements OnInit {
    readonly typeOptions: ImageCategory[] = ['signature', 'logo', 'formula', 'image'];
    readonly translations = imageCategoriesTranslations;

    constructor(
        protected readonly _dialogRef: MatDialogRef<RecategorizeImageDialogComponent>,
        @Inject(MAT_DIALOG_DATA) readonly data: { annotations: AnnotationWrapper[]; dossier: Dossier },
    ) {
        super(_dialogRef);
    }

    get changed(): boolean {
        return this.form.get('type').value !== this.data.annotations[0].type;
    }

    ngOnInit() {
        this.form = this._formBuilder.group({
            type: [this.data.annotations[0].type, Validators.required],
            comment: [null],
        });
        this.initialFormValue = this.form.getRawValue();
    }

    save() {
        this._dialogRef.close({
            type: this.form.get('type').value,
            comment: this.form.get('comment').value,
        });
    }
}
