import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {environment} from "../environments/environment";
import {AppVersion} from "@ionic-native/app-version/ngx";
import {Storage} from "@ionic/storage";
import {Router} from "@angular/router";

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private appVersion:AppVersion,
    private storage:Storage,
    private router:Router,
  ) {
    this.initializeApp();
    // console.log(App)
  }

  initializeApp() {
    this.platform.ready().then(() => {
        this.splashScreen.hide();
        this.statusBar.show();
        this.statusBar.overlaysWebView(false);
        this.statusBar.backgroundColorByHexString('#e12724');
        this.statusBar.styleLightContent();
        this.appVersion.getVersionNumber().then((version:string)=>{
            alert(version);
        })

        this.loadLogin();

    });
  }

    loadLogin(){
      this.storage.get("userLoginInfo").then((value)=>{
          if (value != null && value != '') {
              this.router.navigate(['tabs/home'])
              // this.user = value;
              // if(this.user.remember){
              //     this.appService.ObserverHttpPost("/wisdomgroup/app/loginpost", this.user)
              //         .subscribe((res: Response) => {
              //                 let data = res.json();
              //                 if (data["code"] == '200') {
              //                     this.storage.set('user', data.data);
              //                     this.user.userid = data.data.id;
              //                     this.storage.set('userLoginInfo', this.user);
              //                     this.rootPage = TabsPage;
              //                 } else {
              //                     this.appService.alert('手机号或密码错误！');
              //                     this.rootPage = LoginPage;
              //                 }
              //             }, error => {
              //                 this.rootPage = LoginPage;
              //                 this.appService.alert('网络异常！');
              //             }
              //         );
              // }else{
              //     this.rootPage = LoginPage;
              // }

          }
          else {
              console.log('login')
              // this.rootPage = LoginPage;
          }
      })
    }
}
