import { ui } from "../ui/layaMaxUI";
import { SC, ViewManager, ViewType } from "./ViewManager";
import { EventManager, StageMode } from "../Tool/EventManager";

export default class ReviveView extends ui.ReviveViewUI implements SC{
    private static ins:ReviveView;
    constructor(){
        super();
    }
    public static get Instance():ReviveView{
        if(ReviveView.ins){
            return ReviveView.ins
        }
        else{
            return new ReviveView();
        }
    }
    Show(){
        this.VideoBtn.clickHandler = Laya.Handler.create(this,this.VideoRevive)
        this.NoBtn.visible = false;
        Laya.timer.once(1000,this,()=>{
            this.NoBtn.visible = true;
            this.NoBtn.clickHandler = Laya.Handler.create(this,this.DontRevive,null,false);
        })
        this.count = true;
        Laya.timer.loop(1000,this,this.CountTime);
        this.height = Laya.stage.height; 
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
    }
     time = 9;
     count = false;
     fuhuo = false;
     //倒计时
     CountTime()
     {
         if(this.count && this.time > 0)
         {
             this.time -= 1;
             this.Time.text = this.time.toString();
             if(this.time < 1)
             {
                Laya.timer.clear(this,this.CountTime);
                this.DontRevive();
             }
         }
     }
     //不用复活
     DontRevive(){
         Laya.timer.clear(this,this.CountTime);
         this.count = false;
         ViewManager.Instance.OpenPopView(ViewType.FailureView);
     }
     //视频复活
     VideoRevive(){
        Laya.timer.clear(this,this.CountTime);
        this.count = false;
        EventManager.StageTrigger(StageMode.Revive);
        ViewManager.Instance.ClearPopViews();
     }
    Close(){
        Laya.timer.clearAll(this);
    }

} 