;function iSPFrame(ops={}){let has=Object.prototype.hasOwnProperty;let origin="https://cloud.interactivespares.com";let client="ljm";let iframe;let allowed_langs=["dk","en","de"];if(ops&&ops.iframe){if(typeof ops.iframe=="string"){iframe=document.getElementById(ops.iframe)}else if(typeof ops.iframe){iframe=ops.iframe}};if(!iframe||!(iframe instanceof HTMLIFrameElement)){throw new Error("Passed tag must be an iframe");};let currentLanguage=null;if(ops&&ops.language){if(!allowed_langs.includes(language.toLowerCase())){throw new Error("Unsupported language");};currentLanguage=language.toLowerCase()};let bootOrigin=window.origin;let addToCartHandler=null;let priceRequestHandler=null;function mustBeFunction(e){if(typeof e!="function"){throw new Error("Argument must be callable");}};this.onAddToCart=(handler)=>{mustBeFunction(handler);addToCartHandler=handler;return this};this.onPriceRequest=(handler)=>{mustBeFunction(handler);priceRequestHandler=handler;return this};function addParamsToUrl(e){if(ops&&ops.prices==!1){e.searchParams.set("noprices",!0)};if(currentLanguage){e.searchParams.set("lang",currentLanguage)}};this.goToCatalogue=function(e){if(!e||e.toString().trim()==""){throw new TypeError("goToCatalogue requires a non-empty string parameter");};var a="/:client/catalogo_iframe/:catalogue".replace(":client",client).replace(":catalogue",btoa(e)),r=new URL(a,origin);addParamsToUrl(r);iframe.src=r.toString()};this.goToDrawing=function(e){if(!e||e.toString().trim()==""){throw new TypeError("goToDrawing requires a non-empty string parameter");};var a="/:client/catalogo_iframe/tavola/:drawing".replace(":client",client).replace(":drawing",btoa(e)),r=new URL(a,origin);addParamsToUrl(r);iframe.src=r.toString()};function reloadIframe(){if(!iframe.src)return;var e=new URL(iframe.src);addParamsToUrl(e);iframe.src=e};this.setLanguage=function(e,reload=!1){if(!e)return;e=e.toLowerCase();if(!allowed_langs.includes(e)){throw new Error("Unsupported language");};currentLanguage=e;if(reload)reloadIframe()};let messageHandler=function(r){if(r.origin!==origin){return};if(!iframe){console.error("invalid iframe");return};if(r.source!==iframe.contentWindow){console.error("event source is not the iframe");return};let data=r.data;switch(data.type){case"isp-msg-add-to-cart":{if(!addToCartHandler){throw new Error("Event handler not defined: 'AddToCart'");};addToCartHandler(data)};break;case"isp-msg-price-request":{if(!priceRequestHandler){throw new Error("Event handler not defined: 'PriceRequest'");};let result=priceRequestHandler(data);Promise.resolve(result).then((data)=>{if(typeof data!=="object"||!has.call(data,"code")||!has.call(data,"price")){throw new Error("Invalid object data in PriceRequest handler result");};var a={type:"isp-msg-price-response",code:data.code,price:data.price,};iframe.contentWindow.postMessage(a,origin)}).catch((e)=>{console.error(e)})};break;default:break}};this.startListener=function(){this.removeListener();window.addEventListener("message",messageHandler);return this};this.removeListener=function(){window.removeEventListener("message",messageHandler);return this}};