/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Order
* Free version
* Unminify code for Dev
**/
const { createApp: createApp } = Vue;
var pdappVueApp = createApp({
    data: () => ({
        loadingPage: !0,
        uploadUrl: pdappUploadUrl,
        pluginUrl: pdappPluginUrl,
        adminUrl: pdappAdminUrl,
        pdappPluginSlug: pdappPluginSlug,
        modal: { show: !1 },
        toast: { show: !1, type: "success", text: "" },
        pageDetail: { show: !1, langCode: "en_US", data: { id: 0, items: [] } },
        pageList: { show: !0, data: [] },
        langs: {},
        listLang: { default: pdappLangDefault, list: [] },
        newOrders: [],
        orders: { searchMobile: !1, search: "", status: "", pages: 1, paged: 1, perpage: 24 },
        listStatus: ["pending", "processing", "completed", "on-hold", "cancelled", "refunded", "failed"],
    }),
    created() {
        jQuery("#productdesignerapp-app").show(), this.getOrderSetting();
    },
    computed: {
        breadcrumbs() {
            let e = { title: "", pages: [] };
            return (
                void 0 === this.langs.menu ||
                    (this.pageDetail.show
                        ? ((e.title = this.langs.menu.order + " #" + this.pageDetail.data.id),
                          (e.pages = [
                              { to: "orders", title: this.langs.menu.orders },
                              { to: "", title: e.title },
                          ]))
                        : ((e.title = this.langs.menu.orders), (e.pages = [{ to: "", title: e.title }]))),
                e
            );
        },
        listOrders() {
            let e = this,
                a = {};
            for (let t = 0; t < e.newOrders.length; t++) a[e.newOrders[t]] = "";
            let t = [];
            for (let d = 0; d < e.pageList.data.length; d++)
                (e.pageList.data[d].new = 0),
                    void 0 !== a[e.pageList.data[d].id] && (e.pageList.data[d].new = 1),
                    ("" == e.orders.status ||
                        ("" != e.orders.status && e.orders.status == e.pageList.data[d].status)) &&
                        ("" != e.orders.search
                            ? -1 != e.pageList.data[d].id.indexOf(e.orders.search) && t.push(e.pageList.data[d])
                            : t.push(e.pageList.data[d]));
            e.orders.pages = Math.ceil(t.length / e.orders.perpage);
            let d = [],
                s = (e.orders.paged - 1) * e.orders.perpage;
            for (let a = 0; a < t.length; a++) a >= s && a < s + e.orders.perpage && d.push(t[a]);
            return d;
        },
    },
    methods: {
        goToPage(e) {
            "orders" == e && this.showListOrders("");
        },
        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 getOrderSetting() {
            let e = this,
                a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-load-setting&listLangs=1&newOrders=1&langs=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
            try {
                let t = await pdappAPI.tool.getData(a);
                (e.langs = t.data.langs),
                    (e.listLang.list = t.data.listLangs),
                    (e.newOrders = t.data.newOrders),
                    (e.pageDetail.langCode = pdappLangDefault);
                let d = 0 == pdappDetailPage ? "" : { id: pdappDetailPage };
                "" === pdappDetailPage || e.viewDetail(d, !0), e.showListOrders(!0);
            } catch (e) {}
            setTimeout(() => {
                e.getRefreshToken();
            }, 6e4);
        },
        async showListOrders(e) {
            let a = this;
            if (
                ("" == e && ((a.pageDetail.show = !1), (a.pageList.show = !0)),
                (a.loadingPage = !0),
                0 == a.pageList.data.length)
            ) {
                let e = pdappAdminUrl + "admin-ajax.php?action=pdapp-orders&admin=1&pdapp-nonce=" + pdappNonce;
                try {
                    let t = await pdappAPI.tool.getData(e);
                    a.pageList.data = t.data;
                } catch (e) {
                    (a.toast = { show: !0, type: "warning", text: e.msg }),
                        setTimeout(() => {
                            a.toast.show = !1;
                        }, 5e3);
                }
            }
            "" == e && pdappAPI.tool.updateURL("orders"), (a.loadingPage = !1);
        },
        getClassBtn(e) {
            let a = "btn-danger";
            return (
                "pending" == e && (a = "btn-secondary"),
                "processing" == e && (a = "btn-info"),
                "completed" == e && (a = "btn-success"),
                "on-hold" == e && (a = "btn-warning"),
                a
            );
        },
        convertDate: (e) => pdappAPI.tool.toDate(e),
        showImg(e) {
            return void 0 === e || "" == e
                ? this.pluginUrl + "assets/images/image.png"
                : ("" != e && -1 == e.indexOf("base64,") && (e = this.uploadUrl + "/orders/" + e), e);
        },
        async viewDetail(e, a) {
            let t = this;
            if (
                ((t.pageDetail.show = !0),
                (t.pageList.show = !1),
                (t.loadingPage = !0),
                pdappAPI.tool.updateURL("orders&detail=" + e.id),
                void 0 === e.items)
            ) {
                let a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-order&id=" +
                    e.id +
                    "&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let d = await pdappAPI.tool.getData(a);
                    e.items = d.data;
                    for (let a = 0; a < t.pageList.data.length; a++)
                        t.pageList.data[a].id == e.id && (t.pageList.data[a].items = d.data);
                } catch (e) {
                    return (
                        (t.loadingPage = !1),
                        (t.toast = { show: !0, type: "warning", text: e.msg }),
                        setTimeout(() => {
                            t.toast.show = !1;
                        }, 5e3),
                        !1
                    );
                }
            }
            if (void 0 !== a && a && "" != pdappItemID)
                for (let a = 0; a < e.items.length; a++) e.items[a].id == pdappItemID && t.openDownload(e.items[a]);
            (t.pageDetail.data = e), (t.loadingPage = !1);
        },
        openDownload(e) {
            let a = this,
                t = "";
            if (
                ((t =
                    1 == e.designs.length
                        ? "col-12"
                        : 2 == e.designs.length
                          ? "col-6"
                          : "col-12 col-sm-6 col-lg-4 col-xl-3"),
                void 0 === e.team && (e.team = []),
                e.team.length && void 0 === e.teams)
            ) {
                e.teams = [];
                for (let a = 0; a < e.team.length; a++)
                    e.teams.push({ name: e.team[a].name, number: e.team[a].number, team: [], loading: !0 });
            }
            if (e.designs.length) for (let a = 0; a < e.designs.length; a++) e.designs[a].loading = !0;
            (a.modal = {
                show: !0,
                header: !0,
                title: a.langs.order.download_design,
                size: "full-width modal-dialog-scrollable",
                type: "download",
                clss: t,
                unit: e.print.unit,
                data: e,
            }),
                pdappAPI.design.renderPNGs(e.designs, e.team, function (t, d, s, p) {
                    void 0 !== a.modal.data.designs[t] &&
                        ((a.modal.data.designs[t].png = s),
                        (a.modal.data.designs[t].loading = !1),
                        "" != d && (a.modal.data.designs[t].svg = d)),
                        void 0 !== p &&
                            "" != p &&
                            pdappAPI.design.renderTeams(p, e.team, function (e, t) {
                                void 0 !== a.modal.data.teams[e] &&
                                    ((a.modal.data.teams[e].loading = !1), a.modal.data.teams[e].team.push(t));
                            });
                });
        },
        startDownload(e, a, t) {
            let d = this;
            if (((e.loading = !0), "svg" == a)) {
                if ("" == e.svg) return (e.loading = !1), !1;
                pdappAPI.design.downloadFile(e.svg, "download_" + a + "_" + t, a, d.modal.unit, function () {
                    e.loading = !1;
                });
            } else {
                if ("" == e.svg || "" == e.png) return (e.loading = !1), !1;
                pdappAPI.design.downloadFile(e.png, "download_" + a + "_" + t, a, d.modal.unit, function () {
                    e.loading = !1;
                });
            }
        },
        confirmRemove(e) {
            this.modal = {
                show: !0,
                header: !1,
                title: "",
                size: "md modal-dialog-centered",
                type: "message",
                data: {
                    id: e,
                    title: this.langs.msg.confirm_title,
                    text: this.langs.msg.confirm_data,
                    type: "warning",
                    btn: this.langs.delete,
                    confirm: "order",
                },
            };
        },
        async removeOrder(e) {
            let a = this;
            a.loadingPage = !0;
            let t = pdappAdminUrl + "admin-ajax.php?action=pdapp-remove-order&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let d = await pdappAPI.tool.postData(t, { id: e });
                for (let t = a.pageList.data.length - 1; t >= 0; t--)
                    a.pageList.data[t].oid == e && a.pageList.data.splice(t, 1);
                (a.toast = { show: !0, type: "success", text: d.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            } catch (e) {
                (a.toast = { show: !0, type: "warning", text: e.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
            a.loadingPage = !1;
        },
        confirmEvt(e) {
            "order" == e && this.removeOrder(this.modal.data.id), (this.modal.show = !1);
        },
    },
}).mount("#productdesignerapp-app");