import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Component({
  selector: 'app-authentication-password-reset',
  templateUrl: './password-reset.component.html',
  styleUrls: ['./password-reset.component.scss']
})
export class PasswordResetComponent implements OnInit {
  resetKey: Observable<string>;

  constructor(
    private readonly $router: Router,
    private readonly $activatedRoute: ActivatedRoute
  ) {
    this.resetKey = this.$activatedRoute.queryParams.pipe(
      map((params) => params['reset-key'])
    );
  }

  ngOnInit(): void {
    this.resetKey.subscribe((key) => {
      if (!key) {
        this.$router.navigateByUrl('/');
      }
    });
  }
}
