import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,ViewController } from 'ionic-angular';
import { Myservice } from '../../providers/myservice';
import { Storage } from "@ionic/storage";
import { driver } from "../../models/mymodel";
import { TranslateService } from "@ngx-translate/core";

@IonicPage()
@Component({
  selector: 'page-reject',
  templateUrl: 'reject.html',
})
export class RejectPage {
  reason:any;
  local:driver
  lang: string = 'en';

  constructor(public navCtrl: NavController, public navParams: NavParams, public viewctrl: ViewController, private myservice: Myservice, private storage: Storage, private translate: TranslateService) {
  }

  ionViewDidEnter() {
    this.langTrans()

    this.storage.get('driver_data').then(data=>{
      if(data)
      this.local = data
    })
  }

  langTrans() {
    this.storage.get('lang').then(lang => {
      if (lang != null) {
        this.translate.use(lang)
        this.lang = lang;
      }
      else {
        this.translate.use('en')
      }
    })
  }

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

  submit(){
    var booking_id = this.navParams.get('bookId');

    this.myservice.load_post({ booking_id: booking_id, driver_id: this.local.id, comment: this.reason }, 'rideReject').subscribe(response => {
      if (response.status == 'success') {
        this.viewctrl.dismiss(response.message);
      }
      else {
        this.translate.get(['reject.' + response.message]).subscribe(value => {
          this.myservice.show_alert('', value['reject.' + response.message])
        })
      }
    })
    
  }
}
