/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Printing
* Free version
* Unminify code for Dev
**/
var pdappAPI = {
    tool: {
        toDate: function (e) {
            let t = new Date(e.replaceAll("-", "/")).toLocaleTimeString(),
                r = e.split(" "),
                o = t.split(" "),
                n = o[0].split(":");
            return void 0 !== o[1] ? r[0] + " " + n[0] + ":" + n[1] + o[1] : e;
        },
        getData: function (e) {
            return new Promise(function (t, r) {
                let o = {
                    method: "GET",
                    url: e,
                    dataType: "json",
                    success: function (e) {
                        0 == e
                            ? r({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? t({ msg: e.msg, data: e.data }) : r({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, o) {
                        r({ msg: o, error: 1 });
                    },
                };
                jQuery.ajax(o);
            });
        },
        postData: function (e, t) {
            return new Promise(function (r, o) {
                let n = {
                    method: "POST",
                    url: e,
                    dataType: "json",
                    data: t,
                    success: function (e) {
                        0 == e
                            ? o({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? r({ msg: e.msg, data: e.data }) : o({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, r) {
                        o({ msg: r, error: 1 });
                    },
                };
                jQuery.ajax(n);
            });
        },
        uploadData: function (e, t, r) {
            return new Promise(function (o, n) {
                let a = {
                    url: e,
                    type: "POST",
                    processData: !1,
                    contentType: !1,
                    dataType: "json",
                    data: t,
                    xhr: function () {
                        let e = new window.XMLHttpRequest();
                        return (
                            e.upload.addEventListener(
                                "progress",
                                function (e) {
                                    if (e.lengthComputable) {
                                        let t = (e.loaded / e.total) * 100;
                                        "function" == typeof r && r(t);
                                    }
                                },
                                !1
                            ),
                            e
                        );
                    },
                    success: function (e) {
                        0 == e
                            ? n({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? o({ msg: e.msg, data: e.data }) : n({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, r) {
                        n({ msg: r, error: 1 });
                    },
                };
                jQuery.ajax(a);
            });
        },
        updateURL: function (e) {
            let t = pdappAdminUrl + "admin.php?page=product-designer-app-" + e;
            window.history.pushState(null, "", t);
        },
        changeThumb: function (e, t, r, o) {
            if ("image/png" != e.type && "image/jpg" != e.type && "image/jpeg" != e.type)
                return (
                    (pdappVueApp.toast = { show: !0, type: "error", text: t.msg.file_type_error + " PNG, JPG, JPEG" }),
                    !1
                );
            let n = document.createElement("canvas"),
                a = n.getContext("2d"),
                i = new Image();
            (i.onload = function () {
                (n.width = void 0 === o ? 500 : o), (n.height = n.width);
                let e = n.width,
                    t = n.width,
                    d = 0,
                    s = 0;
                i.width > i.height
                    ? ((t = (n.width * i.height) / i.width), (d = Math.round((n.width - t) / 2)))
                    : ((e = (n.width * i.width) / i.height), (s = Math.round((n.width - e) / 2))),
                    a.drawImage(i, s, d, e, t);
                let u = n.toDataURL();
                setTimeout(() => {
                    "function" == typeof r && r(u);
                });
            }),
                (i.src = URL.createObjectURL(e));
        },
    },
};