{"version":3,"file":"_id_-zUVVlCPY.js","sources":["../../src/pages/categories/[id].tsx"],"sourcesContent":["import {PrettyTitle} from '..';\nimport {ProductCard} from '@/components/products';\nimport {Product as TProduct} from '@/lib/sdk';\nimport {useGlobalStore} from '@/stores';\nimport {useAuth} from '@/stores/auth';\nimport {dispatchGAEvent, dispatchGAPage, formatCategoryIdForGA, formatPriceForGA,} from '@/utils/googleAnalytics';\nimport {Title} from '@solidjs/meta';\nimport {useParams} from '@solidjs/router';\nimport {createEffect, For, onMount, Show} from 'solid-js';\n\nexport default function ProductCategory() {\n const [auth] = useAuth();\n const params = useParams();\n const [globalStore] = useGlobalStore();\n\n const category = () =>\n\t globalStore.catalog.find((category) => String(category.id) === params.id);\n\n const products = () => {\n\ttype Product = TProduct & { category: string };\n\tconst categoryProducts: Product[] = [];\n\n\tif (!category()) {\n\t return categoryProducts;\n\t}\n\n\tcategoryProducts.push(\n\t\t...category().products.map((product) => ({\n\t\t ...product,\n\t\t category: category().name,\n\t\t})),\n\t);\n\n\tif (category().children.length) {\n\t const products = category().children.flatMap<Product>(\n\t\t ({products, name}) => {\n\t\t\treturn products.map((product) => ({...product, category: name}));\n\t\t },\n\t );\n\t categoryProducts.push(...products);\n\t}\n\n\treturn categoryProducts;\n };\n\n onMount(() => {\n\tdispatchGAPage('category', auth.user);\n });\n\n createEffect(() => {\n\tif (!products().length) {\n\t return;\n\t}\n\n\tconst dataGA = {\n\t ecommerce: {\n\t\titem_list_id: formatCategoryIdForGA(category().id),\n\t\titem_list_name: category()?.name,\n\t\titems: products().map((product, index) => ({\n\t\t item_id: product.id,\n\t\t item_name: product.title,\n\t\t item_brand: product.category,\n\t\t item_list_id: formatCategoryIdForGA(category().id),\n\t\t item_list_name: product.category,\n\t\t price: formatPriceForGA(product.price),\n\t\t currency: 'EUR',\n\t\t quantity: '1',\n\t\t index: index + 1,\n\t\t item_category: product.category,\n\t\t})),\n\t },\n\t};\n\n\tdispatchGAEvent('view_item_list', null, auth.user, dataGA);\n\n\n\tconst hash = window.location.hash;\n\tif (hash) {\n\t document.getElementById(hash.substring(1)).scrollIntoView();\n\t}\n });\n\n return (\n\t <main class=\"flex-1\">\n\t\t<section class=\"mx-auto max-w-5xl px-4 py-12\">\n\t\t <div class=\"mx-auto flex max-w-7xl flex-col\">\n\t\t\t<Show when={category()} keyed>\n\t\t\t {(category) => {\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t <Title>Boutique en ligne TBM : {category.name}</Title>\n\t\t\t\t\t <PrettyTitle color=\"blue\">{category.name}</PrettyTitle>\n\n\t\t\t\t\t <div class=\"mt-8\">\n\t\t\t\t\t\t<For each={products()}>\n\t\t\t\t\t\t {(product) => <ProductCard product={product}/>}\n\t\t\t\t\t\t</For>\n\t\t\t\t\t </div>\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t }}\n\t\t\t</Show>\n\t\t </div>\n\t\t</section>\n\t </main>\n );\n}\n"],"names":["ProductCategory","auth","useAuth","params","useParams","globalStore","useGlobalStore","category","catalog","find","String","id","products","categoryProducts","push","map","product","name","children","length","flatMap","onMount","dispatchGAPage","user","createEffect","dataGA","ecommerce","item_list_id","formatCategoryIdForGA","item_list_name","items","index","item_id","item_name","title","item_brand","price","formatPriceForGA","currency","quantity","item_category","dispatchGAEvent","hash","window","location","document","getElementById","substring","scrollIntoView","_el$","_tmpl$","_el$3","firstChild","_$insert","_$createComponent","Show","when","keyed","Title","_$memo","PrettyTitle","color","_el$4","_tmpl$2","For","each","ProductCard"],"mappings":"uqBAUe,SAASA,IACtB,MAAOC,GAAQC,IACTC,EAASC,KACRC,GAAeC,IAEhBC,EAAWA,IAChBF,EAAYG,QAAQC,MAAMF,GAAaG,OAAOH,EAASI,MAAQR,EAAOQ,KAEjEC,EAAWA,KAElB,MAAMC,EAA8B,GAEpC,IAAKN,IACH,OAAOM,EAUT,GAPAA,EAAiBC,QACbP,IAAWK,SAASG,KAAKC,IAAa,IACpCA,EACHT,SAAUA,IAAWU,UAI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