/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Artwork
* Free version
* Unminify code for Dev
**/
const { createApp: createApp } = Vue;
var pdappVueApp = createApp({
    data: () => ({
        loadingPage: !0,
        uploadUrl: pdappUploadUrl,
        pluginUrl: pdappPluginUrl,
        folderID: pdappFolderID,
        modal: { show: !1 },
        toast: { show: !1, type: "success", text: "" },
        listArtsData: {},
        listFolders: {},
        langs: {},
        listLang: { default: pdappLangDefault, list: [] },
        artOption: { search: "", searchMobile: !1, folder: "", pages: 1, paged: 1, perpage: 24 },
        artCheckbox: !1,
        artCheckboxs: [],
        listAttrArts: [],
        pdappPurchasedCode: pdappPurchasedCode,
        pdappApiToken: "",
        showStore: !1,
        confirmEmail: { code: "", timeLess: 0, error: "", refresh: !0 },
        loadedStore: !1,
        loadingStore: !1,
    }),
    created() {
        jQuery("#productdesignerapp-app").show(), this.getArtSetting();
    },
    computed: {
        breadcrumbs() {
            let t = { title: "", pages: [] };
            if (void 0 === this.langs.menu) return t;
            if (void 0 !== this.listFolders && void 0 !== this.listLang.list) {
                let a = { id: 0, pid: 0, title: {} };
                for (let t in this.listLang.list) void 0 === a.title[t] && (a.title[t] = this.langs.menu.arts);
                let e = this;
                pdappAPI.folder.getFolderBreads(e.listFolders, a, e.folderID, function (a) {
                    for (let o = 0; o < a.length; o++) {
                        let i = a[o].id == e.folderID ? "" : a[o].id;
                        t.pages.push({ to: i, title: a[o].title });
                    }
                    return (t.title = a[a.length - 1].title), t;
                });
            }
            return t;
        },
        listDatas() {
            let t = { folders: [], arts: [] };
            return (
                void 0 !== this.listFolders &&
                    void 0 !== this.listFolders[this.folderID] &&
                    (t.folders = this.listFolders[this.folderID]),
                void 0 !== this.listArtsData &&
                    void 0 !== this.listArtsData[this.folderID] &&
                    (t.arts = this.listArtsData[this.folderID]),
                t
            );
        },
        listArts() {
            let t = this,
                a = [];
            for (let e = 0; e < t.listDatas.arts.length; e++)
                "" != t.artOption.search
                    ? -1 !=
                          t
                              .getTitle(t.listDatas.arts[e].title)
                              .toLowerCase()
                              .indexOf(t.artOption.search.toLowerCase()) && a.push(t.listDatas.arts[e])
                    : a.push(t.listDatas.arts[e]);
            t.artOption.pages = Math.ceil(a.length / t.artOption.perpage);
            let e = [],
                o = (t.artOption.paged - 1) * t.artOption.perpage;
            for (let i = 0; i < a.length; i++) i >= o && i < o + t.artOption.perpage && e.push(a[i]);
            return (
                setTimeout(() => {
                    t.checkAllArt();
                }),
                e
            );
        },
        artEdits() {
            let t = [];
            for (let a = 0; a < this.listArts.length; a++)
                t.push({
                    id: this.listArts[a].id,
                    pid: this.listArts[a].pid,
                    title: this.listArts[a].title,
                    price: this.listArts[a].price,
                });
            return t;
        },
        timeDown() {
            let t = "" + Math.floor(this.confirmEmail.timeLess / 60),
                a = "" + (this.confirmEmail.timeLess - 60 * t);
            return 1 == t.length && (t = "0" + t), 1 == a.length && (a = "0" + a), t + ":" + a;
        },
    },
    methods: {
        goToPage(t) {
            (this.artOption.paged = 1), (this.folderID = t), this.showListArts();
        },
        async getRefreshToken() {
            let t = this,
                a = pdappAdminUrl + "admin-ajax.php?action=pdapp-refresh-token&admin=1";
            try {
                let t = await pdappAPI.tool.getData(a);
                pdappNonce = t.data.token;
            } catch (t) {}
            setTimeout(() => {
                t.getRefreshToken();
            }, 6e4);
        },
        async getArtSetting() {
            let t = this,
                a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-load-setting&listLangs=1&langs=1&artFolder=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
            try {
                let e = await pdappAPI.tool.getData(a);
                (t.langs = e.data.langs),
                    (t.listLang.list = e.data.listLangs),
                    (t.listFolders = e.data.folders),
                    t.showListArts();
            } catch (t) {}
            setTimeout(() => {
                t.getRefreshToken();
            }, 6e4);
        },
        async showListArts() {
            let t = this;
            if (((t.loadingPage = !0), void 0 === t.listArtsData[t.folderID])) {
                let a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-arts&folder=" +
                    t.folderID +
                    "&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let e = await pdappAPI.tool.getData(a);
                    t.listArtsData[t.folderID] = e.data;
                } catch (a) {
                    (t.toast = { show: !0, type: "warning", text: a.msg }),
                        setTimeout(() => {
                            t.toast.show = !1;
                        }, 5e3);
                }
            }
            let a = 0 != t.folderID ? "arts&folder=" + t.folderID : "arts";
            pdappAPI.tool.updateURL(a), (t.loadingPage = !1);
        },
        childFolders(t) {
            let a = 0;
            return void 0 !== this.listFolders[t] && (a = this.listFolders[t].length), a;
        },
        openFolder(t) {
            let a = this;
            (a.folderID = t.id), (a.artOption.paged = 1), a.showListArts(), (this.artOption.folder = "");
        },
        editFolder(t) {
            t =
                "" == t
                    ? { id: "", pid: this.folderID, title: {}, filetype: "", thumb: "" }
                    : JSON.parse(JSON.stringify(t));
            for (let a in this.listLang.list) void 0 === t.title[a] && (t.title[a] = "Untitled");
            let a = "" == t.id ? this.langs.art.create_folder : this.langs.art.edit_folder;
            (this.modal = {
                show: !0,
                header: !0,
                size: "lg",
                title: a,
                type: "folder",
                data: t,
                saving: !1,
                langCode: this.listLang.default,
            }),
                (this.artOption.folder = "");
        },
        editArt(t) {
            if ("" == t)
                this.modal = {
                    show: !0,
                    header: !0,
                    size: "xl modal-dialog-scrollable",
                    title: this.langs.art.upload_art,
                    type: "upload",
                    data: [],
                    saving: !1,
                    upload: !1,
                    checkbox: !1,
                    checkboxs: [],
                    langCode: this.listLang.default,
                };
            else {
                let a = JSON.parse(JSON.stringify(t));
                for (let t in this.listLang.list) void 0 === a.title[t] && (a.title[t] = "");
                (a.upload = ""),
                    (this.modal = {
                        show: !0,
                        header: !0,
                        size: "lg",
                        title: this.langs.art.update_art,
                        type: "art",
                        data: a,
                        saving: !1,
                        langCode: this.listLang.default,
                    });
            }
        },
        async saveModal() {
            let t = this;
            t.modal.saving = !0;
            for (let a in t.listLang.list)
                void 0 === t.modal.data.title[a] &&
                    (t.modal.data.title[a] =
                        "" != typeof t.modal.data.title[t.modal.langCode]
                            ? t.modal.data.title[t.modal.langCode]
                            : "Untitled");
            let a = {},
                e = void 0 !== t.modal.data.created ? t.modal.data.created : "",
                o = pdappAdminUrl + "admin-ajax.php?action=pdapp-save-art&admin=1&pdapp-nonce=" + pdappNonce,
                i = {};
            try {
                if (
                    ("folder" == t.modal.type
                        ? ((a = {
                              id: t.modal.data.id,
                              pid: t.modal.data.pid,
                              title: t.modal.data.title,
                              type: "folder",
                              filetype: t.modal.data.filetype,
                              thumb: t.modal.data.thumb,
                              created: e,
                          }),
                          (i = await pdappAPI.tool.postData(o, a)))
                        : ((a = new FormData()),
                          a.append("id", t.modal.data.id),
                          a.append("pid", t.modal.data.pid),
                          a.append("title", JSON.stringify(t.modal.data.title)),
                          a.append("type", "art"),
                          a.append("filetype", t.modal.data.filetype),
                          a.append("thumb", t.modal.data.thumb),
                          a.append("price", t.modal.data.price),
                          a.append("upload", t.modal.data.upload),
                          a.append("created", t.modal.data.created),
                          (i = await pdappAPI.tool.uploadData(o, a))),
                    "folder" == t.modal.type)
                )
                    if ("" == t.modal.data.id)
                        void 0 === t.listFolders[t.folderID] && (t.listFolders[t.folderID] = []),
                            t.listFolders[t.folderID].push(i.data);
                    else
                        for (let a = 0; a < t.listFolders[t.folderID].length; a++)
                            t.listFolders[t.folderID][a].id == t.modal.data.id &&
                                (t.listFolders[t.folderID][a] = i.data);
                else if ("" == t.modal.data.id)
                    void 0 === t.listArtsData[t.folderID] && (t.listArtsData[t.folderID] = []),
                        t.listArtsData[t.folderID].push(i.data);
                else
                    for (let a = 0; a < t.listArtsData[t.folderID].length; a++)
                        t.listArtsData[t.folderID][a].id == t.modal.data.id && (t.listArtsData[t.folderID][a] = i.data);
                (t.toast = { show: !0, type: "success", text: i.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3),
                    (t.modal.show = !1);
            } catch (i) {
                (t.toast = { show: !0, type: "warning", text: i.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3);
            }
            t.modal.saving = !1;
        },
        confirmMoveArt(t, a) {
            let e = { id: 0, pid: 0, title: {} };
            for (let t in this.listLang.list) void 0 === e.title[t] && (e.title[t] = this.langs.menu.arts);
            let o = "art" == a ? this.langs.art.move_art : this.langs.art.move_folder;
            (this.modal = {
                show: !0,
                header: !0,
                size: "md modal-dialog-scrollable",
                title: o,
                type: "move",
                data: { id: t, tid: this.folderID, confirm: a, breadcrumbs: [] },
                saving: !1,
            }),
                (this.artOption.folder = "");
            let i = this;
            pdappAPI.folder.getFolderBreads(this.listFolders, e, this.folderID, function (t) {
                i.modal.data.breadcrumbs = t;
            });
        },
        openMove(t) {
            let a = { id: 0, pid: 0, title: {} };
            for (let t in this.listLang.list) void 0 === a.title[t] && (a.title[t] = this.langs.menu.arts);
            let e = this;
            pdappAPI.folder.getFolderBreads(this.listFolders, a, t.id, function (t) {
                e.modal.data.breadcrumbs = t;
            }),
                (e.modal.data.tid = t.id);
        },
        async moveArt() {
            let t = this;
            t.modal.saving = !0;
            let a = { id: t.modal.data.id, pid: t.folderID, tid: t.modal.data.tid, type: t.modal.data.confirm },
                e = pdappAdminUrl + "admin-ajax.php?action=pdapp-move-art&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let o = await pdappAPI.tool.postData(e, a);
                if ("art" == t.modal.data.confirm) {
                    for (let a = 0; a < t.listDatas.arts.length; a++)
                        if (t.listDatas.arts[a].id == t.modal.data.id) {
                            let e = JSON.parse(JSON.stringify(t.listDatas.arts[a]));
                            t.listArtsData[t.folderID].splice(a, 1),
                                (e.pid = t.modal.data.tid),
                                void 0 !== t.listArtsData[t.modal.data.tid] && t.listArtsData[t.modal.data.tid].push(e);
                        }
                } else
                    for (let a = 0; a < t.listDatas.folders.length; a++)
                        if (t.listDatas.folders[a].id == t.modal.data.id) {
                            let e = JSON.parse(JSON.stringify(t.listDatas.folders[a]));
                            t.listFolders[t.folderID].splice(a, 1),
                                (e.pid = t.modal.data.tid),
                                void 0 === t.listFolders[t.modal.data.tid] && (t.listFolders[t.modal.data.tid] = []),
                                t.listFolders[t.modal.data.tid].push(e);
                        }
                (t.toast = { show: !0, type: "success", text: o.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3),
                    (t.modal.show = !1);
            } catch (a) {
                (t.toast = { show: !0, type: "warning", text: a.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3);
            }
            t.modal.saving = !1;
        },
        confirmRemove(t, a) {
            (this.modal = {
                show: !0,
                header: !1,
                size: "",
                title: "",
                size: "md modal-dialog-centered",
                type: "message",
                data: {
                    id: t,
                    title: this.langs.msg.confirm_title,
                    text: this.langs.msg.confirm_data,
                    btn: this.langs.delete,
                    type: "warning",
                    confirm: a,
                },
            }),
                (this.artOption.folder = "");
        },
        confirmEvt(t) {
            ("art" != t && "folder" != t) || this.removeArt(this.modal.data.id, t), (this.modal.show = !1);
        },
        async removeArt(t, a) {
            let e = this,
                o = [];
            if ("" === t) {
                if ("folder" == a) return !1;
                if (0 == e.artCheckboxs.length) return !1;
                for (let t = 0; t < e.listDatas.arts.length; t++)
                    e.artCheckboxs.includes(e.listDatas.arts[t].id) &&
                        o.push({ id: e.listDatas.arts[t].id, pid: e.listDatas.arts[t].pid });
            } else o.push({ id: t, pid: e.folderID });
            e.loadingPage = !0;
            let i = pdappAdminUrl + "admin-ajax.php?action=pdapp-remove-art&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let t = await pdappAPI.tool.postData(i, { data: o, type: a });
                if ("art" == a) {
                    for (let a = e.listArtsData[e.folderID].length - 1; a >= 0; a--)
                        t.data.includes(parseInt(e.listArtsData[e.folderID][a].id)) &&
                            e.listArtsData[e.folderID].splice(a, 1);
                    (e.artCheckbox = !1), (e.artCheckboxs = []);
                } else {
                    let t =
                        pdappAdminUrl +
                        "admin-ajax.php?action=pdapp-load-setting&artFolder=1&type=folder&admin=1&pdapp-nonce=" +
                        pdappNonce;
                    try {
                        let a = await pdappAPI.tool.getData(t);
                        e.listFolders = a.data;
                    } catch (t) {}
                    t =
                        pdappAdminUrl +
                        "admin-ajax.php?action=pdapp-arts&folder=" +
                        e.folderID +
                        "&admin=1&pdapp-nonce=" +
                        pdappNonce;
                    try {
                        let a = await pdappAPI.tool.getData(t);
                        e.listArtsData[e.folderID] = a.data;
                    } catch (t) {}
                }
                (e.toast = { show: !0, type: "success", text: t.msg }),
                    setTimeout(() => {
                        e.toast.show = !1;
                    }, 5e3);
            } catch (t) {
                (e.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        e.toast.show = !1;
                    }, 5e3);
            }
            e.loadingPage = !1;
        },
        async saveUpdate() {
            let t = this;
            if (0 == t.artCheckboxs.length) return !1;
            let a = [];
            for (let e = 0; e < t.artEdits.length; e++)
                t.artCheckboxs.includes(t.artEdits[e].id) &&
                    a.push({
                        id: t.artEdits[e].id,
                        pid: t.artEdits[e].pid,
                        title: t.artEdits[e].title,
                        price: t.artEdits[e].price,
                    });
            t.loadingPage = !0;
            let e = pdappAdminUrl + "admin-ajax.php?action=pdapp-update-arts&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let o = await pdappAPI.tool.postData(e, { data: a });
                for (let e = 0; e < t.listArtsData[t.folderID].length; e++)
                    if (o.data.includes(parseInt(t.listArtsData[t.folderID][e].id)))
                        for (let o = 0; o < a.length; o++)
                            a[o].id == t.listArtsData[t.folderID][e].id &&
                                ((t.listArtsData[t.folderID][e].title = a[o].title),
                                (t.listArtsData[t.folderID][e].price = a[o].price));
                (t.artCheckbox = !1),
                    (t.artCheckboxs = []),
                    (t.toast = { show: !0, type: "success", text: o.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3);
            } catch (a) {
                (t.toast = { show: !0, type: "warning", text: a.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3);
            }
            t.loadingPage = !1;
        },
        checkAllArt() {
            if (((this.artCheckboxs = []), this.artCheckbox))
                for (let t = 0; t < this.listArts.length; t++) this.artCheckboxs.push(this.listArts[t].id);
        },
        convertDate: (t) => pdappAPI.tool.toDate(t),
        getTitle(t) {
            let a = "Untitled";
            if (null == t || "" == t) return a;
            if (void 0 !== t[pdappLangDefault] && "" != t[pdappLangDefault]) a = t[pdappLangDefault];
            else for (let e in t) "" != t[e] && (a = t[e]);
            return a;
        },
        showImg(t, a) {
            return void 0 === t || "" == t
                ? "art" == a
                    ? this.pluginUrl + "assets/images/image.png"
                    : this.pluginUrl + "assets/images/folder.png"
                : (-1 == t.indexOf("base64,") &&
                      (t =
                          "art" == a
                              ? this.uploadUrl + "thumbnails/arts/art-" + t
                              : this.uploadUrl + "thumbnails/arts/art-folder-" + t),
                  t);
        },
        changeThumbFile(t) {
            if (void 0 === t.target.files[0]) return !1;
            const a = t.target.files[0];
            let e = this;
            pdappAPI.tool.changeThumb(a, function (t) {
                e.modal.data.thumb = t;
            }) ||
                ((e.toast = { show: !0, type: "error", text: e.langs.msg.file_type_error + " PNG, JPG, JPEG, SVG" }),
                setTimeout(() => {
                    e.toast.show = !1;
                }, 5e3));
        },
        changeArtFile(t) {
            if (void 0 === t.target.files[0]) return !1;
            const a = t.target.files[0];
            let e = this;
            (e.modal.data.upload = a),
                pdappAPI.tool.changeThumb(a, function (t) {
                    e.modal.data.thumb = t;
                }) ||
                    ((e.toast = {
                        show: !0,
                        type: "error",
                        text: e.langs.msg.file_type_error + " PNG, JPG, JPEG, SVG",
                    }),
                    setTimeout(() => {
                        e.toast.show = !1;
                    }, 5e3));
        },
        changeArtFiles(t) {
            if (void 0 === t.target.files[0]) return !1;
            let a = t.target.files;
            for (let t = 0; t < a.length; t++) {
                let e = a[t],
                    o = e.name.split("."),
                    i = o[o.length - 1],
                    d = e.name.replace("." + i, "");
                if (((i = i.toLowerCase()), "jpg" == i || "jpeg" == i || "png" == i || "svg" == i)) {
                    let t = { title: {}, upload: e };
                    for (let a in this.listLang.list) void 0 === t.title[a] && (t.title[a] = d);
                    (t.id = pdappAPI.tool.uID()),
                        (t.price = 0),
                        (t.uploading = 0),
                        (t.size = (e.size / 1048576).toFixed(3)),
                        (t.filetype = i),
                        (t.error = "");
                    let a = this;
                    pdappAPI.tool.changeThumb(
                        e,
                        function (e) {
                            (t.thumb = e), a.modal.data.push(t);
                        },
                        300
                    ) ||
                        ((a.toast = {
                            show: !0,
                            type: "error",
                            text: a.langs.msg.file_type_error + " PNG, JPG, JPEG, SVG",
                        }),
                        setTimeout(() => {
                            a.toast.show = !1;
                        }, 5e3));
                }
            }
            (t.target.value = ""), (this.modal.upload = !0);
        },
        startUploadFiles() {
            let t = this,
                a = !0;
            (t.modal.upload = !1), (t.modal.saving = !0);
            for (let e = 0; e < t.modal.data.length; e++)
                if (0 == t.modal.data[e].uploading) {
                    t.uploadArtwork(t.modal.data[e]), (t.modal.data[e].uploading = 1), (a = !1);
                    break;
                }
            return (
                a &&
                    setTimeout(() => {
                        (t.toast = { show: !0, type: "success", text: t.langs.msg.uploaded }),
                            setTimeout(() => {
                                t.toast.show = !1;
                            }, 5e3),
                            (t.modal.saving = !1);
                    }, 1e3),
                !1
            );
        },
        async uploadArtwork(t) {
            let a = this;
            for (let e in a.listLang.list)
                void 0 === t.title[e] &&
                    (t.title[e] = "" != typeof t.title[a.modal.langCode] ? t.title[a.modal.langCode] : "Untitled");
            let e = new FormData();
            e.append("id", ""),
                e.append("pid", a.folderID),
                e.append("title", JSON.stringify(t.title)),
                e.append("type", "art"),
                e.append("price", t.price),
                e.append("filetype", t.filetype),
                e.append("thumb", t.thumb),
                e.append("upload", t.upload);
            let o = pdappAdminUrl + "admin-ajax.php?action=pdapp-save-art&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let i = await pdappAPI.tool.uploadData(o, e, function (a) {
                    t.uploading = a;
                });
                void 0 === a.listArtsData[a.folderID] && (a.listArtsData[a.folderID] = []),
                    a.listArtsData[a.folderID].push(i.data),
                    (t.uploading = 100);
            } catch (a) {
                t.error = a.msg;
            }
            setTimeout(() => {
                a.startUploadFiles();
            }, 100);
        },
        removeListUpload() {
            for (let t = this.modal.data.length - 1; t >= 0; t--)
                0 == this.modal.data[t].uploading &&
                    this.modal.checkboxs.includes(this.modal.data[t].id) &&
                    this.modal.data.splice(t, 1);
        },
        checkAllFile() {
            if (((this.modal.checkboxs = []), this.modal.checkbox))
                for (let t = 0; t < this.modal.data.length; t++)
                    100 != this.modal.data[t].uploading && this.modal.checkboxs.push(this.modal.data[t].id);
        },
        verifyPurchased() {
            "" != this.modal.purchased &&
                ((this.modal.verifing = !0),
                postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                    purchased: this.modal.purchased,
                    domain: pdappDomain,
                }));
        },
        showVerifyModal() {
            this.modal = {
                show: !0,
                type: "verifycode",
                purchased: this.pdappPurchasedCode,
                error: "",
                checked: !0,
                verifing: !1,
            };
        },
        async updatePurchased(t) {
            let a = this,
                e = pdappAdminUrl + "admin-ajax.php?action=pdapp-dashboard-purchased&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                await pdappAPI.tool.postData(e, { purchased: a.modal.purchased });
                (a.pdappPurchasedCode = a.modal.purchased), a.checkAuthCode(t.data);
            } catch (t) {
                (a.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
        },
        checkAuthCode(t) {
            let a = this;
            void 0 !== t.refreshToken &&
                "" != t.refreshToken &&
                ((a.pdappApiToken = t.refreshToken), pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken)),
                "shop" == t.scope
                    ? ((a.modal.show = !1), a.showStore || ((a.showStore = !0), a.showArtStore()))
                    : "confirm" == t.scope
                      ? ((a.modal = {
                            show: !0,
                            type: "confirmemail",
                            code: t.code,
                            email: t.email,
                            verifing: !1,
                            error: "",
                            scope: t.scope,
                        }),
                        (a.confirmEmail.timeLess = parseInt(t.time)),
                        a.countDown())
                      : ("verify" != t.scope && "code" != t.scope) ||
                        (a.modal = {
                            show: !0,
                            type: "verifyemail",
                            code: t.code,
                            email: t.email,
                            verifing: !1,
                            error: "",
                            scope: t.scope,
                        });
        },
        codeValidate() {
            let t = this.confirmEmail.code.toString();
            t.length > 6 && (t = t.substring(0, 6)), (this.confirmEmail.code = parseInt(t));
        },
        expireConfirmCode(t) {
            let a = this;
            t && ((a.pdappApiToken = ""), pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken)),
                (a.modal.show = !1);
        },
        countDown() {
            let t = this;
            0 == t.confirmEmail.timeLess && t.expireConfirmCode(!0),
                (t.confirmEmail.timeLess = t.confirmEmail.timeLess - 1),
                t.confirmEmail.timeLess > 0 &&
                    setTimeout(() => {
                        t.countDown();
                    }, 1e3);
        },
        refreshCode() {
            postToChild(document.getElementById("pdapp-login-frame"), "refreshemail", { token: this.pdappApiToken });
        },
        confirmEmailCode() {
            let t = this;
            (t.confirmEmail.verifing = !0),
                postToChild(document.getElementById("pdapp-login-frame"), "confirmemail", {
                    emailcode: t.confirmEmail.code,
                    token: t.pdappApiToken,
                });
        },
        verifyEmail() {
            let t = this;
            return "" == t.modal.email
                ? ((t.modal.error = "A email is required."), !1)
                : /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(
                        String(t.modal.email).toLowerCase()
                    )
                  ? ((t.modal.error = ""),
                    (t.modal.verifing = !0),
                    void postToChild(document.getElementById("pdapp-login-frame"), "verifyemail", {
                        email: t.modal.email,
                        token: t.pdappApiToken,
                    }))
                  : ((t.modal.error = "A email is invalid."), !1);
        },
        onAuthCode(t) {
            let a = this;
            if (0 == t.error)
                return (
                    void 0 !== a.modal.type && "verifycode" == a.modal.type
                        ? void 0 !== t.data && void 0 !== t.data.platform && t.data.platform == pdappPlatform
                            ? a.updatePurchased(t)
                            : ((a.modal.error = "Your platform verify incorrect"), (a.modal.verifing = !1))
                        : a.checkAuthCode(t.data),
                    !1
                );
            void 0 !== a.modal.type && "verifycode" == a.modal.type
                ? ((a.modal.error = t.msg), (a.modal.verifing = !1))
                : "" != a.pdappApiToken && "" != a.pdappPurchasedCode
                  ? ((a.pdappApiToken = ""),
                    pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                    postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                        purchased: a.pdappPurchasedCode,
                        domain: pdappDomain,
                    }))
                  : (a.modal = {
                        show: !0,
                        type: "verifycode",
                        purchased: a.pdappPurchasedCode,
                        error: "",
                        checked: !1,
                        verifing: !1,
                    });
        },
        onAuthEmail(t) {
            let a = this;
            if (((a.modal.verifing = !1), 0 == t.error))
                return (
                    (a.modal.show = !0),
                    (a.modal.email = t.data.email),
                    (a.modal.code = t.data.code),
                    (a.modal.scope = t.data.scope),
                    (a.pdappApiToken = t.data.refreshToken),
                    pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                    (a.confirmEmail.timeLess = parseInt(t.data.time)),
                    a.countDown(),
                    (a.modal.type = "confirmemail"),
                    !1
                );
            a.modal.error = t.msg;
        },
        onAuthRefreshEmail(t) {
            let a = this;
            (a.confirmEmail.refresh = !1),
                0 == t.error
                    ? ((a.pdappApiToken = t.data.refreshToken),
                      pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                      (a.confirmEmail.timeLess = parseInt(t.data.time)))
                    : (a.confirmEmail.error = t.msg);
        },
        onAuthConfirmEmail(t) {
            let a = this;
            0 == t.error
                ? ((a.modal.email = t.data.email),
                  (a.modal.code = t.data.code),
                  (a.modal.scope = t.data.scope),
                  (a.confirmEmail.timeLess = -1),
                  a.expireConfirmCode(!1),
                  (a.pdappApiToken = t.data.refreshToken),
                  pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                  (a.confirmEmail.timeLess = parseInt(t.data.time)))
                : (a.confirmEmail.error = t.msg),
                (a.confirmEmail.verifing = !1);
        },
        showArtStore() {
            let t = this;
            "" != t.pdappPurchasedCode
                ? t.showStore
                    ? ((t.modal = { store: !0 }),
                      "" != t.pdappApiToken &&
                          postToChild(document.getElementById("pdapp-resource-frame"), "startartwork", t.pdappApiToken),
                      (t.loadingStore = !1))
                    : ((t.pdappApiToken = pdappAPI.tool.getLocalVar("pdapp_api_token", "")),
                      "" != t.pdappApiToken && "" != t.pdappApiToken
                          ? postToChild(document.getElementById("pdapp-login-frame"), "verifytoken", t.pdappApiToken)
                          : postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                                purchased: t.pdappPurchasedCode,
                                domain: pdappDomain,
                            }),
                      (t.loadingStore = !0),
                      setTimeout(() => {
                          t.loadingStore = !1;
                      }, 1500))
                : t.showVerifyModal();
        },
        onImportArt(t) {
            if (void 0 === t.id || void 0 === t.data) return !1;
            this.startUploadArt(t.data, t.id);
        },
        async startUploadArt(t, a) {
            let e = this;
            t.pid = e.folderID;
            let o = pdappAdminUrl + "admin-ajax.php?action=pdapp-upload-art&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let i = await pdappAPI.tool.postData(o, t);
                postToChild(document.getElementById("pdapp-resource-frame"), "addedartwork", a),
                    e.listArtsData[e.folderID].push(i.data);
            } catch (t) {
                (e.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        e.toast.show = !1;
                    }, 5e3);
            }
        },
    },
}).mount("#productdesignerapp-app");
function postToChild(t, a, e) {
    t.contentWindow.postMessage({ type: a, data: e }, pdappHomeUrl);
}
window.onmessage = function (t) {
    if (void 0 !== t.data.type) {
        let a = t.data.type,
            e = t.data.data;
        "loadedstore" == a && "ok" == e && (pdappVueApp.loadedStore = !0),
            "importartwork" == a && pdappVueApp.onImportArt(e),
            "authcode" == a && pdappVueApp.onAuthCode(e),
            "authemail" == a && pdappVueApp.onAuthEmail(e),
            "authrefreshemail" == a && pdappVueApp.onAuthRefreshEmail(e),
            "authconfirmemail" == a && pdappVueApp.onAuthConfirmEmail(e);
    }
};