(function appFotoformaWarranty($){let App=function App(){this.optionsLinkUrl='https://fotoforma.pl/tu-europa-dodatkowa-ochrona-urzadzen-dla-klientow-fotoforma';this.shopId=2;this.translations_array={"add_text":{"__default":"Dodaj do koszyka"}};this.promoCodes=[{"code":"qwerty","value":0.25},{"code":"test_tueuropa","value":0.5}];this.warrantyId=22890;this.optionNameId=313;this.optionDataId=319;this.warrantyQuestion1FieldId=23;this.warrantyQuestion2FieldId=24;this.warrantyQuestion3FieldId=25;this.taxIdentificationFieldId=12;this.birthDateFieldId=13;this.marketingConsent1FieldId=14;this.marketingConsent2FieldId=15;this.marketingConsent3FieldId=16;this.marketingConsent4FieldId=17;this.marketingConsent5FieldId=18;this.marketingConsent6FieldId=19;this.marketingConsent7FieldId=20;this.marketingConsent8FieldId=21;this.marketingConsent9FieldId=22;this.lang=Shop.lang.name;this.currency=Shop.values.currency?Shop.values.currency:"PLN";this.$style=$('').appendTo('head');this.warrantyData=[];if(localStorage.appFotoformaWarrantyData){this.warrantyData=JSON.parse(localStorage.appFotoformaWarrantyData);} this.currentCode=null;if(localStorage.appFotoformaPromoCode){this.currentCode=JSON.parse(localStorage.appFotoformaPromoCode);const codeExists=this.promoCodes.find(item=>item.code===this.currentCode.code);if(codeExists===undefined){delete localStorage.appFotoformaPromoCode;this.currentCode=null;}} this.warrantyOptions=[{key:'basicWarranty',name:'Ochrona Basic, awaria po zakończeniu okresu gwarancji producenta',nameShort:'Ochrona Basic',icon:'https://sklep164610.shoparena.pl/upload/shield_blue.png',options:[{name:'12 miesięcy',value:1.68,code:'W1_A_24',pakiet:1,wariant:1},{name:'24 miesięcy',value:3.08,code:'W2_A_24',pakiet:1,wariant:2},{name:'36 miesięcy',value:4.48,code:'W3_A_24',pakiet:1,wariant:3},],features:[{name:'Awaria urządzenia',avaliable:true,tooltip:'Ochrona urządzenia w przypadku awarii po zakończeniu gwarancji producenta'},{name:'Przypadkowe uszkodzenie',avaliable:false,tooltip:'Ochrona urządzenia wskutek przypadkowego uszkodzenia urządzenia'},{name:'Kradzież urządzenia',avaliable:false,tooltip:'Ochrona urządzenia wskutek kradzieży z włamaniem lub rabunku'},{name:'Bezpłatny serwis',avaliable:true,tooltip:'Nie ponosisz kosztów naprawy uszkodzonego urządzenia nawet do 5 lat od chwili zakupu'},{name:'Prosta i szybka realizacja świadczenia',avaliable:true,tooltip:'Organizujemy transport urządzenia do i z punktu serwisowego oraz zapewniamy organizację i pokrycie kosztów naprawy'},{name:'Naprawa sprzętu przez profesjonalny serwis',avaliable:true,tooltip:'Gwarancja, że Twój sprzęt trafi w ręce trafi w ręce profesjonalnego serwisu'},{name:'Karta podarunkowa',avaliable:true,tooltip:'W przypadku szkody całkowitej lub szkody wskutek kradzieży z włamaniem lub rabunku urządzenia, otrzymasz kartę podarunkową, którą można dokonywać bezgotówkowych zakupów w sieci Fotoforma'},],},{key:'bestWarranty',name:'Ochrona Best, awaria po zakończeniu okresu gwarancji producenta, przypadkowe uszkodzenie, kradzież z włamaniem lub rabunek',nameShort:'Ochrona Best',icon:'https://sklep164610.shoparena.pl/upload/shield_gold.png',options:[{name:'36 miesięcy',value:14.05,code:'W4_APUK_24',pakiet:2,wariant:4},{name:'48 miesięcy',value:19.63,code:'W5_APUK_24',pakiet:2,wariant:5},{name:'60 miesięcy',value:25.25,code:'W6_APUK_24',pakiet:2,wariant:6},],features:[{name:'Awaria urządzenia',avaliable:true,tooltip:'Ochrona urządzenia w przypadku awarii po zakończeniu gwarancji producenta'},{name:'Przypadkowe uszkodzenie',avaliable:true,tooltip:'Ochrona urządzenia wskutek przypadkowego uszkodzenia urządzenia'},{name:'Kradzież urządzenia',avaliable:true,tooltip:'Ochrona urządzenia wskutek kradzieży z włamaniem lub rabunku'},{name:'Bezpłatny serwis',avaliable:true,tooltip:'Nie ponosisz kosztów naprawy uszkodzonego urządzenia nawet do 5 lat od chwili zakupu'},{name:'Prosta i szybka realizacja świadczenia',avaliable:true,tooltip:'Organizujemy transport urządzenia do i z punktu serwisowego oraz zapewniamy organizację i pokrycie kosztów naprawy'},{name:'Naprawa sprzętu przez profesjonalny serwis',avaliable:true,tooltip:'Gwarancja, że Twój sprzęt trafi w ręce trafi w ręce profesjonalnego serwisu'},{name:'Karta podarunkowa',avaliable:true,tooltip:'W przypadku szkody całkowitej lub szkody wskutek kradzieży z włamaniem lub rabunku urządzenia, otrzymasz kartę podarunkową, którą można dokonywać bezgotówkowych zakupów w sieci Fotoforma'},],}];this.insertStyle();if($('body').hasClass('shop_basket')){this.basketIndex();} if($('body').hasClass('shop_basket_address')){this.basketAddress();} if($('body').hasClass('shop_basket_step3')){this.basketStep3();} if($('body').hasClass('shop_basket_done')){delete localStorage.appFotoformaPromoCode;} if($('body').hasClass('shop_product')){this.productIndex();}};App.prototype.basketIndex=function basketIndex(){this.waitFor(function(){return(typeof window.frontAPI==='object'&&typeof window.frontAPI.getProduct==='function'&&typeof window.frontAPI.getBasketInfo==='function');},function(){frontAPI.getProduct(function(warranty){if('error_description'in warranty)return false;this.warranty=warranty;frontAPI.getBasketInfo(function(basket){this.basketInfo=basket;if(this.checkWarranty()===false){return false;} if(this.warrantyData.length!=0){$('#shipping_12').parent().parent().parent().addClass('none');} let productsWithWarranty=$(`#box_basketlist .productlist > tbody > tr[data-product-id]`);productsWithWarranty.each(function(index,item){item=$(item);if(item.find('.prodremove').length==0||item.find('.prodremove').attr('href')=='')return true;let productBasketId=item.find('.prodremove').attr('href').split("/").pop();item.attr('data-product-basket-id',productBasketId);if(item.data('product-id')!=this.warrantyId){let dataIndex=this.warrantyData.findIndex(function(a){return a.productBasketId==productBasketId;}.bind(this));let productBasket=this.basketInfo.products.find(function(a){return a.id==productBasketId;}.bind(this));if(item.find('.warrantyTUEurope').val()=='1'&&500<=productBasket.price_float&&productBasket.price_float<35000){if(dataIndex==-1){this.insertForm(item);}} else{if(dataIndex!=-1){frontAPI.removeFromBasket(function(response){if(response._flash_messenger.error.length==0){this.warrantyData.splice(dataIndex,1);localStorage.appFotoformaWarrantyData=JSON.stringify(this.warrantyData);} location.replace(location.href);}.bind(this),{id:this.warrantyData[dataIndex].warrantyBasketId});return false;}}} else{let dataIndex=this.warrantyData.findIndex(function(a){return a.warrantyBasketId==productBasketId;}.bind(this));let productBasket=this.basketInfo.products.find(function(a){return a.id==this.warrantyData[dataIndex].productBasketId;}.bind(this));let productItem=$(`#box_basketlist .productlist > tbody > tr[data-product-basket-id="${productBasket.id}"]`);item.insertAfter(productItem);item.find('.name a').attr('href',this.optionsLinkUrl).attr('target','_blank').attr('rel','noopener');item.find('.quantity .shaded_inputwrap').hide();let key=this.warrantyData[dataIndex].optionGroup;let key2=this.warrantyData[dataIndex].option;item.find('.price').html(`${this.warrantyOptions[key].name}: ${this.warrantyOptions[key].options[key2].name}`);productItem.find('.quantity input').on('change',function(e){const priceChange=(this.currentCode===null)?1:1-this.currentCode.value;let quantity=Math.round((productBasket.price_float*this.warrantyOptions[key].options[key2].value*priceChange)*e.target.value);item.find('.quantity input').val(quantity);item.find('.sum .color').html(this.priceFormat(quantity / 100));}.bind(this)).trigger('change');}}.bind(this));$('.promocode button').on('click',function(e){const promocode=$('.promocode input').val().trim();const code=this.promoCodes.find(item=>item.code===promocode);if(code===undefined||code==null)return true;e.preventDefault();$('.promocode input').val('');const priceChange=(this.currentCode===null)?code.value:code.value-this.currentCode.value;this.currentCode=code;localStorage.appFotoformaPromoCode=JSON.stringify(code);this.insertAddedCodeMessage(code.code);if(priceChange===0)return true;$(`#box_basketlist .productlist > tbody > tr[data-product-id] .quantity input`).trigger('change');}.bind(this))}.bind(this),{lang:this.lang,currency:this.currency});}.bind(this),{id:this.warrantyId,lang:this.lang,currency:this.currency});}.bind(this));};App.prototype.basketAddress=function basketAddress(){if(this.warrantyData.length>0){let appFotoformaWarrantyQuestions=JSON.parse(localStorage.appFotoformaWarrantyQuestions);$(`#additional_${this.warrantyQuestion1FieldId}`).val(appFotoformaWarrantyQuestions.warrantyQuestion1?"Tak":"Nie");$(`#additional_${this.warrantyQuestion2FieldId}`).val(appFotoformaWarrantyQuestions.warrantyQuestion2?"Tak":"Nie");$(`#additional_${this.warrantyQuestion3FieldId}`).val(appFotoformaWarrantyQuestions.warrantyQuestion3?"Tak":"Nie");let mailInfo=$(`
`);buttonAdd.append(`Dodaj`);options.find('input').on('change',function(e){price.html(this.priceFormat(productBasket.price_float*productBasket.quantity*e.target.value / 100));}.bind(this)).first().change();buttonAdd.on('click',function(e){let wait=$('').appendTo('head');let option=options.find('input:checked');const priceChange=(this.currentCode===null)?1:1-this.currentCode.value;let query={data:{stock_id:this.warranty.stockId,quantity:Math.round((productBasket.price_float*option.val()*priceChange)*productBasket.quantity),options:{},}};query.data.options[this.optionNameId]=`${productBasket.name}`;if(productBasket.variant!=''){query.data.options[this.optionNameId]+=` (${productBasket.variant})`;}
query.data.options[this.optionDataId]=`${productBasket.stock_id}, ${option.data('group')}, ${option.data('option')}`;frontAPI.addToBasket(function(response){if(response.added.length>0){let warrantyData=[];if(localStorage.appFotoformaWarrantyData){warrantyData=JSON.parse(localStorage.appFotoformaWarrantyData);}
warrantyData.push({warrantyBasketId:response.added[0].id,productBasketId:productBasket.id,optionGroup:option.data('group'),option:option.data('option'),});localStorage.appFotoformaWarrantyData=JSON.stringify(warrantyData);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);}.bind(this));checkbox.on('change',function(e){if($(e.target).is(':checked')&&this.warrantyQuestions(checkbox)){form.insertAfter(item);}
else{form.detach();}}.bind(this));};App.prototype.checkWarranty=function checkWarranty(){let update=false;let refresh=false;for(let productBasket of this.basketInfo.products){if(productBasket.product_id==this.warrantyId){let dataIndex=this.warrantyData.findIndex(function(a){return a.warrantyBasketId==productBasket.id;});if(dataIndex==-1){frontAPI.removeFromBasket(function(){},{id:productBasket.id});refresh=true;continue;}}}
for(let dataIndex in this.warrantyData){let warrantyInBasket=this.basketInfo.products.find(function(a){return a.id==this.warrantyData[dataIndex].warrantyBasketId;}.bind(this));if(warrantyInBasket===undefined){this.warrantyData.splice(dataIndex,1);update=true;continue;}
let productInBasket=this.basketInfo.products.find(function(a){return a.id==this.warrantyData[dataIndex].productBasketId;}.bind(this));if(productInBasket===undefined){frontAPI.removeFromBasket(function(response){if(response._flash_messenger.error.length==0){this.warrantyData.splice(dataIndex,1);update=true;}}.bind(this),{id:this.warrantyData[dataIndex].warrantyBasketId});refresh=true;continue;}}
if(update){localStorage.appFotoformaWarrantyData=JSON.stringify(this.warrantyData);}
if(refresh){location.replace(location.href);return false;}};App.prototype.warrantyQuestions=function warrantyQuestions(item){if(item.data('answer')==true){return true;}
let form=$(``);let questions=$('').appendTo(form);let question,checkbox;question=$(``).appendTo(questions);question.append(`
`);buttonSave.append(`Zapisz`);let modal=new Shop.Modal({showMask:true,position:'center',positionType:'fixed',offset:20,header:'',content:form,footer:'',});modal.createModal();modal.callbacks.close=function(){item.prop('checked',false);setTimeout(function(){modal.destroyModal();},400);};buttonSave.on('click',function(e){modal.callbacks.close=null;modal.hideModal();modal._hideMask();setTimeout(function(){modal.destroyModal();},400);let checkedInputs=form.find('input:checked');if(checkedInputs.length>=2){let appFotoformaWarrantyQuestions={"warrantyQuestion1":false,"warrantyQuestion2":false,"warrantyQuestion3":false};checkedInputs.each(function(){appFotoformaWarrantyQuestions[this.id]=true;});localStorage.appFotoformaWarrantyQuestions=JSON.stringify(appFotoformaWarrantyQuestions);item.data('answer',true);item.change();}
else{item.prop('checked',false);let info=$(`
`);buttonChange.append(`Wstecz`);let modal2=new Shop.Modal({showMask:true,position:'center',positionType:'fixed',offset:20,header:'',content:info,footer:'',});modal2.createModal();modal2.callbacks.close=function(){setTimeout(function(){modal2.destroyModal();},400);};buttonChange.on('click',function(e){modal2.hideModal();modal2._hideMask();setTimeout(function(){modal2.destroyModal();},400);item.prop('checked',true);this.warrantyQuestions(item);}.bind(this));}}.bind(this));return false;};App.prototype.insertProductIndexFeature=function insertProductIndexFeature(warrantyInput){$("#box_productfull .addtobasket").on('click',e=>{e.preventDefault();let price=shoper.toPrimaryValue($('#box_productfull .main-price').text());let quantity=shoper.toPrimaryValue($('#box_productfull input[name="quantity"]').val());this.showProductIndexForm(price,quantity);});};App.prototype.showProductIndexForm=function showProductIndexForm(price,quantity){let appFotoformaWarrantyQuestions=[];if(localStorage.appFotoformaWarrantyQuestions){appFotoformaWarrantyQuestions=JSON.parse(localStorage.appFotoformaWarrantyQuestions);}
let form=$(``);let questions=$('').appendTo(form);let question,checkbox;question=$(``).appendTo(questions);question.append(`
`);buttonAdd.append(`Dodaj do koszyka`);let questionsInputs=form.find('#warrantyQuestion1, #warrantyQuestion2, #warrantyQuestion3');questionsInputs.on('change',e=>{let checkedInputs=questionsInputs.filter(':checked');if(checkedInputs.length<2){form.find('.warrantyOptionOption input:not([data-group="-1"])').prop('disabled',true);let temp=form.find('.warrantyOption').removeClass('recomended');temp.eq(0).addClass('recomended');}
else{form.find('.warrantyOptionOption input:not([data-group="-1"])').prop('disabled',false);let temp=form.find('.warrantyOption').removeClass('recomended');if(!form.find('#warrantyQuestion3').is(':checked')){temp.eq(1).addClass('recomended');}
if(!form.find('#warrantyQuestion2').is(':checked')){temp.eq(2).addClass('recomended');}}}).eq(0).change();let modal=new Shop.Modal({showMask:true,position:'center',positionType:'fixed',offset:20,header:'Dodatkowa ochrona Twojego sprzętu',content:form,footer:'',});modal.createModal();modal.object.container.css('min-height','min-content');modal.callbacks.close=function(){setTimeout(function(){modal.destroyModal();},400);};buttonAdd.on('click',function(e){let selectedOption=form.find('.warrantyOptionOption input:checked');if(selectedOption.length!=1)return;if(selectedOption.data('group')==-1){modal.callbacks.close=null;modal.hideModal();modal._hideMask();setTimeout(function(){modal.destroyModal();},400);$('#box_productfull .form-basket').submit();return;}
let checkedInputs=questionsInputs.filter(':checked');if(checkedInputs.length<2)return;modal.callbacks.close=null;modal.hideModal();modal._hideMask();setTimeout(function(){modal.destroyModal();},400);let appFotoformaWarrantyQuestions={"warrantyQuestion1":false,"warrantyQuestion2":false,"warrantyQuestion3":false};checkedInputs.each(function(){appFotoformaWarrantyQuestions[this.id]=true;});localStorage.appFotoformaWarrantyQuestions=JSON.stringify(appFotoformaWarrantyQuestions);if(typeof this.productIndexOption==='undefined'){shoper.addEvent('cart:add:ajax',()=>{let productBasket=null;let addedProduct=shoper.ajaxbasket.json.added[0];for(let product of shoper.ajaxbasket.json.basket.products){if(product.basket_id!=addedProduct.b_id)continue;productBasket=product;break;}
if(productBasket!==null&&productBasket.quantity!=addedProduct.quantity){let warrantyData=[];if(localStorage.appFotoformaWarrantyData){warrantyData=JSON.parse(localStorage.appFotoformaWarrantyData);}
let currentWarranty=null;for(let warranty of warrantyData){if(warranty.productBasketId!=addedProduct.b_id)continue;currentWarranty=warranty;break;}
if(currentWarranty!==null)
if(currentWarranty.optionGroup===this.productIndexOption.group)
if(currentWarranty.option===this.productIndexOption.option)return;}
this.addWarranty(shoper.toPrimaryValue(addedProduct.price),addedProduct.quantity,this.productIndexOption.multiplier,addedProduct.name,addedProduct.variant,addedProduct.id,this.productIndexOption.group,this.productIndexOption.option,addedProduct.b_id);});}
this.productIndexOption={multiplier:selectedOption.val(),group:selectedOption.data('group'),option:selectedOption.data('option'),};$('#box_productfull .form-basket').submit();}.bind(this));};App.prototype.insertWarrantyOption=function insertWarrantyOption(key,optionsData,warrantyOptions,price,quantity){let warrantyOption=$(`