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

@IonicPage()
@Component({
  selector: 'page-popover',
  templateUrl: 'popover.html',
})
export class PopoverPage {
  languages = [{ 'name': 'English', 'code': 'en' }]//code will be same as filename of lang
  lang: string = 'en';

  constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController, public modalCtrl: ModalController, public storage: Storage, public events: Events, private myservice: Myservice, private translate: TranslateService) {
  }

  ionViewDidEnter() {
    this.storage.get('lang').then(lang => {
      if (lang) {
        this.lang = lang
        document.getElementById(lang).style.background = '#91195b';
        document.getElementById(lang).style.color = '#fff';
      }
    })
  }

  changeLang(lang) {
    this.myservice.show_loader()
    this.storage.set('lang', lang);
    var This = this;
    setTimeout(function () {
      This.events.publish('patient:lang', lang);
      This.myservice.hide_loader()
      This.close();
    }, 500)
  }

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


}
