import React from "react";

let kwaiPixel_ID = null;
export const kwai_setPixelID = (pixelID, ex_id) => {
    if (!pixelID) return;
    kwaiPixel_ID = pixelID;
    (function (e, t) {
        if (typeof exports === "object" && typeof module === "object") {
            module.exports = t();
        } else if (typeof exports === "object") {
            exports.install = t();
        } else {
            e.install = t();
        }
    }(window, function () {
        return function (e) {
            var t = {};

            function n(o) {
                if (t[o]) return t[o].exports;
                var r = t[o] = { i: o, l: false, exports: {} };
                e[o].call(r.exports, r, r.exports, n);
                r.l = true;
                return r.exports;
            }

            n.m = e;
            n.c = t;
            n.d = function (e, t, o) {
                if (!n.o(e, t)) {
                    Object.defineProperty(e, t, { enumerable: true, get: o });
                }
            };
            n.r = function (e) {
                if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
                    Object.defineProperty(e, Symbol.toStringTag, { value: "Module" });
                }
                Object.defineProperty(e, "__esModule", { value: true });
            };
            n.t = function (e, t) {
                if (t & 1) e = n(e);
                if (t & 8) return e;
                if (t & 4 && typeof e === "object" && e && e.__esModule) return e;
                var o = Object.create(null);
                n.r(o);
                Object.defineProperty(o, "default", { enumerable: true, value: e });
                if (t & 2 && typeof e !== "string") {
                    for (var r in e) {
                        n.d(o, r, function (t) { return e[t]; }.bind(null, r));
                    }
                }
                return o;
            };
            n.n = function (e) {
                var t = e && e.__esModule ? function () { return e.default; } : function () { return e; };
                n.d(t, "a", t);
                return t;
            };
            n.o = function (e, t) {
                return Object.prototype.hasOwnProperty.call(e, t);
            };
            n.p = "";
            return n(n.s = 0);
        }([function (e, t, n) {
            "use strict";
            var o = this && this.__spreadArray || function (e, t, n) {
                if (n || arguments.length === 2) {
                    for (var o, r = 0, i = t.length; r < i; r++) {
                        if (!o && r in t || o) {
                            o || (o = Array.prototype.slice.call(t, 0, r));
                            o[r] = t[r];
                        }
                    }
                }
                return e.concat(o || Array.prototype.slice.call(t));
            };
            Object.defineProperty(t, "__esModule", { value: true });
            var r = function (e, t, n) {
                var o, i = e.createElement("script");
                i.type = "text/javascript";
                i.async = true;
                i.src = t;
                if (n) {
                    i.onerror = function () {
                        r(e, n);
                    };
                }
                var a = e.getElementsByTagName("script")[0];
                var parentNode = a.parentNode;
                if (parentNode) {
                    parentNode.insertBefore(i, a);
                }
            };
            (function (e, t, n) {
                e.KwaiAnalyticsObject = n;
                var i = e[n] = e[n] || [];
                i.methods = ["page", "track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"];
                var a = function (e, t) {
                    e[t] = function () {
                        var n = [];
                        for (var r = 0; r < arguments.length; r++) {
                            n[r] = arguments[r];
                        }
                        var i = o([t], n, true);
                        e.push(i);
                    };
                };
                i.methods.forEach(function (e) {
                    a(i, e);
                });
                i.instance = function (e) {
                    var t, n = (i._i && i._i[e]) || [];
                    i.methods.forEach(function (e) {
                        a(n, e);
                    });
                    return n;
                };
                i.load = function (e, o) {
                    var a = "https://s1.kwai.net/kos/s101/nlav11187/pixel/events.js";
                    i._i = i._i || {};
                    i._i[e] = [];
                    i._i[e]._u = a;
                    i._t = i._t || {};
                    i._t[e] = +new Date();
                    i._o = i._o || {};
                    i._o[e] = o || {};
                    var c = "?sdkid=".concat(e, "&lib=").concat(n);
                    r(t, a + c, "https://s16-11187.ap4r.com/kos/s101/nlav11187/pixel/events.js" + c);
                };
            }(window, document, "kwaiq"));
        }]); // Add semicolon here
    })); // Add semicolon here

    window.kwaiq.load(pixelID);
    window.kwaiq.page();
};

// fbPixel.js
export const kwai_trackPageView = () => {
    if (window.kwaiq) {
        window.kwaiq.page();
    }
};
///kwaiq.track('addPaymentInfo')
// kwaiq.track('addToCart')
// kwaiq.track('buttonClick')
// kwaiq.track('purchase')
// kwaiq.track('contentView')
// kwaiq.track('download')
// kwaiq.track('formSubmit')
// kwaiq.track('initiatedCheckout')
// kwaiq.track('contact')
// kwaiq.track('placeOrder')
// kwaiq.track('search')
// kwaiq.track('completeRegistration')
// kwaiq.track('addToWishlist')
// kwaiq.track('subscribe')
/**
 * fbq('trackCustom', "firstpayD0", {external_id: data.udid})
 * @param eventName
 * @param params
 */
export const kwai_trackEvent = (eventName, params) => {
    if (window.kwaiq) {
        window.kwaiq.instance(kwaiPixel_ID).track(eventName, params);
    }
};
