'use client'; import React from 'react'; import { BaseCard, BaseCardProps, CardSize, CardLayout } from './BaseCard'; import { Badge, BadgeGroup } from '@/components/ui'; import { ProductCategory } from '@/lib/data'; import { cn } from '@/lib/utils'; // CategoryCard specific props export interface CategoryCardProps extends Omit { /** Category data from WordPress */ category: ProductCategory; /** Display product count */ showCount?: boolean; /** Display description */ showDescription?: boolean; /** Display as icon instead of image */ useIcon?: boolean; /** Icon component (if useIcon is true) */ icon?: React.ReactNode; /** Category type */ categoryType?: 'product' | 'blog'; /** Locale for formatting */ locale?: string; } // Helper to get category image const getCategoryImage = (category: ProductCategory): string | undefined => { // In a real implementation, this would use getMediaById // For now, return a placeholder based on category ID if (category.id % 3 === 0) { return '/media/6517-medium-voltage-category.webp'; } else if (category.id % 3 === 1) { return '/media/6521-low-voltage-category.webp'; } else { return '/media/10863-klz-directory-2-scaled.webp'; } }; // Helper to get icon for category const getCategoryIcon = (category: ProductCategory): React.ReactNode => { const iconMap = { 1: '🔌', // Low Voltage 2: '⚡', // Medium Voltage 3: '🏭', // Industrial 4: '🏗️', // Construction 5: '🏠', // Residential }; return iconMap[category.id as keyof typeof iconMap] || '📁'; }; // Helper to get category color variant const getCategoryVariant = (category: ProductCategory): 'primary' | 'secondary' | 'success' | 'info' => { const variants = ['primary', 'secondary', 'success', 'info'] as const; return variants[category.id % variants.length]; }; export const CategoryCard: React.FC = ({ category, size = 'md', layout = 'vertical', showCount = true, showDescription = true, useIcon = false, icon, categoryType = 'product', locale = 'de', className = '', ...props }) => { // Get category data const title = category.name; const description = showDescription && category.description ? category.description.replace(/<[^>]*>/g, '').substring(0, 100) + (category.description.length > 100 ? '...' : '') : ''; const count = showCount ? category.count : 0; const image = useIcon ? undefined : getCategoryImage(category); const categoryIcon = icon || getCategoryIcon(category); // Build badge with count const badge = showCount && count > 0 ? ( {count} {locale === 'de' ? 'Produkte' : 'Products'} ) : null; // Build header with icon const header = useIcon ? ( {categoryIcon} ) : null; // Build footer with link text const footer = ( {locale === 'de' ? 'Anzeigen' : 'View'} → ); // Build description with count const descriptionContent = (
{description &&
{description}
} {showCount && count > 0 && (
{count} {locale === 'de' ? 'Produkte' : 'Products'}
)}
); // Build icon content for vertical layout const iconContent = useIcon ? (
{categoryIcon}
) : null; // Override title to include icon for horizontal layout const titleContent = useIcon && layout === 'horizontal' ? (
{iconContent} {title}
) : title; return ( {/* For vertical layout with icon, add icon above title */} {useIcon && layout === 'vertical' && (
{iconContent}
)}
); }; // CategoryCard variations export const CategoryCardVertical: React.FC = (props) => ( ); export const CategoryCardHorizontal: React.FC = (props) => ( ); export const CategoryCardSmall: React.FC = (props) => ( ); export const CategoryCardLarge: React.FC = (props) => ( ); // Icon-only category card export const CategoryCardIcon: React.FC = (props) => ( ); // Export types export type { CardSize, CardLayout };