var BASE_URL = 'https://imprint.mibmsdev.co.za/designer/'
  , STORE_URL = 'https://imprint.mibmsdev.co.za/'
  , SECRET_KEY='SgUkXp2s5v8y/B?E(H+MbQeThWmYq3t6w9z^C&F)J@NcRfUjXn2r4u7x!A%D*G-K', RVN = 78, LANG = 'en'
  , DPI = 96
  , FORCE_RETAIN_DESIGN = true
  , STORE = 'Others', SHOW_TOOL_BAR = false
  , COLOR_NO = 6
  , CONVERTED_SVG_COLOR_CHANGE = true
  , IS_CUSTOM_DEVELOPMENT = false
  , COMMA_SEPARATE_PRICE = true
  , HIDE_DECIMAL_PRICE = false
  , DEFAULT_EDIT_TEMPLATE = false
  , SHARE_WITH_LINK = false
  , TEMPLATE_RESIZE = true
  , CMPLX_SVG_COLOR_CHANGE = true
  , PRINT_AREA_THICKNESS = 1
  , ENABLE_CLIPART_COLOR = true;

// --------------------Multi store starts------------------
let tempUrl = "";
tempUrl = "Shopify" !== STORE && "Bigcommerce" !== STORE && "Others" !== STORE && "Hosted" !== STORE ? window.parent.location.href : window.location.href;
let curnetUrl2 = new URL(tempUrl)
  , currentUrl = tempUrl.includes("id=") || "" == tempUrl ? new URL(tempUrl) : decrypt(tempUrl);
tempUrl.includes("id=") || (currentUrl = new URLSearchParams(currentUrl));
let storeId = tempUrl.includes("id=") ? currentUrl.searchParams.get("store_id") : currentUrl.get("store_id");
if (storeId && (storeId = parseInt(storeId)) > 1) {
    let e = new URL(BASE_URL)
      , r = new URL(STORE_URL);
    BASE_URL = BASE_URL.replace(e.origin, curnetUrl2.origin),
    STORE_URL = STORE_URL.replace(r.origin, curnetUrl2.origin)
}
//---------------------Multi store ends--------------------

// --------------- load product data starts ---------------
function loadProdData() {
    try {
        window.in_isapicall = "1";
        let t = getUrlAfterDecode();
        if (t.get("id")){
            i = t.get("id"),
            r = t.get("vid"),
            tid = t.get("tier_id"),
            a = t.get("option_id"),
            o = t.get("store_id") ? parseInt(t.get("store_id")) : 1,
            n = t.get("temp"),
            d = t.get("quot");
        }
        else {
            let e = getParentUrlAfterDecode();
            i = e.get("id"),
            r = e.get("vid"),
            tid = e.get("tier_id"),
            a = e.get("option_id"),
            o = e.get("store_id") ? parseInt(e.get("store_id")) : 1,
            n = e.get("temp"),
            d = e.get("quot")
        }
        var i, r, a, o, n, d, c = "";
        i && r ? (c = a ? n || d ? BASE_URL + "api/v1/product-details/" + i + "?variant_id=" + r + "&option_id=" + a + "&store_id=" + o + "&source=admin" : BASE_URL + "api/v1/product-details/" + i + "?variant_id=" + r + "&option_id=" + a + "&store_id=" + o : n || d ? BASE_URL + "api/v1/product-details/" + i + "?variant_id=" + r + "&store_id=" + o + "&source=admin" : BASE_URL + "api/v1/product-details/" + i + "?variant_id=" + r + "&store_id=" + o + "&tier_id=" + tid,
        fetch(c).then(t=>t.json()).then(t=>{
            console.log("Success on indexHTML:", t.data);
            t.status ? window.in_prodData = JSON.stringify(t.data) : window.in_prodData = JSON.stringify({})
        }
        ).catch(t=>{
            window.in_prodData = JSON.stringify({})
        }
        )) : window.in_prodData = JSON.stringify({})
    } catch (l) {}
}
function decrypt(t) {
    t = window.atob(t.split("?")[1]);
    let e, i = "";
    for (let r = 0; r < t.length; r++)
        i += e = String.fromCharCode(t[r].charCodeAt(0) - 53);
    return i.split(window.SECRET_KEY)[0].split("&").toString().replaceAll(",", "&")
}
function getParentUrlAfterDecode() {
    let t;
    return window.parent.location.search.includes("id=") || "" == window.parent.location.search ? t = new URLSearchParams(window.parent.location.search) : (t = decrypt(window.parent.location.search),
    t = new URLSearchParams(t)),
    t
}
function getUrlAfterDecode() {
    let t;
    return window.location.search.includes("id=") || "" == window.location.search ? t = new URLSearchParams(window.location.search) : (t = decrypt(window.location.search),
    t = new URLSearchParams(t)),
    t
}
loadProdData();
// --------------- load product data ends ---------------
