import React, { useEffect, useState } from 'react'; import useCategoryManagement from '../hooks/useCategoryManagement'; import NextImage from 'next/image'; import Link from "next/link"; import router from 'next/router'; import { createSlug } from '@/core/utils/slug'; const CategoryDynamic = () => { const { categoryManagement } = useCategoryManagement(); const calculateLevel3Products = (category) => { return category.childFrontendIdI.reduce((total, child) => total + (child.numFound || 0), 0); }; const calculateLevel2Products = (category) => { return category.categories.reduce((total, subCategory) => { const level3Products = calculateLevel3Products(subCategory); return total + (subCategory.numFound || 0) + level3Products; }, 0); }; return (
{categoryManagement && categoryManagement.data?.map((category) => { const countLevel2 = calculateLevel2Products(category); return (
{category.name}

{countLevel2} Produk tersedia

Lihat Semua
{category.categories.map((subCategory) => { const countLevel3 = calculateLevel3Products(subCategory); return (
{subCategory.name}

{(subCategory.numFound || 0) + countLevel3} Produk

Lihat Semua
{subCategory.childFrontendIdI.map((childCategory) => (
{childCategory.name}
))}
); })}
); })}
); }; export default CategoryDynamic;