window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=function(t,e){e=e||window;for(let a=0;a1&&i.includes(theme.shop.currency.symbol)?a.slice(0,-1).join(" - ").trim():t}function _(t){let e=this;this._expectsJson=!0,this.expectsJson=function(e){return console.log("Set expectJson to ("+e+") for "+t),this._expectsJson=e,this};let a=new XMLHttpRequest;this.error=!1,this.errorCallback=function(t,e){return h("DEFAULT ERROR: "+t,"error"),h(e),this},this.get=function(e){return this.callback=e,a.open("GET",t),a.timeout=1e4,a.send(),h("AJAX GET executed for "+t),this},this.post=function(e,i,n){for(let o in this.callback=i,a.open("POST",t),a.timeout=1e4,a.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),a.setRequestHeader("Accept","application/json"),n)a.setRequestHeader(o,n[o]);var r=Object.keys(e).map(function(t){return t+"="+e[t]}).join("&");return a.send(r),h("AJAX POST executed for "+t+" with data:"),h(r),this},this.error=function(t){return this.errorCallback=t,this},a.onload=function(){if(h("AJAX Onload completed for "+t),this.status>=200&&this.status<400){if(e._expectsJson){try{let a=JSON.parse(this.response);e.callback(a)}catch(i){e.errorCallback("No valid JSON returned",i)}return}e.callback(this.response);return}e.errorCallback("Unknown error (HTTP "+this.status+"). Please try again later, apologies for the inconvenience.",this)},a.onerror=function(){e.errorCallback("Unknown error. Please try again later, apologies for the inconvenience.",this)},a.ontimeout=function(){e.errorCallback("Request timed out...",this)}}this.helpers={makeSelectsVisible:function(){o(".dy-advanced-variants-form-loading").forEach(function(t){t.classList.remove("dy-advanced-variants-form-loading")})},parsePrice:function(t){return(t=parseFloat(t),-1!==["USD","GBP","CAD"].indexOf(theme.shop.currency.code.toUpperCase()))?theme.shop.currency.symbol+(t*theme.shop.currency.ratio).toFixed(2):theme.shop.currency.symbol+(t*theme.shop.currency.ratio).toFixed(2).replace(".",",")},getShopVatType:function(){return theme.shop.b2b?"excl":"incl"}},this.debug={enable:function(){localStorage.setItem("dyapps_debug",!0)},disable:function(){localStorage.removeItem("dyapps_debug")},disableAddons:function(){localStorage.setItem("dyapps_disable",!0)},enableAddons:function(){localStorage.removeItem("dyapps_disable")},enableParsetimeLogs:function(){localStorage.setItem("log_parsetime",!0)},disableParsetimeLogs:function(){localStorage.removeItem("log_parsetime")},getParseTimes:function(){return a}},this.advancedVariants=new function(){if(!s.advancedVariants.enabled){console.log("ThemeAddons::AdvancedVariants disabled, bail..");return}let a=this,n=new p("advancedVariantsTotal"),r="blocks",l="advanced_variants";if(this.parseCollectionGrid=function(){let t=new p("parseCollectionGrid");console.log("ScanGrid()"),console.group();let e=o(".product-block");[].forEach.call(e,function(t){let e=t.dataset.pid,i=theme.productHandler.storage[e]||!1;i&&(h("Forcing swatch process for pid "+e),a.injectSwatchesIntoGridProduct(i,t))}),t.stop(),t.log(),console.groupEnd()},this.getColorGroup=function(t){let e=new p("getColorGroup"),a={},i=[],n={},o=[];for(let r in t.variants){let l=t.variants[r],d=l.title;t.matrix&&(d=-1!==d.indexOf('","')?d.replace(RegExp(/^"|"$/,"g"),"").replace(RegExp(/","/,"g"),", ").replace(/\s+/g," ").replace(" :",":").trim():d.replace(" :",":")),a[d.toLowerCase()]=l;d.toLowerCase().split(s.matrix_separator).forEach(function(e){let a=e.split(":"),s=a[0].trim(),l=a[1]||a[0];l=l.trim(),t.options||t.matrix||(s="default"),h(" - GroupName: "+s+" variantName: "+l),n[s]=n[s]||[],n[s].includes(l)||(n[s].push(l),o[l]=r),c[l]&&!i.includes(s)&&i.push(s)})}let u=i[0]||null;return(e.stop(),e.log(),u)?{groupNamesWithColors:i,availableColors:n[u],variantIdsPerColor:o,variantsByName:a}:{groupNamesWithColors:null,availableColors:null,variantIdsPerColor:null,variantsByName:a}},this.injectSwatchesIntoGridProduct=function(t,e){if(s.plan.can_data01_colors){let a=e.querySelector(".dy-data01-colors");a&&a.classList.add("dy-visible")}if(!t.variants){h(" No variants found: "+t.title,"color:#000; background:#eee;");return}if(v(l,t.data_01)){h("Disabled advanced variants for: "+t.title,"color:#fff; font-weight:bold; background:#f00000;");return}g(" Start injectSwatches for: "+t.title,!0);let i=t;new p("injectSwatchesIntoGridProduct");let n=this.getColorGroup(i);if(n&&n.availableColors){h(n);let o=e.querySelector(s.advancedVariants.grid_swatches_container_selector||".dy-collection-grid-swatch-holder");if(!o){h("holderElem .dy-collection-grid-swatch-holder not found. Probably custom color swatches in data 01?");return}let r=0,c=document.createElement("div");for(let d in c.classList.add("dy-collection-color-swatches"),n.availableColors){if(r>=s.advancedVariants.grid_swatches_max_colors)break;let u=n.availableColors[d],f=n.variantIdsPerColor[u]||0,$=y(u);if(!f){h("No variant ID found for colorName "+u,"background:orange; color:#000;");continue}let _=document.createElement("a");_.href=theme.url.shop+i.url+"?id="+f,_.title=u,_.classList.add("dy-variant-color","dy-color-swatch"),_.classList.add("dy-text-"+s.advancedVariants.grid_swatches_position),_.classList.add("dy-justify-content-"+s.advancedVariants.grid_swatches_position),_.setAttribute("data-title",u),b(_,$),c.appendChild(_),r++}n.availableColors&&n.availableColors.length>s.advancedVariants.grid_swatches_max_colors&&c.insertAdjacentHTML("beforeend",'
+'+(n.availableColors.length-s.advancedVariants.grid_swatches_max_colors)+"
"),o.appendChild(c)}m()},s.advancedVariants.grid_swatches_enabled&&(h("advancedVariants - parseGridBlocks()","background:blue;"),window.addEventListener("themeProductBlockLoaded",function(t){h("Called listener themeProductBlockLoaded for: "+t.detail.product.title,"background:#fff; color:#ccc;"),a.injectSwatchesIntoGridProduct(t.detail.product,t.detail.element)})),this.currentOptionsPath=[],this.parseProductPage=function(e){if(v(l,e.data_01)){h("Disabled advanced variants for this product","color:#fff; font-weight:bold; background:#f00000;"),t.helpers.makeSelectsVisible();return}g("DyApps Addons :: advancedVariants.parseProductPage()"),h(e);let n=new p("parseProductPage"),c=[i("product_configure_variants")],_=d.VARIANTS,k=e.matrix||e.options;if(!e.variants){h("No variants found, bail","background:orange;");return}if((e.matrix||e.options)&&(_=e.matrix?d.MATRIX:d.OPTIONS,c=o(".product-configure-options-option select[id^=product_configure]")),!c.length||c.length&&null===c[0]){h("Product has variants but no selects found...","background:red;");return}h("VariantsType: "+_+", optional groups:"),h(k);let w=a.getColorGroup(e),L=w.variantsByName;window.variantsByName=L,h("Color groups found:"),h(w),c.forEach(function(t,e){g("Current dropdown (index: "+e+")",!0),h(t);let i=!1,n=null,o="default";if(["matrix","options"].includes(_)&&k){let l=t.getAttribute("name").replace("option[","").replace("matrix[","").replace("]","");h("OptionGroupId "+l),h(Object.keys(k)),o=k[n=l].title.toLowerCase()}h("Current matrix groupId: "+n+" has groupName: "+o),w.groupNamesWithColors&&w.groupNamesWithColors.includes(o)&&(h("Groupname "+o+" in colorGroups.groupNamesWithColors","background:lime;"),i=!0);let p=document.createElement("select");if(i)(p=document.createElement("div")).classList.add("dy-flex-group","dy-variant-color-group");else if("default"===s.advancedVariants.display_type){t.classList.add("dy-loaded");return}else s.advancedVariants.display_type===r?(p=document.createElement("div")).classList.add("dy-flex-group","dy-variant-block-group"):(p.classList.add("fancy-select"),p.addEventListener("change",function(e){t.value=this.options[this.selectedIndex].value,t.dispatchEvent(new Event("change"))}));if(h("Looping through dropdown options to create html options/blocks"),[].forEach.call(t.options,function(e,n){var c,l,f,g,m,v,k,w,L;let A="",E=e.value===t.options[t.selectedIndex].value,P=$(e.text);if(h(' - parsing option "'+P+'"'),i||s.advancedVariants.display_type===r){let x,C,T,I,S,V;(A=i?(c=e,l=o,f=E,C=y(x=$(c.innerText)),h('Creating color swatch for name: "'+x+'" / optioninnertext: "'+c.innerText+'"'),(T=document.createElement("a")).classList.add("dy-item-selectable","dy-variant-block-swatch","dy-color-swatch"),T.innerHTML=x,f&&T.classList.add("dy-variant-active","dy-active"),_===d.VARIANTS?T.setAttribute("data-variant",x):(T.setAttribute("data-group",l),T.setAttribute("data-variant",l+": "+x)),T.setAttribute("data-variant-type",_),T.setAttribute("data-value",c.value),T.setAttribute("title",x),s.advancedVariants.large_swatches&&T.classList.add("dy-swatch-large"),b(T,C),T):(g=e,m=o,v=E,I=$(g.innerText,!1),(S=document.createElement("a")).classList.add("dy-variant-block"),v&&S.classList.add("dy-variant-active","dy-active"),_===d.VARIANTS?S.setAttribute("data-variant",I.toLowerCase()):_===d.MATRIX?(S.setAttribute("data-group",m),S.setAttribute("data-variant",m+": "+I)):(S.setAttribute("data-group",m),S.setAttribute("data-variant",m+": "+I.toLowerCase())),S.setAttribute("data-variant-type",_),S.setAttribute("data-value",g.value),S.setAttribute("title",I),(V=document.createElement("span")).classList.add("dy-variant-block-inner"),V.innerHTML=I,S.appendChild(V),S)).addEventListener("click",function(e){let a=e.currentTarget.getAttribute("data-value");h("Clicked value: "+a),t.value=a,t.dispatchEvent(new Event("change"))}),p.appendChild(A)}else{let M,O;A=(k=e,w=o,L=E,M=k.innerText,(O=document.createElement("option")).classList.add("variant-option"),_===d.VARIANTS?(O.setAttribute("data-variant",$(M,!1)),u("vat_switcher_enabled")&&(M+=" "+(theme.shop.b2b?theme.text.exclVAT:theme.text.inclVAT))):(O.setAttribute("data-group",w),O.setAttribute("data-variant",w+": "+M)),O.setAttribute("data-variant-type",_),O.setAttribute("data-value",k.value),O.value=k.value,O.selected=L,O.innerText=M,O.setAttribute("title",M),O)}p.appendChild(A),E&&(h(' - option "'+P+'" is selected',"background:#009900;"),a.currentOptionsPath.push(o+": "+P))}),t.parentElement.appendChild(p),t.style.display="none",p.setAttribute("data-group-index",e),setTimeout(function(){p.classList.add("dy-loaded")},50),s.advancedVariants.disable_out_of_stock&&e===c.length-1){g("Last element in loop done, now check stock.....",!0),h(a.currentOptionsPath),h(L);f(document.querySelectorAll("[data-group-index]"),function(t,e){let i="SELECT"===e.tagName;f(e.children,function(e,n){h(n);let o="",r=a.currentOptionsPath.slice(0);r[t]=n.getAttribute("data-variant"),o=r.join(", ");let c=L[o.toLowerCase()];if(c||_!==d.MATRIX){if(!c){h("no variant found with name: ["+o.toLowerCase()+"]","background:red;");return}}else{n.setAttribute("data-tree",o),i?n.innerText+=" ("+theme.text.outOfStock+")":(n.classList.add("dy-variant-block-out-of-stock"),s.advancedVariants.variant_status_icon&&n.classList.add("dy-variant-with-status-icon"));return}h('full variant by name "'+o+'": '),h(L[o]),n.setAttribute("data-tree",o),i?c.stock.available||(n.innerText+=" ("+theme.text.outOfStock+")"):(c.stock.available?n.classList.add("dy-variant-block-in-stock"):n.classList.add("dy-variant-block-out-of-stock"),s.advancedVariants.variant_status_icon&&n.classList.add("dy-variant-with-status-icon"))})}),m()}h("done parsing group "+o),m()}),m(),n.stop(),n.log()},this.parseCustomOptions=function(e){if(g("Addons.parseCustomOptions()",!0),!e.custom){h("No custom fields, nothing to parse, bail");return}let a=o('select[id^="product_configure_custom_"]');f(a,function(a,i){let n=!1;h("processing elements"),h(i);let r=i.getAttribute("name").replace("custom[","").replace("]",""),c=e.custom[r];if(h(c),h(c.values),c&&s.swatchesForCustomFields.includes(c.title.toLowerCase())){let l=document.createElement("div");l.classList.add("dy-product-configure-custom-option","dy-option-swatches","dy-option-select","dy-flex-group"),l.setAttribute("data-name",c.title.toLowerCase()),f(i.options,function(e,a){h("Looping through options for group: "+c.title);let d=a.value;if(!d){n=!0;return}let u=d===i.options[i.selectedIndex].value;$(a.text),h(" -- optionValueid: "+d);let p=c.values[d],f=document.createElement("div");f.classList.add("dy-product-option-swatch-holder","dy-flex-group-item"),u&&f.classList.add("dy-active");let g=y(p.title),m=document.createElement("div");if(b(m,g),m.addEventListener("click",function(t){let e=t.currentTarget.getAttribute("data-value"),a=t.currentTarget.getAttribute("data-option-id");h("Clicked custom option value: "+e),o('[data-option-id="'+a+'"]').forEach(function(t){t.classList.remove("dy-active")}),i.value==e?i.value="":(t.currentTarget.classList.add("dy-active"),i.value=e),i.dispatchEvent(new Event("change"))}),m.classList.add("dy-item-selectable","dy-product-option-swatch"),m.title=p.title,m.setAttribute("data-value",d),m.setAttribute("data-option-id",r),f.appendChild(m),s.advancedVariants.option_swatch_show_name){let v=document.createElement("div");v.classList.add("dy-option-swatch-name"),v.textContent=p.title,f.appendChild(v)}if(p.price){let _=document.createElement("div");_.classList.add("dy-option-swatch-price"),_.textContent="+"+t.helpers.parsePrice(p.price),f.appendChild(_)}l.appendChild(f)}),i.parentElement.appendChild(l),i.style.display="none"}}),m()},"pages/product.rain"===theme.template){let k=new p("totalPPParsetime");theme.pageData.product?(a.parseProductPage(theme.pageData.product),s.swatchesForCustomFields&&a.parseCustomOptions(theme.pageData.product),k.stop(),k.log()):new _(e+"?format=json").get(function(t){h("got product AJAX","background:#009900;"),a.parseProductPage(t.product),s.swatchesForCustomFields&&a.parseCustomOptions(theme.pageData.product),k.stop(),k.log()})}n.stop(),n.log()},u("vat_switcher_enabled")&&(this.vatSwitcher=new function(){let t=this,e=u("b2b_default_pricing"),a="incl"===e?"excl":"incl",i=!1;this.isEnabled=function(){return i},this.getType=function(){return this.getUserPrefType()||e},this.getOppositeType=function(){return"excl"===(this.getUserPrefType()||e)?"incl":"excl"},this.getUserPrefType=function(){return localStorage.getItem("vat_type_pref")},this.showIncl=function(t){void 0!==t||(n("body").classList.remove("b2b-pricing-excl"),n("body").classList.add("b2b-pricing-incl"))},this.showExcl=function(t){n("body").classList.remove("b2b-pricing-incl"),n("body").classList.add("b2b-pricing-excl")},this.toggleElements=function(){h("vatSwitcher.toggleElements()"),"incl"==this.getType()?this.showIncl():this.showExcl()},this.init=function(){g("Init VAT switcher",!0),h("Userpref: "+this.getUserPrefType()),h("PrefOpposite: "+this.getOppositeType()),h("Pref: "+this.getType()),h("Default vat: "+e),m(),i=!0,o(".vat-switcher-checkbox").forEach(function(i){i.addEventListener("click",function(n){h("Clicked vat switch toggle"),i.checked?localStorage.setItem("vat_type_pref",e):localStorage.setItem("vat_type_pref",a),t.toggleElements(),o(".vat-switcher-checkbox").forEach(function(t){t.checked=i.checked})})}),o(".vat-switcher-checkbox").forEach(function(a){a.checked=t.getType()===e}),this.toggleElements()}},this.vatSwitcher.init()),"pages/product.rain"===theme.template&&s.advancedVariants.live_pricing&&(this.livePricing=new function(){let a=this;this.options={},this.productBasePrice=0,this.productBasePriceIncl=0,this.productBasePriceExcl=0,this.getSelectedOptions=function(){return document.querySelectorAll('.product-configure-custom select, .product-configure-custom input[type="checkbox"]:checked, .product-configure-custom input[type="radio"]:checked')},this.calculateAdditionalPrice=function(){let t=0;return this.getSelectedOptions().forEach(function(e){let i=e.value;h("Selected option ID: "+i);let n=a.options[i];if(n){let o=n.price;t+=o,h("Additional price: "+o)}h("Total additional: "+t)}),t},this.calculatePrice=function(t){let e=this.calculateAdditionalPrice(),i=0;switch(t){case"incl":i=a.productBasePriceIncl;break;case"excl":i=a.productBasePriceExcl;break;default:i=a.productBasePrice}return h("NEW TOTAL PRICE: "+(i+e),"background:purple; color:#fff; font-weight:bold;"),i+e},this.toggleVatPrice=function(t,e){e?(t.style.display="initial",t.style.display="revert",t.style.fontWeight="bold",t.classList.contains("vat-text")&&(t.style.fontSize="1em",t.style.textDecoration="underline")):t.style.display="none"},this.updateProductPrice=function(){let e=a.calculatePrice();if(o(".product-price .price").forEach(function(a){a.innerHTML=t.helpers.parsePrice(e)}),t.vatSwitcher&&t.vatSwitcher.isEnabled()){let i=t.helpers.getShopVatType();o(".product-price .price-excl").forEach(function(t){a.toggleVatPrice(t,"incl"!==i)}),o(".product-price .price-incl").forEach(function(t){a.toggleVatPrice(t,"excl"!==i)})}},this.parseOptions=function(t){for(let e in g("livePricing.parseOptions(customFields)"),t){let i=t[e];for(let n in h("Found custom field:"),h(i),i.values){let o=i.values[n];o.price&&(a.options[n]={id:n,fieldName:i.title,optionName:o.title,price:o.price})}}h("Options registered:"),h(a.options),m()},this.parseProductPage=function(t){if(g("livePricing.parseProductPage(productData);",!0),h(t),a.productBasePrice=t.price.price,a.productBasePriceIncl=t.price.price_incl,a.productBasePriceExcl=t.price.price_excl,!t.custom){h("No custom fields found, so bail","background:#f00000;");return}a.parseOptions(t.custom),a.updateProductPrice(),o('[id^="product_configure_custom_"]').forEach(function(t){h("processing elements"),h(t),t.addEventListener("change",function(t){h("Element onchange fired","background:#f00000;"),a.updateProductPrice()})}),m()},this.init=function(){if(h("Live pricing enabled"),"pages/product.rain"===theme.template){if(theme.pageData.product){a.parseProductPage(theme.pageData.product);return}new _(e+"?format=json").get(function(t){h("got product AJAX","background:#009900;"),a.parseProductPage(t.product)})}}},this.livePricing.init()),"pages/collection.rain"===theme.template&&(this.categoryBanner=new function(){if(s.categoryBanners.enabled&&theme.pageData&&theme.pageData.collection){let t=i("dy-cat-banner-holder"),e=theme.pageData.collection.category_id,a=s.categoryBanners.banners,n=s.categoryBanners.category_banner[e]||"default",o=s.categoryBanners.banners.default;if(n&&a[n]&&a[n][r]&&(o=s.categoryBanners.banners[n][r]),!o||!t){h("No default banner and no banner for category id "+e+" and language "+r);return}let c=document.createElement("a");c.id="dy-categorybanner-link",c.href=o.link_url,c.target=o.target||"_blank";let l=document.createElement("picture");if(l.id="dy-categorybanner-picture",o.mobile_image_url){let d=document.createElement("source");d.srcset=o.mobile_image_url,d.media="(max-width: "+s.categoryBanners.mobile_breakpoint+")",l.appendChild(d)}let u=document.createElement("img");u.id="dy-categorybanner-img",u.src=o.desktop_image_url,u.loading="lazy",l.appendChild(u),c.appendChild(l),t.appendChild(c)}},this.filterSwatches=new function(){this.parse=function(){let t=o(".filter-group");f(t,function(t,e){var a;let n=e.getAttribute("data-filter-title");if(a=n,!s.filterGroupSwatches.includes(a.trim().toLowerCase()))return;let o=document.createElement("div");o.classList.add("dy-swatch-filter-values");let r=e.querySelectorAll(".filter-value input");f(r,function(t,e){let a=e.getAttribute("data-filter-value-title"),n=e.getAttribute("data-filter-count"),r=y(a),s=document.createElement("div");s.classList.add("dy-swatch-filter-value");let c=document.createElement("div");c.classList.add("dy-swatch-filter-value-inner"),c.setAttribute("data-input-id",e.id);let l=document.createElement("div");l.title=a,l.classList.add("dy-filter-swatch"),l.setAttribute("data-input-id",e.id),b(l,r);let d=document.createElement("div");if(d.classList.add("dy-swatch-filter-title"),d.innerText=a,n){let u=document.createElement("span");u.classList.add("dy-filter-count"),u.innerText="("+n+")",d.appendChild(u)}e.checked&&l.classList.add("dy-active"),c.addEventListener("click",function(t){let e=this.querySelector(".dy-filter-swatch"),a=e.getAttribute("data-input-id");h("Clicked filter swatch"+a);let n=i(a);n.click(),h("Checked = "+n.checked),n.checked?e.classList.add("dy-active"):e.classList.remove("dy-active")}),c.appendChild(l),c.appendChild(d),s.appendChild(c),o.appendChild(s)});let c=e.querySelector(".filter-values");c.style.display="none",e.appendChild(o)});let e=i("collection-sidebar");e&&(e.scrollTop=e.getAttribute("data-scrolltop"))},this.parse()},this.categoryViewB2b=new function(){window.addEventListener("themeProductBlockLoaded",function(t){h("variants:"),h(t.detail.product.variants)})},window.addEventListener("themeCollectionChanged",function(e){h("Called listener themeCollectionChanged","background:#fff; color:#ccc;"),t.filterSwatches.parse(),s.advancedVariants.grid_swatches_enabled&&t.advancedVariants.parseCollectionGrid()})),"pages/product.rain"===theme.template&&(this.productDeliveryTimer=new function(){let t=this,e=n(".product-delivery-timer"),a=new Date().getTime(),i=null,o=!1;function r(t){return 1===(t=t.toString()).length?"0"+t:t}this.expire=function(){o=!0;let t=e.closest(".delivery-time-text"),a=e.closest(".product-deliverytime"),i=t.getAttribute("data-original-delivery-title"),n="true"==t.getAttribute("data-hide-expired");i&&!n?t.innerText=i:a&&a.remove()},this.tick=function(){let n=new Date().getTime(),o=a-n,s=r(Math.floor(o%864e5/36e5))+":"+r(Math.floor(o%36e5/6e4))+":"+r(Math.floor(o%6e4/1e3))+" ";e.innerText=s,o<=0&&(clearInterval(i),t.expire())},e&&(a=new Date(e.getAttribute("data-datetime-end")).getTime(),this.tick(),o||(i=setInterval(t.tick,1e3)))}),s.stockify.enabled&&(this.stockify=new function(){let t=this,a,n='',o=s.stockify.text[r],c=null,l;this.popup=function(t){if(!t)return;t.vid;let e,a,n,c,u,p,f,h,g,m;this.close=function(){console.log("close popup stockify"),i("dy-stockify-modal").remove(),l=null},(e=document.createElement("div")).classList.add("dy-modal","dy-active"),e.id="dy-stockify-modal",(a=document.createElement("div")).classList.add("dy-modal-inner"),a.id="dy-stockify-modal-inner",(n=document.createElement("div")).classList.add("dy-modal-close","dy-x"),(c=document.createElement("h4")).innerHTML=o.title,(u=document.createElement("div")).innerHTML=o.desc,p=document.createElement("form"),(f=document.createElement("input")).classList.add("dy-input","dy-text-input","dy-mt-3"),f.type="email",f.maxLength=65,f.required=!0,f.placeholder=o.email_placeholder,(h=document.createElement("button")).type="submit",h.classList.add("dy-w-100","dy-mt-2"),h.innerHTML=o.button_submit,(g=document.createElement("div")).classList.add("dy-stockify-bottom-text"),g.innerHTML=o.bottom_text,(m=document.createElement("div")).classList.add("dy-ajax-error"),n.addEventListener("click",function(t){l.close()}),e.addEventListener("click",function(t){t.target===t.currentTarget&&l.close()}),p.addEventListener("submit",function(e){e.preventDefault(),function e(a){if(!t.vid||a.length<5)return;m.innerHTML="";let i={product_id:t.id,variant_id:t.vid,product_title:t.title,variant_title:t.variant,variant_type:(t.matrix||t.options)&&t.matrix?d.MATRIX:d.VARIANTS,product_url:window.location.origin+"/"+t.url,language:r,email:a};new _(s.stockify.api).post(i,function(t){p.innerHTML='
'}).error(function(t,e){m.classList.add("dy-mt-2");let a=function t(e){try{let a=JSON.parse(e);return a}catch(i){return null}}(e.response);if(a&&a.errors){t=a.message||t,"object"==typeof a.errors&&(t=a.errors[Object.keys(a.errors)[0]]),m.innerHTML=t;return}m.innerHTML=t})}(f.value)}),p.append(f,h,g),a.append(n,c,u,p,m),e.appendChild(a),document.body.appendChild(e)},this.hookIntoGrid=function(e,a){if(!e){h("Stockify.hookIntoGrid() - No productData set/found ");return}let i=e.stock.available;if(e.variants&&!i){for(let o in e.variants)if(e.variants[o].stock.available){i=!0;break}}if(!1!==i){h("Stockify.hookIntoGrid() - product is not out of stock, so bail");return}let r=a.querySelector(".quick-order");if(!r)return;let s=r.querySelector(".quick-order-button");console.log("quickoerderbutton"),console.log(s),console.log(r);let c=document.createElement("button");c.classList.add("button","quick-order-button"),c.innerHTML=n,s&&c.setAttribute("data-metadata",s.getAttribute("data-metadata")),c.addEventListener("click",function(i){if(i.preventDefault(),!r.getAttribute("data-is-single-product")||-1!==e.data_01.toLowerCase().indexOf("bundle:")){console.log("/go/product/"+a.getAttribute("data-pid")),document.location="/go/product/"+a.getAttribute("data-pid");return}l=new t.popup(e)}),r.innerHTML="",r.appendChild(c)},this.hookIntoProductPage=function(e){if(!e){h("Stockify.hookIntoProductPage() - No productData set/found ");return}if("backorder"===s.stockify.stock_trigger_type&&e.stock.available&&e.stock.level<1?c="backorder":e.stock.available||(c="outofstock"),!c){h("Stockify.hookIntoProductPage() - product is not out of stock, so bail");return}if(!o){h("Stockify.hookIntoProductPage() - No language found for "+r);return}let a=i("add-to-cart-holder");if(!a){h("Stockify.hookIntoProductPage() - injectMainButton target was not found (#add-to-cart-holder)");return}let d=document.createElement("button");if(d.id="dy-stockify-main-button",d.classList.add("dy-button"),d.innerHTML=o.button_trigger+" "+n,d.setAttribute("data-vid",e.vid),d.addEventListener("click",function(a){a.preventDefault(),l=new t.popup(e)}),"outofstock"!==c){d.classList.add("button-small","px-2","py-1");let u=document.createElement("div");u.classList.add("stockify-button-holder","type-add","mt-3","col"),a.after(u),u.append(d)}else d.classList.add("dy-w-100","dy-fz-110"),a.innerHTML="",a.append(d)},this.init=function(){"pages/product.rain"==theme.template&&(theme.pageData.product?(a=theme.pageData.product,t.hookIntoProductPage(a)):new _(e+"?format=json").get(function(e){h("got product AJAX","background:#009900;"),a=e,t.hookIntoProductPage(a)})),h("stockify - parseGridBlocks()","background:blue;"),window.addEventListener("themeProductBlockLoaded",function(e){h("Called listener themeProductBlockLoaded for: "+e.detail.product.title,"background:#fff; color:#ccc;"),t.hookIntoGrid(e.detail.product,e.detail.element)})},this.init()}),s.age_popup&&s.age_popup.enabled&&(this.agePopup=new function(){let t=this,e=null,a=s.age_popup.text[r];this.close=function(){console.log("close age popup"),e.classList.remove("dy-active"),document.body.classList.remove("dy-overflow-hidden"),localStorage.setItem("dy_age_popup_closed",!0),document.cookie="dy_age_popup_closed=true; path=/;"},this.show=function(){e||function i(){let n,o,c,l,d;if(!a){h("AgePopup::init() - No "+r+" language found, bail");return}(e=document.createElement("div")).classList.add("dy-modal","dy-modal-blurred"),e.id="dy-age-popup-modal",(n=document.createElement("div")).classList.add("dy-modal-inner","text-center"),n.id="dy-stockify-modal-inner",(o=document.createElement("img")).id="age-popup-logo",o.classList.add("mb-4"),o.src=s.age_popup.logo_url,(c=document.createElement("div")).innerHTML=a.content,(l=document.createElement("button")).type="button",l.classList.add("dy-w-100","dy-mt-2","button-cta","button-large"),l.innerHTML=a.button_yes,(d=document.createElement("a")).href=a.button_no_url,d.classList.add("button","button-lined-soft","dy-w-100","dy-mt-2"),d.innerHTML=a.button_no,l.addEventListener("click",function(e){t.close()}),d.addEventListener("click",function(t){t.preventDefault(),n.innerHTML=a.content_no}),s.age_popup.logo_url&&n.append(o),n.append(c,l,d),e.appendChild(n)}(),document.body.appendChild(e),document.body.classList.add("dy-overflow-hidden"),setTimeout(function(){e.classList.add("dy-active")},60)},this.init=function(){!document.cookie.includes("dy_age_popup_closed=true")&&!window.frameElement&&t.show()},this.init()}),"pages/article.rain"===theme.template&&(this.blogArticleProducts=new function(){console.log("blogArticleProducts()"),this.parse=function(){console.log("ThemeAddons.blogArticleProducts.parse():");let t=i("blog-content");if(!t)return;let e=t.innerHTML.match(/\\[products=([a-z0-9\_]+)\]\<\/p\>/ig);if(console.log(e),!e)return;e.forEach(function(e){let a=e.match(/\\[products=([a-z0-9\_]+)\]\<\/p\>/i);if(!a[1])return;h(a[1]);let i=a[1].replace(/_/g,"-"),n=theme.url.shop+"tags/"+i+"/?request_type=ajax&request_action=collection&mode=grid_list&limit=6&sort=popular";t.innerHTML=t.innerHTML.replace(e,'
')});let a=new IntersectionObserver(function(t){t.forEach(function(t){t.isIntersecting&&(new theme.dynamicProducts(t.target).run(),a.unobserve(t.target))})},{rootMargin:"150px"});o(".dynamic-products").forEach(function(t){a.observe(t)})},this.parse()}),this.loaded=!0};