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,cAAgB,GACjBR,KAAKI,SACLJ,KAAKI,QAAQJ,KAAKQ,cAAcoB,QAG5C,GAER,CAEAF,SAAAA,CAAUG,GACN,IAAKA,EAAG,OAAO,EAEf7B,KAAK8B,aAAaD,GAEd7B,KAAKQ,cAAgBqB,EAAEL,SAAQxB,KAAKQ,aAAe,GACnDR,KAAKQ,aAAe,IAAGR,KAAKQ,aAAeqB,EAAEL,OAAS,GAC1DK,EAAE7B,KAAKQ,cAAcK,UAAUK,IAAI,SACvC,CAEAY,YAAAA,CAAaD,GACT,IAAK,IAAIE,EAAI,EAAGA,EAAIF,EAAEL,OAAQO,IAC1BF,EAAEE,GAAGlB,UAAUC,OAAO,SAE9B,E","sources":["webpack://intracto-deheus/./Frontend/js/components/zipcode-autocomplete/index.js"],"sourcesContent":["export default class ZipcodeAutocomplete {\r\n constructor(component) {\r\n this.component = component;\r\n\r\n this.input = this.component.querySelector('[data-zipcodes]');\r\n this.list = this.component.querySelector('[data-zipcodes-list]');\r\n this.options = this.list.querySelectorAll('[data-zipcode-item]');\r\n this.noResultText = this.list.querySelector('[data-no-result]');\r\n\r\n this.init();\r\n\r\n this.currentFocus = 1;\r\n }\r\n\r\n init() {\r\n for (const option of this.options) {\r\n option.addEventListener('click', (e) => {\r\n this.options.forEach((option) => {\r\n option.classList.remove('active');\r\n });\r\n\r\n this.input.value = option.value;\r\n this.list.style.display = 'none';\r\n option.classList.add('active');\r\n });\r\n }\r\n\r\n this.input.addEventListener('input', (e) => {\r\n const currentLength = [];\r\n\r\n const text = this.input.value.toUpperCase();\r\n this.list.style.display = 'block';\r\n\r\n for (const option of this.options) {\r\n if (option.value.toUpperCase().indexOf(text) > -1) {\r\n option.style.display = 'block';\r\n currentLength.push(1);\r\n } else {\r\n option.style.display = 'none';\r\n }\r\n }\r\n\r\n if (currentLength.length === 0) {\r\n this.noResultText.classList.remove('d-none');\r\n } else {\r\n this.noResultText.classList.add('d-none');\r\n }\r\n });\r\n\r\n this.input.addEventListener('keydown', (e) => {\r\n // Down key\r\n if (e.keyCode === 40) {\r\n this.currentFocus += 1;\r\n this.addActive(this.options);\r\n } else if (e.keyCode === 38) {\r\n // Up key\r\n this.currentFocus -= 1;\r\n this.addActive(this.options);\r\n } else if (e.keyCode === 13 || e.keyCode === 32) {\r\n // Enter or spacebar\r\n e.preventDefault();\r\n if (this.currentFocus > -1) {\r\n if (this.options) {\r\n this.options[this.currentFocus].click();\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n addActive(x) {\r\n if (!x) return false;\r\n\r\n this.removeActive(x);\r\n\r\n if (this.currentFocus >= x.length) this.currentFocus = 0;\r\n if (this.currentFocus < 0) this.currentFocus = x.length - 1;\r\n x[this.currentFocus].classList.add('active');\r\n }\r\n\r\n removeActive(x) {\r\n for (let i = 0; i < x.length; i++) {\r\n x[i].classList.remove('active');\r\n }\r\n }\r\n}\r\n"],"names":["ZipcodeAutocomplete","constructor","component","this","input","querySelector","list","options","querySelectorAll","noResultText","init","currentFocus","option","addEventListener","e","forEach","classList","remove","value","style","display","add","currentLength","text","toUpperCase","indexOf","push","length","keyCode","addActive","preventDefault","click","x","removeActive","i"],"sourceRoot":""}