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

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

  cancelForm:any;

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

    this.cancelForm = new FormGroup({
      
 
      reason: new FormControl('', [ Validators.required])
    
    });
  }

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

 
   let  param ={id:this.data.id, reason: this.cancelForm.value.reason, status:'Cancelled' ,orderId:this.data.orderId}
    
     
      
     
    
   
       
       this._api.CreateOrder (param).subscribe(res => {
         if (res.status == 200) {
   console.log(res)
    this.windowRef.close(1);
         }else{
           this.windowRef.close(0);
         }
       })

  }

}
