import { cn } from '@/lib/utils'; import * as LucideIcons from 'lucide-react'; import { getSectionBackground } from '@/lib/sectionStyles'; import { SectionBackgroundRenderer } from '@/components/SectionBackgroundRenderer'; interface FeatureItem { title?: string; description?: string; icon?: string; // Post-card fields (from related_posts dynamic source) url?: string; featured_image?: string; excerpt?: string; date?: string; } interface FeatureGridSectionProps { id: string; layout?: string; colorScheme?: string; heading?: string; items?: FeatureItem[]; elementStyles?: Record; } export function FeatureGridSection({ id, layout = 'grid-3', colorScheme = 'default', heading, items = [], features = [], elementStyles, styles, }: FeatureGridSectionProps & { features?: FeatureItem[], styles?: Record }) { const heightMap: Record = { 'default': 'py-12 md:py-20', 'small': 'py-8 md:py-12', 'medium': 'py-16 md:py-24', 'large': 'py-24 md:py-36', 'fullscreen': 'min-h-screen flex flex-col justify-center', }; const customPadding = styles?.paddingTop || styles?.paddingBottom; const heightClasses = customPadding ? '' : (heightMap[styles?.heightPreset || 'default'] || 'py-12 md:py-20'); const safeItems = Array.isArray(items) ? items : []; const safeFeatures = Array.isArray(features) ? features : []; const listItems = safeItems.length > 0 ? safeItems : safeFeatures; const gridCols = { 'grid-2': 'md:grid-cols-2', 'grid-3': 'md:grid-cols-3', 'grid-4': 'md:grid-cols-2 lg:grid-cols-4', }[layout] || 'md:grid-cols-3'; // Detect if these are post-cards (from related_posts) — they have a url field const isPostCards = listItems.some(item => !!item.url); const getTextStyles = (elementName: string) => { const styles = elementStyles?.[elementName] || {}; return { classNames: cn( styles.fontSize, styles.fontWeight, { 'font-sans': styles.fontFamily === 'secondary', 'font-serif': styles.fontFamily === 'primary', } ), style: { color: styles.color, textAlign: styles.textAlign, backgroundColor: styles.backgroundColor, borderColor: styles.borderColor, borderWidth: styles.borderWidth, borderRadius: styles.borderRadius, } }; }; const headingStyle = getTextStyles('heading'); const featureItemStyle = getTextStyles('feature_item'); const linkStyle = getTextStyles('link'); const sectionBg = getSectionBackground(styles); return (
{heading && (

{heading}

)}
{listItems.map((item, index) => { // ── Post Card (from related_posts) ────────────────────────── if (isPostCards) { return ( {/* Thumbnail */} {item.featured_image ? (
{item.title
) : (
)} {/* Card Body */}
{item.date && (

{item.date}

)} {item.title && (

{item.title}

)} {(item.excerpt || item.description) && (

{item.excerpt || item.description}

)} Read more
); } // ── Feature Card (icon + title + desc) ───────────────────── return (
{item.icon && (() => { const IconComponent = (LucideIcons as any)[item.icon]; if (!IconComponent) return null; return (
); })()} {item.title && (

{item.title}

)} {item.description && (

{item.description}

)}
); })}
{/* Empty state for related posts */} {isPostCards && listItems.length === 0 && (

No related articles found.

)}
); }