import { Link } from 'react-router-dom'; import type { FeaturedTilesSectionPayload } from '@homaroma/types'; import { useTranslation } from 'react-i18next'; import { getLocalizedField } from '../utils/localization'; interface DynamicFeaturedTilesProps { payload: FeaturedTilesSectionPayload; } export default function DynamicFeaturedTiles({ payload }: DynamicFeaturedTilesProps) { const { i18n } = useTranslation(); const lang = i18n.language; const tiles = Array.isArray(payload.tiles) ? payload.tiles : []; const columns = payload.columns || 2; const layoutPreset = payload.layoutPreset; const textAlign = payload.textAlign || (layoutPreset === 'editorial' ? 'left' : 'center'); const ctaStyle = payload.ctaStyle || (layoutPreset === 'editorial' ? 'arrow_link' : 'pill_button'); const sectionAspect = payload.imageAspectRatio || (layoutPreset === 'editorial' ? 'landscape' : undefined); const imageRounded = payload.imageRounded || (layoutPreset === 'editorial' ? 'md' : '3xl'); const sectionTitle = getLocalizedField(payload.title, lang); const sectionSubtitle = getLocalizedField(payload.subtitle, lang); const getGridColsClass = (cols: number) => { switch (cols) { case 3: return 'grid-cols-1 md:grid-cols-3'; case 4: return 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4'; case 2: default: return 'grid-cols-1 md:grid-cols-2'; } }; const getAspectClass = (ratio?: string) => { const r = ratio || sectionAspect || 'square'; switch (r) { case 'landscape': return 'aspect-[16/9]'; case 'wide': return 'aspect-[4/3]'; case 'portrait': return 'aspect-[3/4]'; case 'tall': return 'aspect-[2/3]'; case 'auto': return 'aspect-auto'; case 'square': default: return 'aspect-square'; } }; const getRoundedClass = (rounded?: string) => { switch (rounded) { case 'none': return 'rounded-none'; case 'sm': return 'rounded-md'; case 'md': return 'rounded-xl'; case '2xl': return 'rounded-2xl'; case 'full': return 'rounded-full'; case '3xl': default: return 'rounded-3xl'; } }; const isLeftAlign = textAlign === 'left'; const isRightAlign = textAlign === 'right'; const alignContainerClass = isLeftAlign ? 'items-start text-left' : isRightAlign ? 'items-end text-right' : 'items-center text-center'; return (
{/* Optional Section Header */} {(sectionTitle || sectionSubtitle) && (
{sectionTitle && (

{sectionTitle}

)} {sectionSubtitle && (

{sectionSubtitle}

)}
)} {/* Campaign Tiles Grid */}
{tiles.map((tile, idx) => { const tileTitle = getLocalizedField(tile.title, lang); const tileDescription = getLocalizedField(tile.description, lang); const buttonText = getLocalizedField(tile.buttonText, lang); const imageAspectRatio = tile.imageAspectRatio || sectionAspect || 'square'; const cardContent = (
{/* Image Container */}
{tile.imageUrl ? ( {tileTitle} { (e.target as HTMLImageElement).style.display = 'none'; }} /> ) : (
No Image
)}
{/* Content Details */}
{tileTitle && (

{tileTitle}

)} {tileDescription && (

{tileDescription}

)} {/* CTA Button */} {buttonText && ctaStyle !== 'none' && (
{ctaStyle === 'arrow_link' ? ( {buttonText} → ) : ctaStyle === 'solid_button' ? ( {buttonText} ) : ( {buttonText} )}
)}
); return tile.buttonLink ? ( {cardContent} ) : (
{cardContent}
); })}
); }