/** * @page Products Catalog Router Shell (`app/products/page.tsx`) * @purpose Evaluates whether the selected category has `is_parent_feature = True`. * If enabled, renders (Brand -> Series -> Model hierarchical mode). * Otherwise, renders (Standard sidebar filter mode). */ 'use client'; import { useState, useEffect, Suspense } from 'react'; import { useSearchParams } from 'next/navigation'; import { catalogService, CategoryResponse } from '@/services/api/catalogService'; import { ParentFeatureCatalog } from '@/components/catalog/ParentFeatureCatalog'; import { StandardCatalog } from '@/components/catalog/StandardCatalog'; function CatalogPageContent() { const searchParams = useSearchParams(); const categoryParam = searchParams.get('category'); const brandParam = searchParams.get('brand'); const searchQuery = searchParams.get('search'); const [categories, setCategories] = useState([]); const [activeCategory, setActiveCategory] = useState(null); const [isLoadingCategory, setIsLoadingCategory] = useState(true); // Fetch Categories and evaluate parent feature flag useEffect(() => { setIsLoadingCategory(true); catalogService .getCategories() .then((catData) => { setCategories(catData); if (categoryParam) { const found = catData.find( (c) => c.category_id === categoryParam || c.slug.toLowerCase() === categoryParam.toLowerCase() ); setActiveCategory(found || null); } else { setActiveCategory(null); } }) .catch(() => { setCategories([]); setActiveCategory(null); }) .finally(() => { setIsLoadingCategory(false); }); }, [categoryParam]); if (isLoadingCategory) { return (

Loading catalog...

); } // If a category is selected AND has is_parent_feature enabled -> Render ParentFeatureCatalog if (activeCategory && activeCategory.is_parent_feature) { return ; } // Otherwise -> Render StandardCatalog return ( ); } export default function ProductsPage() { return (
} >
); }