import { ryw_Event } from "../FrameWork/Event/EventEnum";
import EventMgr from "../FrameWork/Event/EventMgr";
import GameReport, { ENTERTYPE, OUTTYPE } from "../FrameWork/Report/ZyZyReport";
import User from "../FrameWork/User/User";
import Common5 from "../Platform/th/Common5";
import TTAPI from "../Platform/tt/TTAPI";
// import DayUnlock from "../../ttFrame/manager/DayUnlock";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CeBianLan extends cc.Component {
    @property(cc.Node)
    btnEnter: cc.Node = null;

    @property(cc.Node)
    btnGetAward: cc.Node = null;

    @property(cc.Node)
    getRewardBtn: cc.Node = null;


    
    protected onLoad(): void {
        this.checkIsShowJiangLiBtn()
        EventMgr.onEvent_custom(ryw_Event.CheckIsEnterFromCeBianLan, () => {
            this.checkIsShowJiangLiBtn()
        }, this);
    }

    btnCloseFunc() {
        GameReport.OUTReport(OUTTYPE.FANHUI,'领取福利')
        Common5.playEffect("ui")
        this.node.removeFromParent();
    }

    btnJinRuCeBianLan() {
        Common5.playEffect("ui")
        GameReport.BtnsReport('进入侧边栏','普通按钮点击集合','领取福利');
        User.setDaojuArr([1,1,1]);
        EventMgr.emitEvent_custom(ryw_Event.CheckCeBianLan,false);
        //检测侧边栏是否可用
        TTAPI.navigateToScene(()=>{
            console.log('加入侧边栏成功')
        },()=>{
            console.log('加入侧边栏失败')
        })
    }

    onBtnClickGetAward(){
        GameReport.BtnsReport('领取奖励','普通按钮点击集合','领取福利');
        Common5.playEffect("ui")
        console.log('领取奖励')
        Common5.isCeBianLanEnter = false
        User.setFinishCeBianLanAward(true)
        User.setLevelAryy_custom(Common5.getRandomNum(0,Common5.gameConfig.GameAllType[0].Levels.length))
        EventMgr.emitEvent_custom(ryw_Event.CheckCeBianLan,false);
        // PrefabManage.showTextTips('成功获得500金币!')
        this.node.removeFromParent()
    }
    
    checkIsShowJiangLiBtn(){
        //是否已经领取过奖励        
        let isGetAward = User.getFinishCeBianLanAward()
        if(Common5.isCeBianLanEnter && !isGetAward){
            this.btnEnter.active = false
            this.btnGetAward.active = true
        }else{
            if(isGetAward){
                this.getRewardBtn.active = true
                this.btnEnter.active = false
            }else{
                this.btnEnter.active = true
                this.getRewardBtn.active = false
            }
            this.btnGetAward.active = false
        }
    }
}