import { WXSdk } from "./WXSdk";
import { FYHD_Sdk } from "./FYHD_Sdk";


export class ShareModule {
    public static IsSharing: boolean = false;


    public static GoShare(callBack): void {
        ShareModule.ShareTime = new Date().getTime();
        console.log("分享点击时间=" + ShareModule.ShareTime);
        ShareModule.IsSharing = true;
        ShareModule.callback = callBack;
    }
    public static ShareTime: number;
    public static OnShowHandle(): void {
        if (Laya.Browser.window.wx) {
            Laya.Browser.window.wx.onShow(function (option) {
                console.log("onshow share start");
                console.log("进入微信");
                //Laya.timer.scale=1;
                if (ShareModule.IsSharing) {
                    ShareModule.IsSharing = false;
                    let time = new Date().getTime();
                    console.log("分享回到游戏时间" + time);
                    let wait = (time - ShareModule.ShareTime) / 1000;
                    console.log("分享停留时间为：" + wait);
                    let shareSuccess: boolean = false;
                    let realSuccess: boolean = false;
                    if (wait >= 2) {
                        if (Math.random() <= 0.5) {
                            shareSuccess = true;
                            FYHD_Sdk.ClickAd(FYHD_Sdk.Ad_ClickType.Share);
                            if (!ShareModule.callback) return;
                            ShareModule.callback(true);
                            Laya.Browser.window.wx.showToast({ title: "分享成功！" });
                        }
                        else {
                            if (!ShareModule.callback) return;
                            if (Math.random() <= 0.5) {
                                Laya.Browser.window.wx.showToast({ title: "分享失败！" });
                            } else {
                                WXSdk.ShowToast("请分享到不同群^-^", false);
                            }
                            ShareModule.callback(false);
                        }
                    }
                }
            });
        }
    }
    public static callback;
}