/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Product
* Free version
* Unminify code for Dev
**/
const { createApp: createApp } = Vue;
var pdappVueApp = createApp({
    data: () => ({
        loadingPage: !0,
        uploadUrl: pdappUploadUrl,
        pluginUrl: pdappPluginUrl,
        adminUrl: pdappAdminUrl,
        modal: { show: !1 },
        toast: { show: !1, type: "success", text: "" },
        pageAdd: {
            show: !1,
            saving: !1,
            data: {},
            layout: {},
            discount: { type: "fixed", list: [] },
            minQty: 1,
            tempID: 0,
            artID: 0,
        },
        pageList: { show: !0, data: [] },
        langs: {},
        langDefault: pdappLangDefault,
        printings: [],
        units: ["px", "cm", "in"],
        productOption: { id: "", type: "", value: "", saving: !1 },
        productColor: { addNew: "", color: { id: "", title: "", type: "picker", active: "#ffffff", values: [] } },
        productSize: { addNew: "", id: "", size: "" },
        productActive: { setup: "setup", info: "info", layer: "0", view: 0 },
        products: { searchMobile: !1, search: "", pages: 1, paged: 1, perpage: 24 },
        productCheckbox: !1,
        productCheckboxs: [],
        stores: [],
        settingLayout: {},
        discounts: ["fixed", "percent"],
        screenSize: 1e3,
        pageView: !1,
        pdappPurchasedCode: pdappPurchasedCode,
        pdappApiToken: "",
        showStore: !1,
        confirmEmail: { code: "", timeLess: 0, error: "", refresh: !0 },
        loadedStore: !1,
        loadingStore: !1,
        tempFolders: {},
        artFolders: {},
        listTemps: [],
        listArts: [],
        listColors: [],
        searchProduct: "",
    }),
    created() {
        jQuery("#productdesignerapp-app").show(), this.getProductSetting();
    },
    computed: {
        breadcrumbs() {
            let t = { title: "", pages: [] };
            return (
                this.pageAdd.show
                    ? ((t.title =
                          void 0 !== this.pageAdd.data.id && "" != this.pageAdd.data.id
                              ? this.langs.menu.edit_product
                              : this.langs.menu.add_product),
                      (t.pages = [
                          { to: "products", title: this.langs.menu.products },
                          { to: "", title: t.title },
                      ]))
                    : ((t.title = this.langs.menu.products), (t.pages = [{ to: "", title: t.title }])),
                t
            );
        },
        viewActive() {
            let t = {};
            return (
                void 0 !== this.pageAdd.data.views[this.productActive.view] &&
                    ("string" == typeof this.pageAdd.data.views &&
                        (this.pageAdd.data.views = JSON.parse(this.pageAdd.data.views)),
                    (t = this.pageAdd.data.views[this.productActive.view])),
                t
            );
        },
        productDataPX() {
            let t = this;
            "string" == typeof t.pageAdd.data.unit && (t.pageAdd.data.unit = JSON.parse(t.pageAdd.data.unit)),
                "string" == typeof t.pageAdd.data.colors && (t.pageAdd.data.colors = JSON.parse(t.pageAdd.data.colors)),
                "string" == typeof t.pageAdd.data.sizes && (t.pageAdd.data.sizes = JSON.parse(t.pageAdd.data.sizes)),
                "string" == typeof t.pageAdd.data.views && (t.pageAdd.data.views = JSON.parse(t.pageAdd.data.views)),
                "string" == typeof t.pageAdd.data.attributes &&
                    (t.pageAdd.data.attributes = JSON.parse(t.pageAdd.data.attributes)),
                "string" == typeof t.pageAdd.data.advanced &&
                    (t.pageAdd.data.advanced = JSON.parse(t.pageAdd.data.advanced));
            let e = JSON.parse(JSON.stringify(this.pageAdd.data));
            return pdappAPI.tool.toProductPX(e);
        },
        viewActivePX() {
            let t = {};
            return (
                void 0 !== this.productDataPX.views[this.productActive.view] &&
                    (t = this.productDataPX.views[this.productActive.view]),
                t
            );
        },
        productBoxStyle() {
            let t = this,
                e = [];
            if (void 0 !== t.productDataPX.unit && "setup" == t.productActive.setup)
                for (let a = 0; a < t.productDataPX.views.length; a++) {
                    let d = parseFloat(t.productDataPX.views[a].canvas.width),
                        o = parseFloat(t.productDataPX.views[a].canvas.height),
                        p = t.screenSize,
                        i = t.screenSize;
                    d / o > 1 ? (i = (p * o) / d) : (p = (i * d) / o);
                    let s = p / d;
                    this.productActive.view == a && jQuery("#pdapp-design-box").attr("data-zoom", s);
                    let r = {
                        viewPort: "width:" + p + "px;height:" + i + "px;",
                        backgrounds: [],
                        layers: [],
                        mask: "",
                    };
                    if (t.productDataPX.views[a].backgrounds.length)
                        for (let e = 0; e < t.productDataPX.views[a].backgrounds.length; e++) {
                            let d = t.productDataPX.views[a].backgrounds[e].width * s,
                                o = t.productDataPX.views[a].backgrounds[e].height * s,
                                p = t.productDataPX.views[a].backgrounds[e].left * s,
                                i = t.productDataPX.views[a].backgrounds[e].top * s,
                                l =
                                    "width:" +
                                    d.toFixed(3) +
                                    "px;height:" +
                                    o.toFixed(3) +
                                    "px;transform:matrix(1, 0, 0, 1, " +
                                    p.toFixed(3) +
                                    ", " +
                                    i.toFixed(3) +
                                    ");";
                            r.backgrounds.push(l);
                        }
                    if (void 0 !== t.productDataPX.views[a].mask.width) {
                        let e = t.productDataPX.views[a].mask.width * s,
                            d = t.productDataPX.views[a].mask.height * s,
                            o = t.productDataPX.views[a].mask.left * s,
                            p = t.productDataPX.views[a].mask.top * s;
                        r.mask =
                            "width:" +
                            e.toFixed(3) +
                            "px;height:" +
                            d.toFixed(3) +
                            "px;transform:matrix(1, 0, 0, 1, " +
                            o.toFixed(3) +
                            ", " +
                            p.toFixed(3) +
                            ");";
                    }
                    if (t.productDataPX.views[a].layers.length)
                        for (let e = 0; e < t.productDataPX.views[a].layers.length; e++) {
                            let d = t.productDataPX.views[a].layers[e].width * s,
                                o = t.productDataPX.views[a].layers[e].height * s,
                                p = t.productDataPX.views[a].layers[e].left * s,
                                i = t.productDataPX.views[a].layers[e].top * s,
                                l = t.productDataPX.views[a].layers[e].radius,
                                c =
                                    "width:" +
                                    d.toFixed(3) +
                                    "px;height:" +
                                    o.toFixed(3) +
                                    "px;transform:matrix(1, 0, 0, 1, " +
                                    p.toFixed(3) +
                                    ", " +
                                    i.toFixed(3) +
                                    ");overflow:hidden;border-radius:" +
                                    l +
                                    "%;";
                            r.layers.push(c);
                        }
                    e.push(r);
                }
            return e;
        },
        productColors() {
            let t = {};
            for (let e = 0; e < this.productDataPX.colors.length; e++)
                t[this.productDataPX.colors[e].id] = this.productDataPX.colors[e].active;
            return t;
        },
        disabledSave() {
            let t = !0;
            return (
                1 != this.pageAdd.saving &&
                    "" != this.pageAdd.data.title &&
                    void 0 !== this.pageAdd.data.views &&
                    "" != this.pageAdd.data.pid &&
                    this.pageAdd.data.colors.length &&
                    (this.pageAdd.data.views.length || this.pageAdd.data.attributes.length) &&
                    (t = !1),
                t
            );
        },
        listProducts() {
            let t = this,
                e = [];
            for (let a = 0; a < t.pageList.data.length; a++)
                "" != t.products.search
                    ? -1 != t.pageList.data[a].title.toLowerCase().indexOf(t.products.search.toLowerCase()) &&
                      e.push(t.pageList.data[a])
                    : e.push(t.pageList.data[a]);
            t.products.pages = Math.ceil(e.length / t.products.perpage);
            let a = [],
                d = (t.products.paged - 1) * t.products.perpage;
            for (let o = 0; o < e.length; o++) o >= d && o < d + t.products.perpage && a.push(e[o]);
            return (
                setTimeout(() => {
                    t.checkAllProduct();
                }, 1),
                a
            );
        },
        listProductDesigns() {
            let t = this,
                e = [];
            for (let a = 0; a < t.pageList.data.length; a++)
                "" != t.searchProduct
                    ? -1 != t.pageList.data[a].title.toLowerCase().indexOf(t.searchProduct.toLowerCase()) &&
                      e.push(t.pageList.data[a])
                    : e.push(t.pageList.data[a]);
            return e;
        },
        colors() {
            let t = this,
                e = [],
                a = [];
            for (let a = 0; a < t.productColor.color.values.length; a++)
                e.push(t.productColor.color.values[a].hex.toLowerCase());
            if (void 0 !== t.modal.data && void 0 !== t.modal.data.color && void 0 !== t.modal.data.color.title)
                for (let d = 0; d < t.listColors.length; d++)
                    -1 != t.listColors[d].title.toLowerCase().indexOf(t.modal.data.color.title.toLowerCase()) &&
                        0 == e.includes(t.listColors[d].hex.toLowerCase()) &&
                        a.push(t.listColors[d]);
            else a = t.listColors;
            return a;
        },
        timeDown() {
            let t = "" + Math.floor(this.confirmEmail.timeLess / 60),
                e = "" + (this.confirmEmail.timeLess - 60 * t);
            return 1 == t.length && (t = "0" + t), 1 == e.length && (e = "0" + e), t + ":" + e;
        },
    },
    methods: {
        goToPage(t) {
            "products" == t && this.showListProducts();
        },
        async getRefreshToken() {
            let t = this,
                e = pdappAdminUrl + "admin-ajax.php?action=pdapp-refresh-token&admin=1";
            try {
                let t = await pdappAPI.tool.getData(e);
                pdappNonce = t.data.token;
            } catch (t) {}
            setTimeout(() => {
                t.getRefreshToken();
            }, 6e4);
        },
        async getProductSetting() {
            let t = this,
                e =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-load-setting&langs=1&printings=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
            try {
                let a = await pdappAPI.tool.getData(e);
                (t.langs = a.data.langs),
                    (t.printings = a.data.printings),
                    0 == a.data.printings.length &&
                        ((t.toast = { show: !0, type: "warning", text: t.langs.msg.add_printing_msg }),
                        setTimeout(() => {
                            t.toast.show = !1;
                        }, 5e3)),
                    (t.pageAdd.data.pid = void 0 !== t.printings[0] ? t.printings[0].id : 0);
                let d = 0 == pdappEditPage ? "" : { id: pdappEditPage };
                "" === pdappEditPage ? t.showListProducts() : (t.editProduct(d), t.showListProducts(!0));
            } catch (t) {}
            t.applyHotKeys(),
                setTimeout(() => {
                    t.getRefreshToken();
                }, 6e4);
        },
        applyHotKeys() {
            let t = this;
            pdappAPI.hotkeys.init(function (e, a, d) {
                "move" == e && t.moveItem(a), "del" == e && t.removeLayer(d, a);
            });
        },
        async showListProducts(t) {
            let e = this;
            if (
                (void 0 === t && ((e.pageAdd.show = !1), (e.pageList.show = !0)),
                (e.loadingPage = !0),
                0 == e.pageList.data.length)
            ) {
                let t = pdappAdminUrl + "admin-ajax.php?action=pdapp-products&admin=1&pdapp-nonce=" + pdappNonce;
                try {
                    let a = await pdappAPI.tool.getData(t);
                    e.pageList.data = a.data;
                } catch (t) {
                    (e.toast = { show: !0, type: "warning", text: t.msg }),
                        setTimeout(() => {
                            e.toast.show = !1;
                        }, 5e3);
                }
            }
            void 0 === t && pdappAPI.tool.updateURL("products"), (e.loadingPage = !1);
        },
        checkAllProduct() {
            if (((this.productCheckboxs = []), this.productCheckbox))
                for (let t = 0; t < this.listProducts.length; t++) this.productCheckboxs.push(this.listProducts[t].id);
        },
        convertDate: (t) => pdappAPI.tool.toDate(t),
        getPrintingType(t) {
            let e = "--";
            for (let a = 0; a < this.printings.length; a++) this.printings[a].id == t && (e = this.printings[a].title);
            return e;
        },
        confirmRemovePr(t, e) {
            this.modal = {
                show: !0,
                header: !1,
                title: "",
                size: "md modal-dialog-centered",
                type: "message",
                data: {
                    pid: t,
                    vid: e,
                    title: this.langs.msg.confirm_title,
                    text: this.langs.msg.confirm_data,
                    type: "warning",
                    btn: this.langs.delete,
                    confirm: "product",
                },
            };
        },
        async removeProduct(t, e) {
            let a = this,
                d = [];
            if ("" === t && "" === e) {
                if (0 == a.productCheckboxs.length) return !1;
                for (let t = 0; t < a.listProducts.length; t++)
                    a.productCheckboxs.includes(a.listProducts[t].id) &&
                        d.push({ pid: a.listProducts[t].id, vid: a.listProducts[t].vid });
            } else d.push({ pid: t, vid: e });
            a.loadingPage = !0;
            let o = pdappAdminUrl + "admin-ajax.php?action=pdapp-remove-product&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let t = await pdappAPI.tool.postData(o, { data: d });
                for (let e = a.pageList.data.length - 1; e >= 0; e--)
                    t.data.includes(parseInt(a.pageList.data[e].id)) && a.pageList.data.splice(e, 1);
                (a.productCheckbox = !1),
                    (a.productCheckboxs = []),
                    (a.toast = { show: !0, type: "success", text: t.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            } catch (t) {
                (a.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
            a.loadingPage = !1;
        },
        confirmEvt(t) {
            "product" == t && this.removeProduct(this.modal.data.pid, this.modal.data.vid),
                "attr" == t && this.generatorAttribute(this.modal.data.attr.type, this.modal.data.attr.value),
                (this.modal.show = !1);
        },
        showImg(t, e) {
            return void 0 === t || "" == t
                ? this.pluginUrl + "assets/images/image.png"
                : ("" != t &&
                      -1 == t.indexOf("base64,") &&
                      -1 == t.indexOf("://") &&
                      (t = this.uploadUrl + "products/product-" + e + "/" + t),
                  t);
        },
        async editProduct(t) {
            let e = this;
            if (((e.productActive.setup = "setup"), (e.loadingPage = !0), "" == t)) {
                let t = void 0 !== this.printings[0] ? this.printings[0].id : 0;
                (e.pageAdd.data = {
                    id: "",
                    vid: "",
                    title: "",
                    type: [],
                    thumb: "",
                    pid: t,
                    unit: { type: "px", edit: !1, zoom: "100", ratio: "1" },
                    colors: [],
                    sizes: [],
                    views: [],
                    extras: [],
                    attributes: { color: "_", size: "_", values: [] },
                }),
                    pdappAPI.tool.updateURL("products&edit=0");
            } else if (void 0 !== t.views)
                (e.pageAdd.data = JSON.parse(JSON.stringify(t))), pdappAPI.tool.updateURL("products&edit=" + t.id);
            else {
                let a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-product&id=" +
                    t.id +
                    "&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let d = await pdappAPI.tool.getData(a);
                    void 0 === d.data.attributes.values && (d.data.attributes.values = []),
                        (e.pageAdd.data = JSON.parse(JSON.stringify(d.data)));
                    for (let a = 0; a < e.pageList.data.length; a++)
                        e.pageList.data[a].id == t.id && (e.pageList.data[a] = d.data);
                    pdappAPI.tool.updateURL("products&edit=" + e.pageAdd.data.id),
                        e.changeBackgroundColorImg(),
                        setTimeout(() => {
                            let t = jQuery("#pdapp-design-box").width(),
                                a = jQuery("#pdapp-design-box").height();
                            e.screenSize = t > a ? a - 1 : t - 1;
                        }, 1),
                        setTimeout(() => {
                            jQuery(".pdapp-viewport.active .moveable-control-box").length &&
                                jQuery(".pdapp-viewport.active .moveable-control-box").remove(),
                                pdappAPI.tool.enableMoveAble(
                                    function (t) {
                                        let a = jQuery(t.target);
                                        (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                            (pdappAPI.tool.targets = []),
                                            pdappAPI.layer.afterUpdateArea(
                                                a,
                                                e.pageAdd.data.views[e.productActive.view],
                                                e.pageAdd.data.unit.type,
                                                function (t) {
                                                    e.pageAdd.data.views[e.productActive.view] = t;
                                                }
                                            ),
                                            setTimeout(() => {
                                                (pdappAPI.tool.pdappMoveAbleRef.target = a[0]),
                                                    (pdappAPI.tool.targets = a[0]);
                                            });
                                    },
                                    function (t) {
                                        "layer" != e.productActive.info && (e.productActive.info = "layer");
                                        let a = jQuery(t[0]).attr("data-target");
                                        e.activeLayer(a, !0);
                                    }
                                ),
                                jQuery("body").scrollTop(jQuery(document).height()),
                                setTimeout(() => {
                                    pdappAPI.tool.setElementGuideLines();
                                }, 1);
                        }, 100);
                } catch (t) {
                    (e.toast = { show: !0, type: "warning", text: t.msg }),
                        setTimeout(() => {
                            e.toast.show = !1;
                        }, 5e3);
                }
            }
            void 0 !== e.pageAdd.data.id && ((e.pageAdd.show = !0), (e.pageList.show = !1));
            let a = void 0 !== e.pageAdd.data.advanced ? JSON.parse(JSON.stringify(e.pageAdd.data.advanced)) : {};
            if ((void 0 === a.viewtitle && (a.viewtitle = ""), void 0 === e.settingLayout.text)) {
                let t =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-settings&general=1&layout=1&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let a = await pdappAPI.tool.getData(t);
                    (e.settingLayout = a.data.layout),
                        void 0 !== a.data.general.cart && (e.settingLayout.cart = a.data.general.cart);
                } catch (t) {}
            }
            (e.pageAdd.layout = pdappAPI.tool.getProductLayout(e.settingLayout, a)),
                (e.pageAdd.discount = void 0 !== a.discount ? a.discount : { type: "fixed", list: [] }),
                void 0 === e.pageAdd.discount.list && (e.pageAdd.discount.list = []),
                (e.pageAdd.minQty = void 0 !== a.minQty ? a.minQty : 1),
                (e.pageAdd.tempID = void 0 !== a.tempID ? a.tempID : 0),
                (e.pageAdd.artID = void 0 !== a.artID ? a.artID : 0),
                (e.pageAdd.relatives = void 0 !== a.relatives ? a.relatives : []),
                (e.loadingPage = !1),
                (ajaxUrl = pdappAdminUrl + "admin-ajax.php?action=pdapp-art-folders&admin=1&pdapp-nonce=" + pdappNonce);
            try {
                (res = await pdappAPI.tool.getData(ajaxUrl)),
                    (e.artFolders = res.data),
                    e.openFolder("art", e.pageAdd.artID);
            } catch {}
            ajaxUrl = pdappAdminUrl + "admin-ajax.php?action=pdapp-temp-folders&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                (res = await pdappAPI.tool.getData(ajaxUrl)),
                    (e.tempFolders = res.data),
                    e.openFolder("temp", e.pageAdd.tempID);
            } catch {}
            ajaxUrl = pdappAdminUrl + "admin-ajax.php?action=pdapp-get-colors&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                (res = await pdappAPI.tool.getData(ajaxUrl)), (e.listColors = res.data);
            } catch {}
        },
        async copyProduct(t) {
            let e = this;
            if (((e.loadingPage = !0), "" != t && void 0 !== t.id)) {
                let a =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-copy-product&id=" +
                    t.id +
                    "&admin=1&pdapp-nonce=" +
                    pdappNonce;
                try {
                    let t = await pdappAPI.tool.getData(a);
                    e.pageList.data.push(t.data),
                        (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;
            }
        },
        openFolder(t, e) {
            let a = this;
            "art" == t
                ? ((a.pageAdd.artID = e),
                  pdappAPI.folder.getFolders(a.artFolders, e, function (t) {
                      a.listArts = t;
                  }))
                : ((a.pageAdd.tempID = e),
                  pdappAPI.folder.getFolders(a.tempFolders, e, function (t) {
                      a.listTemps = t;
                  }));
        },
        getTitle(t) {
            let e = this,
                a = "Untitled";
            if (null == t || "" == t) return a;
            if (void 0 !== t[e.langDefault] && "" != t[e.langDefault]) a = t[e.langDefault];
            else for (let e in t) "" != t[e] && (a = t[e]);
            return a;
        },
        changeThumbFile(t) {
            if (void 0 === t.target.files[0]) return !1;
            const e = t.target.files[0];
            let a = this;
            pdappAPI.tool.changeThumb(e, function (t) {
                a.pageAdd.data.thumb = t;
            }) ||
                ((a.toast = { show: !0, type: "error", text: a.langs.msg.file_type_error + " PNG, JPG, JPEG" }),
                setTimeout(() => {
                    a.toast.show = !1;
                }, 5e3));
        },
        showCustomView() {
            this.modal = {
                show: !0,
                header: !0,
                size: "",
                title: this.langs.product.custom_view,
                type: "view",
                data: { view: 14 },
            };
        },
        setCustomView(t) {
            let e = this;
            "modal" == t && (t = e.modal.data.view), (e.modal.show = !1), (t = parseInt(t)), (e.pageView = t > 4);
            let a = ["Front", "Back", "Left", "Right"],
                d = "Body",
                o = { id: pdappAPI.tool.uID(), title: d, type: "picker", active: "#ffffff", values: [] };
            e.pageAdd.data.colors.length ? (o = e.pageAdd.data.colors[0]) : e.pageAdd.data.colors.push(o),
                0 == e.pageAdd.data.sizes.length && e.pageAdd.data.sizes.push("Normal");
            let p = 1e3,
                i = pdappAPI.tool.createBackground(p, p, "#ffffff");
            for (let s = 0; s < t; s++) {
                let t = { id: o.id, image: i, images: [], colorType: "color", top: 0, left: 0, width: p, height: p },
                    r = {
                        id: pdappAPI.tool.uID(),
                        title: d,
                        top: 50,
                        left: 50,
                        width: 900,
                        height: 900,
                        radius: 0,
                        mask: "",
                    },
                    l = e.pageView || void 0 === a[s] ? "Page " + (s + 1) : a[s],
                    c = {
                        id: pdappAPI.tool.uID(),
                        title: l,
                        canvas: { width: p, height: p },
                        backgrounds: [t],
                        layers: [r],
                        mask: {},
                    };
                e.pageAdd.data.views.push(c);
            }
            setTimeout(() => {
                let t = jQuery("#pdapp-design-box").width(),
                    a = jQuery("#pdapp-design-box").height();
                e.screenSize = t > a ? a - 1 : t - 1;
            }, 1),
                setTimeout(() => {
                    jQuery(".pdapp-viewport.active .moveable-control-box").length &&
                        jQuery(".pdapp-viewport.active .moveable-control-box").remove(),
                        pdappAPI.tool.enableMoveAble(
                            function (t) {
                                let a = jQuery(t.target);
                                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                    (pdappAPI.tool.targets = []),
                                    pdappAPI.layer.afterUpdateArea(
                                        a,
                                        e.pageAdd.data.views[e.productActive.view],
                                        e.pageAdd.data.unit.type,
                                        function (t) {
                                            e.pageAdd.data.views[e.productActive.view] = t;
                                        }
                                    ),
                                    setTimeout(() => {
                                        (pdappAPI.tool.pdappMoveAbleRef.target = a[0]), (pdappAPI.tool.targets = a[0]);
                                    });
                            },
                            function (t) {
                                "layer" != e.productActive.info && (e.productActive.info = "layer");
                                let a = jQuery(t[0]).attr("data-target");
                                e.activeLayer(a, !0);
                            }
                        ),
                        jQuery("body").scrollTop(jQuery(document).height()),
                        setTimeout(() => {
                            pdappAPI.tool.setElementGuideLines();
                        }, 1);
                }, 10);
        },
        addNewMoreView() {
            let t = this,
                e = ["Front", "Back", "Left", "Right"],
                a = t.pageAdd.data.views.length,
                d = t.pageView || void 0 === e[a] ? "Page " + (a + 1) : e[a],
                o = JSON.parse(JSON.stringify(t.pageAdd.data.views[t.pageAdd.data.views.length - 1].canvas)),
                p = JSON.parse(JSON.stringify(t.pageAdd.data.views[t.pageAdd.data.views.length - 1].backgrounds)),
                i = JSON.parse(JSON.stringify(t.pageAdd.data.views[t.pageAdd.data.views.length - 1].layers));
            for (let t = 0; t < i.length; t++) i[t].id = pdappAPI.tool.uID();
            let s = { id: pdappAPI.tool.uID(), title: d, canvas: o, backgrounds: p, layers: i, mask: {} };
            t.pageAdd.data.views.push(s);
        },
        removeView(t) {
            (this.productActive.view = 0),
                this.pageAdd.data.views.splice(t, 1),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []);
        },
        addMoreBG() {
            let t = this,
                e = pdappAPI.tool.createBackground(1e3, 1e3, t.pageAdd.data.colors[0].active),
                a = {
                    id: t.pageAdd.data.colors[0].id,
                    image: e,
                    images: [],
                    colorType: "color",
                    top: 0,
                    left: 0,
                    width: t.viewActive.canvas.width,
                    height: t.viewActive.canvas.height,
                };
            t.pageAdd.data.views[t.productActive.view].backgrounds.push(a),
                setTimeout(() => {
                    pdappAPI.tool.setElementGuideLines();
                }, 1);
        },
        addMoreArea() {
            (pdappAPI.tool.pdappMoveAbleRef.target = null), (pdappAPI.tool.targets = []);
            let t = this.pageAdd.data.views[this.productActive.view].canvas,
                e = {
                    id: pdappAPI.tool.uID(),
                    title: "Body",
                    top: parseFloat(((t.height - this.viewActive.layers[0].height) / 2).toFixed(3)),
                    left: parseFloat(((t.width - this.viewActive.layers[0].width) / 2).toFixed(3)),
                    width: this.viewActive.layers[0].width,
                    height: this.viewActive.layers[0].height,
                    radius: 0,
                    mask: "",
                };
            this.pageAdd.data.views[this.productActive.view].layers.push(e);
            let a = this.pageAdd.data.views[this.productActive.view],
                d = a.layers.length - 1,
                o = this;
            setTimeout(() => {
                let t = jQuery("#pdapp-view-" + a.id + "-lay-" + d);
                (pdappAPI.tool.pdappMoveAbleRef.target = t[0]),
                    (pdappAPI.tool.targets = t[0]),
                    o.activeLayer("lay-" + d),
                    setTimeout(() => {
                        pdappAPI.tool.setElementGuideLines();
                    }, 1);
            });
        },
        removeLayer(t, e) {
            "mask" == e && void 0 !== this.pageAdd.data.views[this.productActive.view].layers[t]
                ? (this.pageAdd.data.views[this.productActive.view].layers[t].mask = "")
                : "layer" == e
                  ? this.pageAdd.data.views[this.productActive.view].layers.splice(t, 1)
                  : "bg" == e && this.pageAdd.data.views[this.productActive.view].backgrounds.splice(t, 1),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []);
        },
        getColor(t) {
            self = this;
            for (let e = 0; e < self.pageAdd.data.colors.length; e++)
                if (self.pageAdd.data.colors[e].id == t)
                    return void 0 !== self.pageAdd.data.colors[e].active && "" != self.pageAdd.data.colors[e].active
                        ? self.pageAdd.data.colors[e].active
                        : "#ffffff";
            return "#ffffff";
        },
        addMoreColor(t) {
            void 0 !== t && void 0 !== t.id
                ? (1 == this.productColor.addNew
                      ? (this.productColor.addNew = "")
                      : ((this.productColor.addNew = 1), (this.productColor.color = JSON.parse(JSON.stringify(t)))),
                  void 0 === this.productColor.color.values && (this.productColor.color.values = []))
                : (this.productColor = {
                      addNew: 1,
                      color: { id: "", title: "", type: "picker", active: "#ffffff", values: [] },
                  });
        },
        resetColor() {
            this.productColor.color.values = [];
        },
        addNewColor() {
            if ("" == this.productColor.color.id)
                (this.productColor.color.id = pdappAPI.tool.uID()),
                    this.pageAdd.data.colors.push(this.productColor.color);
            else
                for (let t = 0; t < this.pageAdd.data.colors.length; t++)
                    if (this.pageAdd.data.colors[t].id == this.productColor.color.id) {
                        this.pageAdd.data.colors[t] = this.productColor.color;
                        for (let t = 0; t < this.pageAdd.data.views.length; t++)
                            for (let e = 0; e < this.pageAdd.data.views[t].backgrounds.length; e++)
                                if (this.pageAdd.data.views[t].backgrounds[e].id == this.productColor.color.id) {
                                    let a = jQuery("#pdapp-view-" + this.pageAdd.data.views[t].id + "-bg-" + e);
                                    if (a.attr("data-color") != this.productColor.color.active) {
                                        let d = this;
                                        pdappAPI.layer.replaceColor(
                                            a.attr("src"),
                                            this.productColor.color.active,
                                            function (o) {
                                                (d.pageAdd.data.views[t].backgrounds[e].image = o),
                                                    a.attr("data-color", d.productColor.color.active);
                                            }
                                        );
                                    }
                                }
                    }
            this.productColor.addNew = "";
        },
        addMoreCustomColor() {
            this.modal = {
                show: !0,
                header: !0,
                size: "xl modal-dialog-scrollable",
                title: this.langs.product.add_custom_color,
                type: "color",
                data: { color: { hex: "#ffffff", title: "" } },
            };
        },
        addListColor(t) {
            let e = !1,
                a = this.modal.data.color;
            void 0 !== t && void 0 !== t.hex ? (a = t) : (this.modal.data.color = { hex: "#ffffff", title: "" }),
                0 == this.productColor.color.values.length && (this.productColor.color.active = a.hex);
            for (let t = 0; t < this.productColor.color.values.length; t++)
                this.productColor.color.values[t].hex.toLowerCase() == a.hex.toLowerCase() && (e = !0);
            if (e)
                return (
                    (this.toast = { show: !0, type: "warning", text: this.langs.msg.product_color_exits }),
                    setTimeout(() => {
                        this.toast.show = !1;
                    }, 3e3),
                    !1
                );
            this.productColor.color.values.push(a),
                1 == this.productColor.color.values.length && (this.modal.data.active = a.hex);
        },
        addSizeAttr(t, e) {
            void 0 !== t && void 0 !== e
                ? 1 == this.productSize.addNew && this.productSize.id == e
                    ? (this.productSize.addNew = "")
                    : ((this.productSize.addNew = 1),
                      (this.productSize.id = e),
                      (this.productSize.size = JSON.parse(JSON.stringify(t))))
                : (this.productSize = { addNew: 1, id: "", size: "" });
        },
        addNewSize() {
            if ("" === this.productSize.id) this.pageAdd.data.sizes.push(this.productSize.size);
            else
                for (let t = 0; t < this.pageAdd.data.sizes.length; t++)
                    t == this.productSize.id && (this.pageAdd.data.sizes[t] = this.productSize.size);
            this.productSize.addNew = "";
        },
        removeSizeAttr(t) {
            this.pageAdd.data.sizes.splice(t, 1);
        },
        unselectLayer() {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                setTimeout(() => {
                    (pdappAPI.tool.pdappMoveAbleRef.target = t), (pdappAPI.tool.targets = t);
                });
        },
        updateLayerValue(t, e, a) {
            let d = this,
                o = jQuery(pdappAPI.tool.pdappMoveAbleRef.target),
                p = parseFloat(a.target.value),
                i =
                    "width" == e
                        ? p + d.pageAdd.data.views[d.productActive.view].layers[t].left
                        : p + d.pageAdd.data.views[d.productActive.view].layers[t].top;
            d.pageAdd.data.views[d.productActive.view].canvas[e] <= i &&
                0 != t &&
                (p = d.pageAdd.data.views[d.productActive.view].canvas[e]),
                (d.pageAdd.data.views[d.productActive.view].layers[t][e] = p),
                p != parseFloat(a.target.value) &&
                    ("width" == e
                        ? (d.pageAdd.data.views[d.productActive.view].layers[t].left =
                              d.pageAdd.data.views[d.productActive.view].canvas[e] - p)
                        : (d.pageAdd.data.views[d.productActive.view].layers[t].top =
                              d.pageAdd.data.views[d.productActive.view].canvas[e] - p)),
                pdappAPI.layer.afterUpdateArea(
                    o,
                    d.pageAdd.data.views[d.productActive.view],
                    d.pageAdd.data.unit.type,
                    function (t) {
                        d.pageAdd.data.views[d.productActive.view] = t;
                    }
                ),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                setTimeout(() => {
                    (pdappAPI.tool.pdappMoveAbleRef.target = o[0]), (pdappAPI.tool.targets = o[0]);
                });
        },
        activeLayer(t, e) {
            void 0 === e && (e = !1);
            let a = jQuery("#pdapp-view-" + this.viewActive.id + "-" + t);
            this.productActive.layer != t || e
                ? ((this.productActive.layer = t),
                  a.hasClass("pdapp-lock-resize")
                      ? ((pdappAPI.tool.pdappMoveAbleRef.scalable = !1),
                        (pdappAPI.tool.pdappMoveAbleRef.renderDirections = []))
                      : ((pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                        (pdappAPI.tool.pdappMoveAbleRef.renderDirections = [
                            "nw",
                            "n",
                            "ne",
                            "w",
                            "e",
                            "sw",
                            "s",
                            "se",
                        ])))
                : ((this.productActive.layer = ""), (a = null), (pdappAPI.tool.targets = [])),
                (pdappAPI.tool.pdappMoveAbleRef.target = a),
                null != a && (pdappAPI.tool.targets = a);
        },
        activeTabStep(t) {
            let e = this;
            if (e.productActive.setup == t) return !1;
            (e.productActive.setup = t), "setup" == t && e.activeProductView(0);
        },
        activeProductView(t) {
            let e = this;
            (e.productActive.view = t),
                (e.productActive.layer = ""),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                setTimeout(() => {
                    jQuery(".pdapp-viewport.active .moveable-control-box").length &&
                        jQuery(".pdapp-viewport.active .moveable-control-box").remove(),
                        pdappAPI.tool.enableMoveAble(
                            function (t) {
                                let a = jQuery(t.target);
                                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                    (pdappAPI.tool.targets = []),
                                    pdappAPI.layer.afterUpdateArea(
                                        a,
                                        e.pageAdd.data.views[e.productActive.view],
                                        e.pageAdd.data.unit.type,
                                        function (t) {
                                            e.pageAdd.data.views[e.productActive.view] = t;
                                        }
                                    ),
                                    setTimeout(() => {
                                        (pdappAPI.tool.pdappMoveAbleRef.target = a[0]), (pdappAPI.tool.targets = a[0]);
                                    });
                            },
                            function (t) {
                                "layer" != e.productActive.info && (e.productActive.info = "layer");
                                let a = jQuery(t[0]).attr("data-target");
                                e.activeLayer(a, !0);
                            }
                        ),
                        setTimeout(() => {
                            pdappAPI.tool.setElementGuideLines();
                        }, 1);
                }, 10);
        },
        updatePrintSize(t) {
            this.pageAdd.data = pdappAPI.tool.updatePrintSize(t, this.pageAdd.data);
        },
        changeBackgroundFile(t, e) {
            if (void 0 === t.target.files[0]) return !1;
            const a = t.target.files[0];
            let d = this,
                o = jQuery("#pdapp-view-" + d.viewActive.id + "-bg-" + e);
            pdappAPI.layer.changeBackground(a, o, function (t) {
                let a = d.viewActive.backgrounds[e].id,
                    o = !1;
                for (let p = 0; p < d.pageAdd.data.colors.length; p++)
                    d.pageAdd.data.colors[p].id == a &&
                        ((o = !0),
                        pdappAPI.layer.replaceColor(t, d.pageAdd.data.colors[p].active, function (t) {
                            d.pageAdd.data.views[d.productActive.view].backgrounds[e].image = t;
                        }));
                o || (d.pageAdd.data.views[d.productActive.view].backgrounds[e].image = t),
                    jQuery(".pdapp-input-file").val("");
            }) ||
                ((d.toast = { show: !0, type: "error", text: d.langs.msg.file_type_error + " PNG" }),
                setTimeout(() => {
                    d.toast.show = !1;
                }, 5e3));
        },
        updateBackground(t, e) {
            let a = this;
            0 != e && (a.pageAdd.data.views[a.productActive.view].backgrounds[t].images = []);
            for (let d = 0; d < a.pageAdd.data.colors.length; d++) {
                a.viewActive.backgrounds[t].id == a.pageAdd.data.colors[d].id &&
                    (-1 == a.pageAdd.data.views[a.productActive.view].backgrounds[t].image.indexOf("://") &&
                        -1 == a.pageAdd.data.views[a.productActive.view].backgrounds[t].image.indexOf("base64,") &&
                        (a.pageAdd.data.views[a.productActive.view].backgrounds[t].image =
                            pdappUploadUrl +
                            "products/product-" +
                            a.pageAdd.data.id +
                            "/" +
                            a.pageAdd.data.views[a.productActive.view].backgrounds[t].image),
                    pdappAPI.layer.replaceColor(
                        a.pageAdd.data.views[a.productActive.view].backgrounds[t].image,
                        a.pageAdd.data.colors[d].active,
                        function (e) {
                            a.pageAdd.data.views[a.productActive.view].backgrounds[t].image = e;
                        }
                    )),
                    0 != e && (a.pageAdd.data.views[a.productActive.view].backgrounds[t].images[d] = "");
            }
        },
        updateBackgroundImg(t) {
            let e = this;
            "color" == e.pageAdd.data.views[e.productActive.view].backgrounds[t].colorType
                ? e.updateBackground(t, !1)
                : e.changeBackgroundColorImg();
        },
        changeBackgroundColorImg() {
            let t = this;
            for (let e = 0; e < t.pageAdd.data.views.length; e++)
                for (let a = 0; a < t.pageAdd.data.views[e].backgrounds.length; a++)
                    if (
                        void 0 !== t.pageAdd.data.views[e].backgrounds[a].colorType &&
                        "image" == t.pageAdd.data.views[e].backgrounds[a].colorType &&
                        !t.pageAdd.data.views[e].backgrounds[a].images.includes(
                            t.pageAdd.data.views[e].backgrounds[a].image
                        )
                    )
                        for (let d = 0; d < t.pageAdd.data.colors.length; d++)
                            if (
                                t.pageAdd.data.views[e].backgrounds[a].id == t.pageAdd.data.colors[d].id &&
                                t.pageAdd.data.colors[d].values.length
                            )
                                for (let o = 0; o < t.pageAdd.data.colors[d].values.length; o++)
                                    t.pageAdd.data.colors[d].active == t.pageAdd.data.colors[d].values[o].hex &&
                                        void 0 !== t.pageAdd.data.views[e].backgrounds[a].images[o] &&
                                        (t.pageAdd.data.views[e].backgrounds[a].image =
                                            t.pageAdd.data.views[e].backgrounds[a].images[o]);
        },
        showBackground(t) {
            let e = this;
            for (let a = 0; a < e.pageAdd.data.colors.length; a++) {
                if (
                    e.viewActive.backgrounds[t].id == e.pageAdd.data.colors[a].id &&
                    "custom" == e.pageAdd.data.colors[a].type
                )
                    return !0;
            }
            return !1;
        },
        showListColors(t) {
            let e = this;
            for (let a = 0; a < e.pageAdd.data.colors.length; a++)
                if (t == e.pageAdd.data.colors[a].id) return e.pageAdd.data.colors[a].values;
            return [];
        },
        showBackgroundImg(t, e, a) {
            return void 0 === t[e] || "" == t[e] || null == t[e]
                ? this.pluginUrl + "assets/images/image.png"
                : "" != t[e] && -1 == t[e].indexOf("base64,")
                  ? this.uploadUrl + "products/product-" + a + "/" + t[e]
                  : void 0 !== t[e]
                    ? t[e]
                    : "";
        },
        restartBackgroundColor(t, e) {
            let a = this;
            for (let d = 0; d < a.pageAdd.data.colors.length; d++) {
                a.viewActive.backgrounds[t].id == a.pageAdd.data.colors[d].id &&
                    (a.pageAdd.data.views[a.productActive.view].backgrounds[t].images[e] = "");
            }
        },
        changeBackgroundColorFile(t, e, a) {
            if (void 0 === t.target.files[0]) return !1;
            const d = t.target.files[0];
            let o = this,
                p = jQuery("#pdapp-view-" + o.viewActive.id + "-bg-" + e);
            pdappAPI.layer.changeBackground(
                d,
                p,
                function (t) {
                    (o.pageAdd.data.views[o.productActive.view].backgrounds[e].images[a] = t),
                        jQuery(".pdapp-input-file").val("");
                },
                "color"
            ) ||
                ((o.toast = { show: !0, type: "error", text: o.langs.msg.file_type_error + " PNG" }),
                setTimeout(() => {
                    o.toast.show = !1;
                }, 5e3));
        },
        restartBgColor(t) {
            let e = this;
            for (let a = 0; a < e.pageAdd.data.colors.length; a++) {
                if (e.viewActive.backgrounds[t].id == e.pageAdd.data.colors[a].id) {
                    let d = pdappAPI.tool.createBackground(1e3, 1e3, e.pageAdd.data.colors[a].active);
                    (e.pageAdd.data.views[e.productActive.view].backgrounds[t].image = d),
                        (e.pageAdd.data.views[e.productActive.view].backgrounds[t].top = 0),
                        (e.pageAdd.data.views[e.productActive.view].backgrounds[t].left = 0),
                        (e.pageAdd.data.views[e.productActive.view].backgrounds[t].width = e.viewActivePX.canvas.width),
                        (e.pageAdd.data.views[e.productActive.view].backgrounds[t].height =
                            e.viewActivePX.canvas.height);
                }
            }
        },
        activeProductTab(t) {
            (this.productActive.info = t),
                (this.productActive.layer = ""),
                null != pdappAPI.tool.pdappMoveAbleRef &&
                    ((pdappAPI.tool.pdappMoveAbleRef.target = null), (pdappAPI.tool.targets = []));
        },
        alignItem(t) {
            let e = this,
                a = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                "function" == typeof pdappAPI.tool[t] &&
                    (pdappAPI.tool[t](a),
                    setTimeout(() => {
                        (pdappAPI.tool.pdappMoveAbleRef.target = a[0]),
                            (pdappAPI.tool.targets = a[0]),
                            pdappAPI.layer.afterUpdateArea(
                                a,
                                e.pageAdd.data.views[e.productActive.view],
                                e.pageAdd.data.unit.type,
                                function (t) {
                                    e.pageAdd.data.views[e.productActive.view] = t;
                                }
                            );
                    }));
        },
        moveItem(t) {
            let e = this,
                a = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                pdappAPI.tool.setTransformMove(a, t),
                setTimeout(() => {
                    (pdappAPI.tool.pdappMoveAbleRef.target = a[0]),
                        (pdappAPI.tool.targets = a[0]),
                        pdappAPI.layer.afterUpdateArea(
                            a,
                            e.pageAdd.data.views[e.productActive.view],
                            e.pageAdd.data.unit.type,
                            function (t) {
                                e.pageAdd.data.views[e.productActive.view] = t;
                            }
                        );
                });
        },
        fitInside() {
            let t = this,
                e = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                (pdappAPI.tool.targets = []),
                pdappAPI.tool.fitInside(e),
                setTimeout(() => {
                    (pdappAPI.tool.pdappMoveAbleRef.target = e[0]),
                        (pdappAPI.tool.targets = e[0]),
                        pdappAPI.layer.afterUpdateArea(
                            e,
                            t.pageAdd.data.views[t.productActive.view],
                            t.pageAdd.data.unit.type,
                            function (e) {
                                t.pageAdd.data.views[t.productActive.view] = e;
                            }
                        );
                });
        },
        changeMaskFile(t, e) {
            if (void 0 === t.target.files[0]) return !1;
            const a = t.target.files[0];
            let d = this;
            pdappAPI.layer.changeMaskLayer(a, function (t) {
                (d.pageAdd.data.views[d.productActive.view].layers[e].mask = t), jQuery(".pdapp-input-file").val("");
            }) ||
                ((d.toast = { show: !0, type: "error", text: d.langs.msg.file_type_error + " PNG" }),
                setTimeout(() => {
                    d.toast.show = !1;
                }, 5e3));
        },
        changeMaskLayer(t) {
            if (void 0 === t.target.files[0]) return !1;
            const e = t.target.files[0];
            let a = this;
            pdappAPI.layer.changeMaskLayer(e, function (t) {
                let e = {
                    image: t,
                    top: 0,
                    left: 0,
                    width: a.pageAdd.data.views[a.productActive.view].canvas.width,
                    height: a.pageAdd.data.views[a.productActive.view].canvas.height,
                };
                (a.pageAdd.data.views[a.productActive.view].mask = e), jQuery(".pdapp-input-file").val("");
            }) ||
                ((a.toast = { show: !0, type: "error", text: a.langs.msg.file_type_error + " PNG" }),
                setTimeout(() => {
                    a.toast.show = !1;
                }, 5e3));
        },
        removeMask() {
            (this.viewActive.mask = {}), (pdappAPI.tool.pdappMoveAbleRef.target = null), (pdappAPI.tool.targets = []);
        },
        addExtraAttribute(t) {
            let e = [],
                a = "";
            void 0 !== t && void 0 !== this.pageAdd.data.extras[t]
                ? ((a = this.pageAdd.data.extras[t].title),
                  (e = JSON.parse(JSON.stringify(this.pageAdd.data.extras[t].values))))
                : (t = ""),
                (this.modal = {
                    show: !0,
                    header: !0,
                    title: this.langs.product.add_attribute,
                    type: "extra",
                    data: { attrs: e, attr: a, edit: t },
                });
        },
        removeExtraAttr(t) {
            let e = this,
                a = JSON.parse(JSON.stringify(e.pageAdd.data.extras));
            a.splice(t, 1),
                e.pageAdd.data.attributes.values.length
                    ? (e.modal = {
                          show: !0,
                          header: !1,
                          title: "",
                          size: "md modal-dialog-centered",
                          type: "message",
                          data: {
                              title: e.langs.msg.generator_attr,
                              text: e.langs.msg.generator_attr_data,
                              type: "warning",
                              btn: e.langs.ok,
                              confirm: "attr",
                              attr: { type: "extra", value: a },
                          },
                      })
                    : e.generatorAttribute("extra", a);
        },
        addAttr() {
            this.modal.data.attrs.push("");
        },
        saveAttrs() {
            let t = this,
                e = JSON.parse(JSON.stringify(this.pageAdd.data.extras));
            "" !== this.modal.data.edit && void 0 !== e[this.modal.data.edit]
                ? (e[this.modal.data.edit] = { title: this.modal.data.attr, active: 0, values: this.modal.data.attrs })
                : e.push({ title: this.modal.data.attr, active: 0, values: this.modal.data.attrs }),
                t.pageAdd.data.attributes.values.length
                    ? (t.modal = {
                          show: !0,
                          header: !1,
                          title: "",
                          size: "md modal-dialog-centered",
                          type: "message",
                          data: {
                              title: t.langs.msg.generator_attr,
                              text: t.langs.msg.generator_attr_data,
                              type: "warning",
                              btn: t.langs.ok,
                              confirm: "attr",
                              attr: { type: "extra", value: e },
                          },
                      })
                    : t.generatorAttribute("extra", e);
        },
        confirmGeneratorAttr(t, e) {
            let a = e.target.value,
                d = this;
            d.pageAdd.data.attributes.values.length
                ? ((d.modal = {
                      show: !0,
                      header: !1,
                      title: "",
                      size: "md modal-dialog-centered",
                      type: "message",
                      data: {
                          title: d.langs.msg.generator_attr,
                          text: d.langs.msg.generator_attr_data,
                          type: "warning",
                          btn: d.langs.ok,
                          confirm: "attr",
                          attr: { type: t, value: a },
                      },
                  }),
                  (e.target.value = "color" == t ? d.pageAdd.data.attributes.color : d.pageAdd.data.attributes.size))
                : d.generatorAttribute(t, a);
        },
        generatorAttribute(t, e) {
            let a = this;
            "color" == t && (a.pageAdd.data.attributes.color = e),
                "size" == t && (a.pageAdd.data.attributes.size = e),
                "extra" == t && (a.pageAdd.data.extras = e),
                (a.modal.show = !1),
                (a.pageAdd.data.attributes.values = []),
                pdappAPI.attr.generatorAttr(a.pageAdd.data, function (t) {
                    a.pageAdd.data.attributes.values.push(t);
                });
        },
        addDiscount() {
            let t = 1;
            if (this.pageAdd.discount.list.length) {
                let e = this.pageAdd.discount.list[this.pageAdd.discount.list.length - 1];
                t =
                    e.qty < 10
                        ? 10
                        : e.qty < 100
                          ? 100
                          : e.qty < 1e3
                            ? 1e3
                            : e.qty < 1e4
                              ? 1e4
                              : e.qty < 1e5
                                ? 1e5
                                : 1e6;
            }
            this.pageAdd.discount.list.push({ qty: t, price: 0 });
        },
        async saveProduct() {
            let t = this;
            (t.pageAdd.saving = !0),
                t.pageAdd.layout.customize || t.pageAdd.layout.customview
                    ? (t.pageAdd.data.advanced = t.pageAdd.layout)
                    : (t.pageAdd.data.advanced = {
                          cartdesign: t.pageAdd.layout.cartdesign,
                          addons: t.pageAdd.layout.addons,
                          customize: !1,
                      }),
                (t.pageAdd.data.advanced.discount = t.pageAdd.discount),
                (t.pageAdd.data.advanced.minQty = t.pageAdd.minQty),
                (t.pageAdd.data.advanced.tempID = t.pageAdd.tempID),
                (t.pageAdd.data.advanced.artID = t.pageAdd.artID),
                (t.pageAdd.data.advanced.relatives = t.pageAdd.relatives);
            let e = JSON.parse(JSON.stringify(t.pageAdd.data));
            (e.unit = JSON.stringify(e.unit)),
                (e.colors = JSON.stringify(e.colors)),
                (e.sizes = JSON.stringify(e.sizes)),
                (e.views = JSON.stringify(e.views)),
                (e.attributes = JSON.stringify(e.attributes)),
                (e.advanced = JSON.stringify(e.advanced)),
                void 0 !== e.extras && (e.extras = JSON.stringify(e.extras));
            let a = pdappAdminUrl + "admin-ajax.php?action=pdapp-save-product&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let d = new Blob([JSON.stringify(e)], { type: "application/json" }),
                    o = new FormData();
                o.append("product", d, "product.json");
                let p = await pdappAPI.tool.uploadData(a, o);
                if (((t.pageAdd.show = !1), (t.pageList.show = !0), "" == t.pageAdd.data.id))
                    t.pageList.data.push(p.data);
                else
                    for (let e = 0; e < t.pageList.data.length; e++)
                        t.pageList.data[e].id == t.pageAdd.data.id && (t.pageList.data[e] = p.data);
                (t.toast = { show: !0, type: "success", text: p.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3),
                    pdappAPI.tool.updateURL("products");
            } catch (e) {
                (t.toast = { show: !0, type: "warning", text: e.msg }),
                    setTimeout(() => {
                        t.toast.show = !1;
                    }, 5e3);
            }
            t.pageAdd.saving = !1;
        },
        exportProduct() {
            let t = this;
            t.pageAdd.saving = !0;
            let e = JSON.parse(JSON.stringify(t.pageAdd.data));
            t.pageAdd.layout.customize || t.pageAdd.layout.customview
                ? (e.advanced = t.pageAdd.layout)
                : (e.advanced = { cartdesign: t.pageAdd.layout.cartdesign, customize: !1 }),
                (e.advanced.discount = t.pageAdd.discount),
                (e.advanced.minQty = t.pageAdd.minQty),
                (e.advanced.tempID = t.pageAdd.tempID),
                (e.advanced.artID = t.pageAdd.artID),
                (e.advanced.relatives = t.pageAdd.relatives),
                pdappAPI.exportData(e, function (e) {
                    e.id = "";
                    let a = "" != e.title ? e.title : "Untitled",
                        d = { type: "product", data: e },
                        o = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(d)),
                        p = document.createElement("a");
                    (p.href = o),
                        (p.download = t.sanitizeFileName(a) + ".json"),
                        document.body.appendChild(p),
                        p.click(),
                        delete p;
                }),
                (t.pageAdd.saving = !1);
        },
        sanitizeFileName: (t) => t.replace(/[\\/:"*?<>|]/g, "").replace(/\0/g, ""),
        uploadProductFile(t) {
            let e = this;
            if (void 0 === t.target.files[0]) return !1;
            let a = t.target.files[0],
                d = a.name.split("."),
                o = d[d.length - 1];
            (o = o.toLowerCase()),
                "json" == o &&
                    e.loadProductJson(a, function (t, a) {
                        t && e.uploadProduct(a);
                    }),
                (t.target.value = ""),
                (this.modal.upload = !0);
        },
        async uploadProduct(t, e) {
            let a = this;
            a.loadingPage = !0;
            let d = !1;
            for (let e = 0; e < a.printings.length; e++) parseInt(a.printings[e].id) == parseInt(t.pid) && (d = !0);
            d || (t.pid = void 0 !== a.printings[0] ? a.printings[0].id : 0);
            let o = JSON.parse(JSON.stringify(t));
            (o.unit = JSON.stringify(o.unit)),
                (o.colors = JSON.stringify(o.colors)),
                (o.sizes = JSON.stringify(o.sizes)),
                (o.views = JSON.stringify(o.views)),
                (o.attributes = JSON.stringify(o.attributes)),
                (o.advanced = JSON.stringify(o.advanced)),
                void 0 !== o.extras && (o.extras = JSON.stringify(o.extras));
            let p = pdappAdminUrl + "admin-ajax.php?action=pdapp-upload-product&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let t = new Blob([JSON.stringify(o)], { type: "application/json" }),
                    d = new FormData();
                d.append("product", t, "product.json");
                let i = await pdappAPI.tool.uploadData(p, d);
                a.pageList.data.push(i.data),
                    (a.toast = { show: !0, type: "success", text: i.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3),
                    void 0 !== e &&
                        "" != e &&
                        postToChild(document.getElementById("pdapp-resource-frame"), "addedproduct", e);
            } catch (t) {
                (a.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        a.toast.show = !1;
                    }, 5e3);
            }
            a.loadingPage = !1;
        },
        loadProductJson(t, e) {
            const a = new FileReader();
            (a.onload = () => {
                let t = a.result.replace("data:application/json;base64,", ""),
                    d = JSON.parse(pdappAPI.decodeBase64(t)),
                    o = void 0 !== d.type && "product" == d.type;
                void 0 === d.data && (o = !1), "function" == typeof e && e(o, d.data);
            }),
                a.readAsDataURL(t);
        },
        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 e = this,
                a = pdappAdminUrl + "admin-ajax.php?action=pdapp-dashboard-purchased&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                await pdappAPI.tool.postData(a, { purchased: e.modal.purchased });
                (e.pdappPurchasedCode = e.modal.purchased), e.checkAuthCode(t.data);
            } catch (t) {
                (e.toast = { show: !0, type: "warning", text: t.msg }),
                    setTimeout(() => {
                        e.toast.show = !1;
                    }, 5e3);
            }
        },
        checkAuthCode(t) {
            let e = this;
            void 0 !== t.refreshToken &&
                "" != t.refreshToken &&
                ((e.pdappApiToken = t.refreshToken), pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken)),
                "shop" == t.scope
                    ? ((e.modal.show = !1), e.showStore || ((e.showStore = !0), e.showProductStore()))
                    : "confirm" == t.scope
                      ? ((e.modal = {
                            show: !0,
                            type: "confirmemail",
                            code: t.code,
                            email: t.email,
                            verifing: !1,
                            error: "",
                            scope: t.scope,
                        }),
                        (e.confirmEmail.timeLess = parseInt(t.time)),
                        e.countDown())
                      : ("verify" != t.scope && "code" != t.scope) ||
                        (e.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 e = this;
            t && ((e.pdappApiToken = ""), pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken)),
                (e.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 e = this;
            if (0 == t.error)
                return (
                    void 0 !== e.modal.type && "verifycode" == e.modal.type
                        ? void 0 !== t.data && void 0 !== t.data.platform && t.data.platform == pdappPlatform
                            ? e.updatePurchased(t)
                            : ((e.modal.error = "Your platform verify incorrect"), (e.modal.verifing = !1))
                        : e.checkAuthCode(t.data),
                    !1
                );
            void 0 !== e.modal.type && "verifycode" == e.modal.type
                ? ((e.modal.error = t.msg), (e.modal.verifing = !1))
                : "" != e.pdappApiToken && "" != e.pdappPurchasedCode
                  ? ((e.pdappApiToken = ""),
                    pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken),
                    postToChild(document.getElementById("pdapp-login-frame"), "verifycode", {
                        purchased: e.pdappPurchasedCode,
                        domain: pdappDomain,
                    }))
                  : (e.modal = {
                        show: !0,
                        type: "verifycode",
                        purchased: e.pdappPurchasedCode,
                        error: "",
                        checked: !1,
                        verifing: !1,
                    });
        },
        onAuthEmail(t) {
            let e = this;
            if (((e.modal.verifing = !1), 0 == t.error))
                return (
                    (e.modal.show = !0),
                    (e.modal.email = t.data.email),
                    (e.modal.code = t.data.code),
                    (e.modal.scope = t.data.scope),
                    (e.pdappApiToken = t.data.refreshToken),
                    pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken),
                    (e.confirmEmail.timeLess = parseInt(t.data.time)),
                    e.countDown(),
                    (e.modal.type = "confirmemail"),
                    !1
                );
            e.modal.error = t.msg;
        },
        onAuthRefreshEmail(t) {
            let e = this;
            (e.confirmEmail.refresh = !1),
                0 == t.error
                    ? ((e.pdappApiToken = t.data.refreshToken),
                      pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken),
                      (e.confirmEmail.timeLess = parseInt(t.data.time)))
                    : (e.confirmEmail.error = t.msg);
        },
        onAuthConfirmEmail(t) {
            let e = this;
            0 == t.error
                ? ((e.modal.email = t.data.email),
                  (e.modal.code = t.data.code),
                  (e.modal.scope = t.data.scope),
                  (e.confirmEmail.timeLess = -1),
                  e.expireConfirmCode(!1),
                  (e.pdappApiToken = t.data.refreshToken),
                  pdappAPI.tool.setLocalVar("pdapp_api_token", e.pdappApiToken),
                  (e.confirmEmail.timeLess = parseInt(t.data.time)))
                : (e.confirmEmail.error = t.msg),
                (e.confirmEmail.verifing = !1);
        },
        showProductStore() {
            let t = this;
            "" != t.pdappPurchasedCode
                ? t.showStore
                    ? ((t.modal = { store: !0 }),
                      "" != t.pdappApiToken &&
                          postToChild(document.getElementById("pdapp-resource-frame"), "startproduct", 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();
        },
        onImportProduct(t) {
            if (void 0 === t.id || void 0 === t.data) return !1;
            this.uploadProduct(t.data, t.id);
        },
        toUnitVal(t) {
            let e = t;
            return (
                "px" == this.pageAdd.data.unit.type && (e = pdappAPI.tool.toPx(t, "px")),
                "cm" == this.pageAdd.data.unit.type && (e = pdappAPI.tool.toCm(t, "px")),
                "in" == this.pageAdd.data.unit.type && (e = pdappAPI.tool.toIn(t, "px")),
                e
            );
        },
    },
}).mount("#productdesignerapp-app");
function postToChild(t, e, a) {
    t.contentWindow.postMessage({ type: e, data: a }, pdappHomeUrl);
}
window.onmessage = function (t) {
    if (void 0 !== t.data.type) {
        let e = t.data.type,
            a = t.data.data;
        "loadedstore" == e && "ok" == a && (pdappVueApp.loadedStore = !0),
            "importproduct" == e && pdappVueApp.onImportProduct(a),
            "authcode" == e && pdappVueApp.onAuthCode(a),
            "authemail" == e && pdappVueApp.onAuthEmail(a),
            "authrefreshemail" == e && pdappVueApp.onAuthRefreshEmail(a),
            "authconfirmemail" == e && pdappVueApp.onAuthConfirmEmail(a);
    }
};