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gB/B,GAEnBe,EAASW,SAAQd,EAAKe,UAAYC,gBAAgBhB,IAEnDG,EAASW,QACTX,EAASJ,SAASqB,IACd,MAAMC,EAAiBD,EAAQlB,cAAchB,GACxCmC,IAELD,EAAQV,UAAUC,OAAOxB,GACzBkC,EAAeF,gBAAgB/B,GAE/BgC,EAAQL,UAAYC,gBAAgBI,WASpD,SAASE,aAAaC,GAClB,OAAOA,EAAOC,QAAQ,sBAAuB,QAMjD,SAASP,aAAaQ,EAAiB7B,GACnC,OAAO6B,EAAGV,UAAUS,QAChB,IAAIE,OAAO,wBAAyBJ,aAAa1B,MAAS,OACzD+B,GAAU,SAASA,aAO5B,SAASX,gBAAgBS,GACrB,OAAOA,EAAGV,UAAUS,QAAQ,qBAAsB,KAnGtD7B,CAAcF","sources":["webpack://frontend-setup/./src/components/organisms/faq/faq.ts"],"sourcesContent":["import { defineElement, FC, useElement, useElements, useListen } from '@atomify/hooks';\n\nconst FAQ_ACCORDEON_ITEM = '.accordeon-item__subitem';\nconst FAQ_CONTENT_COLLAPSE = 'bpd-content-collapse';\nconst HIDDEN_CLASS = 'u-hidden';\nconst EXPANDED_ATTR = 'expanded';\n\nconst Faq: FC = () => {\n const input = useElement('[js-hook-faq-input]');\n const items = useElements('[js-hook-faq-items] > div');\n\n useListen(input, 'input', onInput);\n\n function onInput(e: InputEvent) {\n const { value } = e.currentTarget as HTMLInputElement;\n toggleResults(value);\n }\n\n function toggleResults(val: string) {\n const itemArray = items.current as HTMLDivElement[];\n\n if (val) {\n itemArray.forEach((item) => {\n const content = item.querySelector(FAQ_CONTENT_COLLAPSE);\n const subItems = Array.from(\n item.querySelectorAll(FAQ_ACCORDEON_ITEM),\n ) as HTMLDivElement[];\n if (!content) return;\n\n if (!item.innerText.toLowerCase().includes(val.toLowerCase())) {\n item.classList.add(HIDDEN_CLASS);\n content.removeAttribute(EXPANDED_ATTR);\n } else {\n item.classList.remove(HIDDEN_CLASS);\n content.setAttribute(EXPANDED_ATTR, '');\n\n Array.from(item.children).forEach((item: HTMLElement) => {\n const subItems = Array.from(\n item.querySelectorAll(FAQ_ACCORDEON_ITEM),\n ) as HTMLDivElement[];\n\n if (!subItems.length) {\n item.innerHTML = removeHighlight(item);\n item.innerHTML = addHighlight(item, val);\n }\n });\n }\n\n if (subItems.length) {\n subItems.forEach((subItem) => {\n const subItemContent = subItem.querySelector(FAQ_CONTENT_COLLAPSE);\n if (!subItemContent) return;\n\n if (!subItem.innerText.toLowerCase().includes(val.toLowerCase())) {\n subItem.classList.add(HIDDEN_CLASS);\n subItemContent.removeAttribute(EXPANDED_ATTR);\n } else {\n subItem.classList.remove(HIDDEN_CLASS);\n subItemContent.setAttribute(EXPANDED_ATTR, '');\n\n subItem.innerHTML = removeHighlight(subItem);\n subItem.innerHTML = addHighlight(subItem, val);\n }\n });\n }\n });\n } else {\n itemArray.forEach((item) => {\n const content = item.querySelector(FAQ_CONTENT_COLLAPSE);\n const subItems = Array.from(\n item.querySelectorAll(FAQ_ACCORDEON_ITEM),\n ) as HTMLDivElement[];\n if (!content) return;\n\n item.classList.remove(HIDDEN_CLASS);\n content.removeAttribute(EXPANDED_ATTR);\n\n if (!subItems.length) item.innerHTML = removeHighlight(item);\n\n if (subItems.length) {\n subItems.forEach((subItem) => {\n const subItemContent = subItem.querySelector(FAQ_CONTENT_COLLAPSE);\n if (!subItemContent) return;\n\n subItem.classList.remove(HIDDEN_CLASS);\n subItemContent.removeAttribute(EXPANDED_ATTR);\n\n subItem.innerHTML = removeHighlight(subItem);\n });\n }\n });\n }\n\n /**\n * escape regex\n */\n function escapeRegExp(string: string) {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n }\n\n /**\n * Add tag to matching values\n */\n function addHighlight(el: HTMLElement, val: string) {\n return el.innerHTML.replace(\n new RegExp(`(?]*|&[^;]*)(${escapeRegExp(val)})`, 'gi'),\n (match) => `${match}`,\n );\n }\n\n /**\n * Remove tags\n */\n function removeHighlight(el: HTMLElement) {\n return el.innerHTML.replace(/(|<\\/mark>)/g, '');\n }\n }\n};\n\ndefineElement('bpd-faq', Faq);\n"],"names":["FAQ_ACCORDEON_ITEM","FAQ_CONTENT_COLLAPSE","HIDDEN_CLASS","EXPANDED_ATTR","input","items","onInput","e","value","currentTarget","toggleResults","val","itemArray","current","forEach","item","content","querySelector","subItems","Array","from","querySelectorAll","innerText","toLowerCase","includes","classList","remove","setAttribute","children","length","innerHTML","removeHighlight","addHighlight","add","removeAttribute","subItem","subItemContent","escapeRegExp","string","replace","el","RegExp","match"],"sourceRoot":""}