import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

import { DialogService } from '@ucap-webmessenger/ui';

export interface ChangePasswordDialogData {
  loginId: string;
  phoneNumber?: string;
  encryptedLoginPw?: string;
}

export interface ChangePasswordDialogResult {
  choice: boolean;
  currentLoginPw?: string;
  newLoginPw?: string;
}

@Component({
  selector: 'app-change-password.dialog',
  templateUrl: './change-password.dialog.component.html',
  styleUrls: ['./change-password.dialog.component.scss']
})
export class ChangePasswordDialogComponent implements OnInit, OnDestroy {
  constructor(
    public dialogRef: MatDialogRef<
      ChangePasswordDialogData,
      ChangePasswordDialogResult
    >,
    @Inject(MAT_DIALOG_DATA) public data: ChangePasswordDialogData,
    private dialogService: DialogService
  ) {}

  ngOnInit() {}

  ngOnDestroy(): void {}

  onChangePassword(info: { currentLoginPw: string; newLoginPw: string }): void {
    this.dialogRef.close({
      choice: true,
      currentLoginPw: info.currentLoginPw,
      newLoginPw: info.newLoginPw
    });
  }

  onClickChoice(choice: boolean): void {
    this.dialogRef.close({ choice });
  }
}
