import { WXSDK } from "./WXSDK";
import { AccountManager } from "./AccountManager";
import ListItem from "../Tools/ListItem";
import { Main } from "../Main";
import { ViewManager, ViewType } from "../View/ViewManager";

export class SDKZS{
    static data: any;
    static isReady: boolean = false;
    static SetHuTuiList(list: Laya.List, scrol: number = 1, type: string = "") { //scrol 1:竖的  2横的
        console.log("互推数据--",SDKZS.data);
        console.log("互推数据准备状态---",SDKZS.isReady);
        let arr = SDKZS.data.promotion;
        if (!arr || arr.length == 0) return;
        list.selectEnable = false;
        scrol == 1 ? list.vScrollBarSkin = "" : list.hScrollBarSkin = "";
        list.renderHandler = Laya.Handler.create(this, SDKZS.updateItem, [type], false);
        list.array = arr;
        list.refresh();
    }
    private  static updateItem(type: string, cell: Laya.Box, index: number) {
        var aditem = cell.getComponent(ListItem) as ListItem;
        aditem.Refresh(type);
    }
    static loadData() {
        zs.sdk.loadAd((res) => {
            console.log("[LOG]互推数据");
            console.log(res);
            SDKZS.data = res;
            console.log("拉取互推数据--",SDKZS.data);
            SDKZS.isReady = true;
        })
    }
    //小程序跳转
    static navigate2Mini(data: zs.sdk.adData) {
        zs.sdk.navigate2Mini(data, AccountManager.Instance.curplayerData.openid, () => {
            WXSDK.AldEvent("成功跳转到" + data.app_title);
        }, () => {
            WXSDK.AldEvent("跳转" + data.app_title +"失败");
            if(ViewManager.Instance.showexportview == 0){
                ViewManager.Instance.OpenPopView(ViewType.ExportView);
            }
        }, () => {
        });
    }
    /**是否误触 */
    public static get CanCheat(): boolean {
        var checkscence = AccountManager.Instance.curplayerData.CheckScene;
        if (checkscence == false) {
            return true;
        }
        if (Main.SceneNum == "1037" || Main.SceneNum == "1058"
            || Main.SceneNum == "1067" || Main.SceneNum == "1095") {
            return true;
        }
        return false;
    }
}