{"version":3,"file":"house-rebuild.min.js","names":["sInputKeyValidationHelper","sIsValidPostcode","houseRebuildCost","endpoint","document","getElementById","apiKey","dataset","apikey","addressLookupURL","address","propertyLookupURL","property","banner","querySelector","progressBar","progressTitle","progressStep","inputPostcodeSection","postcode","findPropertyButton","postcodeSubmit","postCodeFieldGroup","postCodeInput","postCodeErrorMessage","houseDetailsSection","changePostcode","addressSelect","findAddressButton","addressSubmit","backToStart","querySelectorAll","displayResult","displayResultFail","resultCost","isValid","getAddressData","async","response","fetch","headers","ok","addressLookupData","json","length","errorMessage","errorProperties","textContent","classList","add","populateAddress","remove","handleApiErrorStates","errorServer","submitButtonState","error","showPropertyResultsFail","getAttribute","showPropertyResultsSuccess","rebuildCost","defaultValue","formattedRebuildCost","toLocaleString","formattedResult","replace","innerText","displayProperty","selectedValue","propertyLookupData","value","console","getPropertyData","status","Error","button","disabled","innerButtonText","setAttribute","removeAttribute","formValidation","elem","type","valTarget","fieldset","closest","errorMessages","empty","errorErrorLength","tooShort","tooLong","invalidFormat","errorErrorProperties","alert","postcodeData","forEach","option","opt","createElement","udprn","preview","appendChild","selectedIndex","reset","step","options","init","fieldGroup","setupKeyListener","addEventListener","event","preventDefault","addressLookupURLpostcode","getAddresses","btn","scrollIntoView","behavior"],"sources":["house-rebuild/house-rebuild.js"],"mappings":"OAASA,8BAAiC,6BACjCC,qBAAwB,sBAEjC,MAAMC,iBAAmB,MACxB,MAAMC,EAAWC,SAASC,eAAe,aACnCC,EAASH,EAASI,QAAQC,OAM1BC,EAAgFN,EAASI,QAAQG,QACjGC,EAEHR,EAASI,QAAQK,SAGdC,EAAST,SAASU,cAAc,WAChCC,EAAcF,EAAOC,cAAc,8BACnCE,EAAgBH,EAAOC,cAAc,kBACrCG,EAAeJ,EAAOC,cAAc,gCAGpCI,EAAuBd,SAASC,eAAe,kBAC/Cc,EAAWf,SAASC,eAAe,cACnCe,EAAqBF,EAAqBJ,cAAc,oBACxDO,EAAiBjB,SAASC,eAAe,mBAE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BAAiB,SAASC,IAMvC,GALAA,EAAMC,iBACNxD,EAAkB1B,GAAmB,GAErCmD,EAAe,kBAAmB,cAE9B5C,EAAS,CACZ,MAAMgC,EAAgBxC,EAAc0C,MACpCH,EAAgBC,EACjB,MACCb,EAAkB1B,GAAmB,EACtC,IAGDD,EAAciF,iBAAiB,UAAU,KACxC7B,EAAe,kBAAmB,aAAa,GAC9C,EAMH,EA/UwB,GAiVzB3E,SAASwG,iBAAiB,oBAAoB,KAC7C1G,iBAAiBuG,MAAM","ignoreList":[],"sourcesContent":["import { sInputKeyValidationHelper } from '../../shared.min.js';\r\nimport { sIsValidPostcode } from '../../shared.min.js';\r\n\r\nconst houseRebuildCost = (() => {\r\n\tconst endpoint = document.getElementById('endpoints');\r\n\tconst apiKey = endpoint.dataset.apikey;\r\n\r\n\t//FLAG FOR TESTING\r\n\tconst testing = false;\r\n\r\n\t//URLS\r\n\tconst addressLookupURL = testing ? 'http://localhost:3000/address-lookup?postcode=' : endpoint.dataset.address;\r\n\tconst propertyLookupURL = testing\r\n\t\t? 'http://localhost:3000/property-lookup/rebuild?udprn='\r\n\t\t: endpoint.dataset.property;\r\n\r\n\t//BANNER\r\n\tconst banner = document.querySelector('.banner');\r\n\tconst progressBar = banner.querySelector('.banner__progress-bar span');\r\n\tconst progressTitle = banner.querySelector('.banner__title');\r\n\tconst progressStep = banner.querySelector('.banner__progress-step-value');\r\n\r\n\t//POSTCODE SCREEN (#1)\r\n\tconst inputPostcodeSection = document.getElementById('input-postcode');\r\n\tconst postcode = document.getElementById('hbPostcode');\r\n\tconst findPropertyButton = inputPostcodeSection.querySelector('#submit-postcode');\r\n\tconst postcodeSubmit = document.getElementById('submit-postcode');\r\n\r\n\tconst postCodeFieldGroup = inputPostcodeSection.querySelector('.field-group');\r\n\tconst postCodeInput = postCodeFieldGroup.querySelector('input');\r\n\tconst postCodeErrorMessage = postCodeFieldGroup.querySelector('.error-message');\r\n\r\n\t//ADDRESS FINDER SCREEN (#2)\r\n\tconst houseDetailsSection = document.getElementById('house-details');\r\n\tconst changePostcode = document.getElementById('changePostcode');\r\n\tconst addressSelect = document.getElementById('address-select');\r\n\tconst findAddressButton = houseDetailsSection.querySelector('#submit-address');\r\n\tconst addressSubmit = document.getElementById('submit-address');\r\n\r\n\t//RESTART BUTTON\r\n\tconst backToStart = document.querySelectorAll('.back-to-start');\r\n\r\n\t//RESULTS\r\n\tconst displayResult = document.getElementById('house-results');\r\n\tconst displayResultFail = document.getElementById('house-results-notfound');\r\n\tconst resultCost = document.getElementById('rebuild-value');\r\n\r\n\t//VALIDATION\r\n\tlet isValid;\r\n\r\n\tconst getAddresses = (postcode, addressSelect) => {\r\n\t\tconst addressLookupURLpostcode = `${addressLookupURL}${postcode.value}`;\r\n\t\tgetAddressData(addressLookupURLpostcode, addressSelect);\r\n\t};\r\n\r\n\tconst getAddressData = async (addressLookupURL, addressSelect) => {\r\n\t\ttry {\r\n\t\t\tconst response = await fetch(addressLookupURL, {\r\n\t\t\t\theaders: { 'Ocp-Apim-Subscription-Key': apiKey },\r\n\t\t\t});\r\n\r\n\t\t\tif (!response.ok) {\r\n\t\t\t\thandleApiErrorStates(response);\r\n\r\n\t\t\t\tconst errorMessage =\r\n\t\t\t\t\tpostCodeInput.dataset.errorServer ||\r\n\t\t\t\t\t'Sorry, we are unable to find your postcode at the moment. Please try again later.';\r\n\t\t\t\tpostCodeErrorMessage.textContent = errorMessage;\r\n\t\t\t\tpostCodeFieldGroup.classList.add('field-group--error');\r\n\t\t\t} else {\r\n\t\t\t\tconst addressLookupData = await response.json();\r\n\r\n\t\t\t\tif (addressLookupData === null || addressLookupData.length === 0) {\r\n\t\t\t\t\t//IF NO PROPERTIES RETURNED\r\n\t\t\t\t\tconst errorMessage =\r\n\t\t\t\t\t\tpostCodeInput.dataset.errorProperties ||\r\n\t\t\t\t\t\t\"We've been unable to find any properties for that postcode. Check if the postcode is correct and try again.\";\r\n\t\t\t\t\tpostCodeErrorMessage.textContent = errorMessage;\r\n\t\t\t\t\tpostCodeFieldGroup.classList.add('field-group--error');\r\n\t\t\t\t} else {\r\n\t\t\t\t\t//SUCCESS\r\n\t\t\t\t\tpopulateAddress(addressSelect, addressLookupData);\r\n\t\t\t\t\tpostCodeFieldGroup.classList.remove('field-group--error');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tsubmitButtonState(findPropertyButton, false);\r\n\t\t} catch (error) {\r\n\t\t\t// console.error('Unable to fetch data:', error);\r\n\t\t\tconst errorMessage =\r\n\t\t\t\tpostCodeInput.dataset.errorServer ||\r\n\t\t\t\t'Sorry, we are unable to find your postcode at the moment. Please try again later.';\r\n\t\t\tpostCodeErrorMessage.textContent = errorMessage;\r\n\t\t\tpostCodeFieldGroup.classList.add('field-group--error');\r\n\t\t}\r\n\t};\r\n\r\n\tconst getPropertyData = async propertyLookupURL => {\r\n\t\ttry {\r\n\t\t\tconst response = await fetch(propertyLookupURL, {\r\n\t\t\t\theaders: { 'Ocp-Apim-Subscription-Key': apiKey },\r\n\t\t\t});\r\n\r\n\t\t\tif (!response.ok) {\r\n\t\t\t\thandleApiErrorStates(response);\r\n\t\t\t} else {\r\n\t\t\t\tconst propertyLookupData = await response.json();\r\n\r\n\t\t\t\tif (propertyLookupData !== null) {\r\n\t\t\t\t\tconst rebuildCost = propertyLookupData.value;\r\n\t\t\t\t\tshowPropertyResultsSuccess(rebuildCost);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tshowPropertyResultsFail();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tsubmitButtonState(addressSubmit, false);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t\tshowPropertyResultsFail();\r\n\t\t}\r\n\t};\r\n\r\n\tconst showPropertyResultsFail = () => {\r\n\t\tprogressTitle.textContent = displayResultFail.getAttribute('data-title');\r\n\t\tdisplayResultFail.classList.remove('display-none');\r\n\t\thouseDetailsSection.classList.add('display-none');\r\n\t\tsubmitButtonState(findAddressButton, false);\r\n\t};\r\n\r\n\tconst showPropertyResultsSuccess = rebuildCost => {\r\n\t\tif (!rebuildCost) return;\r\n\r\n\t\t//GETS THE VALUE DATA ATTRIBUTE PROVIDED BY CMS\r\n\t\tconst defaultValue = resultCost.getAttribute('data-default-val');\r\n\r\n\t\t//FORMAT REBUILD COST\r\n\t\tconst formattedRebuildCost = rebuildCost?.toLocaleString();\r\n\r\n\t\t//REPLACE THE {VALUE} IN THE DATA ATTRIBUTE WITH THE REBUILD COST RESULT\r\n\t\tconst formattedResult = defaultValue.replace('{Value}', formattedRebuildCost);\r\n\r\n\t\t//SET THE INNERTEXT TO THE NEW STRING WITH CMS FORMATTING\r\n\t\tresultCost.innerText = formattedResult;\r\n\r\n\t\tprogressTitle.textContent = displayResult.getAttribute('data-title');\r\n\t\tdisplayResult.classList.remove('display-none');\r\n\t\thouseDetailsSection.classList.add('display-none');\r\n\t};\r\n\r\n\tconst displayProperty = selectedValue => {\r\n\t\tconst propertyLookupURLudprn = `${propertyLookupURL}${selectedValue}`;\r\n\r\n\t\tgetPropertyData(propertyLookupURLudprn);\r\n\r\n\t\tprogressStep.textContent = 3;\r\n\t\tprogressBar.classList = '';\r\n\t\tprogressBar.classList.add('progress-3');\r\n\t};\r\n\r\n\tconst handleApiErrorStates = response => {\r\n\t\tlet errorMessage;\r\n\t\tswitch (response.status) {\r\n\t\t\tcase 400:\r\n\t\t\t\terrorMessage = 'Bad Request: The server could not understand the request due to invalid syntax.';\r\n\t\t\t\tthrow new Error(errorMessage);\r\n\t\t\tcase 401:\r\n\t\t\t\terrorMessage = 'Unauthorized: Access is denied due to invalid credentials.';\r\n\t\t\t\tthrow new Error(errorMessage);\r\n\t\t\tcase 403:\r\n\t\t\t\terrorMessage = 'Forbidden: You do not have the necessary permissions to access this resource.';\r\n\t\t\t\tthrow new Error(errorMessage);\r\n\t\t\tcase 500:\r\n\t\t\t\terrorMessage =\r\n\t\t\t\t\t\"Internal Server Error: The server has encountered a situation it doesn't know how to handle.\";\r\n\t\t\t\tthrow new Error(errorMessage);\r\n\t\t\tcase 404:\r\n\t\t\tdefault:\r\n\t\t\t\terrorMessage = 'Error';\r\n\t\t\t\tthrow new Error(errorMessage);\r\n\t\t}\r\n\t};\r\n\r\n\tconst submitButtonState = (button, disabled) => {\r\n\t\tif (button.getAttribute('data-originaltext') === '' || button.getAttribute('data-originaltext') === null) {\r\n\t\t\tconst innerButtonText = button.textContent;\r\n\t\t\tbutton.setAttribute('data-originaltext', innerButtonText);\r\n\t\t}\r\n\r\n\t\tif (disabled === true) {\r\n\t\t\tbutton.classList.add('btn--loading');\r\n\t\t\tbutton.setAttribute('aria-disabled', true);\r\n\t\t\tbutton.setAttribute('disabled', true);\r\n\t\t\tbutton.textContent = 'loading';\r\n\t\t} else {\r\n\t\t\tbutton.classList.remove('btn--loading');\r\n\t\t\tbutton.removeAttribute('aria-disabled');\r\n\t\t\tbutton.removeAttribute('disabled');\r\n\t\t\tbutton.textContent = button.getAttribute('data-originaltext');\r\n\t\t}\r\n\t};\r\n\r\n\tconst formValidation = (elem, type) => {\r\n\t\tconst valTarget = document.querySelector(elem);\r\n\t\tconst fieldset = valTarget.closest('.field-group');\r\n\t\tfieldset.classList.remove('field-group--error');\r\n\r\n\t\tconst errorMessages = {\r\n\t\t\tempty: postCodeInput.dataset.errorErrorLength,\r\n\t\t\ttooShort: postCodeInput.dataset.errorErrorLength,\r\n\t\t\ttooLong: postCodeInput.dataset.errorErrorLength,\r\n\t\t\tinvalidFormat: postCodeInput.dataset.errorErrorProperties,\r\n\t\t};\r\n\r\n\t\tlet errorMessage = '';\r\n\r\n\t\tswitch (type) {\r\n\t\t\tcase 'postcode':\r\n\t\t\t\t({ isValid, errorMessage } = sIsValidPostcode(valTarget.value, errorMessages));\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 'isSelected':\r\n\t\t\t\tvalTarget.value === '' || valTarget.value === null ? (isValid = false) : (isValid = true);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\talert('Unknown validation type');\r\n\t\t}\r\n\r\n\t\tif (isValid) {\r\n\t\t\tfieldset.classList.remove('field-group--error');\r\n\t\t} else {\r\n\t\t\tif (errorMessage) fieldset.querySelector('.error-message').textContent = errorMessage;\r\n\t\t\tfieldset.classList.add('field-group--error');\r\n\t\t}\r\n\t\treturn isValid;\r\n\t};\r\n\r\n\tconst populateAddress = (addressSelect, postcodeData) => {\r\n\t\tpostcodeData.forEach(option => {\r\n\t\t\tconst opt = document.createElement('option');\r\n\t\t\topt.value = option.udprn;\r\n\t\t\topt.textContent = option.preview;\r\n\t\t\taddressSelect.appendChild(opt);\r\n\t\t\taddressSelect.selectedIndex = 0;\r\n\t\t});\r\n\r\n\t\tprogressStep.textContent = 2;\r\n\t\tprogressBar.classList = '';\r\n\t\tprogressBar.classList.add('progress-2');\r\n\t\tprogressTitle.textContent = houseDetailsSection.getAttribute('data-title');\r\n\r\n\t\tinputPostcodeSection.classList.add('display-none');\r\n\t\thouseDetailsSection.classList.remove('display-none');\r\n\r\n\t\tconst pcResult = document.getElementById('pc-result');\r\n\t\tpcResult.textContent = postcode.value;\r\n\t};\r\n\r\n\tconst reset = (postcode, displayResult, displayResultFail, step, addressSelect) => {\r\n\t\tprogressStep.textContent = 1;\r\n\t\tprogressBar.classList = '';\r\n\t\tprogressBar.classList.add('progress-1');\r\n\t\tprogressTitle.textContent = inputPostcodeSection.getAttribute('data-title');\r\n\r\n\t\tif (step === '2') {\r\n\t\t\thouseDetailsSection.classList.add('display-none');\r\n\t\t} else if (step === '3') {\r\n\t\t\tdisplayResult.classList.add('display-none');\r\n\t\t} else if (step === '4') {\r\n\t\t\tdisplayResultFail.classList.add('display-none');\r\n\t\t}\r\n\r\n\t\twhile (addressSelect.options.length > 1) {\r\n\t\t\taddressSelect.remove(1);\r\n\t\t}\r\n\r\n\t\tinputPostcodeSection.classList.remove('display-none');\r\n\t\tpostcode.value = '';\r\n\t};\r\n\r\n\tconst setupKeyListener = () => {\r\n\t\tconst fieldGroup = postcode.closest('.field-group');\r\n\t\tsInputKeyValidationHelper(postcode, 'alphaNumeric', fieldGroup);\r\n\t};\r\n\r\n\tconst init = () => {\r\n\t\tsetupKeyListener();\r\n\r\n\t\tpostcodeSubmit.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\tsubmitButtonState(findPropertyButton, true);\r\n\r\n\t\t\tformValidation('#hbPostcode', 'postcode');\r\n\t\t\tif (isValid) {\r\n\t\t\t\tgetAddresses(postcode, addressSelect);\r\n\t\t\t} else {\r\n\t\t\t\tsubmitButtonState(findPropertyButton, false);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tchangePostcode.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\tconst step = changePostcode.getAttribute('data-step');\r\n\t\t\treset(postcode, displayResult, displayResultFail, step, addressSelect);\r\n\t\t});\r\n\r\n\t\tbackToStart.forEach(btn => {\r\n\t\t\tbtn.addEventListener('click', event => {\r\n\t\t\t\tconst step = btn.getAttribute('data-step');\r\n\t\t\t\tevent.preventDefault();\r\n\t\t\t\treset(postcode, displayResult, displayResultFail, step, addressSelect);\r\n\t\t\t\tbanner.scrollIntoView({ behavior: 'smooth' });\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\taddressSubmit.addEventListener('click', event => {\r\n\t\t\tevent.preventDefault();\r\n\t\t\tsubmitButtonState(findAddressButton, true);\r\n\r\n\t\t\tformValidation('#address-select', 'isSelected');\r\n\r\n\t\t\tif (isValid) {\r\n\t\t\t\tconst selectedValue = addressSelect.value;\r\n\t\t\t\tdisplayProperty(selectedValue);\r\n\t\t\t} else {\r\n\t\t\t\tsubmitButtonState(findAddressButton, false);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\taddressSelect.addEventListener('change', () => {\r\n\t\t\tformValidation('#address-select', 'isSelected');\r\n\t\t});\r\n\t};\r\n\r\n\treturn {\r\n\t\tinit: init,\r\n\t};\r\n})();\r\n\r\ndocument.addEventListener('DOMContentLoaded', () => {\r\n\thouseRebuildCost.init();\r\n});\r\n"]}