import { DataManager } from "../libs/tw/manager/DataManager";
import { NetName } from "../libs/tw/enum/NetName";
import Loading from "./loading/Loading";

export default class DoShare {
   
    static _instance: DoShare;
    static get instance() {
        return DoShare._instance || (DoShare._instance = new DoShare())
    }

    doShare(state){

        let yunji_from =this.getQueryString("yunji_from")
        if(!yunji_from||yunji_from=="1"||yunji_from=="2"){
            yunji_from="4"
        }

        var linkShare=`http://activity.m.duiba.com.cn/customShare/share?id=3446&yunji_from=${yunji_from}&is_share=1`;
        var linkHelp=`https://activity.m.duiba.com.cn/customShare/share?id=3346&yunji_from=${yunji_from}&is_share=1`;
        var link
        if(state=="help"){
            link=`${linkHelp}&shareCode=${DataManager.ins.getData(NetName.GET_SHARECODE).shareCode}`;
        }else{
            link=`${linkShare}`;
        }
        console.log(link)
        var shareData = {
            title: window["shareData"].title,//标题
            desc: window["shareData"].desc,//描述
            link: link,//链接
            imgUrl: window["shareData"].imgUrl,//图片
        }
        console.log(shareData)
        window["invokeWX"](shareData)
        window["wx"].ready(function(){
            console.log("微信好了")
            window["invokeWX"](shareData);
        });
    }

    doShareApp(state){

        let yunji_from =this.getQueryString("yunji_from")
        if(!yunji_from||yunji_from=="1"||yunji_from=="2"){
            yunji_from="3"
        }

        var linkShare=`http://activity.m.duiba.com.cn/customShare/share?id=3446&yunji_from=${yunji_from}&is_share=1`;
        var linkHelp=`https://activity.m.duiba.com.cn/customShare/share?id=3346&yunji_from=${yunji_from}&is_share=1`;
        var link;
        if(state=="help"){
            link=`${linkHelp}&shareCode=${DataManager.ins.getData(NetName.GET_SHARECODE).shareCode}`;
        }else{
            link=`${linkShare}`;
        }
        console.log(link)
		let href=`yunji://doubleTwelve/share?link=${encodeURIComponent(link)}&imgUrl=${window["shareData"].imgUrl}&title=${window["shareData"].title}&content=${window["shareData"].desc}`;
		window.location.href = href;
    }

    getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
	};
}