import {Component, ViewChild} from '@angular/core';
import {IonicPage, NavController, NavParams, Slides, ToastController} from 'ionic-angular';
import {message} from "../../../../app/main";

@IonicPage()
@Component({
  selector: 'page-learning-do',
  templateUrl: 'learning-do.html',
})
export class LearningDoPage {
    @ViewChild(Slides) slides: Slides;

  list = [
      {title:"你最喜欢玩的游戏是什么？",},
      {title:"你最喜欢吃的水果是什么",},
      {title:"你最喜欢玩的地方是什么？",},
      {title:"你最喜欢什么手机？",},
      {title:"你最喜欢什么耳机？",}

  ];
  index = 1;  //当前题目的序号
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public toastCtrl:ToastController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad LearningDoPage');
  }

  //上一题
  prev(){
    if(this.index == 1){
        const toast = this.toastCtrl.create(message);
        toast.setMessage('已经是第一题哦');
        toast.present();
    }else{
      this.index -= 1;
      this.slides.slideTo(this.index-1)
    }
  }

  //下一题
  next(){
      if(this.index == this.list.length){
          const toast = this.toastCtrl.create(message);
          toast.setMessage('已经是最后一题了哦');
          toast.present();
      }else{
          this.index += 1;
          this.slides.slideTo(this.index-1)
      }
  }
}
