import { Component } from '@angular/core';
import { IonicPage,NavController,ViewController,NavParams } from 'ionic-angular';
import {Myservice} from '../../providers/myservice';
import { Storage } from '@ionic/storage';
@IonicPage()
@Component({
  selector: 'page-secureseat',
  templateUrl: 'secureseat.html'
})
export class Secureseat {
data:any;
source_sp:any;
source_head:any;
source_new:any;
destination_sp:any;
destination_head:any;
destination_new:any;
seat:any;
seat_new:any;
bookid:any;
user_data:any;
newdata:any;
rate:any;

  constructor(public navCtrl: NavController,public navParams: NavParams,public viewCtrl: ViewController,public myservice:Myservice,public storage:Storage) {
        this.storage.get('userdata').then((userdata) => {
         this.user_data=userdata;
   
		  console.log(this.user_data);
  })
   
   
   
    this.data= navParams.get("data");
    this.seat= navParams.get("seats");
    this.bookid =navParams.get("bookid");
    this.rate=navParams.get("rate");

    console.log(this.bookid);
    this.source_sp= this.data.source.split(',');
            this.source_head=this.source_sp[0];
            console.log(this.source_sp);           
              let string_val=this.data.source;
              let toArray = string_val.split(",");
              toArray.splice (0, 1);
              let str=toArray.toString();
              this.source_new=str;
            this.destination_sp= this.data.destination.split(',',2);
            this.destination_head=this.destination_sp[0];
             let string_val1=this.data.destination;
              let toArray1 = string_val1.split(",");
              toArray1.splice (0, 1);
              let str1=toArray.toString();
             

             this.destination_new= str1;
             console.log(this.data.no_of_seats)
             console.log( this.seat);
             console.log( this.data.no_of_seats - this.seat)
             console.log( this.data.no_of_seats - this.seat)
             this.seat_new = this.data.no_of_seats - this.seat;
             console.log(this.seat_new);
  }

  ionViewDidLoad() {
  }

  dismiss() {
   this.viewCtrl.dismiss();
   }

   request() {
     console.log(this.bookid);
    this.myservice.show_loader();
	    this.myservice.load_post(this.bookid,"sendmessage").subscribe(response => {
        console.log(response);
       
	  	this.myservice.hide_loader();
       this.navCtrl.push('Request',{'data': this.data,'rate':this.rate});
    })
  
   }

}