import { Component, OnInit } from '@angular/core';
import { HitAWodService } from 'src/app/services/hit-a-wod.service';
import { Router, ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-change-password',
  templateUrl: './change-password.component.html',
  styleUrls: ['./change-password.component.css']
})
export class ChangePasswordComponent implements OnInit {

  token_provided:boolean = false;
  token:string;
  password:string;

  constructor(private api:HitAWodService,
              private router:Router,
              private activatedRoute:ActivatedRoute) { }

  ngOnInit(): void {
    this.token = this.activatedRoute.snapshot.queryParamMap.get("token");
    this.token_provided = this.token ? true : false;
  }

  change() {
    this.api.changePassword(this.token, this.password).subscribe(
      data => {
        this.router.navigate(["/auth", "login"]);
      }
    );
  }

}
