'use client' import { useRef, useEffect } from 'react' import { ShieldAlert, FileText, Building2, Bot, BookOpen, Database, } from 'lucide-react' import type { CatalogModule, CatalogOverviewStats, } from '@/lib/sdk/catalog-manager/types' import { CATALOG_MODULE_LABELS } from '@/lib/sdk/catalog-manager/types' interface CatalogModuleTabsProps { activeModule: CatalogModule | 'all' onModuleChange: (module: CatalogModule | 'all') => void stats: CatalogOverviewStats } const MODULE_ICON_MAP: Record> = { dsfa: ShieldAlert, vvt: FileText, vendor: Building2, ai_act: Bot, reference: BookOpen, } interface TabDefinition { key: CatalogModule | 'all' label: string icon: React.ComponentType<{ className?: string }> } export default function CatalogModuleTabs({ activeModule, onModuleChange, stats, }: CatalogModuleTabsProps) { const scrollRef = useRef(null) const activeTabRef = useRef(null) // Scroll active tab into view on mount and when active changes useEffect(() => { if (activeTabRef.current && scrollRef.current) { const container = scrollRef.current const tab = activeTabRef.current const containerRect = container.getBoundingClientRect() const tabRect = tab.getBoundingClientRect() if (tabRect.left < containerRect.left || tabRect.right > containerRect.right) { tab.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }) } } }, [activeModule]) const tabs: TabDefinition[] = [ { key: 'all', label: 'Alle', icon: Database }, ...Object.entries(CATALOG_MODULE_LABELS).map(([key, label]) => ({ key: key as CatalogModule, label, icon: MODULE_ICON_MAP[key as CatalogModule], })), ] const getCount = (key: CatalogModule | 'all'): number => { if (key === 'all') { return stats.totalEntries } return stats.byModule?.[key]?.entries ?? 0 } return (
{tabs.map(tab => { const isActive = activeModule === tab.key const Icon = tab.icon const count = getCount(tab.key) return ( ) })}
) }