1import{M as L}from"./modal.4UHXGg1k.js";import{$ as r}from"../chunks/jquery.CKSFNtpw.js";import{b as x,a as P,R as M,c as b,d as w,e as u}from"../chunks/config.ZTCpf2uF.js";import"../chunks/modal.XuKL5uPu.js";import"../vendor/vendor~common.8Elyt_ZV.js";const E="ingredient.increase",o="ingredient.increased",p="ingredient.decrease",c="ingredient.decreased",d="ingredient.delete",h="ingredient.deleted",n=".js-recipe-ingredient-container",G=n+'[data-ingredient-is-bound="true"]',k=n+':not([data-ingredient-is-bound="true"])',T=".js-ingredient-counter",N=".js-ingredient-price-tag",F=".js-add",U=".js-subtract",V=".js-ingredient-price",j=".js-ingredient-price-decimal",B=".js-delete-from-recipe",R="ingredient.alternatives.not_found",I="ingredient.alternatives.found",v="ingredient.alternatives.replace",g="ingredient.alternatives.replaced",A="ingredient.alternatives.toggle",m="-has-products-loaded",y=".js-slider-wrapper",W=".js-recipe-cart-product-slider",K="[data-error-container]",_="ingredient.price.updated",C="ingredient.error.max-amount",S="ingredient.error.big-order-amount",f="ingredient.amount-ok",Q="kg";class X{ingredient;container;text;amount;step;increase;decrease;constructor(t){this.ingredient=t,this.container=t.find(T),this.text=this.container.find(".counter__number"),this.amount=this.container.find('[name="amount"]'),this.step=this.container.find('[name="step"]'),this.increase=this.container.find(F),this.decrease=this.container.find(U),this.listen(),this.checkAmountLimits()}listen=()=>{this.ingredient.on(E,this.increaseAmount),this.ingredient.on(o,this.increasedAmount),this.ingredient.on(p,this.decreaseAmount),this.ingredient.on(c,this.decreasedAmount),this.ingredient.on(d,this.deleteFromRecipe),this.ingredient.on(h,this.deletedFromRecipe),this.increase.on("click",t=>this.trigger(E,t)),this.decrease.on("click",t=>this.trigger(p,t))};getStep(){return Number.parseFloat(this.step.val())}getMin(){return Number.parseFloat(this.amount.attr("min"))}getMax(){return Number.parseFloat(this.amount.attr("max"))}getBigOrderQuantity(){return Number.parseFloat(this.amount.attr("data-big-order-quantity"))}getUnit(){return this.amount.data("unit")}isWeighable(){return this.getUnit()===Q}getValue=()=>Number.parseFloat(this.amount.val());isBelowMinValue=t=>t<this.getMin();isAboveMaxValue=t=>t>this.getMax();isMaxAmountReached=t=>this.getValue()===0||!this.getMax()?!1:Number(t)+this.getStep()>this.getMax();isBigOrderQuantityReached=t=>this.getValue()===0||!this.getBigOrderQuantity()?!1:Number(t)+this.getStep()>this.getBigOrderQuantity();formatAmount(t){return this.isWeighable()?t.toString()+this.getUnit():t}getIngredientCode(){return r(n+'[data-recipe-ingredient-code="'+this.ingredient.data("recipe-ingredient-code")+'"]')}increaseAmount=t=>{this.decrease.removeAttr("disabled");const e=Math.round((this.getValue()+this.getStep())*100)/100;this.isAboveMaxValue(e)||(this.amount.val(e),this.triggerIncreasedAmount())};triggerIncreasedAmount=()=>{this.getIngredientCode().trigger(o,{value:this.amount.val(),text:this.formatAmou
1nt(this.amount.val())})};increasedAmount=(t,e)=>{this.amount.val(e.value),this.text.text(e.text),this.checkAmountLimits()};checkAmountLimits=()=>{if(this.isMaxAmountReached(this.getValue())){this.showMaxAmountError();return}if(this.increase.removeAttr("disabled"),this.isBigOrderQuantityReached(this.getValue())){this.showBigOrderAmountError();return}this.ingredient.trigger(f)};showMaxAmountError=()=>{this.increase.prop("disabled",!0),this.ingredient.trigger(C)};showBigOrderAmountError=()=>{this.ingredient.trigger(S)};decreaseAmount=t=>{const e=Math.round((this.getValue()-this.getStep())*100)/100;if(this.isBelowMinValue(e)){this.ingredient.trigger(d);return}this.amount.val(e),this.triggerDecreasedAmount()};decreasedAmount=(t,e)=>{this.amount.val(e.value),this.text.text(e.text),this.checkAmountLimits()};triggerDecreasedAmount=()=>{this.getIngredientCode().trigger(c,{value:this.amount.val(),text:this.formatAmount(this.amount.val())})};deleteFromRecipe=t=>{this.amount.val(0),this.decrease.prop("disabled",!0),this.getIngredientCode().trigger(h,{value:this.amount.val(),text:this.formatAmou
1nt(this.amount.val())})};deletedFromRecipe=(t,e)=>{this.amount.val(e.value),this.text.text(e.text),this.ingredient.removeClass("-has-strict-error").removeClass("-has-error"),this.container.removeClass("-visible"),this.increase.removeAttr("disabled")};trigger=(t,e)=>{this.container.trigger(t,e)}}class ${ingredient;container;netContent;pricePerUnit;priceIntContainer;priceDecimalContainer;constructor(t){this.ingredient=t,this.container=t.find(N),this.netContent=Number.parseFloat(this.container.attr("data-net-content")),this.pricePerUnit=Number.parseFloat(this.container.attr("data-price-per-unit")),this.priceIntContainer=this.container.find(V),this.priceDecimalContainer=this.container.find(j),this.listen()}listen=()=>{this.ingredient.on(o,this.changedAmount),this.ingredient.on(c,this.changedAmount),this.ingredient.on(h,this.changedAmount)};changedAmount=(t,e)=>{const i=this.getNewPrice(e.value),[O,D]=i.split(".");this.container.attr("data-price",i),this.priceIntContainer.text(O),this.priceDecimalContainer.text(D),this.ingredient.trigger(_)};getNewPrice=t=>{const e=this.netContent*this.pricePerUnit*Number.parseFloat(t);return(Math.floor(e*100)/100).toFixed(2)};trigger=(t,e)=>{this.container.trigger(t,e)}}class l{ingredient;container;form;servings;constructor(t,e,i){this.servings=i,this.ingredient=t,this.container=r(e),this.form=this.container.find(".js-recipe-ingredient-replace")}listen=()=>{this.form.on("submit",this.replaceProduct)};replaceProduct=t=>{t.preventDefault(),this.putProduct().done(e=>{this.ingredient.trigger(v,{html:e})})};putProduct=()=>{const t={servings:this.servings};return this.form.serializeArray().forEach(function(e){t[e.name]=e.value}),r.ajax({url:this.form.attr("action"),type:"PUT",data:JSON.stringify(t),headers:{"Content-Type":"application/json",Accept:"application/json","X-CSRF-TOKEN":l.getToken()}}).fail(e=>{console.trace(e.statusText)})};static getToken(){return r('meta[name="csrf-token"]').attr("content")}trigger=(t,e)=>{this.container.trigger(t,e)}}class H{ingredient;container;slider;url;constructor(t,e){this.ingredient=t,this.url=e,this.container=this.ingredient.find(y),this.slider=this.container.find(W),this.listen()}listen=()=>{this.ingredient.on(A,this.toggle)};toggle=()=>{if(this.hasLoadedProducts()){this.show();return}this.loadProducts().done(this.initSlider).catch(t=>{this.container.trigger(R)})};loadProducts=()=>r.ajax({url:this.url,type:"get",headers:{Accept:"application/json"}});show=()=>{this.container.slideToggle(300),this.slider.slick("setPosition")};hasLoadedProducts(){return this.container.hasClass(m)}initSlider=(t,e,i)=>{this.slider.html(t),this.container.addClass(m),this.initSlickCarousel(),this.show(),this.container.trigger(I)};initSlickCarousel=()=>{const t={mobileFirst:!0,arrows:!1,slidesToShow:1,slidesToScroll:1,infinite:!1,prevArrow:` 2 <button type="button" class="slick-prev" aria-label="Previous"> 3 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"> 4 <path d="M32 8L16 24l16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10"/> 5 </svg> 6 </button> 7 `,nextArrow:` 8 <button type="button" class="slick-next" aria-label="Next"> 9 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"> 10 <path d="M16 40l16-16L16 8" fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10"/> 11 </svg> 12 </button> 13 `,responsive:[{breakpoint:420,settings:{slidesToShow:2,slidesToScroll:2}},{breakpoint:768,settings:{slidesToShow:3,slidesToScroll:3,arrows:!0}}]};t.appendArrows=this.slider.parent(),this.slider.slick(t)};trigger=(t,e)=>{this.container.trigger(t,e)}}const J="-no-alternatives";class q{container;counter;priceTag;alternativesSlider;alternativesToggle;recipe;error;servings;constructor(t,e,i){e.is(G)||(this.container=e,this.markBound(),this.servings=i,this.recipe=t,this.alternativesToggle=this.container.find(".js-toggle-slider"),this.error=this.container.find(K),this.listen(),this.alternativesSlider=new H(this.container,this.alternativesToggle.attr("href")),this.counter=new X(this.container),this.priceTag=new $(this.container))}listen=()=>{this.container.on("click",B,t=>this.trigger(d,t)),this.container.on(R,this.alternativesNotFound),this.container.on(I,this.alternativesFound),this.container.on(v,this.replaceProduct),this.alternativesToggle.on("click",this.toggleAlternatives),this.container.on(C,this.showMaxAmountError),this.container.on(S,this.showBigOrderAmountError),this.container.on(f,this.clearAmountError)};replaceProduct=(t,e)=>{this.container.replaceWith(e.html),this.recipe.trigger(g)};toggleAlternatives=t=>{t.preventDefault(),this.trigger(A)};alternativesNotFound=()=>{this.container.addClass(J)};alternativesFound=()=>{r(".js-product-container").each((t,e)=>{new l(this.container,e,this.servings).listen()})};trigger=(t,e)=>{this.container.trigger(t,e)};markBound(){this.container.attr("data-ingredient-is-bound","true")}showMaxAmountError=()=>{this.container.addClass("-has-error").addClass("-has-strict-error"),this.error.text(this.error.attr("data-error-max-amount"))};showBigOrderAmountError=()=>{this.container.removeClass("-has-strict-error").addClass("-has-error"),this.error.text(this.error.attr("data-error-big-order-amount"))};clearAmountError=()=>{this.container.removeClass("-has-error").removeClass("-has-strict-error"),this.error.text("")}}class a{RECIPE_MODAL_POST_FORM_SELECTOR=".js-recipe-modal-post-form";container;addRecipeForm;servingsSelect;addToCartButtons;changeServingsUrl;totalPrice;ingredients=[];constructor(t){this.container=t,this.addRecipeForm=this.container.find(x),this.servingsSelect=this.container.find(P),this.addToCartButtons=this.container.find(M),this.changeServingsUrl=this.container.find(b).attr("data-recipe-servings-change-url"),this.totalPrice=this.container.find(w),this.bindIngredients(),this.updateTotalPrice(),this.listen()}listen(){this.addToCartButtons.on("click",this.showAddToCartLoader),this.servingsSelect.on("change",this.changeServings),this.addRecipeForm.on("submit",this.addToCart),this.container.on(u,this.onChangedServings),this.container.on(g,this.bindIngredients),this.container.on(g,this.updateTotalPrice),this.container.on(_,this.updateTotalPrice)}static getToken(){return r('meta[name="csrf-token"]').attr("content")}bindIngredients=()=>{this.ingredients=[],this.container.find(k).each((t,e)=>
13{this.ingredients.push(new q(this.container,r(e),this.getServings()))})};onChangedServings=()=>{this.bindIngredients(),this.updateTotalPrice()};showAddToCartLoader=t=>{this.addToCartButtons.addClass("-loader-active")};addToCartSubmit=t=>{this.container.append(t.form),r(this.RECIPE_MODAL_POST_FORM_SELECTOR).submit()};changeServings=t=>{const e=this.servingsSelect.val();r.ajax({url:this.changeServingsUrl,type:"PUT",data:JSON.stringify({servings:e,products:this.getServingsProductsData()}),headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-TOKEN":a.getToken()}}).done(i=>{this.container.find(".js-recipe-ingredients-container").html(i.ingredients),this.container.trigger("contentloaded"),this.container.trigger(u)})};addToCart=t=>{t.preventDefault();const e={servings:this.getServings(),products:this.getProductsData()};r.ajax({url:this.addRecipeForm.attr("action"),type:"POST",data:e,headers:{"X-CSRF-TOKEN":a.getToken()}}).done(this.addToCartSubmit)};getServingsProductsData(){return this.container.find(n).map((t,e)=>{const i=r(e);return{ingredientCode:i.attr("data-recipe-ingredient-code"),productCode:i.attr("data-recipe-product-code"),position:i.attr("data-recipe-ingredient-position"),productUnitCode:i.attr("data-recipe-product-unit-code"),ingredientName:i.attr("data-recipe-ingredient-name")}}).get()}getProductsData(){return this.container.find(n).map((t,e)=>{const i=r(e);return{productAmount:i.find(T+' input[name="amount"]').val(),amount:i.attr("data-recipe-product-amount"),ingredientCode:i.attr("data-recipe-ingredient-code"),productCode:i.attr("data-recipe-product-code"),position:i.attr("data-recipe-ingredient-position"),productUnitCode:i.attr("data-recipe-product-unit-code")}}).get()}updateTotalPrice=()=>{const t=this.container.find(N).map((e,i)=>Number.parseFloat(r(i).attr("data-price"))).get().reduce(function(e,i){return e+i},0).toFixed(2).toString().replace(".",",");this.totalPrice.text(t)};getServings(){return this.servingsSelect.val().toString()}}class it extends L{ALLOW_CLICK_OUTSIDE=!1;container;recipe;constructor(t,e){super(t,e),this.createModal()}afterCreate(){this.container=r(".modal"),this.recipe=new a(this.container),super.afterCreate()}listen(){super.listen()}}export{it as R};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.