(function(){function i(){var i=t.calculator;totalPrice=0;$(i.amountBlock).each(function(){var t=$(this).data("type"),r=n[t]?n[t].price:"",u=Number($(this).find(i.amountInput).val()),f=u*r;totalPrice+=f});$(i.summaryPrice).text(totalPrice.toLocaleString("ru-RU"))}function u(){var n=null,t=calculatorConfig.Initparams.DcLocations;for(var i in t)if(t[i].DCLocationTechTitle===calculatorConfig.DefaultValues.Dc){n=t[i];break}return n?n[calculatorConfig.DefaultValues.Performance]:n}var r=function(n,t,i,r,u){var e=this,v=n.dataset.type,h=n.querySelector(".amount__increase"),c=n.querySelector(".amount__decrease"),f=n.querySelector(".amount__input"),o=v==="RAM"?1:t.min_value,l=Number(f.max),s=t.step,y=t.start_value,a={max:"Максимальное значение: ",min:"Миниимальное значение: ",closest:"Ближайшее значение: "};this.increaseAmount=function(){var n=Number(f.value);if(n+s>l)return!1;f.value=n+s;h.disabled=n+s*2>l?!0:!1;c.disabled=!1;typeof i=="function"&&i()};this.decreaseAmount=function(n){var n=Number(f.value);if(n-s<o)return!1;f.value=n-s;c.disabled=n-s*2<o?!0:!1;h.disabled=!1;typeof r=="function"&&r()};this.init=function(){var n;if(f.value=y,typeof h=="undefined"||typeof c=="undefined")return!1;c.disabled=Number(f.value)===o;h.disabled=Number(f.value)===l;typeof u=="function"&&(e.showError=u);h.addEventListener("click",function(n){n.preventDefault();n.stopPropagation();e.increaseAmount()});c.addEventListener("click",function(n){n.preventDefault();n.stopPropagation();e.decreaseAmount()});f.addEventListener("keyup",function(){clearTimeout(n);n=setTimeout(function(){e.checkBtn();e.inputChange();i()},800)});$(f).on("change",function(t){t.preventDefault();clearTimeout(n);n=setTimeout(function(){e.checkBtn();e.inputChange();i()},800)});e.setPresetConfig()};this.checkBtn=function(){c.disabled=Number(f.value)===o?!0:!1;h.disabled=Number(f.value)===l?!0:!1};this.inputChange=function(){f.value=Math.ceil(f.value);var n=(Number(f.value)-o)/s;n%1!=0&&(f.value=Math.ceil(n)*s+o,e.showError(a.closest+f.value));Number(f.value)>l&&(f.value=l,e.showError(a.max+l));Number(f.value)<o&&(f.value=o,e.showError(a.min+o))};this.showError=function(n){e.removeErr();var t=$(f).parent();$('<span class="amount-tooltip amount-tooltip--active">'+n+"<\/span>").hide().insertAfter(t).fadeIn(400);setTimeout(e.removeErr,5e3)};this.setPresetConfig=function(){var t=n.querySelector("[data-preset]"),i;t&&(i=t.querySelectorAll("[data-size]"),[].forEach.call(i,function(n){n.addEventListener("click",function(){f.value=Number(this.dataset.size);f.dispatchEvent(new KeyboardEvent("keyup",{keyCode:13}))})}))};this.removeErr=function(){$(f).parent().next(".amount-tooltip").length>0&&$(f).parent().next(".amount-tooltip").remove()};this.init()},t={calculator:{previewBlockSelector:".calculator-preview__block",amountBlock:".calculator-preview__field",amountInput:".amount__input",amountSize:".amount__size",amountPrice:".amount__price",summaryPrice:"#summary-price"}},n=u();n?($(t.calculator.amountBlock).each(function(){var t=n[$(this).data("type")],u;console.log($(this).data("type"));t?u=new r(this,t,i,i):$(this).remove()}),i()):$(t.calculator.previewBlockSelector).remove()})()