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

@Component({
  selector: 'ngx-order-summary-form',
  templateUrl: './order-summary-form.component.html',
  styleUrls: ['./order-summary-form.component.scss']
})
export class OrderSummaryFormComponent implements OnInit {
  customer:any =[];
  product:any =[];
  setData:any =[];
  constructor(@Inject(NB_WINDOW_CONTEXT) public data: any,public _api:PageapiService,private windowService: NbWindowService, private windowRef: NbWindowRef) { 

    console.log(this.data)
    this.customer = this.data.name
    this.product = this.data.product

    this._api.orderDetails_observable$.subscribe((res) => {
      console.log('booked', res);

      if(res){
 this. setData =   res.data


      }
  
    })

   
  }

  ngOnInit() {

    this.customer = this.data.name
    this.product = this.data.product
  }

  save(){
    console.log(this.data)
   let cus =  this.data.customerData['CusDetails.id']
 let role = localStorage.getItem('user_role')
 let param;
 if(this.setData != undefined){
 if(this.setData.hasOwnProperty('id')){
   param ={id:this.setData.id,customerId:cus,status:'ordered' , product: this.data.product ,createdBy:role }
 }else{
  param ={customerId:cus,status:'ordered' , product: this.data.product ,createdBy:role }
 }
}else{
  param ={customerId:cus,status:'ordered' , product: this.data.product ,createdBy:role }
}
  
   
  
 

    
    this._api.CreateOrder (param).subscribe(res => {
      if (res.status == 200) {
console.log(res)
 this.windowRef.close(1);
      }else{
        this.windowRef.close(0);
      }
    })
  }
  cancel(){
    this.windowService
    console.log( this.windowService)
    this.windowRef.close();
  }
}
