import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import EventMgr from "../../FrameWork/Event/EventMgr";
import { ryw_Event } from "../../FrameWork/Event/EventEnum";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Daily extends cc.Component {

    hour:number = 0
    min:number = 0
    onLoad () {
        EventMgr.onEvent_custom(ryw_Event.addDay,(isChangeData)=>{
            if(isChangeData){
                this.min = 0
                this.hour = 0;
            }
            let day = User.getDay()+1
            User.setDay(day);
         
            this.refreshDailyStr()
            //TaskManager.checkIsTaskFail(day)
        },this)

        EventMgr.onEvent_custom(ryw_Event.updateTime,()=>{
            console.log("更新时间")
            this.hour = User.getTimeHour();
            this.min = User.getTimeMin();
            this.refreshDailyStr()
        },this)
    }

    start () {
        this.hour = User.getTimeHour();
        this.min = User.getTimeMin();
        this.refreshDailyStr()

        this.schedule(()=>{
            if(Common5.isVideoAdStopTime){
                return
            }
            this.hour = User.getTimeHour();
            this.min = User.getTimeMin();
            this.refreshDailyStr()
        },1)
       
    }

    refreshDailyStr(){
        this.node.getChildByName("time").getComponent(cc.Label).string = this.hour.toString() + ":"+(this.min.toString().padStart(2,"0"));
        this.node.getChildByName("day").getComponent(cc.Label).string = "第" + User.getDay().toString() + "天";
    }
    // update (dt) {}
}