import { Node, _decorator } from 'cc';
import { BaseLayer } from '../../common/BaseLayer';
import { tyqSDK } from '../../tyq3.x/tyq-sdk';
import { cocosUtil } from '../../utils/cocosUtil';
import { msgac } from '../data/msgac';
import { eventManager } from '../manager/eventManager';
import { sdkManager } from '../manager/sdkManager';
import { playerModel } from '../model/playerModel';
const { ccclass, property } = _decorator;

@ccclass('GameContinueLayer')
export class GameContinueLayer extends BaseLayer {

    isShowBanner: boolean = false;

    onLoad() {
        console.log('zh:gameContiueLayer.ts onload');
        super.onLoad();

        cocosUtil.tweenScaleBreath(this.getNodeByPath("btnNext"));

        sdkManager.instance.hideCustomAdLeftRight();
        sdkManager.instance.showCustomAdRect();
        sdkManager.instance.hideBannerAd();
    }

    onButtonClick(node: Node, name: string) {
        switch (name) {
            case "btnNext":
                this.onClickBtnNext(node);
                break;
            default:
                break;
        }
    }

    onClickBtnNext(node: Node) {
        let val = tyqSDK.getSwitchValue("tyq_banner_touch");
        if (!cocosUtil.isDesktopBrowser() && val && playerModel.instance.getLevel() >= parseInt(val)) {
            if (!this.isShowBanner) {
                this.isShowBanner = true;
                sdkManager.instance.showBannerAd();
                this.scheduleOnce(() => {
                    sdkManager.instance.hideBannerAd();
                }, 1.5 + Math.random());
                return;
            }
        }

        this.unscheduleAllCallbacks();
        this.closeLayer();
        sdkManager.instance.hideCustomAdRect();
        // 恢复显示
        sdkManager.instance.showBannerAd();
        sdkManager.instance.showCustomAdLeftRight();

        let nextLayerName = this.obj.nextLayerName;
        this.obj.name = nextLayerName;
        eventManager.instance.send(msgac.openLayer, this.obj);
    }

}

