import { Component } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { NanoDialogBaseComponent } from '../nano-base-dialog';

export interface DialogData {
  code: string;
}

@Component({
  selector: 'app-two-factor-dialog',
  templateUrl: './two-factor-dialog.component.html',
  styleUrls: ['./two-factor-dialog.component.scss'],
})
export class TwoFactorDialogComponent extends NanoDialogBaseComponent<TwoFactorDialogComponent> {
  public data: DialogData = {
    code: '',
  };

  constructor(public dialogRef: MatDialogRef<TwoFactorDialogComponent, DialogData>) {
    super(dialogRef);
  }

  onSubmit() {
    this.data.code = this.data.code + ''; // the number input convert it into number instead of string
    if (this.data.code.length > 0) {
      this.dialogRef.close(this.data);
    }
  }

  onCancel() {
    this.dialogRef.close({ code: undefined });
  }
}
