/*
* name;
*/
 export class ShareUtil
{
    public static Instance: ShareUtil = new ShareUtil();
    constructor()
    {

    }
    public ShareUtil():void
    {

    }
    
    public static shareSuccessTime:number = 0;
    public static beginShareTime:number;
    public static  isSharing:boolean = false;
    public static callback;

    public beginShare(callBack):void
    {
          ShareUtil.beginShareTime = new Date().getTime();
            console.log("分享点击时间=" + ShareUtil.beginShareTime);
          ShareUtil.isSharing = true;
          ShareUtil.callback = callBack;
    }
    public onRegister():void
    {
         if(Laya.Browser.window.wx == null)
         {
             return;
         }
         Laya.Browser.window.wx.onShow(function(option)
         {
             console.log("onshow share start");
             if(ShareUtil.isSharing)
             {
                 ShareUtil.isSharing = false;
                 let time = new Date().getTime();
                   console.log("分享回到游戏时间" + time);
                 let wait = (time -  ShareUtil.beginShareTime)/1000;
                 console.log("分享停留时间为：" + wait);
                 let shareSuccess:boolean = false;
                 let realSuccess:boolean = false; 
                 if(wait >= 2)
                 {
                    if(wait < 4)
                    {
                        shareSuccess = (Math.random() > 0.7)?false:true;
                    }
                    else
                    {
                        shareSuccess = true;
                    }
                 }
                 else{
                    shareSuccess = false;
                 }
                 if(shareSuccess == false)
                 {
                     Laya.Browser.window.wx.showToast( {title:"请重试一次"} );
                     ShareUtil.callback(false);
                 }
                 else{
                    Laya.Browser.window.wx.showToast( {title:"分享成功"} );
                    ShareUtil.callback(true);
                 }
             }
            

        });
    }
}