import { InGameView } from "./InGameView";
import { HomeView } from "./HomeView";
import { AccountManager } from "../NetWork/AccountManager";

export enum ViewType{InGameView,HomeView,GameResultView,PauseView,UpGradeView,SkinView,TrialView,BannerView};

export interface SC{
    OnShow();
    OnHide();
}
export class ViewManager{
    private static ins:ViewManager;
    public showexportview:number = 0;
    
    private popViewDic:[any][any] = [];
    public ViewSprite:Laya.Sprite = new Laya.Sprite();
    public OtherViewSprite:Laya.Sprite = new Laya.Sprite();
    public curView:any;
    constructor(){
        ViewManager.ins = this;
        Laya.stage.addChild(this.ViewSprite);
        Laya.stage.addChild(this.OtherViewSprite);
    }
    public static get Instance():ViewManager{
        if(ViewManager.ins){
            return ViewManager.ins
        }
        else{
            return new ViewManager();
        }
    }
    ShowView(_viewtype:ViewType,data = null){
        if(this.curView != null){
            this.curView.OnHide();
            this.curView.destroy();
            this.curView.removeSelf();
        }
        // GuangGao.Clear();
        this.curView = this.CreateView(_viewtype);
        this.curView.name = ViewType[_viewtype];
        this.ViewSprite.addChild(this.curView);
        this.curView.OnShow(data);
    }
    CloseView(){
        if(this.curView != null){
            this.curView.OnHide();
            this.curView.destroy();
            this.curView.removeSelf();
        }
    }
    //全屏导出页
    public OpenPopView(viewType:ViewType,data:any = null)
    {
        // GuangGao.Clear();
        var popView;
        if(this.popViewDic[viewType])
        {
            popView = this.popViewDic[viewType];
            this.OtherViewSprite.setChildIndex(popView,this.OtherViewSprite.numChildren - 1);
            popView.visible = true;
        }
        else
        {
            popView = this.CreateView(viewType);
            this.OtherViewSprite.addChild(popView);
            this.popViewDic[viewType] = popView;
        }
        popView.OnOpen(data);
    }

    public ClosePopView(viewType:ViewType)
    {
        var popView = this.popViewDic[viewType];
        if(popView == null){
            return;
        }
        // GuangGao.Clear();
        popView.OnHide();
        popView.visible = false;
    }

    ClearPopViews()
    {
        // GuangGao.Clear();
    }
    CreateView(_viewtype:ViewType){
        switch (_viewtype) {
           case ViewType.InGameView:
           return new InGameView();
           case ViewType.HomeView:
           return new HomeView();
        }
        return null;
    }
}