{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/search-cure.ts"], "sourcesContent": ["import { breakpoint } from 'utility/breakpoints'\nimport { icelandicToLatin } from 'utility/helpers'\nimport { lenisScroll } from 'utility/smooth-scroll'\n\nconst searchCure = {\n el: {\n accordionItems: document.querySelectorAll('.list-page--skin-cures .accordion__item'),\n cures: document.querySelectorAll('.list-page--skin-cures .accordion__body-content .button .button__text'),\n input: document.querySelector('#skin-cures-search'),\n noResultsText: document.querySelector('.list-page__no-results-text'),\n page: document.querySelector('.list-page--skin-cures'),\n },\n\n init(): void {\n this.el.input.addEventListener('keyup', async (event: KeyboardEvent) => {\n event.preventDefault()\n\n if (event.isComposing || event.key === 'VK_LAST') {\n return\n }\n\n this.resetItems()\n this.handleSearch()\n setTimeout(this.handleScrolling.bind(this), 12)\n })\n },\n\n handleScrolling(): void {\n if (window.scrollY > 123) {\n lenisScroll.scrollTo(this.el.page.querySelector('.list-page__column--right'), {\n offset: window.innerWidth < breakpoint.tablet ? -30 : -40,\n })\n } else {\n lenisScroll.scrollTo(window.scrollY)\n }\n },\n\n handleSearch(): void {\n let clicked = false\n let resultsCount = 0\n const searchValue = this.el.input.value.toLowerCase()\n\n if (searchValue.length < 3) {\n this.el.accordionItems.forEach((item) => {\n item.classList.remove('accordion__item--active')\n })\n\n return\n }\n\n this.el.accordionItems.forEach((item) => {\n item.classList.add('accordion__item--hidden')\n })\n\n this.el.cures.forEach((cure) => {\n const cureName = cure.innerText.toLowerCase()\n const latinCureName = icelandicToLatin(cureName)\n\n if (cureName.includes(searchValue) || latinCureName.includes(searchValue)) {\n const accordionItem = cure.closest('.accordion__item')\n const accordionHead = accordionItem.querySelector('.accordion__head')\n\n accordionItem.classList.remove('accordion__item--hidden')\n\n if (!accordionItem.classList.contains('accordion__item--active') && !clicked) {\n setTimeout(() => accordionHead.click(), 12)\n clicked = true\n }\n\n resultsCount++\n }\n })\n\n if (resultsCount === 0) {\n this.el.noResultsText.classList.remove('list-page__no-results-text--hidden')\n }\n },\n\n resetItems(): void {\n this.el.accordionItems.forEach((item) => {\n item.classList.remove('accordion__item--hidden')\n })\n this.el.noResultsText.classList.add('list-page__no-results-text--hidden')\n },\n}\n\nexport default searchCure\n"], "mappings": "oOAIA,IAAMA,EAAa,CACjB,GAAI,CACF,eAAgB,SAAS,iBAA8B,yCAAyC,EAChG,MAAO,SAAS,iBAA8B,uEAAuE,EACrH,MAAO,SAAS,cAAgC,oBAAoB,EACpE,cAAe,SAAS,cAAc,6BAA6B,EACnE,KAAM,SAAS,cAAc,wBAAwB,CACvD,EAEA,MAAa,CACX,KAAK,GAAG,MAAM,iBAAiB,QAAS,MAAOC,GAAyB,CACtEA,EAAM,eAAe,EAEjB,EAAAA,EAAM,aAAeA,EAAM,MAAQ,aAIvC,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,WAAW,KAAK,gBAAgB,KAAK,IAAI,EAAG,EAAE,EAChD,CAAC,CACH,EAEA,iBAAwB,CAClB,OAAO,QAAU,IACnBC,EAAY,SAAS,KAAK,GAAG,KAAK,cAAc,2BAA2B,EAAG,CAC5E,OAAQ,OAAO,WAAaC,EAAW,OAAS,IAAM,GACxD,CAAC,EAEDD,EAAY,SAAS,OAAO,OAAO,CAEvC,EAEA,cAAqB,CACnB,IAAIE,EAAU,GACVC,EAAe,EACbC,EAAc,KAAK,GAAG,MAAM,MAAM,YAAY,EAEpD,GAAIA,EAAY,OAAS,EAAG,CAC1B,KAAK,GAAG,eAAe,QAASC,GAAS,CACvCA,EAAK,UAAU,OAAO,yBAAyB,CACjD,CAAC,EAED,MACF,CAEA,KAAK,GAAG,eAAe,QAASA,GAAS,CACvCA,EAAK,UAAU,IAAI,yBAAyB,CAC9C,CAAC,EAED,KAAK,GAAG,MAAM,QAASC,GAAS,CAC9B,IAAMC,EAAWD,EAAK,UAAU,YAAY,EACtCE,EAAgBC,EAAiBF,CAAQ,EAE/C,GAAIA,EAAS,SAASH,CAAW,GAAKI,EAAc,SAASJ,CAAW,EAAG,CACzE,IAAMM,EAAgBJ,EAAK,QAAQ,kBAAkB,EAC/CK,EAAgBD,EAAc,cAA2B,kBAAkB,EAEjFA,EAAc,UAAU,OAAO,yBAAyB,EAEpD,CAACA,EAAc,UAAU,SAAS,yBAAyB,GAAK,CAACR,IACnE,WAAW,IAAMS,EAAc,MAAM,EAAG,EAAE,EAC1CT,EAAU,IAGZC,GACF,CACF,CAAC,EAEGA,IAAiB,GACnB,KAAK,GAAG,cAAc,UAAU,OAAO,oCAAoC,CAE/E,EAEA,YAAmB,CACjB,KAAK,GAAG,eAAe,QAASE,GAAS,CACvCA,EAAK,UAAU,OAAO,yBAAyB,CACjD,CAAC,EACD,KAAK,GAAG,cAAc,UAAU,IAAI,oCAAoC,CAC1E,CACF,EAEOO,EAAQd", "names": ["searchCure", "event", "lenisScroll", "breakpoint", "clicked", "resultsCount", "searchValue", "item", "cure", "cureName", "latinCureName", "icelandicToLatin", "accordionItem", "accordionHead", "search_cure_default"] }