import { WXSdk } from "./WXSdk";
import { SettingController } from "../GameLogic/SettingController";
import NetManager from "./NetManager";
import GameSetting from "./GameSetting";
import ViewManager from "./ViewManager";
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) {

                SettingController.Instance.SetSoundV(1);

                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() <= 1) {
                            shareSuccess = true;
                            //  FYHD_Sdk.ClickAd(FYHD_Sdk.Ad_ClickType.Share);
                            if (!ShareModule.callback) return;
                            ShareModule.callback(true, 1);
                            // WXSdk.ShowToast("分享成功！");
                         //   ViewManager.Instance.ShowTips("分享成功!");

                        }
                        else {
                            if (!ShareModule.callback) return;
                            if (Math.random() <= 0.5) {
                                // Laya.Browser.window.wx.showToast({ title: "分享失败！" });
                                ViewManager.Instance.ShowTips("分享失败!");
                            } else {
                                //WXSdk.ShowToast("请分享到不同群^-^", false);
                                ViewManager.Instance.ShowTips("请分享到不同的群!");
                            }
                            ShareModule.callback(false, 1);
                        }
                    }
                    else {
                        if (!ShareModule.callback) return;
                        if (Math.random() <= 0.5) {
                            ViewManager.Instance.ShowTips("分享失败!");
                        } else {
                            ViewManager.Instance.ShowTips("请分享到不同的群!");
                        }
                        ShareModule.callback(false, 1);
                    }
                }
            });


        }
    }
    public static callback;
}
export class OnHideHandler {
    public static Reg() {
        // if (Laya.Browser.window.wx) {
        //     Laya.Browser.window.wx.onHide(function (option) {
        //         NetManager.Instance.UserSyncInfo();

        //         var c = Math.ceil(Laya.timer.currTimer * 0.001);
        //         Laya.LocalStorage.setItem("offline", c.toString());
        //         console.log("-----------切换到后台!!!");
        //     });
        // }
    }

}