var IngredientsAmountCalculator={initialPortionCount:0,initialize:function(t){var e=this;this.setCurrentPortionCountElement(t),this.portionCountElement.is("select")?this.initialPortionCount=this.getSelectedOptionElement().val():this.initialPortionCount=this.portionCountElement.html(),this.initialPortionCount=parseInt(this.initialPortionCount),isNaN(this.initialPortionCount)||(jQuery("#lessPortions").click(function(){e.getSelectedOptionElement().is(":first-child")||e.setNewPortionCount(e.getSelectedOptionElement().prev().val())}),jQuery("#morePortions").click(function(){e.getSelectedOptionElement().is(":last-child")||e.setNewPortionCount(e.getSelectedOptionElement().next().val())}),jQuery("#resetPortions").click(function(){e.setNewPortionCount(e.initialPortionCount)}),this.portionCountElement.change(function(){e.calculateIngredientsAmount()}),this.mindStoredPortionCount())},setCurrentPortionCountElement:function(t){this.portionCountElement=t},getSelectedOptionElement:function(){return this.portionCountElement.children("option:selected")},setNewPortionCount:function(t){t=parseInt(t),this.portionCountElement.is("select")?this.portionCountElement.val(t).trigger("change"):(this.portionCountElement.html(t),this.calculateIngredientsAmount(t))},calculateIngredientsAmount:function(t){var e=this;t||(t=parseInt(this.getSelectedOptionElement().val())),jQuery(".ingredientCapacity").each(function(){if(jQuery(this).data("ingredientsAmountCalculatorId")==e.getCalculatorIdentifier()){var n=parseFloat(jQuery(this).data("initialCapacity").toString().replace(",",".")),i=+(n/e.initialPortionCount*t).toFixed(2),o=jQuery(this).parent(".ingredient").find(".ingredientLabel"),r=i>1?"plural":"singluar",l=$("#recipePortionWarning");jQuery(this).html(i.toString().replace(".",",")),o.html(o.data(r)),l.addClass("d-none").removeAttr("role"),t!==e.initialPortionCount&&l.removeClass("d-none").attr("role","alert")}}),this.storeSelectedPortionCount(t),$("#bringLink").each(function(){var e=$(this).attr("href"),n=e.substr(0,e.lastIndexOf("=")+1)+t;$(this).attr("href",n)})},mindStoredPortionCount:function(){var t=Cookies.get(this.getCookieIdentifier());void 0===t||isNaN(t)||this.setNewPortionCount(t)},storeSelectedPortionCount:function(t){Cookies.set(this.getCookieIdentifier(),t)},getCookieIdentifier:function(){return"recipePortionCount-"+this.getCalculatorIdentifier()},getCalculatorIdentifier:function(){return this.portionCountElement.data("ingredientsAmountCalculatorId")}};jQuery(document).ready(function(){jQuery(".countPortions").each(function(){IngredientsAmountCalculator.initialize(jQuery(this))})});