import MainView from "./MainView";
import InGameView from "./InGameView";
import SetView from "./SetView";
import RankView from "./RankView";
import SignView from "./SignView";
import LotteryView from "./LotteryView";
import FailureView from "./FailureView";
import WinView from "./WinView";
import ReviveView from "./ReviveView";
import GuangGao from "../Net/GuangGao";


export enum ViewType{MainView,SignView,SetView,LotteryView,InGameView,RankView,WinView,FailureView,ReviveView};

export interface SC{
    Show();
    Close();
}
export class ViewManager{
    private static ins:ViewManager;
    public ViewDic:[any][any] = [];
    public OtherViewDic:[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.Close();
            this.curView.destroy();
            this.curView.removeSelf();
        }
        this.ClearPopViews();
        this.curView = this.CreateView(_viewtype);
        this.curView.name = ViewType[_viewtype];
        this.ViewSprite.addChild(this.curView);
        this.curView.Show(data);
    }
    CloseView(){
        if(this.curView != null){
            this.curView.Close();
            this.curView.destroy();
            this.curView.removeSelf();
        }
    }
     //全屏导出页
    public OpenPopView(viewType: ViewType, data: any = null)  {
        GuangGao.Clear();
        var popView;
        if (this.OtherViewDic[viewType])  {
            popView = this.OtherViewDic[viewType];

            this.OtherViewSprite.setChildIndex(popView, this.OtherViewSprite.numChildren - 1);
            popView.visible = true;
        }
        else  {
            popView = this.CreateView(viewType);
            this.OtherViewSprite.addChild(popView);
            this.OtherViewDic[viewType] = popView;
        }
        popView.Show(data);
    }

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

    ClearPopViews()  {
        GuangGao.Clear();
        this.ClosePopView(ViewType.WinView);
        this.ClosePopView(ViewType.FailureView);
        this.ClosePopView(ViewType.ReviveView);
        //this.ClosePopView(ViewType.NewRewardView);
    }
    CreateView(_viewtype:ViewType){
        switch (_viewtype) {
            case ViewType.MainView:
            return new MainView();
            case ViewType.InGameView:
            return new InGameView();
            case ViewType.SetView:
            return new SetView();
            case ViewType.RankView:
            return new RankView();
            case ViewType.SignView:
            return new SignView();
            case ViewType.LotteryView:
            return new LotteryView();
            case ViewType.FailureView:
            return new FailureView();
            case ViewType.WinView:
            return new WinView();
            case ViewType.ReviveView:
            return new ReviveView();
        }
        return null;
    }

   

}