import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { BaseDialogComponent } from '@iqser/common-ui';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';

@Component({
    templateUrl: './resize-annotation-dialog.component.html',
})
export class ResizeAnnotationDialogComponent extends BaseDialogComponent implements OnInit {
    constructor(
        protected readonly _dialogRef: MatDialogRef<ResizeAnnotationDialogComponent>,
        @Inject(MAT_DIALOG_DATA) private readonly _data: { annotation: AnnotationWrapper; text?: string },
    ) {
        super(_dialogRef);
    }

    get disabled(): boolean {
        return !this.valid;
    }

    get text(): string {
        return this._data.text;
    }

    ngOnInit() {
        const controlsConfig = { comment: [null] };

        if (this._data.annotation.isModifyDictionary) {
            controlsConfig['updateDictionary'] = [false];
        }

        this.form = this._formBuilder.group(controlsConfig);
        this.initialFormValue = this.form.getRawValue();
    }

    save() {
        this._dialogRef.close(this.form.getRawValue());
    }
}
