import { Component, Inject, OnInit } from '@angular/core';
import { MdDialogRef, MD_DIALOG_DATA } from '@angular/material';
import { ContactService } from '../../contact.service';

@Component({
  selector: 'app-otp-screen',
  templateUrl: './otp-screen.component.html',
  styleUrls: ['./otp-screen.component.scss']
})
export class OtpScreenComponent implements OnInit {
  otp
 constructor(public dialogRef: MdDialogRef<OtpScreenComponent>,private contactService:ContactService,
    @Inject(MD_DIALOG_DATA) public data: any) {
      console.log(data);

    }

  ngOnInit() {
  }
data_descip;
show:boolean=false;
 verify(){
  console.log(this.otp);
    this.contactService.post('/users/verifyOtp',{user:this.data._id,otp:this.otp}).subscribe((res:any)=>{
      this.data_descip = res.message;
      launch_toast()
      this.dialogRef.close({value:'done'});
    },err=>{
      console.log(err);
      var message=JSON.parse(err._body);
      console.log(message);
      
      this.data_descip = "You entered wrong OTP"
      this.show=true;
      var that=this;
      //  this.data_descip = res.message;
      launch_toast()
     setTimeout(function () {that.show=false  }, 4500);
    })

    function launch_toast() {
      // console.log(divid);
      var x = document.getElementById("toast")
      //console.log(x);
      x.className = "show";
       setTimeout(function () { x.className = x.className.replace("show", ""); }, 4500);
    }
 }

}
