var Calculators;
(function(a){a.ATTR_STEP="step";a.ATTR_MAX="max";a.ATTR_MIN="min";a.ATTR_DATA_MIN="data-min";a.ATTR_VALUE="value";a.ATTR_YEARS="years";a.VAR_AMOUNT="[AMOUNT]";a.VAR_MAX_AGE="[MAX_AGE]";a.VAR_UNIT="[UNIT]";a.VAR_MIN="[MIN]";a.VAR_MAX="[MAX]";a.VAR_YEARS="[YEARS]";a.TOTAL_COST_REPLACEMENT="[TOTAL_COST]";a.DOWNPAYMENT_REPLACEMENT="[DOWNPAYMENT]";a.LOAN_AMOUNT_REPLACEMENT="[LOAN_AMOUNT]";a.INSTALLMENTS_REPLACEMENT="[INSTALLMENTS]";a.INTEREST_RATE_REPLACEMENT="[INTEREST_RATE]";a.REPAYMENT_TIME_REPLACEMENT="[REPAYMENT_TIME]";
a.LAST_MONTHLY_COST_REPLACEMENT="[LAST_MONTHLY_COST]";a.FIRST_MONTHLY_COST_REPLACEMENT="[FIRST_MONTHLY_COST]";a.AVERAGE_MONTHLY_COST_REPLACEMENT="[AVERAGE_MONTHLY_COST]";a.EFFECTIVE_INTEREST_RATE_REPLACEMENT="[EFFECTIVE_INTEREST_RATE]";a.INTEREST_RATES_SPAN_REPLACEMENT="[INTEREST_RATES_SPAN]";a.LAST_MODIFIED_DATE_REPLACEMENT="[LAST_MODIFIED_DATE]";a.MIN_LOAN_ERROR_MESSAGE="[data-js-min-loan-error-message]";a.ERROR_MESSAGE="[data-js-error-message]";a.ATTR_MIN_LOAN_ERROR_MESSAGE="data-js-min-loan-error-message";
a.formatAllNumberInputs=function(a){a.find(WcmsConstants.ELEMENT_INPUT+"[type\x3dtext]").each(function(a,b){a=$(b).val().toString().setDecimal(",");$(b).val(a.formatThousands())})};a.emitInputEvent=function(a){var b=new Event("input",{bubbles:!0,cancelable:!0});a[0].dispatchEvent(b)};a.fixAttributeValues=function(a){a.attr("data-interest-rate")&&a.attr("data-effective-interest-rate")&&a.attr("data-fee")?(a.attr("data-interest-rate",a.attr("data-interest-rate").setDecimal()),a.attr("data-effective-interest-rate",
a.attr("data-effective-interest-rate").setDecimal()),a.attr("data-fee",a.attr("data-fee").setDecimal())):console.error("".concat(a.data("component")," is missing interest rates values. Please publish data source values or add them manually in component configuration"))};a.initArrowKeyListener=function(b){b.find(WcmsConstants.ELEMENT_INPUT+"[type\x3dtext]").on(WcmsConstants.keydown,function(b){var c=$(b.target),d=Number(c.attr(a.ATTR_STEP).setDecimal()),f=Number(c.attr(a.ATTR_MAX).setDecimal()),g=
Number(c.attr(a.ATTR_DATA_MIN).setDecimal()),h=c.val().toString().setDecimal();h=Number(WcmsFunctions.removeSpaces(h));var k="",l=WcmsConstants.KEYCODE_UP,m=WcmsConstants.KEYCODE_DOWN;b=b.which||b.keyCode;if(b===m||b===l)b===m&&0<=h-d?h-d>=g?k=(h-d).prettifyNumber():h-d<g&&(k=g.prettifyNumber()):b===l&&(h+d<=f?k=(h+d).prettifyNumber():h+d>f&&(k=f.prettifyNumber())),d=k.setDecimal(","),c.val(d.formatThousands()),a.emitInputEvent(c)})};a.preventComaInput=function(a){var b=a.val().toString();","===b[b.length-
1]&&a.val(b.substring(0,b.length-1))};a.preventFirstSymbolZeroInput=function(a){var b=a.val().toString();"0"===b[b.length-1]&&1===b.length&&a.val(b.substring(0,b.length-1))};a.setDecimal=function(a,c){switch(c){case ".":return WcmsFunctions.replaceStrings(a,{",":"."});case ",":return WcmsFunctions.replaceStrings(a,{".":","})}return a};a.makeErrorMessage=function(b){var c,e,d,f=b.component.find(b.field).find(a.ERROR_MESSAGE),g=b.component.find(b.input);b=WcmsFunctions.replaceStrings(f.text(),(c={},
c[a.VAR_UNIT]=b.component.attr(b.replacementUnit)||b.replacementUnit,c[a.VAR_MIN]=null===(e=g.attr(a.ATTR_DATA_MIN))||void 0===e?void 0:e.setDecimal(",").formatThousands(),c[a.VAR_MAX]=null===(d=g.attr(a.ATTR_MAX))||void 0===d?void 0:d.setDecimal(",").formatThousands(),c[a.VAR_YEARS]=g.attr(a.ATTR_YEARS),c));f.text(b)};a.formatNumberIntoThousands=function(a){a=a.toString();if(","===a[0]&&2>a.length||"0"===a[0]&&a[1]&&","!==a[1])a=a.substring(1);a=a.replace(/ /g,"").replace(/\B(?=(\d{3})+(?!\d))/g,
" ").replace(/[^\d ,+]+/g,"");if(-1!=a.indexOf(",")&&3<a.length-a.indexOf(",")||a.indexOf(",")!=a.lastIndexOf(","))a=a.substring(0,a.length-1);return a};a.allowCalculation=function(b,c){void 0===c&&(c=!0);var e=!0;b.find("[data-js-error-message-container]").each(function(b,c){$(c).hasClass(WcmsConstants.hidden)||$(c).children(a.MIN_LOAN_ERROR_MESSAGE).hasAttr(a.ATTR_MIN_LOAN_ERROR_MESSAGE)||(e=!1)});b.find(WcmsConstants.ELEMENT_INPUT).each(function(a,b){""===$(b).val().toString()&&(e=!1)});c&&a.updateRepresentativeValues(b);
return e};a.updateRepresentativeValues=function(b,c){var e,d=b.attr("data-representative-text");c=(e={},e[a.LOAN_AMOUNT_REPLACEMENT]=c?c.loanAmount:"\u2014",e[a.EFFECTIVE_INTEREST_RATE_REPLACEMENT]=c?c.effectiveInterestRate:"\u2014",e[a.REPAYMENT_TIME_REPLACEMENT]=c?c.repaymentTime:"\u2014",e[a.INSTALLMENTS_REPLACEMENT]=c?c.installments:"\u2014",e[a.AVERAGE_MONTHLY_COST_REPLACEMENT]=c?c.averageMonthlyCost:"\u2014",e[a.FIRST_MONTHLY_COST_REPLACEMENT]=c?c.firstMonthlyCost:"\u2014",e[a.LAST_MONTHLY_COST_REPLACEMENT]=
c?c.lastMonthlyCost:"\u2014",e[a.TOTAL_COST_REPLACEMENT]=c?c.totalCost:"\u2014",e[a.INTEREST_RATE_REPLACEMENT]=c?c.interestRate:"\u2014",e[a.DOWNPAYMENT_REPLACEMENT]=c?c.downpayment:"\u2014",e[a.INTEREST_RATES_SPAN_REPLACEMENT]=b.attr("data-interest-rates-span"),e[a.LAST_MODIFIED_DATE_REPLACEMENT]=b.attr("data-last-modified-date"),e);b.find("[data-js-representative-text]").html(WcmsFunctions.replaceStrings(d,c))};a.showErrors=function(b,c,e){void 0===c&&(c=!0);var d=b.closest(".".concat(WcmsConstants.CLASS_FIELD)).find("[data-js-error-message-container]"),
f=d.closest(".".concat(WcmsConstants.CLASS_FIELD));WcmsFunctions.show(d.find(a.ERROR_MESSAGE));WcmsFunctions.hide(d.find(a.MIN_LOAN_ERROR_MESSAGE));c?(WcmsFunctions.show(d),f.addClass(WcmsConstants.CLASS_ERROR),e&&(WcmsFunctions.hide(d.find(a.ERROR_MESSAGE)),WcmsFunctions.show(d.find(a.MIN_LOAN_ERROR_MESSAGE)))):(WcmsFunctions.hide(d),f.removeClass(WcmsConstants.CLASS_ERROR));if(e=b.closest(WcmsConstants.COMPONENT).data("component")){d=b.closest(WcmsConstants.COMPONENT);f=d.attr("data-currency-unit");
var g=b.closest("[data-js-downpayment]");switch(e){case "car-loan-calculator":c?(WcmsFunctions.show(g.find("[data-js-error-message-container]")),g.addClass(WcmsConstants.CLASS_ERROR),b.closest(d).find("[data-js-monthly-cost]").text("0 ".concat(f)),a.updateRepresentativeValues(d)):(WcmsFunctions.hide(g.find("[data-js-error-message-container]")),g.removeClass(WcmsConstants.CLASS_ERROR));break;case "loan-calculator":c&&(d.find("[data-js-monthly-cost]").text("0 ".concat(f)),a.updateRepresentativeValues(d));
break;case "compare-your-loans-calculator":c&&(d.find("[data-js-monthly-result]").text("0 ".concat(f)),d.find("[data-js-estimated-savings]").text("0 ".concat(f)),d.find("[data-js-total-savings]").text("0 ".concat(f)),d.find("[data-js-result-bar-savings]").css("width","0px"),a.updateRepresentativeValues(d))}}};Number.prototype.formatThousands=function(){return a.formatNumberIntoThousands(this.toString())};String.prototype.formatThousands=function(){return a.formatNumberIntoThousands(this.toString())};
Number.prototype.prettifyNumber=function(){return Number(this).toFixed(2).replace(".00","")};String.prototype.prettifyNumber=function(){return Number(this).toFixed(2).replace(".00","")};String.prototype.setDecimal=function(b){void 0===b&&(b=".");return a.setDecimal(this.toString(),b)}})(Calculators||(Calculators={}));