/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Addon
* Free version
* Unminify code for Dev
**/
var pdappAPI = {
    tool: {
        toDate: function (r) {
            let e = new Date(r.replaceAll("-", "/")).toLocaleTimeString(),
                t = r.split(" "),
                o = e.split(" "),
                n = o[0].split(":");
            return void 0 !== o[1] ? t[0] + " " + n[0] + ":" + n[1] + o[1] : r;
        },
        setLocalVar: function (r, e) {
            localStorage.setItem(r, e);
        },
        getLocalVar: function (r, e = "") {
            var t = localStorage.getItem(r);
            return null != t ? t : e;
        },
        getData: function (r) {
            return new Promise(function (e, t) {
                let o = {
                    method: "GET",
                    url: r,
                    dataType: "json",
                    success: function (r) {
                        0 == r
                            ? t({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === r.error && (r.error = 1),
                              0 === r.error ? e({ msg: r.msg, data: r.data }) : t({ msg: r.msg, error: r.error }));
                    },
                    error: function (r, e, o) {
                        "" == o && (o = "Request failed"), t({ msg: o, error: 1 });
                    },
                };
                jQuery.ajax(o);
            });
        },
        postData: function (r, e) {
            return new Promise(function (t, o) {
                let n = {
                    method: "POST",
                    url: r,
                    dataType: "json",
                    data: e,
                    success: function (r) {
                        0 == r
                            ? o({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === r.error && (r.error = 1),
                              0 === r.error ? t({ msg: r.msg, data: r.data }) : o({ msg: r.msg, error: r.error }));
                    },
                    error: function (r, e, t) {
                        "" == t && (t = "Request failed"), o({ msg: t, error: 1 });
                    },
                };
                jQuery.ajax(n);
            });
        },
        uploadData: function (r, e, t) {
            return new Promise(function (o, n) {
                let a = {
                    url: r,
                    type: "POST",
                    processData: !1,
                    contentType: !1,
                    dataType: "json",
                    data: e,
                    xhr: function () {
                        let r = new window.XMLHttpRequest();
                        return (
                            r.upload.addEventListener(
                                "progress",
                                function (r) {
                                    if (r.lengthComputable) {
                                        let e = (r.loaded / r.total) * 100;
                                        "function" == typeof t && t(e);
                                    }
                                },
                                !1
                            ),
                            r
                        );
                    },
                    success: function (r) {
                        0 == r
                            ? n({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === r.error && (r.error = 1),
                              0 === r.error ? o({ msg: r.msg, data: r.data }) : n({ msg: r.msg, error: r.error }));
                    },
                    error: function (r, e, t) {
                        "" == t && (t = "Request failed"), n({ msg: t, error: 1 });
                    },
                };
                jQuery.ajax(a);
            });
        },
        updateURL: function (r) {
            let e = pdappAdminUrl + "admin.php?page=product-designer-app-" + r;
            window.history.pushState(null, "", e);
        },
        base64ToFile(r, e) {
            const t = r.split(","),
                o = t[0].match(/:(.*?);/),
                n = o && null != o && void 0 !== o[1] ? o[1] : "application/octet-stream";
            let a = void 0 !== t[1] ? t[1] : t[0];
            const s = atob(a),
                i = new Array(s.length);
            for (let r = 0; r < s.length; r++) i[r] = s.charCodeAt(r);
            const l = new Uint8Array(i);
            return new File([l], e, { type: n });
        },
    },
};