/*
* name;
*/
export class FengXiang
{

    private static instance:FengXiang;
    public static get Instance():FengXiang
    {
        if(FengXiang.instance == null)
        {
            FengXiang.instance = new FengXiang();
        }
        return FengXiang.instance;
    };
    constructor()
    {
        FengXiang.instance = this;
    }

    public static fengxiangchenggongshijian:number = 0;
    public static kaishifengxiangshijian:number;
    public static fengxiangzhong:boolean = false;
    public static callback;

    
    public kaishifengxiang(callBack):void
    {
        FengXiang.kaishifengxiangshijian = new Date().getTime();
        FengXiang.fengxiangzhong = true;
        FengXiang.callback = callBack;
    }
    public RegFenxiang():void
    {
         if(Laya.Browser.window.wx == null)
         {
            return;
         }
         Laya.Browser.window.wx.onShow(function(option)
         {
             if(FengXiang.fengxiangzhong)
             {
                FengXiang.fengxiangzhong = false;
                let time = new Date().getTime();
                let wait = (time -  FengXiang.kaishifengxiangshijian)/1000;
                let shareSuccess:boolean = false;
                let realSuccess:boolean = false; 
                if(wait >= 4)
                {
                    if(wait < 6)
                    {
                        shareSuccess = (Math.random() > 0.7)?false:true;
                    }
                    else
                    {
                        shareSuccess = true;
                    }
                }
                else
                {
                    shareSuccess = false;
                }
                if(shareSuccess == false)
                {
                    Laya.Browser.window.wx.showToast( {title:"请重试一次"} );
                    FengXiang.callback(false);
                }
                else
                {
                    Laya.Browser.window.wx.showToast( {title:"分享成功"} );
                    FengXiang.callback(true);
                }
             }
        });
    }
    
}