import { Component, Inject, OnInit } from '@angular/core';
import { NB_WINDOW_CONTEXT, NbWindowRef, NbWindowService } from '@nebular/theme';
import { AuthService } from '../auth.service';
import { FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'ngx-otp',
  templateUrl: './otp.component.html',
  styleUrls: ['./otp.component.scss']
})
export class OtpComponent   {

  otpform:any;

  constructor(@Inject(NB_WINDOW_CONTEXT) public data: any,public _api:AuthService,private windowService: NbWindowService, private windowRef: NbWindowRef) {

    this.otpform = new FormGroup({
      
 
      reason: new FormControl('', [ Validators.required])
    
    });
    console.log(this.data)
  }

  close() {
    this.windowRef.close();
  }
  onSubmit(){
    console.log( this.data , this.otpform.value)

 
  //  let  param ={id:this.data.id, reason: this.otpform.value.reason, status:'Cancelled'}
    
     
      
   let  param ={email:this.data.email, otp: this.otpform.value.reason,  }
    
   
       
       this._api.verifyOtp (param).subscribe(res => {
         if (res.status == 200) {
   console.log(res)
    this.windowRef.close(1);

    
         }else{
           this.windowRef.close(0);
         }
       })

  }

}
