jQuery(document).ready(function($){
let debtAmount=10000;
function formatCurrency(amount){
return '$' + Math.round(amount).toLocaleString();
}
function calculateConsumerProposal(debt){
return Math.max((debt * 0.20), 6000);
}
function calculateDebtConsolidation(debt){
var months=60;
var interestVal=parseFloat(treefrog_debtcalc.consolidation_rate) / 100;
var interest=interestVal / 12;
var result=(debt * (interest + interest / (Math.pow((1 + interest), months) - 1)));
console.log('Debt Consolidation Debug:', {
debt: debt,
interestVal: interestVal,
interest: interest,
months: months,
monthlyPayment: result,
totalPayment: result * 60
});
return result;
}
function calculateRepayFull(debt){
var months=60;
var interestVal=parseFloat(treefrog_debtcalc.full_pay_rate) / 100;
var interest=interestVal / 12;
var result=(debt * (interest + interest / (Math.pow((1 + interest), months) - 1)));
console.log('Repay Full Debug:', {
debt: debt,
interestVal: interestVal,
interest: interest,
months: months,
monthlyPayment: result,
totalPayment: result * 60
});
return result;
}
let isInputFocused=false;
function updateAllValues(skipInputUpdate=false){
if(!skipInputUpdate&&!isInputFocused){
$('.treefrog-debt-input').val(debtAmount.toLocaleString('en-US'));
}
const consumerProposal=calculateConsumerProposal(debtAmount);
const debtConsolidation=calculateDebtConsolidation(debtAmount);
const repayFull=calculateRepayFull(debtAmount);
$('.treefrog-consumer-proposal-total').text(formatCurrency(consumerProposal));
$('.treefrog-consumer-proposal-monthly').text(formatCurrency(consumerProposal / 60));
$('.treefrog-debt-consolidation-total').text(formatCurrency(debtConsolidation * 60));
$('.treefrog-debt-consolidation-monthly').text(formatCurrency(debtConsolidation));
$('.treefrog-repay-full-total').text(formatCurrency(repayFull * 60));
$('.treefrog-repay-full-monthly').text(formatCurrency(repayFull));
}
$("#slider").rangeslider({
polyfill: false,
onInit: function(){
$(".rangeslider__handle").html(`
<div class="treefrog-slider-arrow-left">
<svg width="24" height="24" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.7498 15.1405V18.7265C12.7498 18.9242 12.6911 19.1175 12.5813 19.2819C12.4714 19.4463 12.3152 19.5745 12.1325 19.6502C11.9498 19.7258 11.7488 19.7456 11.5548 19.7071C11.3609 19.6685 11.1827 19.5733 11.0428 19.4335L4.45685 12.8475C4.26938 12.6599 4.16406 12.4056 4.16406 12.1405C4.16406 11.8753 4.26938 11.621 4.45685 11.4335L11.0428 4.84747C11.1827 4.70766 11.3609 4.61246 11.5548 4.57389C11.7488 4.53532 11.9498 4.55513 12.1325 4.6308C12.3152 4.70647 12.4714 4.83461 12.5813 4.99902C12.6911 5.16343 12.7498 5.35672 12.7498 5.55447V9.14047H15.7498V15.1405H12.7498V15.1405Z" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M21.75 15.1396V9.13965" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M18.75 15.1396V9.13965" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
<span class="treefrog-slider-text">Slide</span>
<div class="treefrog-slider-arrow-right">
<svg width="24" height="24" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg" style="transform: scaleX(-1);">
<path d="M12.7498 15.1405V18.7265C12.7498 18.9242 12.6911 19.1175 12.5813 19.2819C12.4714 19.4463 12.3152 19.5745 12.1325 19.6502C11.9498 19.7258 11.7488 19.7456 11.5548 19.7071C11.3609 19.6685 11.1827 19.5733 11.0428 19.4335L4.45685 12.8475C4.26938 12.6599 4.16406 12.4056 4.16406 12.1405C4.16406 11.8753 4.26938 11.621 4.45685 11.4335L11.0428 4.84747C11.1827 4.70766 11.3609 4.61246 11.5548 4.57389C11.7488 4.53532 11.9498 4.55513 12.1325 4.6308C12.3152 4.70647 12.4714 4.83461 12.5813 4.99902C12.6911 5.16343 12.7498 5.35672 12.7498 5.55447V9.14047H15.7498V15.1405H12.7498V15.1405Z" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M21.75 15.1396V9.13965" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M18.75 15.1396V9.13965" stroke="#3A2572" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
`);
updateAllValues();
},
onSlide: function(position, value){
debtAmount=parseInt(value);
$(".treefrog-slider-text").text("Slide");
updateAllValues();
},
onSlideEnd: function(){
console.log('Slider value: ' + $("#slider").val());
}});
$(document).on('focus', '.treefrog-debt-input', function(){
isInputFocused=true;
$(this).val(debtAmount);
});
$(document).on('blur', '.treefrog-debt-input', function(){
isInputFocused=false;
let value=$(this).val().replace(/[^0-9]/g, '');
if(value===''||isNaN(parseInt(value))){
$(this).val(debtAmount.toLocaleString('en-US'));
return;
}
value=parseInt(value);
if(value < 10000) value=10000;
if(value > 250000) value=250000;
debtAmount=value;
$('#slider').val(debtAmount);
$('#slider').rangeslider('update', true);
updateAllValues();
});
$(document).on('keypress', '.treefrog-debt-input', function(e){
if(e.which===13){
$(this).blur();
}});
});