import { _decorator} from 'cc';
import { Constants } from '../data/Constants';
const { ccclass, property } = _decorator;

class PlatformBrowser {
    adInstance: any = null;
    gtag: any = null;
    openAd: boolean = true;

    public initialize(): void {
        this.adInstance = (window as any)['adInstance'];
        try {
            window["__woso"]?.["TopCallback"]?.();
        } catch (error) { 
        }
        console.log('web ads sdk初始化');
    }
    
    /**显示插屏广告*/
    public showInterstitialAd(cb?:Function): void {
        if(Constants.isDebug){
            console.log('模拟显示插屏广告回调');
            cb?.();
            return
        }
        try {
            window['showAd']('interstitial').then(() => {
                console.log("rewarded11111")
            }).catch(() => {
                // GtagMgr.inst.doGameDot(GtagType.ad_error);
            });
        } catch (error) {
            // tgxUITips.show('The ad failed to load')
        }
    }

    /** 显示激励广告*/
    public showRewardVideo(cb:Function): void {
        if(Constants.isDebug){
            console.log('模拟激励广告回调');
            cb?.(1);
            return
        }
        try {
            window["showAd"]('rewarded')
                .then(() => {
                    if (cb) cb(1);
                })
                .catch(() => {
                    //上报信息
                    // GtagMgr.inst.doGameDot(GtagType.ad_error);
                    // cb && cb();
                })
                return
        } catch (error) {
        }
        //tgxUITips.show('The ads failed to load');
    }

    /** 显示激励广告*/
    public hideBannerAd(): void {
    }
    
    public showBannerAd(): void {
    }

    public vibrateShort(): void {
    }
}

export default new PlatformBrowser();
