import {Component, Inject, OnInit, Optional} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {MAT_DIALOG_DATA} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router';
import {AuthService} from '../../../classes/auth.service';
import {Dialog} from '../../../classes/dialog';
import {GlobalService} from '../../../classes/global.service';

@Component({
  selector: 'app-select-button',
  templateUrl: './selected.component.html',
  styleUrls: ['./selected.component.scss']
})
export class SelectedComponent implements OnInit {
  loading : boolean ;
  completeCtrl = new FormControl();
  public form: FormGroup;

  constructor(private fb: FormBuilder,
              @Inject(MAT_DIALOG_DATA) public data,
              private auth: AuthService,
              private router: Router,
              private dialog: Dialog,
              private global: GlobalService,
  ) {
    this.loading = false ;

    this.global.emailData = data;
      console.log(this.global.emailData , 'data')
}

  ngOnInit() {
    this.form = this.fb.group({
      completeCtrl: this.completeCtrl,
    });
  }

  onSubmit() {
    this.loading = true ;
    console.log('data is  ' , this.data);
    this.auth.forgotPass2(  this.data , this.form.controls['completeCtrl'].value , '2').subscribe(
      (next) => {
        this.loading = false ;
        this.router.navigate(['/auth/submit']);
        this.dialog.closeAll();
      },
      (error) => {
        this.loading = false ;
        console.log('error', error);
      }
    );
  }
}
