/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Dashboard
* Free version
* Unminify code for Dev
**/
const { createApp: createApp } = Vue;
var pdappVueApp = createApp({
    data: () => ({
        loadingPage: !0,
        uploadUrl: pdappUploadUrl,
        pluginUrl: pdappPluginUrl,
        modal: { show: !1 },
        toast: { show: !1, type: "success", text: "" },
        langs: {},
        loading: "",
        pdappPurchasedCode: pdappPurchasedCode,
        pdappApiToken: "",
        dashboard: { totals: [], require: [] },
        listGuide: {},
        chart: { show: !1, type: "month", loading: !1 },
        showNocation: !1,
        notification: { new: [], old: [] },
        confirmEmail: { code: "", timeLess: 0, error: "", refresh: !0 },
    }),
    created() {
        jQuery("#productdesignerapp-app").show(), this.getDashboard();
    },
    computed: {
        breadcrumbs() {
            let e = { title: "", pages: [] };
            return (
                void 0 === this.langs.menu ||
                    ((e.title = this.langs.menu.dashboard), (e.pages = [{ to: "", title: e.title }])),
                e
            );
        },
        timeDown() {
            let e = "" + Math.floor(this.confirmEmail.timeLess / 60),
                a = "" + (this.confirmEmail.timeLess - 60 * e);
            return 1 == e.length && (e = "0" + e), 1 == a.length && (a = "0" + a), e + ":" + a;
        },
    },
    methods: {
        goToPage(e) {
            "dashboard" == e && this.showListDashboards();
        },
        async getRefreshToken() {
            let e = this,
                a = pdappAdminUrl + "admin-ajax.php?action=pdapp-refresh-token&admin=1";
            try {
                let e = await pdappAPI.tool.getData(a);
                pdappNonce = e.data.token;
            } catch (e) {}
            setTimeout(() => {
                e.getRefreshToken();
            }, 6e4);
        },
        async getDashboard() {
            let e = this,
                a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-load-setting&langs=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
            try {
                let o = await pdappAPI.tool.getData(a);
                (e.langs = o.data.langs), e.showListDashboards();
            } catch (e) {}
            setTimeout(() => {
                e.getRefreshToken();
            }, 6e4);
        },
        async showListDashboards() {
            let e = this;
            e.loadingPage = !0;
            let a = pdappAdminUrl + "admin-ajax.php?action=pdapp-dashboards&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let o = await pdappAPI.tool.getData(a);
                e.dashboard = o.data;
                try {
                    let a = await pdappAPI.tool.getData(pdappAPIUrl + "/info.php?type=dashboard-guide");
                    e.listGuide = a.data;
                } catch (e) {}
            } catch (e) {}
            (e.loadingPage = !1), e.showChart("month");
            try {
                let a = await pdappAPI.tool.getData(pdappAPIUrl + "/info.php?type=dashboard_nocation");
                e.notification = a.data;
            } catch (e) {}
        },
        getColorClass: (e, a) =>
            "orders" == e
                ? void 0 === a
                    ? "bg-soft-primary border-primary"
                    : "text-primary"
                : "arts" == e
                  ? void 0 === a
                      ? "bg-soft-success border-success"
                      : "text-success"
                  : "templates" == e
                    ? void 0 === a
                        ? "bg-soft-info border-info"
                        : "text-info"
                    : "products" == e
                      ? void 0 === a
                          ? "bg-soft-warning border-warning"
                          : "text-warning"
                      : void 0,
        getIcon: (e) =>
            "orders" == e
                ? "shopping_cart"
                : "arts" == e
                  ? "brush"
                  : "templates" == e
                    ? "lightbulb"
                    : "products" == e
                      ? "inventory_2"
                      : void 0,
        verifyPurchased() {
            "" != this.modal.purchased &&
                ((this.modal.verifing = !0),
                postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                    purchased: this.modal.purchased,
                    domain: pdappDomain,
                }));
        },
        async showChart(e) {
            let a = this;
            if (((a.chart.show = !0), (a.chart.type = e), (a.chart.loading = e), void 0 === a.chart[e])) {
                let o =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-dashboard-charts&type=" +
                    e +
                    "&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let p = await pdappAPI.tool.getData(o);
                    a.chart[e] = p.data;
                } catch (e) {}
            }
            setTimeout(() => {
                pdappAPI.tool.chartJS(document.getElementById("pdapp-chart-orders"), a.chart[e]),
                    (a.chart.loading = !1);
            }, 10);
        },
        showVerifyModal() {
            this.modal = {
                show: !0,
                type: "verifycode",
                purchased: this.pdappPurchasedCode,
                error: "",
                checked: !0,
                verifing: !1,
            };
        },
        async updatePurchased(e) {
            let a = this,
                o = pdappAdminUrl + "admin-ajax.php?action=pdapp-dashboard-purchased&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                await pdappAPI.tool.postData(o, { purchased: a.modal.purchased });
                (a.pdappPurchasedCode = a.modal.purchased), a.checkAuthCode(e.data);
            } catch (e) {
                (a.toast = { show: !0, type: "warning", text: e.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
        },
        checkAuthCode(e) {
            let a = this;
            void 0 !== e.refreshToken &&
                "" != e.refreshToken &&
                ((a.pdappApiToken = e.refreshToken), pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken)),
                "shop" == e.scope
                    ? (a.modal.show = !1)
                    : "confirm" == e.scope
                      ? ((a.modal = {
                            show: !0,
                            type: "confirmemail",
                            code: e.code,
                            email: e.email,
                            verifing: !1,
                            error: "",
                            scope: e.scope,
                        }),
                        (a.confirmEmail.timeLess = parseInt(e.time)),
                        a.countDown())
                      : ("verify" != e.scope && "code" != e.scope) ||
                        (a.modal = {
                            show: !0,
                            type: "verifyemail",
                            code: e.code,
                            email: e.email,
                            verifing: !1,
                            error: "",
                            scope: e.scope,
                        });
        },
        codeValidate() {
            let e = this.confirmEmail.code.toString();
            e.length > 6 && (e = e.substring(0, 6)), (this.confirmEmail.code = parseInt(e));
        },
        expireConfirmCode(e) {
            let a = this;
            e && ((a.pdappApiToken = ""), pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken)),
                (a.modal.show = !1);
        },
        countDown() {
            let e = this;
            0 == e.confirmEmail.timeLess && e.expireConfirmCode(!0),
                (e.confirmEmail.timeLess = e.confirmEmail.timeLess - 1),
                e.confirmEmail.timeLess > 0 &&
                    setTimeout(() => {
                        e.countDown();
                    }, 1e3);
        },
        refreshCode() {
            postToChild(document.getElementById("pdapp-login-frame"), "refreshemail", { token: this.pdappApiToken });
        },
        confirmEmailCode() {
            let e = this;
            (e.confirmEmail.verifing = !0),
                postToChild(document.getElementById("pdapp-login-frame"), "confirmemail", {
                    emailcode: e.confirmEmail.code,
                    token: e.pdappApiToken,
                });
        },
        verifyEmail() {
            let e = this;
            return "" == e.modal.email
                ? ((e.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(e.modal.email).toLowerCase()
                    )
                  ? ((e.modal.error = ""),
                    (e.modal.verifing = !0),
                    void postToChild(document.getElementById("pdapp-login-frame"), "verifyemail", {
                        email: e.modal.email,
                        token: e.pdappApiToken,
                    }))
                  : ((e.modal.error = "A email is invalid."), !1);
        },
        onAuthCode(e) {
            let a = this;
            if (0 == e.error) {
                if (void 0 !== e.data.platform && e.data.platform != pdappPlatform)
                    return (
                        alert(
                            "Cannot verify your purchased code. Because platform using incorrect with platform purchased!"
                        ),
                        !1
                    );
                if (void 0 !== a.modal.type && "verifycode" == a.modal.type) {
                    for (let e in a.dashboard.require)
                        "purchased" == a.dashboard.require[e].key &&
                            (a.dashboard.require[e] = {
                                current: "Verified",
                                icon: "check",
                                key: "purchased",
                                require: "Verified",
                                status: "success",
                            });
                    void 0 !== e.data &&
                        void 0 !== e.data.platform &&
                        e.data.platform == pdappPlatform &&
                        a.updatePurchased(e);
                } else a.checkAuthCode(e.data);
                return !1;
            }
            void 0 !== a.modal.type && "verifycode" == a.modal.type
                ? ((a.modal.error = e.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(e) {
            let a = this;
            if (((a.modal.verifing = !1), 0 == e.error))
                return (
                    (a.modal.show = !0),
                    (a.modal.email = e.data.email),
                    (a.modal.code = e.data.code),
                    (a.modal.scope = e.data.scope),
                    (a.pdappApiToken = e.data.refreshToken),
                    pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                    (a.confirmEmail.timeLess = parseInt(e.data.time)),
                    a.countDown(),
                    (a.modal.type = "confirmemail"),
                    !1
                );
            a.modal.error = e.msg;
        },
        onAuthRefreshEmail(e) {
            let a = this;
            (a.confirmEmail.refresh = !1),
                0 == e.error
                    ? ((a.pdappApiToken = e.data.refreshToken),
                      pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                      (a.confirmEmail.timeLess = parseInt(e.data.time)))
                    : (a.confirmEmail.error = e.msg);
        },
        onAuthConfirmEmail(e) {
            let a = this;
            0 == e.error
                ? ((a.modal.email = e.data.email),
                  (a.modal.code = e.data.code),
                  (a.modal.scope = e.data.scope),
                  (a.confirmEmail.timeLess = -1),
                  a.expireConfirmCode(!1),
                  (a.pdappApiToken = e.data.refreshToken),
                  pdappAPI.tool.setLocalVar("pdapp_api_token", a.pdappApiToken),
                  (a.confirmEmail.timeLess = parseInt(e.data.time)))
                : (a.confirmEmail.error = e.msg),
                (a.confirmEmail.verifing = !1);
        },
    },
}).mount("#productdesignerapp-app");
function postToChild(e, a, o) {
    e.contentWindow.postMessage({ type: a, data: o }, pdappHomeUrl);
}
window.onmessage = function (e) {
    if (void 0 !== e.data.type) {
        let a = e.data.type,
            o = e.data.data;
        "authcode" == a && pdappVueApp.onAuthCode(o),
            "authemail" == a && pdappVueApp.onAuthEmail(o),
            "authrefreshemail" == a && pdappVueApp.onAuthRefreshEmail(o),
            "authconfirmemail" == a && pdappVueApp.onAuthConfirmEmail(o);
    }
};