!function(e, n) {
    "function" == typeof define && define.amd ? define(function() {
        return n(e)
    }) : "undefined" != typeof module && module.exports ? module.exports = n(e) : e.jdshare = n(e)
}("undefined" != typeof window ? window : this, function(l) {
    var e;
    setTimeout(function() {
        try {
            var e = new MPing.inputs.Click("Mnpm_ComponentApplied");
            e.event_param = "jdshare",
            e.updateEventSeries(),
            (new MPing).send(e)
        } catch (e) {}
    }, 1500);
    var n = navigator.userAgent.toLowerCase()
      , t = n.split(";")
      , a = -1 != n.indexOf("jdapp")
      , c = -1 != n.indexOf("jdltapp")
      , r = function() {
        if (a && t[2])
            try {
                return parseInt(t[2].replace(/\./g, ""))
            } catch (e) {}
    }()
      , i = "android" === t[1]
      , o = "iphone" === t[1]
      , p = i || o
      , h = -1 != n.indexOf("ipad")
      , m = (/MicroMessenger/i.test(n),
    p && a && 500 <= r)
      , s = p && a && 440 <= r && r < 500
      , f = h && a && 360 <= r
      , d = p && a && 702 <= r
      , u = p && a && 836 <= r
      , k = p && a && r <= 840
      , y = p && a && 620 <= r
      , b = l.isJDAppNewShareEnable && 1 == l.isJDAppNewShareEnable
      , I = p ? c ? "openjdlite://" : "openapp.jdmobile://" : h ? "openapp.jdipad://" : void 0
      , S = "Y"
      , v = "N"
      , w = "S"
      , g = "P"
      , C = "O";
    function U(e) {
        var n = I + 'communication?params={"des":"share","type":"111","title":"' + e.title + '","content":"' + e.content + '","shareUrl":"' + e.url + '","iconUrl":"' + e.img + '","shareActionType":"' + e.shareActionType + '","channel":"' + e.channel + '","timeline_title":"' + e.timeline_title + '","qrparam":"' + e.qrparam + '","keyparam":"' + e.keyparam + '","callback":"' + e.callbackSwitcher + '","clickcallback":"' + e.clickcallbackSwitcher + '"}';
        return console.log("schema:", n),
        n
    }
    function _(e) {
        var n = {
            title: e.title,
            content: e.content,
            shareUrl: decodeURIComponent(e.url),
            iconUrl: decodeURIComponent(e.img),
            shareActionType: e.shareActionType,
            channel: e.channel,
            timeline_title: e.timeline_title,
            qrparam: e.qrparam,
            keyparam: e.keyparam,
            callback: e.callbackSwitcher,
            clickcallback: e.clickcallbackSwitcher,
            eventId: ""
        };
        d && e.mpId && e.mpPath && e.mpIconUrl && (n.mpId = e.mpId,
        n.mpPath = e.mpPath,
        n.mpIconUrl = e.mpIconUrl,
        n.mpType = e.mpType),
        y && e.incentiveBizType && e.incentiveBizId && (n.incentiveBizType = e.incentiveBizType,
        n.incentiveBizId = e.incentiveBizId),
        shareHelper.initShare(JSON.stringify(n))
    }
    function T(e, n) {
        shareHelper[e](n.title, n.content, decodeURIComponent(n.url), decodeURIComponent(n.img), n.callbackSwitcher)
    }
    function R(e, n) {
        shareHelper[e](n.title, n.content, decodeURIComponent(n.url), decodeURIComponent(n.img))
    }
    function j(e, n) {
        return I + 'communication?params={"action":"' + n + '","title":"' + e.title + '","content":"' + e.content + '","shareUrl":"' + e.url + '","iconUrl":"' + e.img + '","isCallBack":"' + e.callbackSwitcher + '"}'
    }
    function A(e) {
        var n, t = {
            category: "jump",
            des: "share",
            type: "111",
            title: e.title,
            content: e.content,
            shareUrl: e.url,
            imageUrl: e.img,
            iconUrl: e.img,
            timeline_title: e.timeline_title,
            qrparam: e.qrparam,
            keyparam: e.keyparam,
            channel: e.channel,
            isCallBack: e.callbackSwitcher,
            clickcallback: e.clickcallbackSwitcher,
            shareActionType: e.shareActionType
        };
        if (d && e.mpId && e.mpPath && e.mpIconUrl && (t.mpId = e.mpId,
        t.mpPath = encodeURIComponent(e.mpPath),
        t.mpIconUrl = encodeURIComponent(e.mpIconUrl),
        t.mpType = e.mpType),
        u) {
            n = e.keyparam,
            "[object Object]" === Object.prototype.toString.call(n) && (!function(e, n) {
                var t = {}
                  , a = {};
                for (var c in e)
                    t[c] = e[c];
                for (var c in t)
                    t.hasOwnProperty(c) && -1 < n.indexOf(c) ? a[c] = encodeURIComponent(t[c]) : a[c] = t[c]
            }(e.keyparam, ["keyImg", "url", "keyId"]),
            t.keyparam = e.keyparam)
        }
        y && e.incentiveBizType && e.incentiveBizId && (t.incentiveBizType = e.incentiveBizType,
        t.incentiveBizId = e.incentiveBizId);
        var a = I + "virtual?params=" + JSON.stringify(t);
        return console.log("schema", a),
        a
    }
    function q(e) {
        if (!(this instanceof q))
            return new q(e)
    }
    function O(e) {
        this.message = e,
        this.name = "JdShareException",
        this.toString = function() {
            return this.name + ": " + this.message
        }
    }
    function H(e, n) {
        for (var t in n)
            n.hasOwnProperty(t) && void 0 !== n[t] && (e[t] = n[t])
    }
    function E(e, n) {
        return "" == n ? e : (e + "&" + n).replace(/[&?]{1,2}/, "?")
    }
    function B(n) {
        l.jdappShareRes = function(e) {
            e.hasOwnProperty("shareResult") ? n.callback && n.callback(e) : o && u && k && e.hasOwnProperty("shareEvent") ? ("CANCEL_SHARE_CONTENT" == e.shareEvent ? (e.shareResult = "2",
            e.shareChannel = "") : (e.shareResult = "0",
            e.shareChannel = {
                WeChat_Friend: "Wxfriends",
                WeChat_FriendTimeline: "Wxmoments",
                Weibo: "Sinaweibo",
                QQFriend_SHARE_CLIENT: "QQfriends",
                QQZone_SHARE_CLIENT: "QQzone"
            }[e.shareEvent]),
            n.callback && n.callback(e)) : n.clickcallback && n.clickcallback(e)
        }
    }
    function z(e) {
        var n = "";
        if (e) {
            if (o) {
                if (s) {
                    if (n = {
                        Wxfriends: "WeChat_Friend",
                        Wxmoments: "WeChat_FriendTimeline",
                        Sinaweibo: "Weibo",
                        QQfriends: "QQFriend_SHARE_CLIENT",
                        QQzone: "QQZone_SHARE_CLIENT",
                        Moreshare: ""
                    }[e])
                        return n;
                    throw new O("输入的channel参数在iphone版本中不存在")
                }
                return e
            }
            return e
        }
        return e
    }
    function Q(e) {
        return void 0 !== e.title && void 0 !== e.content && void 0 !== e.url && void 0 !== e.img
    }
    function P(e) {
        if (Q(e)) {
            try {
                var n, t, a, c, r = {
                    timeline_title: "",
                    channel: "",
                    qrparam: null,
                    keyparam: null,
                    callback: null,
                    clickcallback: null,
                    mpId: null,
                    mpPath: null,
                    mpIconUrl: null,
                    mpType: null,
                    incentiveBizType: null,
                    incentiveBizId: null
                };
                "[object Object]" === Object.prototype.toString.call(e) && H(r, e),
                n = "function" == typeof r.callback,
                a = "function" == typeof r.clickcallback,
                t = n ? S : v,
                c = a ? S : v,
                n && a ? B({
                    callback: r.callback,
                    clickcallback: r.clickcallback
                }) : n ? B({
                    callback: r.callback
                }) : a && B({
                    clickcallback: r.clickcallback
                }),
                "[object Object]" === Object.prototype.toString.call(r.qrparam) && (r.qrparam.top_pic = r.qrparam.top_pic ? encodeURIComponent(decodeURIComponent(r.qrparam.top_pic)) : "",
                r.qrparam.mid_pic = r.qrparam.mid_pic ? encodeURIComponent(decodeURIComponent(r.qrparam.mid_pic)) : "",
                r.qrparam.qr_direct = r.qrparam.qr_direct ? encodeURIComponent(decodeURIComponent(r.qrparam.qr_direct)) : ""),
                r.callbackSwitcher = t,
                r.clickcallbackSwitcher = c,
                r.url = E(r.url, "_ts=" + (new Date).getTime()),
                r.channel = z(r.channel),
                r.url = encodeURIComponent(r.url),
                r.img = encodeURIComponent(r.img)
            } catch (e) {
                throw e
            }
            return r
        }
        throw new O("调用方法时传入配置对象格式错误，请查看文档")
    }
    function N(e) {
        if (!Q(e))
            throw new O("调用方法时传入配置对象格式错误，请查看文档");
        try {
            var n, t, a, c, r = {
                category: "jump",
                des: "share",
                type: "111",
                title: e.title,
                content: e.content,
                shareUrl: e.url,
                imageUrl: e.img,
                iconUrl: e.img,
                timeline_title: e.timeline_title,
                qrparam: e.qrparam,
                keyparam: e.keyparam,
                channel: e.channel
            };
            "[object Object]" === Object.prototype.toString.call(e) && H(r, e),
            n = "function" == typeof r.callback,
            a = "function" == typeof r.clickcallback,
            t = n ? S : v,
            c = a ? S : v,
            n && a ? B({
                callback: r.callback,
                clickcallback: r.clickcallback
            }) : n ? B({
                callback: r.callback
            }) : a && B({
                clickcallback: r.clickcallback
            }),
            r.callbackSwitcher = t,
            r.clickcallbackSwitcher = c,
            r.url = E(r.url, "_ts=" + (new Date).getTime()),
            r.channel = z(r.channel);
            var i = {
                method: "configShare",
                params: JSON.stringify(r)
            };
            l.webkit.messageHandlers.JDAppUnite.postMessage(i)
        } catch (e) {
            console.log("分享错误265", e),
            throw console.log("error", e),
            e
        }
    }
    return (O.prototype = Object.create(Error.prototype)).constructor = O,
    q.prototype.setShareInfo = function(e) {
        try {
            var n = null;
            if ((n = P(e)).shareActionType = w,
            a)
                if (i)
                    if (l.shareHelper)
                        if ("function" == typeof shareHelper.initShare)
                            _(n);
                        else if ("function" == typeof shareHelper.setShareInfoCallback)
                            if (n.callbackSwitcher === S)
                                try {
                                    T("setShareInfoCallback", n)
                                } catch (e) {
                                    R("setShareInfoCallback", n)
                                }
                            else
                                try {
                                    T("setShareInfoCallback", n)
                                } catch (e) {
                                    "function" == typeof shareHelper.setShareInfo && R("setShareInfo", n)
                                }
                        else
                            "function" == typeof shareHelper.setShareInfo && R("setShareInfo", n);
                    else
                        l.location.href = U(n);
                else
                    (o || h) && (m || f ? b ? (e.shareActionType = w,
                    N(e)) : location.href = A(n) : o && (location.href = j(n, "syncShareData")));
            else
                c && (i ? l.location.href = U(n) : (o || h) && (location.href = A(n)))
        } catch (e) {
            throw e
        }
    }
    ,
    q.prototype.callSharePane = function(e) {
        try {
            var n = null;
            (n = P(e)).shareActionType = g,
            i ? a && l.shareHelper ? "function" == typeof shareHelper.initShare ? _(n) : "function" == typeof shareHelper.callShare ? T("callShare", n) : l.location.href = U(n) : l.location.href = U(n) : (o || h) && (m || f ? b ? (e.shareActionType = g,
            N(e)) : location.href = A(n) : c ? location.href = A(n) : o && (location.href = j(n, "share")))
        } catch (e) {
            throw e
        }
    }
    ,
    q.prototype.sendDirectShare = function(e) {
        try {
            var n, t = null;
            if ((t = P(e)).shareActionType = C,
            i)
                a && l.shareHelper ? "function" == typeof shareHelper.initShare ? _(t) : "function" == typeof shareHelper.sendShare ? shareHelper.sendShare(t.title, t.content, decodeURIComponent(t.url), decodeURIComponent(t.img), t.channel, t.callbackSwitcher) : location.href = U(t) : l.location.href = U(t);
            else if (o || h) {
                if (!t.channel)
                    throw new O("分享渠道未设置");
                m || f ? b ? (e.shareActionType = C,
                N(e)) : location.href = A(t) : c ? location.href = A(t) : o && (n = I + 'virtual?params={"category":"jump","des":"share","type":"111","title":"' + t.title + '","content":"' + t.content + '","shareUrl":"' + t.url + '","imageUrl":"' + t.img + '","channel":"' + t.channel + '","isCallBack":"' + t.callbackSwitcher + '"}',
                location.href = n)
            }
        } catch (e) {
            throw e
        }
    }
    ,
    e || (e = q()),
    e
});
