/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Upgrade
* 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: "" },
        upgrades: [],
        langs: {},
        storeUrl: "",
        version: pdappVersion,
        package: pdappPackage,
        pdappPurchasedCode: pdappPurchasedCode,
        loading: !1,
        openDefault: 0,
        pdappApiToken: "",
        showStore: !1,
        confirmEmail: { code: "", timeLess: 0, error: "", refresh: !0 },
        loadedStore: !1,
    }),
    created() {
        jQuery("#productdesignerapp-app").show(), this.getUpgradeSetting();
    },
    computed: {
        breadcrumbs() {
            let e = { title: "", pages: [] };
            return (
                void 0 === this.langs.menu ||
                    ((e.title = this.langs.upgrade.upgrades), (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: {
        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 getUpgradeSetting() {
            let e = this,
                a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-load-setting&langs=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
            try {
                let p = await pdappAPI.tool.getData(a);
                (e.langs = p.data.langs), e.showListUpgrades();
            } catch (e) {}
            setTimeout(() => {
                e.getRefreshToken();
            }, 6e4);
        },
        async showListUpgrades() {
            let e = this;
            if (((e.loadingPage = !0), 0 == e.upgrades.length))
                try {
                    let a = await pdappAPI.tool.getData(pdappAPIUrl + "/info.php?type=upgrade-list");
                    e.upgrades = a.data;
                } catch (a) {
                    (e.toast = { show: !0, type: "warning", text: a.msg }),
                        setTimeout(() => {
                            e.toast.show = !1;
                        }, 5e3);
                }
            e.loadingPage = !1;
        },
        confirmUpgrade(e) {
            this.modal = { show: !0, type: "message", version: e, loading: !1 };
        },
        installUpgrade() {
            let e = this;
            "" != e.pdappPurchasedCode
                ? ((e.modal.loading = !0),
                  e.showStore
                      ? ((e.loadingPage = !0),
                        postToChild(document.getElementById("pdapp-resource-frame"), "startupdate", {
                            version: e.modal.version,
                            token: e.pdappApiToken,
                        }))
                      : ((e.pdappApiToken = pdappAPI.tool.getLocalVar("pdapp_api_token", "")),
                        "" != e.pdappApiToken && "" != e.pdappApiToken
                            ? postToChild(document.getElementById("pdapp-login-frame"), "verifytoken", e.pdappApiToken)
                            : postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                                  purchased: e.pdappPurchasedCode,
                                  domain: pdappDomain,
                              })))
                : e.showVerifyModal();
        },
        changeFile(e) {
            let a = this;
            if (void 0 === e.target.files[0]) return !1;
            loadZipFile(e.target.files[0], function (e) {
                (a.loading = !0), (a.loadingPage = !0), a.onUpdateEvent({ version: a.version, data: e });
            });
        },
        async onUpdateEvent(e) {
            let a = this;
            a.modal.loading = !0;
            let p = pdappAdminUrl + "admin-ajax.php?action=pdapp-upgrade-plugin&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let o = await pdappAPI.tool.postData(p, e);
                (a.version = e.version),
                    (a.toast = { show: !0, type: "success", text: o.msg }),
                    setTimeout(() => {
                        (a.toast.show = !1), location.reload(!0);
                    }, 5e3);
            } catch (e) {
                (a.toast = { show: !0, type: "warning", text: e.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
            (a.modal.show = !1), (a.modal.loading = !1), (a.loadingPage = !1), (a.loading = !1);
        },
        checkVersion(e) {
            let a = !1;
            return this.version.replaceAll(".", "") < e.replaceAll(".", "") && (a = !0), a;
        },
        showDate: (e) => pdappAPI.tool.toDate(e),
        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(e) {
            let a = this,
                p = pdappAdminUrl + "admin-ajax.php?action=pdapp-dashboard-purchased&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                await pdappAPI.tool.postData(p, { 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),
                      a.showStore || ((a.showStore = !0), void 0 !== a.modal.version && a.installUpgrade()))
                    : "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,
                        }),
                (a.modal.loading = !1);
        },
        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)
                return (
                    void 0 !== a.modal.type && "verifycode" == a.modal.type
                        ? void 0 !== e.data && void 0 !== e.data.platform && e.data.platform == pdappPlatform
                            ? a.updatePurchased(e)
                            : ((a.modal.error = "Your platform verify incorrect"), (a.modal.verifing = !1))
                        : a.checkAuthCode(e.data),
                    !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 loadZipFile(e, a) {
    const p = new FileReader();
    (p.onload = () => {
        let e = p.result.split("base64,");
        "function" == typeof a && void 0 !== e[1] && a(e[1]);
    }),
        p.readAsDataURL(e);
}
function postToChild(e, a, p) {
    e.contentWindow.postMessage({ type: a, data: p }, pdappHomeUrl);
}
window.onmessage = function (e) {
    if (void 0 !== e.data.type) {
        let a = e.data.type,
            p = e.data.data;
        "authcode" == a && pdappVueApp.onAuthCode(p),
            "authemail" == a && pdappVueApp.onAuthEmail(p),
            "authrefreshemail" == a && pdappVueApp.onAuthRefreshEmail(p),
            "authconfirmemail" == a && pdappVueApp.onAuthConfirmEmail(p),
            "loadedstore" == a && "ok" == p && (pdappVueApp.loadedStore = !0),
            "updated" == a && pdappVueApp.onUpdateEvent(p);
    }
};