import { Component } from "@angular/core";
import {
  IonicPage,
  NavController,
  AlertController,
  MenuController,
  ModalController,
  NavParams,
  Events
} from "ionic-angular";
import { Storage } from "@ionic/storage";

import { AuthProvider } from "../../providers/auth/auth";
import { HomePage } from "../home/home";
import { MockLoginPage } from "../mock-login/mock-login";
import { LoginPage } from "../login/login";


@IonicPage()
@Component({
  selector: "mock",
  templateUrl: "mock.html"
})

export class MockPage {

  mockUp: boolean;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private menuCtrl: MenuController,
    private alertCtrl: AlertController,
    private authProvider: AuthProvider,
    private modalCtrl: ModalController,
    private storage: Storage,
    private events: Events
  ) {}


  loginMock() {
    this.mockUp = true;
    this.storage.set("mockup", this.mockUp);
    // this.navCtrl.setRoot(HomePage);
    this.navCtrl.setRoot(MockLoginPage);

  }

  loginTwitter() {
    this.mockUp = false;
    this.storage.set("mockup", this.mockUp);
    console.log('logging in via twitter');
    const alertText = {
      title: "Login failed",
      subTitle: "Somthing went wrong while trying to log you in. Please try again.",
      buttons: ["OK"]
    };


    this.authProvider
      .login()
      .then(() => this.events.publish("user:login"))
      .then(() => this.navCtrl.setRoot(HomePage))
      .catch(err => this.alertCtrl.create(alertText).present());
  }
}
