
import RankPan from "./RankPan";
    export default class RankSDK  {
   
    constructor() {  }
    private static RankPan: RankPan;
    public static ShuShi() {
        if(!Laya.Browser.onWeiXin)return;
        
        this.SetScreen();
        this.RankPan = new RankPan();
        this.RankPan.ShuShi();
    }

    public static OpenRank(keyName: string="Level") {
        if (Laya.Browser.onWeiXin){
            this.Send(keyName, "show_friend_rank");
            console.log("打开排行榜---openrank");
        }
    }

    // public static showWorldRank(keyName: string, data: any) {
    //     if (Main.OnWx)
    //         this.JHGGGIGO(keyName, "show_world_rank", data);
    // }

    public static Leftpe() {
        if (Laya.Browser.onWeiXin)
            this.Send("", "show_up_page");
    }

    public static Rightpe() {
        if (Laya.Browser.onWeiXin)
            this.Send("", "show_next_page");
    }

    // public static settlement(value: number,callBack:Function=null,keyName: string="score" ) {
    //     if (Main.OnWx)
    //         this.setUserCloudStorage(keyName, value.toString(),callBack);
    // }

    public static OpenPan(){
        console.log("Laya.Browser.onWeiXin",Laya.Browser.onWeiXin);
        if (Laya.Browser.window.wx)
            this.RankPan.open();
    }
    public static ClosePan(){
        if (Laya.Browser.onWeiXin)
        this.RankPan.close();
    }
    // public static sendMoveDelta(delta: number){
    //     if (Main.OnWx)
    //         this.JHGGGIGO("", "move_rank", delta);
    // }

    // public static updateCtx() {
    //     if (Main.OnWx) this.JHGGGIGO("", "update_ctx");
    // }

    private static SetScreen() {
        if (!Laya.Browser.onWeiXin)return;
        let width =  Laya.stage.width;
        let height = Laya.stage.height;
        let data = { width: width, height: height }
        this.Send("", "canvase_width_height", data);
    }
    private static Send(keyName: string, action: string, data?: any) {
        console.log("消息发送成功0---send");
        Laya.Browser.window.wx.postMessage({
            keyName: keyName,
            action: action,
            data: data
        });
        console.log("消息发送成功---send");
    }

    private static SetStage(keyName: string, value: string,callBack:Function=null) {
        let obj = [{
            key: keyName,
            value: value
        }];
        Laya.Browser.window.wx.setUserCloudStorage({
            KVDataList: obj,
            success: function (res) {
                console.log("数据上传成功"+res);
                if(callBack){
                    callBack();
                }
            },
            fail: function (res) {
                console.log("数据上传失败"+res);
                if(callBack){
                    callBack();
                }
            }
        });
    }
   
}