import { Component } from '@angular/core';
import { BaseDialogComponent } from '@iqser/common-ui';
import { MatDialogRef } from '@angular/material/dialog';
import { AbstractControl, FormGroup, Validators } from '@angular/forms';

interface FormType {
    password: AbstractControl<string>;
}

@Component({
    templateUrl: './confirm-password-dialog.component.html',
})
export class ConfirmPasswordDialogComponent extends BaseDialogComponent {
    constructor(protected readonly _dialogRef: MatDialogRef<ConfirmPasswordDialogComponent>) {
        super(_dialogRef);

        this.form = this._getForm();
        this.initialFormValue = this.form.getRawValue();
    }

    save(): void {
        this._dialogRef.close(this.form.get('password').value);
    }

    private _getForm(): FormGroup<FormType> {
        return this._formBuilder.group({
            password: [null, Validators.required],
        });
    }
}
