import React from 'react' import type { FDSpecCardsBlock as Props } from '@/payload-types' import { FDButton } from '@/components/FDButton' import { sectionBg, isExplicitDark, headingColor, bodyColor, bodySubduedColor, fdCardRadius, fdCardRadiusSm, } from '@/utilities/fdTheme' const cardStyleMap: Record = { outlined: { bg: 'bg-transparent', border: 'border border-white/15 dark:border-white/15', title: 'text-white dark:text-white', body: 'text-white/70 dark:text-white/70', specLabel: 'text-white/50 dark:text-white/50', specValue: 'text-white dark:text-white', divider: 'border-white/10 dark:border-white/10', isDark: true, }, navy: { bg: 'bg-fd-navy dark:bg-white/10', border: '', title: 'text-white', body: 'text-white/70', specLabel: 'text-white/50', specValue: 'text-fd-yellow', divider: 'border-white/10', isDark: true, }, gray: { bg: 'bg-fd-gray-light dark:bg-white/10', border: '', title: 'text-fd-navy dark:text-white', body: 'text-fd-navy/70 dark:text-white/70', specLabel: 'text-fd-navy/50 dark:text-white/50', specValue: 'text-fd-navy dark:text-white', divider: 'border-fd-navy/10 dark:border-white/10', isDark: false, }, white: { bg: 'bg-white dark:bg-white/10 shadow-fd-card dark:shadow-none', border: '', title: 'text-fd-navy dark:text-white', body: 'text-fd-navy/70 dark:text-white/70', specLabel: 'text-fd-navy/50 dark:text-white/50', specValue: 'text-fd-navy dark:text-white', divider: 'border-fd-navy/10 dark:border-white/10', isDark: false, }, } /* Light-section overrides for outlined cards */ const cardStyleMapLight: Record = { outlined: { bg: 'bg-transparent', border: 'border border-gray-200 dark:border-white/15', title: 'text-fd-navy dark:text-white', body: 'text-fd-navy/70 dark:text-white/70', specLabel: 'text-fd-navy/50 dark:text-white/50', specValue: 'text-fd-navy dark:text-white', divider: 'border-fd-navy/10 dark:border-white/10', isDark: false, }, } export const FDSpecCardsBlockComponent: React.FC = ({ heading, description, ctaText, ctaLink, secondaryCtaText, secondaryCtaLink, cards, layout = 'sideBySide', cardStyle = 'outlined', sectionBackground = 'navy', anchorId, }) => { const dark = isExplicitDark(sectionBackground) const bg = sectionBg(sectionBackground) const hClr = headingColor(dark) const bClr = bodySubduedColor(dark) const style = (!dark && cardStyle === 'outlined') ? cardStyleMapLight.outlined : (cardStyleMap[cardStyle || 'outlined'] || cardStyleMap.outlined) const isSideBySide = layout === 'sideBySide' || layout === 'sideBySideReverse' const isReversed = layout === 'sideBySideReverse' const cardCount = cards?.length || 1 /* Cards grid: 1 card = 1 col, 2 = 2-col, 3+ = 2-col wrapping */ const cardGridCols = cardCount === 1 ? '' : 'sm:grid-cols-2' const renderCards = () => (
{cards?.map((card, i) => (

{card.title}

{card.description && (

{card.description}

)}
{(card.specLabel || card.specValue) && (
{card.specLabel && ( {card.specLabel} )} {card.specValue && ( {card.specValue} )}
)}
))}
) const renderText = () => (

{heading}

{description && (

{description}

)} {(ctaText || secondaryCtaText) && (
{ctaText && ( {ctaText} )} {secondaryCtaText && ( {secondaryCtaText} )}
)}
) if (!isSideBySide) { /* Full-width layout — heading on top, cards below */ return (
{renderText()}
{renderCards()}
) } /* Side-by-side layout */ return (
{renderText()}
{renderCards()}
) }