{"version":3,"file":"student-budget-calculator.min.js","names":["cnfsdStudentBudgetCalc","totalIncome","totalExpenditure","firstMap","timescaleSet","timescale","totalIncomeSpan","document","querySelectorAll","totalExpenditureSpan","totalRemainingSpan","totalRemainingOpposite","totalRemainingTerm","radios","sections","totalVals","isNotEmptyOrNull","variable","handleRadioInputs","forEach","radio","addEventListener","validateRadios","value","querySelector","classList","remove","text","innerHTML","amount","val","parseInt","getAttribute","tscale","timeTextOpposites","timeTextOpposite","updateTimescales","calculateVals","updateHTMLVals","pushGAEvent","handleButtons","button","event","section","closest","preventDefault","id","toggleSection","scrollCalcTop","contains","addCategory","focus","add","newCategory","questionGroup","newElement","createElement","uniqueIDModifier","Math","floor","random","categoryId","replace","inputPlaceHolderText","getElementById","inputPlaceHolderTextValue","template","appendChild","handleTextInputs","AddCategoryFragment","addNewCategory","downloadLink","breakdownSections","breakdownHolder","breakdownHTML","dataset","heading","question","label","formatter","format","populateHiddenResults","async","pdfOptions","margin","filename","image","type","quality","html2canvas","scale","jsPDF","unit","orientation","element","html2pdf","generatePDF","backlink","input","inputVal","inputId","parseFloat","set","mapToUpdate","find","item","map","updateVals","keyCode","indexOf","regex","keyed","String","fromCharCode","charCode","which","test","validateTextboxes","radioButton","checked","screen1","screen2","progressTitle","progressCount","progressIndicator","progressTitle1","progressTitle2","toggle","progressTitle2Content","progressTitle1Content","scrollIntoView","behavior","block","inline","values","innermap","totalincome","totalexpenditure","totalremaining","style","color","remainingOpposite","remainingTerm","Intl","NumberFormat","currency","inputType","validation","dataLayer","alert","payload","continueValidation","continueValidationErrors","collateErrorMessages","elementId","formId","form","push","error","errorMessage","init","sectionId","index","Map"],"sources":["student-budget-calculator/student-budget-calculator.js"],"mappings":"AAAA,MAAMA,uBAAyB,WAE9B,IAAIC,EACAC,EAGAC,EAFAC,GAAe,EACfC,EAAY,GAEhB,MAAMC,EAAkBC,SAASC,iBAAiB,iBAC5CC,EAAuBF,SAASC,iBAAiB,sBACjDE,EAAqBH,SAASC,i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AMlE,aAAa,mBAAoBkE,EAAMlE,aAAa,MAC9D,CAAC,GAAGkE,EAAMlE,aAAa,kBAAmBkE,EAAM0D,KAAK5H,aAAa,MAGrE,CAEAoH,UAAUS,KAAKP,EAChB,CACD,CAEA,SAASG,IACR,IAAID,EAA2B,GAO/B,OANejJ,SAASC,iBAAiB,uBAElCW,SAAQ2I,IACd,MAAMC,EAAeD,EAAMtI,cAAc,kBACzCgI,GAA4B,GAAGO,EAAanI,YAAY,IAElD4H,CACR,CASA,MAAO,CACNQ,KARD,WAvcClJ,EAASK,SAAQ,CAAC8I,EAAWC,KAC5B,IAAIxD,EAAM,GAAGuD,EAAUnH,KACvB4D,EAAM,IAAIyD,IACND,EAAQ,GACXxD,EAAI5D,GAAKmH,EAAUnH,GACnB/B,EAAU8I,KAAK,CAAE/G,GAAI4D,EAAI5D,GAAI4D,IAAKA,MAElCA,EAAI5D,GAAKmH,EAAUnH,GACnB3C,EAAWuG,EACZ,IAgcDxF,IACAsB,IACA4B,GACD,EAIClD,kBAAmBA,EACnBsB,cAAeA,EACf4B,iBAAkBA,EAClB/B,cAAeA,EACfC,eAAgBA,EAChBrC,YAAaA,EACbC,iBAAkBA,EAClBI,gBAAiBA,EACjBG,qBAAsBA,EACtBC,mBAAoBA,EACpBC,uBAAwBA,EACxBC,mBAAoBA,EACpBC,OAAQA,EACRE,UAAWA,EACXZ,SAAUA,EACV4E,UAAWA,EAEZ,CAvf8B,GAyf/BxE,SAASc,iBAAiB,oBAAoB,WAC7CrB,uBAAuBgK,MACxB","ignoreList":[],"sourcesContent":["const cnfsdStudentBudgetCalc = (function () {\r\n\t// Define your variables\r\n\tlet totalIncome;\r\n\tlet totalExpenditure;\r\n\tlet timescaleSet = false;\r\n\tlet timescale = '';\r\n\tlet firstMap;\r\n\tconst totalIncomeSpan = document.querySelectorAll('.total-income');\r\n\tconst totalExpenditureSpan = document.querySelectorAll('.total-expenditure');\r\n\tconst totalRemainingSpan = document.querySelectorAll('.total-remaining');\r\n\tconst totalRemainingOpposite = document.querySelectorAll('.total-remaining--opposite');\r\n\tconst totalRemainingTerm = document.querySelectorAll('.total-remaining__per-term');\r\n\tconst radios = document.querySelectorAll('#income input[type=\"radio\"]');\r\n\tconst sections = document.querySelectorAll('.student-budget-calculator form');\r\n\tconst totalVals = [];\r\n\r\n\tfunction isNotEmptyOrNull(variable) {\r\n\t\treturn variable !== null && variable !== undefined && variable !== '';\r\n\t}\r\n\r\n\tfunction setupMaps() {\r\n\t\t// Set up a map for the values in each section based on the section ID\r\n\t\tsections.forEach((sectionId, index) => {\r\n\t\t\tlet map = `${sectionId.id}`;\r\n\t\t\tmap = new Map();\r\n\t\t\tif (index > 0) {\r\n\t\t\t\tmap.id = sectionId.id;\r\n\t\t\t\ttotalVals.push({ id: map.id, map: map });\r\n\t\t\t} else {\r\n\t\t\t\tmap.id = sectionId.id;\r\n\t\t\t\tfirstMap = map;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t// Event handlers\r\n\tfunction handleRadioInputs() {\r\n\t\tradios.forEach(radio => {\r\n\t\t\tradio.addEventListener('change', () => {\r\n\t\t\t\tvalidateRadios();\r\n\t\t\t\ttimescale = radio.value;\r\n\t\t\t\tupdateTimescales();\r\n\t\t\t\tcalculateVals();\r\n\t\t\t\tupdateHTMLVals(totalIncome, totalExpenditure);\r\n\t\t\t\tpushGAEvent(radio);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\tfunction handleButtons() {\r\n\t\tconst buttons = document.querySelectorAll('.student-budget-calculator button');\r\n\t\tbuttons.forEach(button => {\r\n\t\t\tbutton.addEventListener('click', event => {\r\n\t\t\t\tconst section = button.closest('form');\r\n\t\t\t\tevent.preventDefault();\r\n\r\n\t\t\t\tif (button.id === 'budgetCalc-continue') {\r\n\t\t\t\t\tif (!timescaleSet) {\r\n\t\t\t\t\t\tvalidateRadios();\r\n\t\t\t\t\t\tpushGAEvent(button, 'continue', false);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\ttoggleSection();\r\n\t\t\t\t\t\tscrollCalcTop();\r\n\t\t\t\t\t\tpushGAEvent(button, 'continue', true);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (button.classList.contains('btn__add-category') || button.classList.contains('btn__new-category')) {\r\n\t\t\t\t\taddNewCategory(button, section);\r\n\t\t\t\t\tif (button.classList.contains('btn__add-category')) {\r\n\t\t\t\t\t\tpushGAEvent(button, 'addCategory', false);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tpushGAEvent(button, 'newCategory', false);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\tconst downloadLink = document.querySelector('#budgetCalc-download-budget');\r\n\t\tdownloadLink.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\tpopulateHiddenResults();\r\n\t\t\tgeneratePDF();\r\n\t\t\tpushGAEvent(downloadLink, 'download', false);\r\n\t\t});\r\n\r\n\t\tconst backlinks = document.querySelectorAll('.edit-previous');\r\n\t\tbacklinks.forEach(backlink => {\r\n\t\t\tbacklink.addEventListener('click', event => {\r\n\t\t\t\tevent.preventDefault();\r\n\t\t\t\ttoggleSection();\r\n\t\t\t\tscrollCalcTop();\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\tfunction handleTextInputs() {\r\n\t\tconst inputs = document.querySelectorAll('.student-budget-calculator input[type=\"text\"]');\r\n\t\tinputs.forEach(input => {\r\n\t\t\tconst section = input.closest('form').id;\r\n\t\t\tinput.addEventListener('keyup', () => {\r\n\t\t\t\tupdateVals(input, section);\r\n\t\t\t\tcalculateVals();\r\n\t\t\t\tupdateHTMLVals(totalIncome, totalExpenditure);\r\n\t\t\t});\r\n\t\t\tinput.addEventListener('keypress', event => {\r\n\t\t\t\tvalidateTextboxes(input, event);\r\n\t\t\t});\r\n\r\n\t\t\tinput.addEventListener('focusout', () => {\r\n\t\t\t\tpushGAEvent(input);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\tfunction validateTextboxes(input, event) {\r\n\t\tif (input.classList.contains('calculation-val')) {\r\n\t\t\tif (\r\n\t\t\t\t(event.keyCode >= 48 && event.keyCode <= 57) ||\r\n\t\t\t\t(event.keyCode >= 37 && event.keyCode <= 39) ||\r\n\t\t\t\tevent.keyCode === 63234 ||\r\n\t\t\t\tevent.keyCode === 63235 ||\r\n\t\t\t\tevent.keyCode === 8 ||\r\n\t\t\t\tevent.keyCode === 45 ||\r\n\t\t\t\tevent.keyCode === 189\r\n\t\t\t) {\r\n\t\t\t\treturn true;\r\n\t\t\t} else if (event.keyCode === 46 && input.value.indexOf('.', 0) === -1) {\r\n\t\t\t\treturn true;\r\n\t\t\t} else {\r\n\t\t\t\tevent.preventDefault();\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconst regex = /^[\\w\\s]+$/;\r\n\t\t\tconst keyed = String.fromCharCode(!event.charCode ? event.which : event.charCode);\r\n\t\t\tconst isValid = regex.test(keyed);\r\n\t\t\tif (!isValid) {\r\n\t\t\t\tevent.preventDefault();\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction validateRadios() {\r\n\t\ttimescaleSet = false;\r\n\t\tfor (const radioButton of radios) {\r\n\t\t\tif (radioButton.checked) {\r\n\t\t\t\ttimescaleSet = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!timescaleSet) {\r\n\t\t\tradios[0].closest('.field-group').classList.add('field-group--error');\r\n\t\t} else {\r\n\t\t\tradios[0].closest('.field-group').classList.remove('field-group--error');\r\n\t\t}\r\n\t\treturn timescaleSet;\r\n\t}\r\n\r\n\tfunction toggleSection() {\r\n\t\tconst screen1 = document.querySelector('.student-budget-calculator__screen-1');\r\n\t\tconst screen2 = document.querySelector('.student-budget-calculator__screen-2');\r\n\t\tconst progressTitle = document.querySelector('.student-budget-calculator__progress--title');\r\n\t\tconst progressCount = document.querySelector('.student-budget-calculator__progress--count');\r\n\t\tconst progressIndicator = document.querySelector('.student-budget-calculator__progress--indicator');\r\n\t\tconst progressTitle1 = document.querySelector('#student-budget-calculator__progress-title-1');\r\n\t\tconst progressTitle2 = document.querySelector('#student-budget-calculator__progress-title-2');\r\n\r\n\t\tscreen1.classList.toggle('display-none');\r\n\t\tscreen2.classList.toggle('display-none');\r\n\t\tprogressIndicator.classList.toggle('complete');\r\n\r\n\t\tif (screen1.classList.contains('display-none')) {\r\n\t\t\tif (isNotEmptyOrNull(progressTitle2)) {\r\n\t\t\t\tconst progressTitle2Content = progressTitle2.innerHTML;\r\n\t\t\t\tprogressTitle.innerHTML = progressTitle2Content;\r\n\t\t\t}\r\n\t\t\tprogressCount.innerHTML = `2`;\r\n\t\t} else {\r\n\t\t\tif (isNotEmptyOrNull(progressTitle1)) {\r\n\t\t\t\tconst progressTitle1Content = progressTitle1.innerHTML;\r\n\t\t\t\tprogressTitle.innerHTML = progressTitle1Content;\r\n\t\t\t}\r\n\t\t\tprogressCount.innerHTML = `1`;\r\n\t\t}\r\n\t}\r\n\r\n\tfunction scrollCalcTop() {\r\n\t\tconst top = document.querySelector('.student-budget-calculator__progress');\r\n\t\ttop.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });\r\n\t}\r\n\r\n\tfunction updateTimescales() {\r\n\t\tconst visibleTimescale = document.querySelector('.visible-timescale');\r\n\t\tvisibleTimescale.classList.remove('display-none');\r\n\t\tconst timeText = document.querySelectorAll('.transform-timescale');\r\n\t\ttimeText.forEach(text => {\r\n\t\t\ttext.innerHTML = timescale;\r\n\t\t});\r\n\t\tconst amounts = document.querySelectorAll('.transform-amount');\r\n\t\tamounts.forEach(amount => {\r\n\t\t\tconst val = parseInt(amount.getAttribute('data-amount'));\r\n\t\t\tconst tscale = amount.getAttribute('data-timescale');\r\n\t\t\tif (tscale === timescale) {\r\n\t\t\t\tamount.innerHTML = `£${val}`;\r\n\t\t\t\treturn;\r\n\t\t\t} else if (tscale === 'week' && timescale === 'month') {\r\n\t\t\t\tamount.innerHTML = `£${parseInt((val * 52) / 12)}`;\r\n\t\t\t} else {\r\n\t\t\t\tamount.innerHTML = `£${parseInt((val * 12) / 52)}`;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst timeTextOpposites = document.querySelectorAll('.transform-timescale__Opposite');\r\n\t\tif (timescale === 'week') {\r\n\t\t\ttimeTextOpposites.forEach(timeTextOpposite => {\r\n\t\t\t\ttimeTextOpposite.innerHTML = 'month';\r\n\t\t\t});\r\n\t\t} else {\r\n\t\t\ttimeTextOpposites.forEach(timeTextOpposite => {\r\n\t\t\t\ttimeTextOpposite.innerHTML = 'week';\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfunction addNewCategory(button, section) {\r\n\t\tconst addCategory = section.querySelector('.add-category') || '';\r\n\t\tif (button.classList.contains('btn__add-category')) {\r\n\t\t\taddCategory.classList.remove('display-none');\r\n\t\t\taddCategory.querySelector('input[type=\"text\"]').focus();\r\n\t\t\tbutton.classList.add('display-none');\r\n\t\t}\r\n\t\tif (button.classList.contains('btn__new-category')) {\r\n\t\t\tconst newCategory = addCategory.querySelector('input[type=\"text\"]').value;\r\n\t\t\tif (newCategory === null || newCategory === '') {\r\n\t\t\t\treturn;\r\n\t\t\t} else {\r\n\t\t\t\taddCategory.classList.add('display-none');\r\n\t\t\t\tAddCategoryFragment(section, newCategory);\r\n\t\t\t\taddCategory.querySelector('input[type=\"text\"]').value = '';\r\n\t\t\t\tsection.querySelector('.btn__add-category').classList.remove('display-none');\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction AddCategoryFragment(section, newCategory) {\r\n\t\tconst questionGroup = section.querySelector('.question-group');\r\n\t\tconst newElement = document.createElement('fieldset');\r\n\t\tnewElement.classList.add('field-group', 'field-group--small', 'field-group--horizontal', 'user-created-input');\r\n\t\tconst uniqueIDModifier = Math.floor(Math.random() * 10000);\r\n\t\tconst categoryId = newCategory.replace(/\\s/g, '');\r\n\t\tconst inputPlaceHolderText = document.getElementById('student-budget-calculator__input-placeholder');\r\n\t\tlet inputPlaceHolderTextValue;\r\n\t\tinputPlaceHolderTextValue = isNotEmptyOrNull(inputPlaceHolderText.innerHTML)\r\n\t\t\t? inputPlaceHolderText.innerHTML\r\n\t\t\t: 0;\r\n\r\n\t\tconst template = `\r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n
\r\n
`;\r\n\t\tnewElement.innerHTML = template;\r\n\t\tquestionGroup.appendChild(newElement);\r\n\t\thandleTextInputs();\r\n\t\tdocument.getElementById(`budgetCalc-${categoryId}-${uniqueIDModifier}`).focus();\r\n\t}\r\n\r\n\tfunction updateVals(input, section) {\r\n\t\tlet inputVal = '';\r\n\t\tconst inputId = input.id;\r\n\r\n\t\tif (input.classList.contains('add-category-input')) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (input.value === null || input.value === '') {\r\n\t\t\tinputVal = 0;\r\n\t\t} else {\r\n\t\t\tinputVal = parseFloat(input.value);\r\n\t\t}\r\n\r\n\t\tif (section === firstMap.id) {\r\n\t\t\t// Update the firstMap directly\r\n\t\t\tfirstMap.set(inputId, inputVal);\r\n\t\t} else {\r\n\t\t\t// Find and update the Map within totalVals\r\n\t\t\tconst mapToUpdate = totalVals.find(item => item.id === section);\r\n\t\t\tif (mapToUpdate) {\r\n\t\t\t\tmapToUpdate.map.set(inputId, inputVal);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction calculateVals() {\r\n\t\ttotalIncome = 0;\r\n\t\ttotalExpenditure = 0;\r\n\r\n\t\tfor (const value of firstMap.values()) {\r\n\t\t\ttotalIncome += value;\r\n\t\t}\r\n\t\tfor (const innermap of totalVals) {\r\n\t\t\tfor (const value of innermap.map.values()) {\r\n\t\t\t\ttotalExpenditure += value;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [totalIncome, totalExpenditure];\r\n\t}\r\n\r\n\tfunction updateHTMLVals(totalIncome, totalExpenditure) {\r\n\t\ttotalIncomeSpan.forEach(totalincome => {\r\n\t\t\ttotalincome.innerHTML = `${formatter.format(totalIncome)}`;\r\n\t\t});\r\n\t\ttotalExpenditureSpan.forEach(totalexpenditure => {\r\n\t\t\ttotalexpenditure.innerHTML = `${formatter.format(totalExpenditure)}`;\r\n\t\t});\r\n\t\ttotalRemainingSpan.forEach(totalremaining => {\r\n\t\t\ttotalremaining.innerHTML = `${formatter.format(totalIncome - totalExpenditure)}`;\r\n\t\t\tif (totalIncome - totalExpenditure < 0) {\r\n\t\t\t\ttotalremaining.style.color = 'var(--themeErrorColour, #e61414)';\r\n\t\t\t} else {\r\n\t\t\t\ttotalremaining.style.color = '';\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tif (timescale === 'week') {\r\n\t\t\ttotalRemainingOpposite.forEach(remainingOpposite => {\r\n\t\t\t\tremainingOpposite.innerHTML = ` ${formatter.format(((totalIncome - totalExpenditure) * 52) / 12)} `;\r\n\t\t\t});\r\n\t\t\ttotalRemainingTerm.forEach(remainingTerm => {\r\n\t\t\t\tremainingTerm.innerHTML = ` ${formatter.format((((totalIncome - totalExpenditure) * 52) / 12) * 3)} `;\r\n\t\t\t});\r\n\t\t} else {\r\n\t\t\ttotalRemainingOpposite.forEach(remainingOpposite => {\r\n\t\t\t\tremainingOpposite.innerHTML = ` ${formatter.format(((totalIncome - totalExpenditure) * 12) / 52)} `;\r\n\t\t\t});\r\n\t\t\ttotalRemainingTerm.forEach(remainingTerm => {\r\n\t\t\t\tremainingTerm.innerHTML = ` ${formatter.format((totalIncome - totalExpenditure) * 3)} `;\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfunction populateHiddenResults() {\r\n\t\tconst breakdownSections = document.querySelectorAll('.question-group');\r\n\t\tconst breakdownHolder = document.querySelector('#budgetCalc-results-card__print .breakdown');\r\n\t\tlet breakdownHTML = '';\r\n\r\n\t\tbreakdownSections.forEach(section => {\r\n\t\t\tbreakdownHTML += `\r\n
\r\n

\r\n ${section.dataset.heading}\r\n

\r\n `;\r\n\r\n\t\t\tconst questions = section.querySelectorAll('.field-group--horizontal');\r\n\t\t\tquestions.forEach(question => {\r\n\t\t\t\tconst label = question.querySelector('label').innerHTML;\r\n\t\t\t\tlet value = question.querySelector('input').value;\r\n\t\t\t\tvalue = formatter.format(value);\r\n\r\n\t\t\t\tif (value !== '') {\r\n\t\t\t\t\tbreakdownHTML += `\r\n

\r\n ${label}\r\n ${value}\r\n

\r\n `;\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tbreakdownHTML += `
`;\r\n\t\t});\r\n\r\n\t\tbreakdownHolder.innerHTML = breakdownHTML;\r\n\t}\r\n\r\n\tconst formatter = new Intl.NumberFormat('en-GB', {\r\n\t\tstyle: 'currency',\r\n\t\tcurrency: 'GBP',\r\n\t});\r\n\r\n\tasync function generatePDF() {\r\n\t\tconst pdfOptions = {\r\n\t\t\tmargin: 16,\r\n\t\t\tfilename: 'Confused.com_Student_Budget.pdf',\r\n\t\t\timage: { type: 'jpeg', quality: 0.98 },\r\n\t\t\thtml2canvas: { scale: 2 },\r\n\t\t\tjsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },\r\n\t\t};\r\n\r\n\t\tconst element = document.getElementById('printPageWrapper');\r\n\t\thtml2pdf(element, pdfOptions);\r\n\t}\r\n\r\n\tasync function pushGAEvent(input, inputType = '', validation = false) {\r\n\t\tif (typeof dataLayer === 'undefined') {\r\n\t\t\t// DataLayer is not defined\r\n\t\t\t// You can handle this situation here\r\n\t\t\talert('no dataLayer');\r\n\t\t} else {\r\n\t\t\t// DataLayer exists and is defined\r\n\t\t\t// You can work with the dataLayer here\r\n\r\n\t\t\tlet payload = {};\r\n\r\n\t\t\tif (input.getAttribute('type') === 'submit') {\r\n\t\t\t\tswitch (inputType) {\r\n\t\t\t\t\tcase 'continue':\r\n\t\t\t\t\t\tpayload = {\r\n\t\t\t\t\t\t\tevent: 'continue',\r\n\t\t\t\t\t\t\tcontinueValidation: validation,\r\n\t\t\t\t\t\t\tcontinueValidationErrors: collateErrorMessages(),\r\n\t\t\t\t\t\t\telementId: input.getAttribute('id'),\r\n\t\t\t\t\t\t\tformId: input.form.getAttribute('id'),\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'addCategory':\r\n\t\t\t\t\t\tpayload = {\r\n\t\t\t\t\t\t\tevent: inputType,\r\n\t\t\t\t\t\t\telementId: input.getAttribute('id'),\r\n\t\t\t\t\t\t\tformId: input.form.getAttribute('id'),\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\tcase 'newCategory':\r\n\t\t\t\t\t\tpayload = {\r\n\t\t\t\t\t\t\tevent: inputType,\r\n\t\t\t\t\t\t\telementId: input.getAttribute('id'),\r\n\t\t\t\t\t\t\tformId: input.form.getAttribute('id'),\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\tcase 'download':\r\n\t\t\t\t\t\tpayload = {\r\n\t\t\t\t\t\t\tevent: 'continue',\r\n\t\t\t\t\t\t\telementId: input.getAttribute('id'),\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (\r\n\t\t\t\t\t(input.getAttribute('type') === 'text' && input.value === '') ||\r\n\t\t\t\t\tinput.classList.contains('add-category-input')\r\n\t\t\t\t) {\r\n\t\t\t\t\treturn;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tpayload = {\r\n\t\t\t\t\t\tevent: `inputChange-${input.getAttribute('name')}`,\r\n\t\t\t\t\t\t[`${input.getAttribute('name')}_type`]: input.getAttribute('type'),\r\n\t\t\t\t\t\t[`${input.getAttribute('name')}_value`]: input.value,\r\n\t\t\t\t\t\t[`${input.getAttribute('name')}_inputId`]: input.getAttribute('id'),\r\n\t\t\t\t\t\t[`${input.getAttribute('name')}_formId`]: input.form.getAttribute('id'),\r\n\t\t\t\t\t};\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tdataLayer.push(payload);\r\n\t\t}\r\n\t}\r\n\r\n\tfunction collateErrorMessages() {\r\n\t\tlet continueValidationErrors = '';\r\n\t\tconst errors = document.querySelectorAll('.field-group--error');\r\n\r\n\t\terrors.forEach(error => {\r\n\t\t\tconst errorMessage = error.querySelector('.error-message');\r\n\t\t\tcontinueValidationErrors += `${errorMessage.innerHTML};`;\r\n\t\t});\r\n\t\treturn continueValidationErrors;\r\n\t}\r\n\r\n\tfunction init() {\r\n\t\tsetupMaps();\r\n\t\thandleRadioInputs();\r\n\t\thandleButtons();\r\n\t\thandleTextInputs();\r\n\t}\r\n\r\n\treturn {\r\n\t\tinit: init,\r\n\t\thandleRadioInputs: handleRadioInputs,\r\n\t\thandleButtons: handleButtons,\r\n\t\thandleTextInputs: handleTextInputs,\r\n\t\tcalculateVals: calculateVals,\r\n\t\tupdateHTMLVals: updateHTMLVals,\r\n\t\ttotalIncome: totalIncome,\r\n\t\ttotalExpenditure: totalExpenditure,\r\n\t\ttotalIncomeSpan: totalIncomeSpan,\r\n\t\ttotalExpenditureSpan: totalExpenditureSpan,\r\n\t\ttotalRemainingSpan: totalRemainingSpan,\r\n\t\ttotalRemainingOpposite: totalRemainingOpposite,\r\n\t\ttotalRemainingTerm: totalRemainingTerm,\r\n\t\tradios: radios,\r\n\t\ttotalVals: totalVals,\r\n\t\tfirstMap: firstMap,\r\n\t\tformatter: formatter,\r\n\t};\r\n})();\r\n\r\ndocument.addEventListener('DOMContentLoaded', function () {\r\n\tcnfsdStudentBudgetCalc.init();\r\n});\r\n"]}