import {Component, ElementRef, Renderer2, ViewChild} from '@angular/core';
import {LoadingController, NavController, Slides} from 'ionic-angular';
import {HomeService} from "./home.service";
import {LearnService} from "../learning/learn.service";
import {CommonService} from "../../core/common.service";
import {LearningPage} from "../learning/learning";
import {Storage} from "@ionic/storage";
import {defaultImg} from "../../app/app.constants";
import {MineService} from "../mine/mine.service";
import {TabService} from "../../core/tab.service";
import {timer} from "rxjs/observable/timer";
import {InAppBrowser} from "@ionic-native/in-app-browser";
import {AppService} from "../../app/app.service";
import {StatusBar} from "@ionic-native/status-bar";

@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {
    @ViewChild('angular') angular: ElementRef;
    @ViewChild('imgWidth') imgWidth: ElementRef;
    @ViewChild(Slides) slides: Slides;

    type = 'teacher';
    personrType = 0;
    saleList = [];  //销售运营
    productList = new Array(5);  //产品体验
    teacherList = [];
    bannerList = [
        {SourceUrl: defaultImg}
    ];
    mineInfo;
    defaultImg = defaultImg;

    info = {
        new: 0,
    };

    wow;   //是否执行动画

    constructor(public navCtrl: NavController, public homeSer: HomeService, private loadCtrl: LoadingController,
                private learnSer: LearnService, private commonSer: CommonService, private storage: Storage,
                private appSer: AppService, public statusBar: StatusBar,
                private mineSer: MineService, private tabSer: TabService, private inAppBrowser: InAppBrowser,
                private renderer: Renderer2) {
        this.statusBar.backgroundColorByHexString('#343435');
        this.storage.get('user').then(value => {
            if (value) {
                this.mineInfo = value;
                if (this.mineInfo.UserName && this.mineInfo.UserName.length > 3) {
                    this.mineInfo.UserName = this.mineInfo.UserName.slice(0, 3) + '...';
                }
            }
        });
    }

    ionViewDidLoad() {
    }

    ionViewWillEnter() {
        this.appSer.wowInfo.subscribe(
            (value) => {
                this.wow = value;
            }
        )
        this.info.new = 0;
    }

    ionViewDidLeave() {
        this.appSer.setWow(false);
    }

    aotuPlay() {
        this.slides.startAutoplay();
    }

    doRefresh(e) {
        this.ionViewDidLoad();
        timer(1000).subscribe((res) => {
            e.complete()
        });
    }


    ionViewWillLeave() {
        this.slides.stopAutoplay();
    }
}
