{ "version": 3, "sources": ["../../../Vettvangur.Heilsuvera/src/scripts/components/Sykurmagn/tags.ts"], "sourcesContent": ["interface Product {\n\tid: number;\n\ttags: string[];\n}\n\nconst tagFiltering = {\n\tproducts: document.querySelectorAll(\".product\"),\n\ttags: document.querySelectorAll(\".sm-tag\"),\n\tproductsArray: [] as Product[],\n\tactiveTags: new Set(),\n\n\tinit: (): void => {\n\t\tif (tagFiltering.products !== null && tagFiltering.products.length > 0) {\n\t\t\ttagFiltering.handleProductsArray();\n\t\t}\n\n\t\tif (tagFiltering.tags !== null && tagFiltering.tags.length > 0) {\n\t\t\ttagFiltering.handleTagButtons();\n\t\t}\n\t},\n\n\thandleProductsArray(): void {\n\t\ttagFiltering.products.forEach((product) => {\n\t\t\tconst tags = [];\n\t\t\tconst productTags = product.querySelectorAll(\".product-tag\");\n\t\t\tproductTags.forEach((tag) => {\n\t\t\t\ttags.push(tag.dataset.tagName);\n\t\t\t});\n\n\t\t\ttagFiltering.productsArray.push({\n\t\t\t\tid: parseInt(product.dataset.id),\n\t\t\t\ttags: tags,\n\t\t\t});\n\t\t});\n\t},\n\n\thandleTagButtons(): void {\n\t\ttagFiltering.tags.forEach((tagEl) => {\n\t\t\ttagEl.addEventListener(\"click\", () => {\n\t\t\t\tconst tag = tagEl.dataset.tag;\n\n\t\t\t\tif (tagFiltering.activeTags.has(tag)) {\n\t\t\t\t\ttagFiltering.activeTags.delete(tag);\n\t\t\t\t\ttagEl.classList.remove(\"sm-tag--active\");\n\t\t\t\t} else {\n\t\t\t\t\ttagFiltering.activeTags.add(tag);\n\t\t\t\t\ttagEl.classList.add(\"sm-tag--active\");\n\t\t\t\t}\n\n\t\t\t\ttagFiltering.productsArray = tagFiltering.filterProductsByTags(\n\t\t\t\t\ttagFiltering.productsArray,\n\t\t\t\t\tArray.from(tagFiltering.activeTags),\n\t\t\t\t);\n\n\t\t\t\ttagFiltering.updateView();\n\t\t\t});\n\t\t});\n\t},\n\n\tupdateView: (): void => {\n\t\ttagFiltering.products.forEach((div) => {\n\t\t\tconst id = div.dataset.id;\n\t\t\tconst ids = tagFiltering.productsArray.map((product) =>\n\t\t\t\tproduct.id.toString(),\n\t\t\t);\n\t\t\tif (ids.includes(id)) {\n\t\t\t\tdiv.classList.remove(\"product--hidden\");\n\t\t\t} else {\n\t\t\t\tdiv.classList.add(\"product--hidden\");\n\t\t\t}\n\t\t});\n\n\t\tif (tagFiltering.activeTags.size === 0) {\n\t\t\ttagFiltering.products.forEach((div) => {\n\t\t\t\tdiv.classList.remove(\"product--hidden\");\n\t\t\t});\n\t\t}\n\n\t\ttagFiltering.handleProductsArray();\n\t},\n\n\tfilterProductsByTags(products: Product[], selectedTags: string[]): Product[] {\n\t\treturn products.filter((product) => {\n\t\t\treturn selectedTags.some((tag) => product.tags.includes(tag));\n\t\t});\n\t},\n};\n\nexport default tagFiltering;\n"], "mappings": "gCAKA,IAAMA,EAAe,CACpB,SAAU,SAAS,iBAA8B,UAAU,EAC3D,KAAM,SAAS,iBAA8B,SAAS,EACtD,cAAe,CAAC,EAChB,WAAY,IAAI,IAEhB,KAAM,IAAY,CACbA,EAAa,WAAa,MAAQA,EAAa,SAAS,OAAS,GACpEA,EAAa,oBAAoB,EAG9BA,EAAa,OAAS,MAAQA,EAAa,KAAK,OAAS,GAC5DA,EAAa,iBAAiB,CAEhC,EAEA,qBAA4B,CAC3BA,EAAa,SAAS,QAASC,GAAY,CAC1C,IAAMC,EAAO,CAAC,EACMD,EAAQ,iBAA8B,cAAc,EAC5D,QAASE,GAAQ,CAC5BD,EAAK,KAAKC,EAAI,QAAQ,OAAO,CAC9B,CAAC,EAEDH,EAAa,cAAc,KAAK,CAC/B,GAAI,SAASC,EAAQ,QAAQ,EAAE,EAC/B,KAAMC,CACP,CAAC,CACF,CAAC,CACF,EAEA,kBAAyB,CACxBF,EAAa,KAAK,QAASI,GAAU,CACpCA,EAAM,iBAAiB,QAAS,IAAM,CACrC,IAAMD,EAAMC,EAAM,QAAQ,IAEtBJ,EA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