import { zgSingleton } from "../../zgSingleton";
import ATSDKMgr from "./ATSDKMgr";

/**
 * banner广告
 * @description
 * @author 冯聪
 */
export default class ATBanner extends zgSingleton {

    init() {
        cc["ATBannerJS"].proxy = this;
        console.log("cc[ATBannerJS]", cc["ATBannerJS"]);
        console.log("window[ATBannerJS]", window["ATBannerJS"]);
        cc["ATBannerJS"].init();
        this.loadBanner();
    }

    /** 广告位id */
    placementID() {
        if (cc.sys.os === cc.sys.OS_IOS) {
            return ATSDKMgr.topon_banner_placementId;
        } else if (cc.sys.os === cc.sys.OS_ANDROID) {
            return ATSDKMgr.topon_banner_placementId;
        }
    }

    /* *加载banner */
    loadBanner() {
        cc["ATBannerJS"].loadBanner();
    }

    /** 显示banner */
    showBanner() {
        cc["ATBannerJS"].showBanner();
    }

    destroyBanner() {
        cc["ATBannerJS"].destroyBanner()
    }

    //广告回调部分------------------------------------------------------------------------
    /**
     * banner加载成功
     * @param {*} placementId 广告位id
     * @returns 
     */
    onBannerAdLoaded(placementId) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdLoaded(" + placementId + ")");
    }

    /**
     *  banner加载失败
     * @param {*} placementId 广告位id
     * @param {*} errorInfo   错误信息
     * @returns 
     */
    onBannerAdLoadFail(placementId, errorInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdLoadFail(" + placementId + ", " + errorInfo + ")");
    }

    /**
     * banner展示成功
     * @param {*} placementId  广告位id
     * @param {*} callbackInfo 回调信息
     * @returns 
     */
    onBannerAdShow(placementId, callbackInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdShow(" + placementId + ", " + callbackInfo + ")");
    }

    /**
     * banner被点击
     * @param {*} placementId  广告位id
     * @param {*} callbackInfo 回调信息
     * @returns 
     */
    onBannerAdClick(placementId, callbackInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdClick(" + placementId + ", " + callbackInfo + ")");
    }

    /** banner自动刷新成功 */
    onBannerAdAutoRefresh(placementId, callbackInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefresh(" + placementId + ", " + callbackInfo + ")");
    }

    /**
     * banner自动刷新失败
     * @param {*} placementId 广告位id
     * @param {*} errorInfo   错误信息
     * @returns 
     */
    onBannerAdAutoRefreshFail(placementId, errorInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefreshFail(" + placementId + ", " + errorInfo + ")");
    }

    /**
     * banner关闭按钮被点击
     * @param {*} placementId  广告位id
     * @param {*} callbackInfo 错误信息
     * @returns 
     */
    onBannerAdCloseButtonTapped(placementId, callbackInfo) {
        // ATJSSDK.printLog("AnyThinkBannerDemo::onBannerAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");

    }
}
