//关卡选择页面

import { ryw_Event } from "../FrameWork/Event/EventEnum";
import EventMgr from "../FrameWork/Event/EventMgr";
import User from "../FrameWork/User/User";
import GameMgr from "../FrameWork/Mgr/GameMgr";
import AppPlatform from "../FrameWork/Util/AppPlatform";
import Common from "../FrameWork/Util/Common";
import Common5 from "../Platform/th/Common5";

import levelPageNew from "./levelPageScriptNew";
import DayUnlock from "../ttFrame/manager/DayUnlock";
import MainScene from "../Scripts/MainSceneScript";
import LevelSelectNew from "./levelSelectNew";
import TTAPI from "../Platform/tt/TTAPI";
import GameReport, { ENTERTYPE, OUTTYPE } from "../FrameWork/Report/ZyZyReport";

const { ccclass, property } = cc._decorator;

@ccclass
export default class firstLevelSelectView extends cc.Component {
    backNode: cc.Node = null;
    clickClear: number = 0;
    public allLevel = 0;
    public unlockLevel = 0;
    protected btnSetting: cc.Node = null;
    protected btnClear: cc.Node = null;
    clearTmOut = null;
    pageIndex: number = 0;
    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.btnSetting = this.node.getChildByName("gameNode").getChildByName("setting");
        //this.btnClear = this.node.getChildByName("clear");
        this.btnSetting.on("click", this.onClickBtnSetting, this);
        //this.btnClear.on("click", this.onclickClear, this);
        this.node.getComponent(cc.Widget).updateAlignment();
        if (Common5.gameConfig == null) {
            Common5.loadConfigLocal_custom();
        }
        

        
        this.node.on(cc.Node.EventType.TOUCH_START,(event)=>{
            //console.log(event.getLocation())
            MainScene.ins.showClickEffect(event.getLocation())
        },this,true)



    }

    protected pageViewEvent(): void {
    //    console.log('updateUI++++++++++++++++====')
    }

    onClickBtnSetting() {
        Common5.playEffect("ui");
        Common5.getPrefabFromBundle("ZoomGame", "Prefabs/UI/Setting", null, (NewPlayerGuider: cc.Node) => {

        })
    }

    onBackClickEvent() {
        MainScene.ins.toMain();
        Common5.playEffect("ui");
        // if (Common5.selectGameNum != -1){
        //     GameReport.EnterReport(ENTERTYPE.TIAOZHUAN,Common5.selectGameInfo.titleUrl);
        //     MainScene.ins.GameNode.scale = 1;
        // }
    }

    
    onclickClear() {
        this.clickClear++;
        if (this.clickClear > 5) {
            // cc.assetManager.removeBundle(cc.assetManager.getBundle("ZoomGame"));
            cc.assetManager.getBundle("ZoomGame").releaseAll();
            cc.director.loadScene("LoadScene");
            this.clickClear = 0;
            this.clearTmOut = null;
        }
        else {
            if (null == this.clearTmOut) {
                this.clearTmOut = setTimeout(() => {
                    this.clickClear = 0;
                    this.clearTmOut = null;
                }, 2000);
            }
        }
    }
    start() {
        // this.allLevel = GameConfig.getInstance().getAll().length;
        // this.unlockLevel = UserData.getInstance().getLevelUnlock().length;
        // this.gameLevel.getComponent(cc.Label).string = this.unlockLevel.toString() + "/" + this.allLevel.toString();
    }

    update(dt) {
    }

    public refresh(): void {
     

    }


    openMoreGameClickEvent(){
        console.log('openMoreGameClickEvent')
        Common5.playEffect("ui")
        TTAPI.showFourGridGamePanel();
    }
    paimingClickEvent(){
        Common5.playEffect("ui")
        TTAPI.getImRankList()
    }
    lingQuFuLiClickEvent(){
        Common5.playEffect("ui")
        GameReport.EnterReport(ENTERTYPE.XUANGUAN,'领取福利');
        Common5.getPrefabFromBundle("ZoomGame","prefab/view/cebianlan",null,(node)=>{
        })
    }
    zuomianClickEvent(Event){
        Common5.playEffect("ui");
        TTAPI.addToZM();
    }
}