(function appEasyProtect($){let App=function App(){this.sessionId='d1727d0e631e7321cbebe41bbddf43ca';this.sessionToken='3a1d325057126c2595d0c896d84918b0d90627b5e41a1c336730ad5031b62425';this.listType='none';this.shopId=243;this.translations={"add_text":{"__default":"Dodaj","pl_PL":"Dodaj"},"no_option_text":{"__default":"brak","pl_PL":"brak"},"protectionAddText":{"__default":"Dodaj","pl_PL":"Dodaj"},"noOptionText":{"__default":"brak","pl_PL":"brak"},"infoPageText":{"__default":"dowiedz si\u0119 wi\u0119cej","pl_PL":"dowiedz si\u0119 wi\u0119cej"},"checkboxEnableEasyProtectText":{"__default":"jestem zainteresowany gwarancj\u0105 EP","pl_PL":"jestem zainteresowany gwarancj\u0105 EP"},"productIndexText2":{"__default":"Zyskaj nawet 3 lata dodatkowej ochrony dla swojego sprz\u0119tu","pl_PL":"Zyskaj nawet 3 lata dodatkowej ochrony dla swojego sprz\u0119tu"},"productIndexOptionText":{"__default":"Ochrona","pl_PL":"Ochrona"},"productIndexNoOptionText":{"__default":"podstawowa","pl_PL":"podstatowa"}};this.productId=1511;this.optionPriceRangeId=27;this.optionTimePeriodId=28;this.optionToProductId=30;this.optionDataId=31;this.infoPageId=263;this.checkboxEnableFieldId=6;this.noOption=0;this.checkboxEnableEasyProtect=0;this.addEasyProtectToProductIndex=0;this.productIds=[];this.categoriesIds={"0":"Wszystkie kategorie","110":"Outlet"};this.producersIds={"0":"Wszyscy producenci"};this.lang=Shop.lang.name?Shop.lang.name:"pl_PL";this.$style=$('').appendTo('head');this.insertStyle();if(Shop.pageType.split(' ').includes('shop_basket')){if(typeof GlobalSoolutionSoobasket!='undefined'&&typeof forceStandardEasyProtect=='undefined'){this.basketSoobasket();}
else{this.basketIndex();}
return true;}
if(Shop.pageType.split(' ').includes('shop_basket_address')){this.basketAddress();return true;}
if(Shop.pageType.split(' ').includes('shop_basket_step3')){this.basketStep3();return true;}
if(this.addEasyProtectToProductIndex&&Shop.pageType.split(' ').includes('shop_product')){this.productIndex();return true;}
if(Shop.pageType.split(' ').includes('shop_infopage')&&Shop.pageId==this.infoPageId){this.insertInfoPageStyle();}
let protectionFromProductIndex=[];if(localStorage.appEasyProtectProtectionFromProductIndex){protectionFromProductIndex=JSON.parse(localStorage.appEasyProtectProtectionFromProductIndex);}
if(protectionFromProductIndex.length>0){this.loadCurrency().then(()=>Promise.all([this.loadBasketInfo(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex(true)).catch((reason)=>this.errorHandler(reason));}
return true;};App.prototype.basketIndex=function basketIndex(){this.preloadAddedProtection().then(()=>this.loadCurrency()).then(()=>Promise.all([this.loadProtection(),this.loadBasketInfo(),this.loadInfoPage(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex()).then(()=>this.checkExceedingProtection()).then(()=>this.loadProductOptions()).then(()=>this.addProtectionToBasket()).catch((reason)=>this.errorHandler(reason));};App.prototype.basketAddress=function basketAddress(){this.loadCurrency().then(()=>Promise.all([this.loadProtection(),this.loadBasketInfo(),this.loadInfoPage(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex()).then(()=>this.checkExceedingProtection()).then(()=>{let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
$(`#additional_${this.checkboxEnableFieldId}`).val(protectionData.length==0&&localStorage.appEasyProtectEnableEasyProtect==='true'?"Tak":"");}).catch((reason)=>this.errorHandler(reason));};App.prototype.basketStep3=function basketStep3(){this.loadCurrency().then(()=>Promise.all([this.loadProtection(),this.loadBasketInfo(),this.loadInfoPage(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex()).then(()=>this.checkExceedingProtection()).catch((reason)=>this.errorHandler(reason));};App.prototype.productIndex=function productIndex(){this.loadCurrency().then(()=>Promise.all([this.loadProtection(),this.loadBasketInfo(),this.loadInfoPage(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex()).then(()=>this.addProtectionToProductIndex()).catch((reason)=>this.errorHandler(reason));};App.prototype.basketSoobasket=function basketSoobasket(){this.loadCurrency().then(()=>Promise.all([this.loadProtection(),this.loadBasketInfo(),this.loadInfoPage(),this.loadCurrencyRate(),])).then(()=>this.addProtectionFromProductIndex()).then(()=>this.checkExceedingProtection()).then(()=>this.loadProductOptions()).then(()=>this.waitForSoobasket()).then((response)=>{if(response==='fallback'){return this.preloadAddedProtection().then(()=>this.addProtectionToBasket());}
return this.addProtectionToSoobasket();}).catch((reason)=>this.errorHandler(reason));};App.prototype.preloadAddedProtection=function preloadAddedProtection(){return new Promise((resolve,reject)=>{let protectionRows=[];let productsTable=$(`#box_basketlist .productlist > tbody > tr[data-product-id]`);productsTable.each((index,tableRow)=>{tableRow=$(tableRow);if(tableRow.data('basket-product-id')==undefined){if(tableRow.find('.prodremove').length==0||tableRow.find('.prodremove').attr('href')=='')return true;let productBasketId=tableRow.find('.prodremove').attr('href').split("/").pop();tableRow.attr('data-basket-product-id',productBasketId);}
if(tableRow.data('product-id')==this.productId){protectionRows.push(tableRow);}});if(protectionRows.length>0){let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionRows){let protectionRow=protectionRows[key];let mxInfoPageUrl=protectionRow.find(`td.name > a`);mxInfoPageUrl.attr('href',`/${this.lang}/i/easy-protect/${this.infoPageId}`);mxInfoPageUrl.attr('title',this.getTranslation('infoPageText'));mxInfoPageUrl.attr('target','_blank').attr('rel','noreferrer');let variants=protectionRow.find(`td.name .variant`).html().split('; ');protectionRow.find(`td.name .variant`).html(`${variants[1]}; ${variants[2]}`);let input=protectionRow.find(`td.quantity input`);input.attr('max',input.val());let basketProductId=0;let basketProtectionId=protectionRow.data('basket-product-id');for(let key2 in protectionData){let data=protectionData[key2];if(data.basketProtectionId!=basketProtectionId)continue;basketProductId=data.basketProductId;break;}
if(basketProductId!=0){protectionRow.attr('data-for-basket-product-id',basketProductId);let parentRow=$(`#box_basketlist .productlist > tbody > tr[data-basket-product-id=${basketProductId}]`);while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionRow.insertAfter(parentRow);}}}
return resolve(true);});};App.prototype.loadProtection=function loadProtection(){return new Promise((resolve,reject)=>{this.waitFor(()=>{return typeof window.frontAPI==='object'&&typeof window.frontAPI.getProduct==='function';},()=>{frontAPI.getProduct((protection)=>{if('error_description'in protection)return reject(new Error('Protection not found'));if(!('options_configuration'in protection))return reject(new Error('Protection missing options'));if(protection.options_configuration.length!=4)return reject(new Error('Protection missing options'));this.protection=protection;return resolve(protection);},{id:this.productId,lang:this.lang,currency:this.currency});});});};App.prototype.loadBasketInfo=function loadBasketInfo(){return new Promise((resolve,reject)=>{this.waitFor(()=>{return typeof window.frontAPI==='object'&&typeof window.frontAPI.getBasketInfo==='function';},()=>{frontAPI.getBasketInfo((basket)=>{this.basketInfo=basket;return resolve(basket);},{lang:this.lang,currency:this.currency});});});};App.prototype.loadInfoPage=function loadInfoPage(){return new Promise((resolve,reject)=>{this.waitFor(()=>{return typeof window.frontAPI==='object'&&typeof window.frontAPI.getPage==='function';},()=>{frontAPI.getPage((page)=>{if('error_description'in page)return reject(new Error('Infopage not found'));this.infoPageUrl=page.url;return resolve(page.url);},{id:this.infoPageId,lang:this.lang});});});};App.prototype.loadCurrencyRate=function loadCurrencyRate(){return new Promise((resolve,reject)=>{let link="https://mxapp2.maxserver.pl/appEasyProtect/getCurrencyRate.php";let postData={sessionId:this.sessionId,sessionToken:this.sessionToken,shopId:this.shopId,currency:this.currency};$.post(link,postData).done((response)=>{response=JSON.parse(response);if('error'in response)return reject(new Error(response.error));this.currencyRate=response.rate;return resolve(response.rate);}).fail((response)=>{return reject(new Error(response));});});};App.prototype.checkExceedingProtection=function checkExceedingProtection(){return new Promise((resolve,reject)=>{let promises=[];let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
let noProtectionProductsQuantity={};for(let key in this.basketInfo.products){let basketProduct=this.basketInfo.products[key];if(basketProduct.product_id==this.productId)continue;let categoryId='category'in basketProduct?basketProduct.category.category_id:-1;let producerId='producer'in basketProduct?basketProduct.producer.producer_id:-1;if(!this.checkAllowProtection(basketProduct.product_id,categoryId,producerId))continue;if(basketProduct.id in noProtectionProductsQuantity){noProtectionProductsQuantity[basketProduct.id]+=basketProduct.quantity;}else{noProtectionProductsQuantity[basketProduct.id]=basketProduct.quantity;}}
loopLabel:for(let key in protectionData){let data=protectionData[key];if(data.basketProductId in noProtectionProductsQuantity){for(let key2 in this.basketInfo.products){let basketProduct=this.basketInfo.products[key2];if(basketProduct.id!=data.basketProtectionId)continue;if(noProtectionProductsQuantity[data.basketProductId]-basketProduct.quantity>=0){noProtectionProductsQuantity[data.basketProductId]-=basketProduct.quantity;break loopLabel;}
if(noProtectionProductsQuantity[data.basketProductId]>0){let newQuantity=noProtectionProductsQuantity[data.basketProductId];noProtectionProductsQuantity[data.basketProductId]=0;promises.push(new Promise((resolve,reject)=>{frontAPI.editBasketProductQuantity(()=>{basketProduct.quantity=newQuantity;return resolve(true);},{id:data.basketProtectionId,data:{quantity:newQuantity}});}));break loopLabel;}
promises.push(new Promise((resolve,reject)=>{frontAPI.removeFromBasket(()=>{protectionData.splice(key,1);return resolve(true);},{id:data.basketProtectionId});}));break loopLabel;}
protectionData.splice(key,1);localStorage.appEasyProtectProtectionData=JSON.stringify(protectionData);}
else{promises.push(new Promise((resolve,reject)=>{frontAPI.removeFromBasket(()=>{protectionData.splice(key,1);return resolve(true);},{id:data.basketProtectionId});}));}}
loopLabel:for(let key in this.basketInfo.products){let basketProduct=this.basketInfo.products[key];if(basketProduct.product_id!=this.productId)continue;for(let key2 in protectionData){let data=protectionData[key2];if(basketProduct.id!=data.basketProtectionId)continue;continue loopLabel;}
promises.push(new Promise((resolve,reject)=>{frontAPI.removeFromBasket(()=>{return resolve(true);},{id:basketProduct.id});}));}
if(promises.length>0){Promise.allSettled(promises).then(()=>{localStorage.appEasyProtectProtectionData=JSON.stringify(protectionData);location.replace(location.href);});return false;}
else{return resolve(true);}});};App.prototype.loadProductOptions=function loadProductOptions(prices=false){if(typeof this.protectionVariants!='object')this.protectionVariants=[];let currentPrices=[];if(prices===false){for(let key in this.basketInfo.products){let basketProduct=this.basketInfo.products[key];if(basketProduct.product_id==this.productId)continue;if(!currentPrices.includes(basketProduct.price_float))currentPrices.push(basketProduct.price_float);}}
else{switch(typeof prices){case'string':currentPrices.push(parseFloat(prices));break;case'number':currentPrices.push(prices);break;case'object':if(!Array.isArray(prices))return Promise.reject(new Error('Wrong prices type in loadProductOptions'));currentPrices=prices;break;default:return Promise.reject(new Error('Wrong prices type in loadProductOptions'));}}
let optionPriceRangeValues=[];let optionPriceRangeBrakets={};let optionTimePeriodValues=[];let optionTimePeriodNames={};for(let key in this.protection.options_configuration){let option=this.protection.options_configuration[key];if(option.id==this.optionPriceRangeId){for(let key2 in option.values){let optionValue=option.values[key2];let priceBraketsArray=optionValue.name.split(',').join('.').split('-');let priceBrakets={priceMin:parseFloat(priceBraketsArray[0])*this.currencyRate,priceMax:parseFloat(priceBraketsArray[1])*this.currencyRate,};let priceInBrakets=false;for(let key3 in currentPrices){let price=currentPrices[key3];if(priceBrakets.priceMin<=price&&price<=priceBrakets.priceMax){priceInBrakets=true;break;}}
if(priceInBrakets){optionPriceRangeValues.push(optionValue.id);optionPriceRangeBrakets[optionValue.id]=priceBrakets;}}}
if(option.id==this.optionTimePeriodId){for(let key2 in option.values){let optionValue=option.values[key2];optionTimePeriodValues.push(optionValue.id);optionTimePeriodNames[optionValue.id]=optionValue.name;}}}
let dataOptions=[];for(let key in optionPriceRangeValues){let optionPriceRangeValue=optionPriceRangeValues[key];for(let key2 in optionTimePeriodValues){let optionTimePeriodValue=optionTimePeriodValues[key2];let options={};options[this.optionPriceRangeId]=optionPriceRangeValue;options[this.optionTimePeriodId]=optionTimePeriodValue;dataOptions.push(options);}}
let promises=[];loopLabel:for(let key in dataOptions){let options=dataOptions[key];for(let key2 in this.protectionVariants){if(this.protectionVariants[key2].options[this.optionPriceRangeId]!=options[this.optionPriceRangeId])continue;if(this.protectionVariants[key2].options[this.optionTimePeriodId]!=options[this.optionTimePeriodId])continue;continue loopLabel;}
promises.push(new Promise((resolve,reject)=>{frontAPI.getProductOption((stock)=>{if('error_description'in stock)return resolve(stock);let priceBrakets=optionPriceRangeBrakets[options[this.optionPriceRangeId]];let protectionWariant={stockId:stock.id,options:options,price:stock.price.gross.final_float,priceMin:priceBrakets.priceMin,priceMax:priceBrakets.priceMax,timePeriod:optionTimePeriodNames[options[this.optionTimePeriodId]],};this.protectionVariants.push(protectionWariant);return resolve(protectionWariant);},{id:this.productId,data:{options:options},lang:this.lang,currency:this.currency});}));}
return Promise.all(promises);};App.prototype.addProtectionToBasket=function addProtectionToBasket(){return new Promise((resolve,reject)=>{let protectionExists=false;let protectionForms={};let productsTable=$(`#box_basketlist .productlist > tbody > tr[data-product-id]`);productsTable.each((index,tableRow)=>{tableRow=$(tableRow);if(tableRow.data('basket-product-id')==undefined){if(tableRow.find('.prodremove').length==0||tableRow.find('.prodremove').attr('href')=='')return true;let productBasketId=tableRow.find('.prodremove').attr('href').split("/").pop();tableRow.attr('data-basket-product-id',productBasketId);}
let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){let categoryId='category'in basketProduct?basketProduct.category.category_id:-1;let producerId='producer'in basketProduct?basketProduct.producer.producer_id:-1;if(!this.checkAllowProtection(productId,categoryId,producerId))return true;let protectionForm=this.createProtectionForm(tableRow);if(protectionForm!=false){protectionForms[basketProductId]=protectionForm;tableRow.find('.quantity input').on('change.maxProtection',(e)=>{this.changeMaxProtectionEvent(basketProductId);});this.changeMaxProtectionEvent(basketProductId);}}
else{protectionExists=true;tableRow.find(`td.name > a`).attr('href',this.infoPageUrl);tableRow.find('.quantity input').on('change.maxProtection',(e)=>{if(tableRow.data('basket-product-id')==undefined)return false;this.changeMaxProtectionEvent(tableRow.data('for-basket-product-id'));});}});if(!protectionExists&&this.checkboxEnableEasyProtect){localStorage.appEasyProtectEnableEasyProtect='false';if(Object.keys(protectionForms).length>0){let mxEnableEasyProtect=$(`
`).prependTo('#box_basketlist .summary-container');let checkbox=$(``).appendTo(mxEnableEasyProtect);checkbox.attr('id','mxEnableEasyProtect');checkbox.wrap(``);$(``).insertAfter(checkbox);let label=$(``).appendTo(mxEnableEasyProtect);label.html(this.getTranslation('checkboxEnableEasyProtectText'));checkbox.on('change.enableEasyProtect',(e)=>{if(checkbox.is(':checked')){localStorage.appEasyProtectEnableEasyProtect='true';productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){let parentRow=tableRow;while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionForms[basketProductId].insertAfter(parentRow);}}});}
else{localStorage.appEasyProtectEnableEasyProtect='false';productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){protectionForms[basketProductId].detach();}}});}});}}
else{productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){let parentRow=tableRow;while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionForms[basketProductId].insertAfter(parentRow);}}});}
return resolve(true);});};App.prototype.checkAllowProtection=function checkAllowProtection(productId,categoryId,producerId){let blockCategory=false;let blockProducer=false;if(0 in this.categoriesIds){if(categoryId in this.categoriesIds){blockCategory=true;}}
else{if(!(categoryId in this.categoriesIds)){blockCategory=true;}}
if(0 in this.producersIds){if(producerId in this.producersIds){blockProducer=true;}}
else{if(!(producerId in this.producersIds)){blockProducer=true;}}
if(this.listType=='whitelist'){if(this.productIds.includes(productId))return true;}
else if(this.listType=='blacklist'){if(this.productIds.includes(productId))return false;}
if(blockCategory)return false;if(blockProducer)return false;return true;};App.prototype.createProtectionForm=function createProtectionForm(tableRow){let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;let chossenProtectionVariants=this.protectionVariants.filter((variant)=>variant.priceMin<=basketProduct.price_float&&basketProduct.price_float<=variant.priceMax);if(chossenProtectionVariants.length==0)return false;chossenProtectionVariants.sort((a,b)=>a.price-b.price);let noProtectionQuantity=basketProduct.quantity;let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProductId)continue;for(let key2 in this.basketInfo.products){let basketProtection=this.basketInfo.products[key2];if(basketProtection.id!=data.basketProtectionId)continue;noProtectionQuantity-=basketProtection.quantity;}}
if(noProtectionQuantity<=0)return false;let form=$(` |
`);let mxWrapper=form.find('.mxWrapper');let mxLeftCol=$(``).appendTo(mxWrapper);let bigPurpleArrow=$(``).appendTo(mxWrapper);bigPurpleArrow.attr('src','https://mxapp2.maxserver.pl/appEasyProtect/gfx/bigPurpleArrow.png');bigPurpleArrow.wrap(``);let mxRightCol=$(``).appendTo(mxWrapper);let name=this.escapeHtml(this.protection.name);let tradeMark='';if(name.charCodeAt(name.length-1)==174){tradeMark=`${name.substr(-1, 1)}`;name=name.substr(0,name.length-1);}
if(name.charCodeAt(name.length-1)==8482){tradeMark=`${name.substr(-1, 1)}`;name=name.substr(0,name.length-1);}
let mxImage=$(``).appendTo(mxLeftCol);mxImage.wrap(``);let mxNameContainer=$(``).appendTo(mxLeftCol);let mxName=$(`${name}${tradeMark}
`).appendTo(mxNameContainer);let mxInfoPageUrl=$(`${this.getTranslation('infoPageText')}`).appendTo(mxNameContainer);mxInfoPageUrl.attr('href',this.infoPageUrl);mxInfoPageUrl.attr('target','_blank').attr('rel','noreferrer');mxInfoPageUrl.wrap(``);let smallPurpleArrow=$(``).insertBefore(mxInfoPageUrl);smallPurpleArrow.attr('src','https://mxapp2.maxserver.pl/appEasyProtect/gfx/smallPurpleArrow.png');smallPurpleArrow.wrap(``);let mxQuantityWrap=$(``).appendTo(mxRightCol);let mxQuantity=$(``).appendTo(mxQuantityWrap);for(let i=1;i<=noProtectionQuantity;i++){mxQuantity.append(``);}
let mxOptions=$(``).appendTo(mxRightCol);if(this.noOption==1){let mxOption=$(``).appendTo(mxOptions);mxOption.attr('name',`radio_${basketProductId}`);mxOption.attr('id',`radio_${basketProductId}_no_option`);mxOption.attr('value',`0`);mxOption.wrap(``);let label=$(``).insertAfter(mxOption);label.attr('for',`radio_${basketProductId}_no_option`);label.append(this.getTranslation('noOptionText'));}
for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];let mxOption=$(``).appendTo(mxOptions);mxOption.attr('name',`radio_${basketProductId}`);mxOption.attr('id',`radio_${basketProductId}_${chossenVariant.stockId}`);mxOption.attr('value',chossenVariant.stockId);mxOption.wrap(``);let label=$(``).insertAfter(mxOption);label.attr('for',`radio_${basketProductId}_${chossenVariant.stockId}`);label.append(`${chossenVariant.timePeriod} `);label.append(`${this.priceFormat(chossenVariant.price)}`);}
let mxSum=$(``).appendTo(mxRightCol);let mxAction=$(``).appendTo(mxRightCol);let mxButtonAdd=$(`${this.getTranslation('protectionAddText')}
`).appendTo(mxAction);mxQuantity.on('change',(e)=>{let quantity=parseFloat($(e.target).val());let stockId=parseFloat(mxOptions.find('input:checked').val());if(stockId==0){mxButtonAdd.stop().animate({'opacity':0.3});mxSum.text(this.priceFormat(0));}
else{mxButtonAdd.stop().animate({'opacity':1});let price=0;for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){price=chossenVariant.price;break;}}
let quantity=mxQuantity.val();mxSum.text(this.priceFormat(price*quantity));}
for(let key in this.$style.get(0).sheet.cssRules){let rule=this.$style.get(0).sheet.cssRules[key];if(rule.selectorText!='.protectionForm .mxRightCol .mxSum')continue;let width=mxSum.get(0).getBoundingClientRect().width;if(parseFloat(rule.style.minWidth){let quantity=parseFloat(mxQuantity.val());let stockId=parseFloat($(e.target).val());if(stockId==0){mxAction.addClass('mxHidden');mxButtonAdd.stop().animate({'opacity':0.3});mxSum.text(this.priceFormat(0));}
else{mxAction.removeClass('mxHidden');mxButtonAdd.stop().animate({'opacity':1});let price=0;for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){price=chossenVariant.price;break;}}
mxSum.text(this.priceFormat(price*quantity));}
for(let key in this.$style.get(0).sheet.cssRules){let rule=this.$style.get(0).sheet.cssRules[key];if(rule.selectorText!='.protectionForm .mxRightCol .mxSum')continue;let width=mxSum.get(0).getBoundingClientRect().width;if(parseFloat(rule.style.minWidth){let quantity=parseFloat(mxQuantity.val());let stockId=parseFloat(mxOptions.find('input:checked').val());if(stockId==0)return false;let options={};for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){options=chossenVariant.options;break;}}
let query={data:{stock_id:stockId,quantity:quantity,options:options,}};query.data.options[this.optionToProductId]=`${basketProduct.name}`;let hasVariant=0;if(basketProduct.variant!=''){hasVariant=1;query.data.options[this.optionToProductId]+=` (${basketProduct.variant})`;}
query.data.options[this.optionDataId]=`${basketProduct.stock_id}, ${hasVariant}`;let wait=$('').appendTo('head');frontAPI.addToBasket((response)=>{if(response.added.length>0){let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
let protectionExisted=false;for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProduct.id)continue;if(data.basketProtectionId!=response.added[0].id)continue;protectionExisted=true;break;}
if(!protectionExisted){protectionData.push({basketProductId:basketProduct.id,basketProtectionId:response.added[0].id,});localStorage.appEasyProtectProtectionData=JSON.stringify(protectionData);}
location.replace(location.href);}
else{if(response._flash_messenger.error.length>0)shoper.alert(response._flash_messenger.error[0],'');if(response._flash_messenger.warning.length>0)shoper.alert(response._flash_messenger.warning[0],'');if(response._flash_messenger.info.length>0)shoper.alert(response._flash_messenger.info[0],'');}
wait.remove();},query);});return form;};App.prototype.changeMaxProtectionEvent=function changeMaxProtectionEvent(basketProductId){let maxProtection=$(`#box_basketlist .productlist > tbody > tr[data-basket-product-id=${basketProductId}] .quantity input`).val();let noProtectionQuantity=maxProtection;let basketProtectionIds=[];let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProductId)continue;basketProtectionIds.push(data.basketProtectionId);}
if(basketProtectionIds.length==0)return false;let protectionsTable=$(`#box_basketlist .productlist > tbody > tr[data-product-id=${this.productId}]`);protectionsTable.each((index2,tableRow)=>{tableRow=$(tableRow);if(!basketProtectionIds.includes(tableRow.data('basket-product-id')))return true;noProtectionQuantity-=tableRow.find('.quantity input').val();});if(noProtectionQuantity<0){noProtectionQuantity=maxProtection;protectionsTable.each((index2,tableRow)=>{tableRow=$(tableRow);if(!basketProtectionIds.includes(tableRow.data('basket-product-id')))return true;let input=tableRow.find('.quantity input');if(noProtectionQuantity-input.val()>0){noProtectionQuantity-=input.val();input.attr('max',input.val());return true;}
if(noProtectionQuantity>0){input.attr('max',noProtectionQuantity);noProtectionQuantity=0;return true;}
input.attr('max',0);});$('#box_basketlist .innerbox > form').get(0).reportValidity();}
else{protectionsTable.each((index2,tableRow)=>{tableRow=$(tableRow);if(!basketProtectionIds.includes(tableRow.data('basket-product-id')))return true;let input=tableRow.find('.quantity input');input.attr('max',input.val()*1+noProtectionQuantity);});}};App.prototype.addProtectionToProductIndex=function addProtectionToProductIndex(){return new Promise((resolve,reject)=>{frontAPI.getProduct((product)=>{if('error_description'in product)return reject(new Error('Product not found'));let categoryId='category'in product?product.category.id:-1;let producerId='producer'in product?product.producer.id:-1;if(!this.checkAllowProtection(product.id,categoryId,producerId))return resolve(true);let mxEasyProtectContainer=$(``).insertBefore('.productdetails-more-details');mxEasyProtectContainer.hide();let mxHeader=$(`${this.getTranslation('productIndexText2')}
`).appendTo(mxEasyProtectContainer);let mxOptions=$(``).appendTo(mxEasyProtectContainer);let mxInfoPageUrl=$(`${this.getTranslation('infoPageText')}`).appendTo(mxEasyProtectContainer);mxInfoPageUrl.attr('href',this.infoPageUrl);mxInfoPageUrl.attr('target','_blank').attr('rel','noreferrer');mxInfoPageUrl.wrap(``);let mxSmallGreyArrow=$(``).insertAfter(mxInfoPageUrl);mxSmallGreyArrow.attr('src','https://mxapp2.maxserver.pl/appEasyProtect/gfx/bigPurpleArrow.png');mxSmallGreyArrow.wrap(``);let price=parseFloat($('#box_productfull .price .main-price').eq(0).text().replaceAll(/[^\d,.-]/g,'').replaceAll(',','.'));this.changeProductStockEvent(mxEasyProtectContainer,mxOptions,price).catch((reason)=>this.errorHandler(reason));let prevPrice=price;let observer=new MutationObserver(()=>{let price=parseFloat($('#box_productfull .price .main-price').eq(0).text().replaceAll(/[^\d,.-]/g,'').replaceAll(',','.'));if(price==prevPrice)return false;prevPrice=price;this.changeProductStockEvent(mxEasyProtectContainer,mxOptions,price).catch((reason)=>this.errorHandler(reason));});observer.observe($('#box_productfull .price .main-price').get(0),{childList:true});$('#box_productfull .addtobasket').on('click',(e)=>{let option=mxOptions.find('input:checked');if(option.length==1&&option.val()!=0){let protectionFromProductIndex=[];if(localStorage.appEasyProtectProtectionFromProductIndex){protectionFromProductIndex=JSON.parse(localStorage.appEasyProtectProtectionFromProductIndex);}
let object={protection:{},product:{},otherProductQuantities:{}};object.protection.stockId=parseFloat(option.val());object.product.stockId=parseFloat($('#box_productfull .addtobasket-container [name="stock_id"]').val());object.product.quantity=parseFloat($('#box_productfull .addtobasket-container [name="quantity"]').val());for(let key in this.protectionVariants){let variant=this.protectionVariants[key];if(variant.stockId==option.val()){object.protection.options=variant.options;break;}}
for(let key in this.basketInfo.products){let basketProduct=this.basketInfo.products[key];object.otherProductQuantities[basketProduct.id]=basketProduct.quantity;}
protectionFromProductIndex.push(object);localStorage.appEasyProtectProtectionFromProductIndex=JSON.stringify(protectionFromProductIndex);}});return resolve(true);},{id:Shop.pageId});});};App.prototype.changeProductStockEvent=function changeProductStockEvent(mxEasyProtectContainer,mxOptions,price){return this.loadProductOptions(price).then(()=>{let chossenProtectionVariants=this.protectionVariants.filter((variant)=>variant.priceMin<=price&&price<=variant.priceMax);mxOptions.empty();if(chossenProtectionVariants.length==0){mxEasyProtectContainer.hide();}
else{chossenProtectionVariants.sort((a,b)=>a.price-b.price);mxEasyProtectContainer.show();{let mxOption=$(``).appendTo(mxOptions);mxOption.attr('for',`mx_easy_protect_radio_no_option`);let mxOptionInput=$(``).appendTo(mxOption);mxOptionInput.attr('name',`mx_easy_protect_radio`);mxOptionInput.attr('id',`mx_easy_protect_radio_no_option`);mxOptionInput.attr('value',`0`);mxOptionInput.attr('checked',`checked`);let mxOptionLabel=$(``).appendTo(mxOption);let mxOptionText=$(`${this.getTranslation('productIndexNoOptionText')}
`).appendTo(mxOption);let mxOptionPrice=$(`/bezpłatna/
`).appendTo(mxOption);}
for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];let mxOption=$(``).appendTo(mxOptions);mxOption.attr('for',`mx_easy_protect_radio_${chossenVariant.stockId}`);let mxOptionInput=$(``).appendTo(mxOption);mxOptionInput.attr('name',`mx_easy_protect_radio`);mxOptionInput.attr('id',`mx_easy_protect_radio_${chossenVariant.stockId}`);mxOptionInput.attr('value',chossenVariant.stockId);let mxOptionLabel=$(``).appendTo(mxOption);let mxOptionText=$(`${this.getTranslation('productIndexOptionText')}
`).appendTo(mxOption);let mxOptionName=$(`EasyProtect® ${chossenVariant.timePeriod}
`).appendTo(mxOption);let mxOptionPrice=$(`/${this.priceFormat(chossenVariant.price)}/
`).appendTo(mxOption);}
let mxRwdTree=$(``).appendTo(mxOptions);$(``).appendTo(mxRwdTree);$(``).appendTo(mxRwdTree);$(``).appendTo(mxOptions);}});};App.prototype.addProtectionFromProductIndex=function addProtectionFromProductIndex(skipRefresh=false){return new Promise((resolve,reject)=>{let protectionFromProductIndexes=[];if(localStorage.appEasyProtectProtectionFromProductIndex){protectionFromProductIndexes=JSON.parse(localStorage.appEasyProtectProtectionFromProductIndex);}
if(protectionFromProductIndexes.length>0){let promises=[];for(let key in protectionFromProductIndexes){let protectionFromProductIndex=protectionFromProductIndexes[key];let correctBasketProduct=null;for(let key2 in this.basketInfo.products){let basketProduct=this.basketInfo.products[key2];if(basketProduct.stock_id!=protectionFromProductIndex.product.stockId)continue;if(basketProduct.quantity==protectionFromProductIndex.otherProductQuantities[basketProduct.id])continue;protectionFromProductIndex.otherProductQuantities[basketProduct.id]+=protectionFromProductIndex.product.quantity;correctBasketProduct=basketProduct;break;}
if(correctBasketProduct==null)continue;promises.push(new Promise((resolve,reject)=>{let query={data:{stock_id:protectionFromProductIndex.protection.stockId,quantity:protectionFromProductIndex.product.quantity,options:protectionFromProductIndex.protection.options,}};query.data.options[this.optionToProductId]=`${correctBasketProduct.name}`;let hasVariant=0;if(correctBasketProduct.variant!=''){hasVariant=1;query.data.options[this.optionToProductId]+=` (${correctBasketProduct.variant})`;}
query.data.options[this.optionDataId]=`${correctBasketProduct.stock_id}, ${hasVariant}`;let wait=$('').appendTo('head');frontAPI.addToBasket((response)=>{if(response.added.length>0){protectionFromProductIndexes.splice(key,1);localStorage.appEasyProtectProtectionFromProductIndex=JSON.stringify(protectionFromProductIndexes);let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
let protectionExisted=false;for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=correctBasketProduct.id)continue;if(data.basketProtectionId!=response.added[0].id)continue;protectionExisted=true;break;}
if(!protectionExisted){protectionData.push({basketProductId:correctBasketProduct.id,basketProtectionId:response.added[0].id,});localStorage.appEasyProtectProtectionData=JSON.stringify(protectionData);}
return resolve(true);}
else{if(response._flash_messenger.error.length>0)shoper.alert(response._flash_messenger.error[0],'');if(response._flash_messenger.warning.length>0)shoper.alert(response._flash_messenger.warning[0],'');if(response._flash_messenger.info.length>0)shoper.alert(response._flash_messenger.info[0],'');}
wait.remove();},query);}));}
Promise.all(promises).then(()=>{if(skipRefresh){return resolve(true);}
else{location.replace(location.href);}});return true;}
else{return resolve(true);}});};App.prototype.waitForSoobasket=function waitForSoobasket(){return new Promise((resolve,reject)=>{let waitingFunction=()=>{if($('#box_basketlist').is(':visible')){return resolve('fallback');}
else if($('.el-table .el-table__row').length==0){setTimeout(waitingFunction,100);}
else{let protectionRows=[];let productsTable=$('.el-table .el-table__row');productsTable.each((index,tableRow)=>{tableRow=$(tableRow);for(let className of tableRow.get(0).classList){let types={'data-basket-product-id':'basket_product_id_','data-product-id':'product_id_',};for(let type in types){if(className.indexOf(types[type])!=-1){tableRow.attr(type,className.slice(types[type].length));}}}
if(tableRow.data('product-id')==this.productId){protectionRows.push(tableRow);}});if(protectionRows.length>0){let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionRows){let protectionRow=protectionRows[key];let mxInfoPageUrl=protectionRow.find(`.cell > .name > a`);mxInfoPageUrl.attr('href',`/${this.lang}/i/easy-protect/${this.infoPageId}`);mxInfoPageUrl.attr('title',this.getTranslation('infoPageText'));mxInfoPageUrl.attr('target','_blank').attr('rel','noreferrer');let variants=protectionRow.find(`.cell > .name .variant`).html().split('; ');protectionRow.find(`.cell > .name .variant`).html(`${variants[1]}; ${variants[2]}`);let basketProductId=0;let basketProtectionId=protectionRow.data('basket-product-id');for(let key2 in protectionData){let data=protectionData[key2];if(data.basketProtectionId!=basketProtectionId)continue;basketProductId=data.basketProductId;break;}
if(basketProductId!=0){protectionRow.attr('data-for-basket-product-id',basketProductId);let parentRow=$(`.el-table .el-table__row.basket_product_id_${basketProductId}`);while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionRow.insertAfter(parentRow);}}}
return resolve('loaded');}};waitingFunction();});};App.prototype.addProtectionToSoobasket=function addProtectionToSoobasket(){return new Promise((resolve,reject)=>{let protectionExists=false;let protectionForms={};let protectionInputs={};let productsTable=$(`.el-table .el-table__row`);productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){let categoryId='category'in basketProduct?basketProduct.category.category_id:-1;let producerId='producer'in basketProduct?basketProduct.producer.producer_id:-1;if(!this.checkAllowProtection(productId,categoryId,producerId))return true;let protectionForm=this.createProtectionFormSoobasket(tableRow);if(protectionForm!=false){protectionForms[basketProductId]=protectionForm;protectionInputs[basketProductId]={product:tableRow.find('.quantity-input input').eq(0),protection:[],};}}
else{protectionExists=true;tableRow.find(`.cell > .name > a`).attr('href',this.infoPageUrl);protectionInputs[tableRow.data('for-basket-product-id')].protection.push(tableRow.find('.quantity-input input').eq(0));tableRow.find('.quantity-input').each((index2,item)=>{item=$(item);let orgInput=item.find('input');let mxQuantity=item.clone().addClass('quantity-input-ep').insertAfter(item);item.addClass('quantity-input-org').hide();});}});productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId==this.productId){let protectionInput=protectionInputs[tableRow.data('for-basket-product-id')];let noProtectionQuantity=protectionInput.product.val();for(let key in protectionInput.protection){noProtectionQuantity-=protectionInput.protection[key].val();}
tableRow.find('.quantity-input-ep input').val(basketProduct.quantity).attr('data-max',basketProduct.quantity+noProtectionQuantity);if(basketProduct.quantity<=1){tableRow.find('.quantity-input-ep .el-input-number__decrease').addClass('is-disabled');}else{tableRow.find('.quantity-input-ep .el-input-number__decrease').removeClass('is-disabled');}
if(noProtectionQuantity<=0){tableRow.find('.quantity-input-ep .el-input-number__increase').addClass('is-disabled');}else{tableRow.find('.quantity-input-ep .el-input-number__increase').removeClass('is-disabled');}
tableRow.find('.quantity-input-ep input').on('change',(e)=>{let value=Math.min(Math.max(1,$(e.currentTarget).val()),$(e.currentTarget).data('max'));let input=tableRow.find('.quantity-input-org input').eq(0);if(value==input.val())return false;input.val(value);input.get(0).dispatchEvent(new Event('change'));});tableRow.find('.quantity-input-ep .el-input-number__decrease').on('click',(e)=>{if($(e.currentTarget).is('.is-disabled'))return false;let input=tableRow.find('.quantity-input-org input').eq(0);input.val(input.val()-1);input.get(0).dispatchEvent(new Event('change'));});tableRow.find('.quantity-input-ep .el-input-number__increase').on('click',(e)=>{if($(e.currentTarget).is('.is-disabled'))return false;let input=tableRow.find('.quantity-input-org input').eq(0);input.val(parseInt(input.val())+1);input.get(0).dispatchEvent(new Event('change'));});}});if(this.checkboxEnableEasyProtect){if(Object.keys(protectionForms).length>0){let mxEnableEasyProtect=$(``).prependTo('.el-form > .el-row + .el-row + .first-part-info > .el-col:last-of-type');mxEnableEasyProtect.wrap(``);let checkbox=$(``).appendTo(mxEnableEasyProtect);checkbox.attr('id','mxEnableEasyProtect');checkbox.wrap(``);$(``).insertAfter(checkbox);let label=$(``).appendTo(mxEnableEasyProtect);label.html(this.getTranslation('checkboxEnableEasyProtectText'));checkbox.on('change.enableEasyProtect',(e)=>{if(checkbox.is(':checked')){productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){let noProtectionQuantity=basketProduct.quantity;let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProductId)continue;for(let key2 in this.basketInfo.products){let basketProtection=this.basketInfo.products[key2];if(basketProtection.id!=data.basketProtectionId)continue;noProtectionQuantity-=basketProtection.quantity;}}
if(noProtectionQuantity>0){let parentRow=tableRow;while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionForms[basketProductId].insertAfter(parentRow);}}}});}
else{productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){protectionForms[basketProductId].detach();}}});}});if(protectionExists)checkbox.prop('checked',true).change();}}
else{productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){let noProtectionQuantity=basketProduct.quantity;let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProductId)continue;for(let key2 in this.basketInfo.products){let basketProtection=this.basketInfo.products[key2];if(basketProtection.id!=data.basketProtectionId)continue;noProtectionQuantity-=basketProtection.quantity;}}
if(noProtectionQuantity>0){let parentRow=tableRow;while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionForms[basketProductId].insertAfter(parentRow);}}}});}
shoper.addEvent("soobasket:refresh",(e,basket)=>{this.basketInfo=basket;this.checkExceedingProtection().then(()=>{productsTable.each((index,tableRow)=>{tableRow=$(tableRow);let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);if(basketProduct===undefined){if(basketProductId in protectionForms){protectionForms[basketProductId].remove();delete protectionForms[basketProductId];}
productsTable=productsTable.filter(i=>i!=index);return true;}
let productId=basketProduct.product_id;if(productId!=this.productId){if(basketProductId in protectionForms){let protectionInput=protectionInputs[basketProductId];let noProtectionQuantity=protectionInput.product.val();for(let key in protectionInput.protection){noProtectionQuantity-=protectionInput.protection[key].val();}
if(noProtectionQuantity>0){let mxQuantity=protectionForms[basketProductId].find('.mxQuantity').empty();for(let i=1;i<=noProtectionQuantity;i++){mxQuantity.append(``);}}
if(!this.checkboxEnableEasyProtect||$('#mxEnableEasyProtect').is(':checked')){if(noProtectionQuantity>0){let parentRow=tableRow;while(parentRow.next().data('product-id')==this.productId){parentRow=parentRow.next();}
protectionForms[basketProductId].insertAfter(parentRow);}
else{protectionForms[basketProductId].detach();}}}}
else{let protectionInput=protectionInputs[tableRow.data('for-basket-product-id')];let noProtectionQuantity=protectionInput.product.val();for(let key in protectionInput.protection){noProtectionQuantity-=protectionInput.protection[key].val();}
tableRow.find('.quantity-input-ep input').val(basketProduct.quantity).attr('data-max',basketProduct.quantity+noProtectionQuantity);if(basketProduct.quantity<=1){tableRow.find('.quantity-input-ep .el-input-number__decrease').addClass('is-disabled');}else{tableRow.find('.quantity-input-ep .el-input-number__decrease').removeClass('is-disabled');}
if(noProtectionQuantity<=0){tableRow.find('.quantity-input-ep .el-input-number__increase').addClass('is-disabled');}else{tableRow.find('.quantity-input-ep .el-input-number__increase').removeClass('is-disabled');}}});}).catch((reason)=>this.errorHandler(reason));});shoper.addEvent("soobasket:beforeorder",(e,basket)=>{let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
if(protectionData.length==0&&$('#mxEnableEasyProtect').is(':checked')){basket.additional_fields[this.checkboxEnableFieldId]='Tak';}else{delete basket.additional_fields[this.checkboxEnableFieldId];}});return resolve(true);});};App.prototype.createProtectionFormSoobasket=function createProtectionFormSoobasket(tableRow){let basketProductId=tableRow.data('basket-product-id');let basketProduct=this.basketInfo.products.find((basketProduct)=>basketProduct.id==basketProductId);let productId=basketProduct.product_id;let chossenProtectionVariants=this.protectionVariants.filter((variant)=>variant.priceMin<=basketProduct.price_float&&basketProduct.price_float<=variant.priceMax);if(chossenProtectionVariants.length==0)return false;chossenProtectionVariants.sort((a,b)=>a.price-b.price);let noProtectionQuantity=basketProduct.quantity;let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProductId)continue;for(let key2 in this.basketInfo.products){let basketProtection=this.basketInfo.products[key2];if(basketProtection.id!=data.basketProtectionId)continue;noProtectionQuantity-=basketProtection.quantity;}}
let form=$(` |
`);let mxWrapper=form.find('.mxWrapper');let mxLeftCol=$(``).appendTo(mxWrapper);let bigPurpleArrow=$(``).appendTo(mxWrapper);bigPurpleArrow.attr('src','https://mxapp2.maxserver.pl/appEasyProtect/gfx/bigPurpleArrow.png');bigPurpleArrow.wrap(``);let mxRightCol=$(``).appendTo(mxWrapper);let name=this.escapeHtml(this.protection.name);let tradeMark='';if(name.charCodeAt(name.length-1)==174){tradeMark=`${name.substr(-1, 1)}`;name=name.substr(0,name.length-1);}
if(name.charCodeAt(name.length-1)==8482){tradeMark=`${name.substr(-1, 1)}`;name=name.substr(0,name.length-1);}
let mxImage=$(``).appendTo(mxLeftCol);mxImage.wrap(``);let mxNameContainer=$(``).appendTo(mxLeftCol);let mxName=$(`${name}${tradeMark}
`).appendTo(mxNameContainer);let mxInfoPageUrl=$(`${this.getTranslation('infoPageText')}`).appendTo(mxNameContainer);mxInfoPageUrl.attr('href',this.infoPageUrl);mxInfoPageUrl.attr('target','_blank').attr('rel','noreferrer');mxInfoPageUrl.wrap(``);let smallPurpleArrow=$(``).insertBefore(mxInfoPageUrl);smallPurpleArrow.attr('src','https://mxapp2.maxserver.pl/appEasyProtect/gfx/smallPurpleArrow.png');smallPurpleArrow.wrap(``);let mxQuantityWrap=$(``).appendTo(mxRightCol);let mxQuantity=$(``).appendTo(mxQuantityWrap);for(let i=1;i<=noProtectionQuantity;i++){mxQuantity.append(``);}
let mxOptions=$(``).appendTo(mxRightCol);if(this.noOption==1){let mxOption=$(``).appendTo(mxOptions);mxOption.attr('name',`radio_${basketProductId}`);mxOption.attr('id',`radio_${basketProductId}_no_option`);mxOption.attr('value',`0`);mxOption.wrap(``);let label=$(``).insertAfter(mxOption);label.attr('for',`radio_${basketProductId}_no_option`);label.append(this.getTranslation('noOptionText'));}
for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];let mxOption=$(``).appendTo(mxOptions);mxOption.attr('name',`radio_${basketProductId}`);mxOption.attr('id',`radio_${basketProductId}_${chossenVariant.stockId}`);mxOption.attr('value',chossenVariant.stockId);mxOption.wrap(``);let label=$(``).insertAfter(mxOption);label.attr('for',`radio_${basketProductId}_${chossenVariant.stockId}`);label.append(`${chossenVariant.timePeriod} `);label.append(`${this.priceFormat(chossenVariant.price)}`);}
let mxSum=$(``).appendTo(mxRightCol);let mxAction=$(``).appendTo(mxRightCol);let mxButtonAdd=$(`${this.getTranslation('protectionAddText')}
`).appendTo(mxAction);mxQuantity.on('change',(e)=>{let quantity=parseFloat($(e.target).val());let stockId=parseFloat(mxOptions.find('input:checked').val());if(stockId==0){mxButtonAdd.stop().animate({'opacity':0.3});mxSum.text(this.priceFormat(0));}
else{mxButtonAdd.stop().animate({'opacity':1});let price=0;for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){price=chossenVariant.price;break;}}
let quantity=mxQuantity.val();mxSum.text(this.priceFormat(price*quantity));}
for(let key in this.$style.get(0).sheet.cssRules){let rule=this.$style.get(0).sheet.cssRules[key];if(rule.selectorText!='.protectionForm .mxRightCol .mxSum')continue;let width=mxSum.get(0).getBoundingClientRect().width;if(parseFloat(rule.style.minWidth){let quantity=parseFloat(mxQuantity.val());let stockId=parseFloat($(e.target).val());if(stockId==0){mxAction.addClass('mxHidden');mxButtonAdd.stop().animate({'opacity':0.3});mxSum.text(this.priceFormat(0));}
else{mxAction.removeClass('mxHidden');mxButtonAdd.stop().animate({'opacity':1});let price=0;for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){price=chossenVariant.price;break;}}
mxSum.text(this.priceFormat(price*quantity));}
for(let key in this.$style.get(0).sheet.cssRules){let rule=this.$style.get(0).sheet.cssRules[key];if(rule.selectorText!='.protectionForm .mxRightCol .mxSum')continue;let width=mxSum.get(0).getBoundingClientRect().width;if(parseFloat(rule.style.minWidth){let quantity=parseFloat(mxQuantity.val());let stockId=parseFloat(mxOptions.find('input:checked').val());if(stockId==0)return false;let options={};for(let key in chossenProtectionVariants){let chossenVariant=chossenProtectionVariants[key];if(stockId==chossenVariant.stockId){options=chossenVariant.options;break;}}
let query={data:{stock_id:stockId,quantity:quantity,options:options,}};query.data.options[this.optionToProductId]=`${basketProduct.name}`;let hasVariant=0;if(basketProduct.variant!=''){hasVariant=1;query.data.options[this.optionToProductId]+=` (${basketProduct.variant})`;}
query.data.options[this.optionDataId]=`${basketProduct.stock_id}, ${hasVariant}`;let wait=$('').appendTo('head');frontAPI.addToBasket((response)=>{if(response.added.length>0){let protectionData=[];if(localStorage.appEasyProtectProtectionData){protectionData=JSON.parse(localStorage.appEasyProtectProtectionData);}
let protectionExisted=false;for(let key in protectionData){let data=protectionData[key];if(data.basketProductId!=basketProduct.id)continue;if(data.basketProtectionId!=response.added[0].id)continue;protectionExisted=true;break;}
if(!protectionExisted){protectionData.push({basketProductId:basketProduct.id,basketProtectionId:response.added[0].id,});localStorage.appEasyProtectProtectionData=JSON.stringify(protectionData);}
location.replace(location.href);}
else{if(response._flash_messenger.error.length>0)shoper.alert(response._flash_messenger.error[0],'');if(response._flash_messenger.warning.length>0)shoper.alert(response._flash_messenger.warning[0],'');if(response._flash_messenger.info.length>0)shoper.alert(response._flash_messenger.info[0],'');}
wait.remove();},query);});return form;};App.prototype.errorHandler=function errorHandler(reason){switch(reason){case'ExceedingProtection':console.log(reason);break;default:console.error(reason);break;}};App.prototype.insertStyle=function insertStyle(){this.$style.append(`
.protectionForm .protectionFormTd {
padding: 0;
}
.protectionForm .mxWrapper {
padding: 10px 30px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}
.protectionForm .mxLeftCol {
display: grid;
grid: auto / 85px auto;
gap: 5px;
}
.protectionForm .mxLeftCol .mxImage {
align-self: center;
justify-self: center;
}
.protectionForm .mxLeftCol .mxNameContainer {
display: grid;
align-content: center;
gap: 10px;
}
.protectionForm .mxLeftCol .mxNameContainer .mxName {
display: block;
max-width: 350px;
line-height: 24px;
color: #666;
font-size: 21px;
font-weight: bold;
text-align: center;
}
.protectionForm .mxLeftCol .mxNameContainer .mxName .mxTradeMark {
margin-left: 3px;
font-size: 15px;
font-weight: normal;
vertical-align: text-top;
}
.protectionForm .mxLeftCol .mxNameContainer .mxInfoPageUrl {
text-align: center;
}
.protectionForm .mxLeftCol .mxNameContainer .mxInfoPageUrl a {
text-decoration: none;
font-size: 14px;
font-weight: bold;
}
.protectionForm .mxLeftCol .mxNameContainer .mxInfoPageUrl .mxSmallPurpleArrow img {
width: 19px;
}
.protectionForm .mxBigPurpleArrow {
width: 30px;
}
.protectionForm .mxRightCol {
position: relative;
display: flex;
align-items: center;
gap: 20px;
}
.protectionForm .mxRightCol .mxQuantityWrap {
position: relative;
display: flex;
align-items: center;
}
.protectionForm .mxRightCol .mxQuantityWrap::after {
content: "";
position: absolute;
display: block;
right: 10px;
width: 4px;
height: 4px;
margin-top: -2px;
transform: rotate(-45deg);
border-color: #392074;
border-style: solid;
border-width: 0 0 1px 1px;
pointer-events: none;
}
.protectionForm .mxRightCol .mxQuantity {
height: 30px;
line-height: 30px;
min-height: unset;
min-width: 45px;
padding: 0 18px 0 6px;
background: #dcdddf !important;
border: 1px solid #cac6d8;
border-radius: 5px;
color: #392074;
font-size: 15px;
font-weight: bold;
cursor: pointer;
}
.protectionForm .mxRightCol .mxQuantity:hover,
.protectionForm .mxRightCol .mxQuantity:focus {
border-color: #a49cba;
}
.protectionForm .mxRightCol .mxOptions {
display: grid;
gap: 5px;
}
.protectionForm .mxRightCol .mxOptions .mxOption {
}
.protectionForm .mxRightCol .mxOptions .mxOption input {
display: none !important;
}
.protectionForm .mxRightCol .mxOptions .mxOption label {
display: block;
line-height: 18px;
min-width: max-content;
padding: 6px 25px;
background: #dcdddf;
border: 1px solid #cac6d8;
border-radius: 6px;
font-size: 15px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
.protectionForm .mxRightCol .mxOptions .mxOption label:hover {
border-color: #a49cba;
}
.protectionForm .mxRightCol .mxOptions .mxOption input:checked + label {
border-color: #a49cba;
}
.protectionForm .mxRightCol .mxOptions .mxOption .mxColor {
color: #392074;
}
.protectionForm .mxRightCol .mxSum {
min-width: 68px;
font-size: 16px;
font-weight: bold;
color: #392074;
text-align: center;
}
.protectionForm .mxRightCol .mxAction .mxButtonAdd {
line-height: 18px;
padding: 6px 15px;
border-radius: 6px;
background: #dcdddf;
border: 1px solid #cac6d8;
color: #392074;
font-size: 15px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
.protectionForm .mxRightCol .mxAction:not(.mxHidden) .mxButtonAdd:hover {
border-color: #a49cba;
}
.protectionForm .mxRightCol .mxAction.mxHidden .mxButtonAdd {
cursor: default;
}
.wce_celltitles .protectionForm {
justify-content: center;
padding: 15px;
}
.wce_celltitles .protectionForm .mxWrapper {
flex-direction: column;
padding: 0;
}
.wce_celltitles .protectionForm .mxBigPurpleArrow {
display: none;
}
.el-table .protectionForm .protectionFormTd {
border-bottom: 1px solid #ebeef5;
}
.el-table .protectionForm .mxWrapper {
padding: 10px 20px 10px 10px;
}
.el-table .protectionForm .mxLeftCol {
grid: auto / 100px auto;
gap: 10px;
}
.el-table .protectionForm .mxLeftCol .mxImage img {
margin: 0 !important;
}
.el-table .protectionForm .mxLeftCol .mxNameContainer .mxInfoPageUrl .mxSmallPurpleArrow img {
margin: 0 !important;
}
.el-table .protectionForm .mxBigPurpleArrow img {
margin: 0 !important;
}
.mxEasyProtectContainer {
clear: both;
margin-top: 30px;
}
.mxEasyProtectContainer .mxText {
margin-bottom: 15px;
line-height: 15px;
color: #4D2F81;
font-size: 15px;
font-weight: bold;
}
.mxEasyProtectContainer .mxOptions {
margin-bottom: 15px;
}
.mxEasyProtectContainer .mxSmallGreyArrow {
display: inline-block;
margin-left: 10px;
}
.mxEasyProtectContainer .mxSmallGreyArrow img {
filter: grayscale(1);
height: 13px;
}
.mxEasyProtectContainer .mxInfoPageUrl {
font-size: 14px;
}
.mxEasyProtectContainer .mxInfoPageUrl a {
color: #4D2E81;
}
.mxEasyProtectContainer .mxOptions .mxOption {
display: block;
margin-bottom: 10px;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionInput {
display: none;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionLabel {
position: relative;
display: inline-block;
vertical-align: bottom;
width: 20px;
height: 21px;
margin-right: 10px;
background: url(https://mxapp2.maxserver.pl/appEasyProtect/gfx/purpleHexagon.svg) center no-repeat;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionLabel::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
border-radius: 4px;
width: 8px;
height: 8px;
transform: translate(-50%, -50%);
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionInput:checked + .mxOptionLabel::before {
background: #4D2F81;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionText {
display: inline-block;
margin-left: 5px;
font-size: 14px;
font-weight: bold;
color: #737477;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionName {
display: inline-block;
margin-left: 5px;
font-size: 15px;
font-weight: bold;
color: #4D2F81;
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionName span {
/* font-weight: normal; */
}
.mxEasyProtectContainer .mxOptions .mxOption .mxOptionPrice {
display: inline-block;
margin-left: 7px;
font-size: 14px;
color: #5B5B5B;
}
@media screen and (max-width: 1200px) {
}
@media screen and (min-width: 980px) and (max-width: 1200px) {
.protectionForm .mxLeftCol .mxNameContainer .mxName {
max-width: 260px;
}
.protectionForm .mxRightCol .mxOptions .mxOption label {
padding: 6px 20px;
}
.wce_celltitles .protectionForm .mxLeftCol .mxNameContainer .mxName {
max-width: 350px;
}
.wce_celltitles .protectionForm .mxRightCol .mxOptions .mxOption label {
padding: 6px 25px;
}
}
@media screen and (max-width: 979px) {
.protectionForm .mxWrapper {
flex-direction: column;
padding: 10px 8px;
}
.protectionForm .mxBigPurpleArrow {
display: none;
}
.el-table .protectionForm .mxWrapper {
flex-direction: row;
padding: 10px 20px 10px 10px;
}
.el-table .protectionForm .mxBigPurpleArrow {
display: block;
}
}
@media screen and (min-width: 768px) and (max-width: 979px) {
/*.protectionForm .mxRightCol .mxAction.mxHidden {
display: none;
}*/
.el-table .protectionForm .mxLeftCol .mxNameContainer .mxName {
max-width: 260px;
}
/*.el-table .protectionForm .mxRightCol .mxAction.mxHidden {
display: block;
}*/
.el-table .protectionForm .mxRightCol .mxOptions .mxOption label {
padding: 6px 20px;
}
}
@media screen and (max-width: 767px) {
.protectionForm .mxRightCol .mxOptions .mxOption label {
padding: 6px 20px;
}
.el-table .protectionForm {
display: flex;
width: 100%;
}
.el-table .protectionForm .protectionFormTd {
width: 100%;
}
.el-table .protectionForm .mxWrapper {
flex-direction: column;
padding: 10px 0;
}
.el-table .protectionForm .mxBigPurpleArrow {
display: none;
}
}
@media screen and (min-width: 481px) and (max-width: 767px) {
/*.protectionForm .mxRightCol .mxAction.mxHidden {
display: none;
}*/
}
@media screen and (max-width: 480px) {
.protectionForm .mxRightCol {
display: grid;
grid: auto 1fr auto / repeat(2, auto);
grid-template-areas:
"mxOptions mxQuantityWrap"
"mxOptions mxSum"
"mxOptions mxAction";
justify-items: center;
gap: 10px 20px;
}
.protectionForm .mxRightCol .mxQuantityWrap {
grid-area: mxQuantityWrap;
}
.protectionForm .mxRightCol .mxOptions {
grid-area: mxOptions;
height: 100%;
align-content: space-between;
}
.protectionForm .mxRightCol .mxSum {
grid-area: mxSum;
}
.protectionForm .mxRightCol .mxAction {
grid-area: mxAction;
}
.el-table .protectionForm .mxLeftCol {
grid: auto / 85px auto;
}
}
@media screen and (min-width: 980px) {
/*.wce_celltitles .protectionForm .mxRightCol .mxAction.mxHidden {
display: none;
}*/
}
`);};App.prototype.insertInfoPageStyle=function insertInfoPageStyle(){this.$style.append(`
.mxArticle .mxMainBanner img {
max-height: 100%;
}
.mxArticle .mxMainTitle {
color: #392074;
font-size: 4em;
text-align: center;
margin-bottom: 30px;
margin-top: 20px;
line-height: 1.3em;
font-weight: bold;
}
.mxArticle .mx_arrow_down {
text-align: center;
}
.mxArticle .mx_under_header_txt {
font-size: 1.4em;
line-height: 1.5em;
font-weight: 600;
text-align: center;
max-width: 640px;
margin: 0 auto;
margin-top: 10px;
}
.mxArticle .mxTitle {
font-size: 1.7rem;
font-weight: 600;
line-height: 1.5em;
text-align: center;
margin: 30px 0 10px 0;
color: #392074;
display: block; /*shoper konvertuje na span*/
}
.mxArticle .mxToolsRepairCost {
max-width: 880px;
margin: 20px auto;
text-align: center;
}
.mxArticle .mx_arrow_up {
text-align: center;
transform: rotate(180deg);
}
.mxArticle .mx_margin {
margin-bottom: 30px;
}
.mxArticle .mxAttributesHoneycomb {
max-width: 880px;
margin: 0 auto;
text-align: center;
}
.mxArticle .mxAttributesHoneycombBackground {
background-color: rgb(230, 231, 233);
padding: 50px 0;
}
.mxArticle .mxServiceSteps {
max-width: 880px;
margin: 50px auto;
text-align: center;
}
.mxArticle .mxInNumbers {
background-color: rgb(230, 231, 233);
padding: 20px 0;
}
.mxArticle .mxInNumbers .logo_img {
text-align: center;
}
.mxArticle .mxInNumbers .mxInNumbersHeader {
font-size: 1.7rem;
text-align: center;
color: rgb(96, 100, 108);
margin-bottom: 10px;
line-height: 1.3em;
font-weight: bold;
}
.mxArticle .mxInNumbers .mxInNumbersHeader .mxColor {
color: #392074;
}
.mxArticle .mxInNumbers .mx_inner_box {
display: grid;
justify-content: center;
grid-template-areas:
"first second third fourth"
". bottom_first bottom_second .";
}
.mxArticle .mxInNumbers .mx_tile {
text-align: center;
background-color: white;
padding: 10px;
height: 150px;
width: 150px;
border-radius: 30px;
margin: 25px;
}
.mxArticle .mxInNumbers .inside_box_tile {
text-align: center;
padding: 5px;
}
.mxArticle .mxInNumbers .mx_smaller_text {
display: block;
width: 80%;
margin: auto;
}
.mxArticle .mxInNumbers .mx_bolder_upper_text {
font-weight: 600;
font-size: 1rem;
color: #60646c;
}
.mxArticle .mxInNumbers .bolder_small_text {
font-weight: 600;
color: #60646c;
}
.mxArticle .mxInNumbers .over_ten_year.mx_tile {
grid-area: first;
}
.mxArticle .mxInNumbers .over_likes.mx_tile {
grid-area: second;
}
.mxArticle .mxInNumbers .every_five_minutes.mx_tile {
grid-area: third;
}
.mxArticle .mxInNumbers .service_points.mx_tile {
grid-area: fourth;
}
.mxArticle .mxInNumbers .mx_partenrs_tile.mx_tile {
grid-area: bottom_first;
}
.mxArticle .mxInNumbers .active_traders.mx_tile {
grid-area: bottom_second;
}
@media screen and (max-width: 1200px) {
}
@media screen and (min-width: 980px) and (max-width: 1200px) {
}
@media screen and (max-width: 979px) {
}
@media screen and (min-width: 768px) and (max-width: 979px) {
.mxArticle .mxInNumbers .mx_inner_box {
grid-template-areas:
"first second third"
"fourth bottom_first bottom_second";
}
}
@media screen and (max-width: 767px) {
}
@media screen and (min-width: 481px) and (max-width: 767px) {
.mxArticle .mxInNumbers .mx_inner_box {
grid-template-areas:
"first second"
"third fourth"
"bottom_first bottom_second";
}
}
@media screen and (max-width: 480px) {
.mxArticle .mxInNumbers .mx_inner_box {
grid-template-areas:
"first"
"second"
"third"
"fourth"
"bottom_first"
"bottom_second";
}
}
`);};App.prototype.getTranslation=function getTranslation(varName,escape=true,lang=this.lang){let translation='';if(lang in this.translations[varName]){translation=this.translations[varName][lang];}else{translation=this.translations[varName]['__default'];}
if(!escape)return translation;return this.escapeHtml(translation);};App.prototype.escapeHtml=function escapeHtml(unsafe){return unsafe.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'");};App.prototype.priceFormat=function priceFormat(price,currency=this.currency,lang=this.lang){if(currency==undefined){throw new Error('Undefined currency');}
if(typeof this._priceFormater==='undefined'||this._priceFormaterLang!=lang||this._priceFormaterCurrency!=currency){this._priceFormaterLang=lang;this._priceFormaterCurrency=currency;this._priceFormater=new Intl.NumberFormat(lang.split('_').join('-'),{style:'currency',currency:currency});}
return this._priceFormater.format(price);};App.prototype.loadCurrency=function loadCurrency(){if('currency'in this)return Promise.resolve(this.currency);return new Promise((resolve,reject)=>{this.waitFor(()=>{return typeof Shop.values==='object'&&typeof Shop.values.currency==='string';},()=>{this.currency=Shop.values.currency;return resolve(this.currency);});});};App.prototype.waitFor=function waitFor(expr,callback,interval=0){if(!expr()){setTimeout(this.waitFor.bind(this,expr,callback,interval),interval);}
else{callback();}};setTimeout(()=>App.prototype.waitFor(()=>typeof Shop.pageType==='string',()=>new App()),0);})(jQuery);