/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Default theme
* Free version
* Unminify code for Dev
**/
var pdappWAPI = {
    get: function (e, t, o) {
        const s = new XMLHttpRequest();
        s.open("GET", e, !0),
            void 0 !== o && (s.responseType = o),
            s.setRequestHeader("Cache-Control", "no-cache"),
            (s.onreadystatechange = function () {
                if (s.readyState === XMLHttpRequest.DONE) {
                    let e = !1;
                    200 === s.status && null != s.response && "" != s.response && (e = s.response),
                        "function" == typeof t && t(e);
                }
            }),
            s.send();
    },
    post: function (e, t, o) {
        let s = new FormData();
        for (let e in t) s.append(e, t[e]);
        const a = new XMLHttpRequest();
        a.open("POST", e, !0),
            a.setRequestHeader("Cache-Control", "no-cache"),
            (a.onreadystatechange = function () {
                if (a.readyState === XMLHttpRequest.DONE) {
                    let e = !1;
                    if (200 === a.status && null != a.response && "" != a.response)
                        try {
                            e = JSON.parse(a.response);
                        } catch (t) {
                            e = !1;
                        }
                    "function" == typeof o && o(e);
                }
            }),
            a.send(s);
    },
    uploadImage: function (e) {
        if (void 0 !== e.post.file && void 0 !== e.post.file.name) {
            let t = { id: e.post.id, file: e.post.file };
            pdappWAPI.post(e.value, t, function (t) {
                let o = void 0 !== t.data && 0 == t.error && t.data,
                    s = { id: e.post.id, action: "getPhoto", type: "origin", value: o, post: e.post };
                self.postMessage(s);
            });
        } else
            pdappWAPI.post(e.value, e.post, function (t) {
                let o = void 0 !== t.data && 0 == t.error && t.data,
                    s = { id: e.post.id, action: "getPhoto", type: "origin", value: o, post: e.post };
                self.postMessage(s);
            });
    },
    getPhoto: function (e) {
        pdappWAPI.get(
            e.value,
            function (t) {
                (e.value = t), self.postMessage(e);
            },
            "blob"
        );
    },
    getPhotoReplace: function (e) {
        pdappWAPI.get(
            e.value,
            function (t) {
                (e.value = t), self.postMessage(e);
            },
            "blob"
        );
    },
    toBase64: function (e) {
        const t = new FileReader();
        t.readAsDataURL(e.value),
            (t.onload = function () {
                (e.value = t.result), -1 != e.value.indexOf(";base64,") && self.postMessage(e);
            });
    },
    cropImage: function (e) {
        pdappWAPI.post(e.value, e.post, function (t) {
            let o = void 0 !== t.data && 0 == t.error && t.data,
                s = { id: e.post.id, action: "cropImage", type: "origin", value: o, post: e.post };
            self.postMessage(s);
        });
    },
};
self.onmessage = function (e) {
    const t = e.data;
    "function" == typeof pdappWAPI[t.action] && pdappWAPI[t.action](t);
};