{ "version": 3, "sources": ["../../../Vettvangur.Heilsuvera/src/scripts/components/Sykurmagn/types.ts"], "sourcesContent": ["interface Product {\n\tid: number;\n\ttypes: string[];\n}\n\nconst typeFiltering = {\n\tproducts: document.querySelectorAll(\".product\"),\n\ttypes: document.querySelectorAll(\".sm-type\"),\n\tproductsArray: [] as Product[],\n\tactiveTypes: new Set(),\n\n\tinit: (): void => {\n\t\tif (typeFiltering.products !== null && typeFiltering.products.length > 0) {\n\t\t\ttypeFiltering.handleProductsArray();\n\t\t}\n\n\t\tif (typeFiltering.types !== null && typeFiltering.types.length > 0) {\n\t\t\ttypeFiltering.handleTypeButtons();\n\t\t}\n\t},\n\n\thandleProductsArray(): void {\n\t\ttypeFiltering.products.forEach((product) => {\n\t\t\tconst types = [];\n\t\t\tconst productTypes = product.dataset.types.split(\",\");\n\n\t\t\tproductTypes.forEach((type) => {\n\t\t\t\ttypes.push(type);\n\t\t\t});\n\n\t\t\ttypeFiltering.productsArray.push({\n\t\t\t\tid: parseInt(product.dataset.id),\n\t\t\t\ttypes: types,\n\t\t\t});\n\t\t});\n\t},\n\n\thandleTypeButtons(): void {\n\t\ttypeFiltering.types.forEach((typeEl) => {\n\t\t\ttypeEl.addEventListener(\"click\", () => {\n\t\t\t\tconst type = typeEl.dataset.type;\n\n\t\t\t\tif (typeFiltering.activeTypes.has(type)) {\n\t\t\t\t\ttypeFiltering.activeTypes.delete(type);\n\t\t\t\t\ttypeEl.classList.remove(\"sm-type--active\");\n\t\t\t\t} else {\n\t\t\t\t\ttypeFiltering.activeTypes.add(type);\n\t\t\t\t\ttypeEl.classList.add(\"sm-type--active\");\n\t\t\t\t}\n\n\t\t\t\ttypeFiltering.productsArray = typeFiltering.filterProductsByTypes(\n\t\t\t\t\ttypeFiltering.productsArray,\n\t\t\t\t\tArray.from(typeFiltering.activeTypes),\n\t\t\t\t);\n\n\t\t\t\ttypeFiltering.updateView();\n\t\t\t});\n\t\t});\n\t},\n\n\tupdateView: (): void => {\n\t\ttypeFiltering.products.forEach((div) => {\n\t\t\tconst id = div.dataset.id;\n\t\t\tconst ids = typeFiltering.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 (typeFiltering.activeTypes.size === 0) {\n\t\t\ttypeFiltering.products.forEach((div) => {\n\t\t\t\tdiv.classList.remove(\"product--hidden\");\n\t\t\t});\n\t\t}\n\n\t\ttypeFiltering.handleProductsArray();\n\t},\n\n\tfilterProductsByTypes(\n\t\tproducts: Product[],\n\t\tselectedTypes: string[],\n\t): Product[] {\n\t\treturn products.filter((product) => {\n\t\t\treturn selectedTypes.some((type) => product.types.includes(type));\n\t\t});\n\t},\n};\n\nexport default typeFiltering;\n"], "mappings": "gCAKA,IAAMA,EAAgB,CACrB,SAAU,SAAS,iBAA8B,UAAU,EAC3D,MAAO,SAAS,iBAA8B,UAAU,EACxD,cAAe,CAAC,EAChB,YAAa,IAAI,IAEjB,KAAM,IAAY,CACbA,EAAc,WAAa,MAAQA,EAAc,SAAS,OAAS,GACtEA,EAAc,oBAAoB,EAG/BA,EAAc,QAAU,MAAQA,EAAc,MAAM,OAAS,GAChEA,EAAc,kBAAkB,CAElC,EAEA,qBAA4B,CAC3BA,EAAc,SAAS,QAASC,GAAY,CAC3C,IAAMC,EAAQ,CAAC,EACMD,EAAQ,QAAQ,MAAM,MAAM,GAAG,EAEvC,QAASE,GAAS,CAC9BD,EAAM,KAAKC,CAAI,CAChB,CAAC,EAEDH,EAAc,cAAc,KAAK,CAChC,GAAI,SAASC,EAAQ,QAAQ,EAAE,EAC/B,MAAOC,CACR,CAAC,CACF,CAAC,CACF,EAEA,mBAA0B,CACzBF,EAAc,MAAM,QAASI,GAAW,CACvCA,EAAO,iBAAiB,QAAS,IAAM,CACtC,IAAMD,EAAOC,EAAO,QAAQ,KAExBJ,EAAc,YAAY,IAAIG,CAAI,GACrCH,EAAc,YAAY,OAAOG,CAAI,EACrCC,EAAO,UAAU,OAAO,iBAAiB,IAEzCJ,EAAc,YAAY,IAAIG,CAAI,EAClCC,EAAO,UAAU,IAAI,iBAAiB,GAGvCJ,EAAc,cAAgBA,EAAc,sBAC3CA,EAAc,cACd,MAAM,KAAKA,EAAc,WAAW,CACrC,EAEAA,EAAc,WAAW,CAC1B,CAAC,CACF,CAAC,CACF,EAEA,WAAY,IAAY,CACvBA,EAAc,SAAS,QAASK,GAAQ,CACvC,IAAMC,EAAKD,EAAI,QAAQ,GACXL,EAAc,cAAc,IAAKC,GAC5CA,EAAQ,GAAG,SAAS,CACrB,EACQ,SAASK,CAAE,EAClBD,EAAI,UAAU,OAAO,iBAAiB,EAEtCA,EAAI,UAAU,IAAI,iBAAiB,CAErC,CAAC,EAEGL,EAAc,YAAY,OAAS,GACtCA,EAAc,SAAS,QAASK,GAAQ,CACvCA,EAAI,UAAU,OAAO,iBAAiB,CACvC,CAAC,EAGFL,EAAc,oBAAoB,CACnC,EAEA,sBACCO,EACAC,EACY,CACZ,OAAOD,EAAS,OAAQN,GAChBO,EAAc,KAAML,GAASF,EAAQ,MAAM,SAASE,CAAI,CAAC,CAChE,CACF,CACD,EAEOM,EAAQT", "names": ["typeFiltering", "product", "types", "type", "typeEl", "div", "id", "products", "selectedTypes", "types_default"] }