import {Component, Input} from "@angular/core";
import {UserService, MessagesService} from "@webbpm/base-package";
import {Router} from "@angular/router";
import {CommonModule} from "@angular/common";
import {FormsModule} from "@angular/forms";

@Component({
    selector: "resetPassword",
    templateUrl: "./reset_password.html",
    imports: [CommonModule, FormsModule]
})
export class ResetPasswordComponent {

  @Input()
  public email: string;

  @Input()
  public errorMessage: string;

  constructor(private router: Router, private userService: UserService, private messagesService: MessagesService) {
  }

  resetPassword(): void {

    this.userService.resetPassword(this.email)
        .then(() => this.router.navigateByUrl("/"),
              (reason: any) => {
                this.errorMessage = this.messagesService.getUnknownErrorMessage();
              });
  }
}
