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

@Component({
             moduleId: module.id,
             selector: "resetPassword",
             templateUrl: "../../../../../src/resources/template/app/component/reset_password.html"
           })
export class ResetPasswordComponent {

  @Input()
  public email: string;

  @Input()
  public errorMessage: string;

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

  resetPassword(): void {

    this.userService.resetPassword(this.email)
        .then(() => this.router.navigateByUrl("/"),
              (reason: any) => {
                this.errorMessage =
                    'Произошла неизвестная ошибка, обратитесь в службу технической поддержки!';
              });
  }
}
