import Image from 'next/image' import { ArrowRight, CakeSlice, CheckCircle, Heart, Leaf, Sparkles, type LucideIcon } from 'lucide-react' import Link from '../LocalizedLink' import type { CustomBlockComponentProps } from '../../config/customRegistry' import { resolveLocalized } from '../../lib/localization' type LocalizedValue = string | Record type MosaicImage = { imageUrl: string alt?: LocalizedValue } type FeatureItem = { icon?: string title: LocalizedValue subtitle?: LocalizedValue } type ResolvedImage = { imageUrl: string alt: string } type ResolvedFeature = { icon: string title: string subtitle: string } const iconMap: Record = { leaf: Leaf, cake: CakeSlice, fresh: CakeSlice, heart: Heart, care: Heart, sparkles: Sparkles, premium: Sparkles, check: CheckCircle, } const defaultImages: MosaicImage[] = [ { imageUrl: '', alt: 'Dessert preparation' }, { imageUrl: '', alt: 'Fresh bakery' }, { imageUrl: '', alt: 'Our team' }, ] const defaultFeatures: FeatureItem[] = [ { icon: 'leaf', title: 'Quality ingredients' }, { icon: 'cake', title: 'Fresh daily' }, { icon: 'heart', title: 'Made with care' }, ] function readString(value: unknown, fallback: string) { return typeof value === 'string' && value.trim() ? value : fallback } function readLocalized(value: unknown, lang: string, fallback: string) { const text = resolveLocalized(value as LocalizedValue | null | undefined, lang) return text.trim() ? text : fallback } function readImages(value: unknown, lang: string): ResolvedImage[] { const sourceImages = Array.isArray(value) ? value : defaultImages return sourceImages.reduce((acc, item, index) => { if (!item || typeof item !== 'object' || Array.isArray(item)) return acc const record = item as Record const imageUrl = readString(record.imageUrl, '') const alt = readLocalized(record.alt, lang, `Story image ${index + 1}`) acc.push({ imageUrl, alt }) return acc }, []).slice(0, 3) } function readFeatures(value: unknown, lang: string): ResolvedFeature[] { const sourceFeatures = Array.isArray(value) ? value : defaultFeatures return sourceFeatures.reduce((acc, item) => { if (!item || typeof item !== 'object' || Array.isArray(item)) return acc const record = item as Record const title = readLocalized(record.title, lang, '') if (!title) return acc acc.push({ icon: readString(record.icon, 'check'), title, subtitle: readLocalized(record.subtitle, lang, ''), }) return acc }, []).slice(0, 4) } function StoryImage({ image, index }: { image: ResolvedImage, index: number }) { const className = index === 0 ? 'lg:col-span-3 lg:aspect-[4/3]' : 'lg:col-span-2 lg:aspect-[4/3]' return (
{image.imageUrl ? ( {image.alt} ) : (
{image.alt}
)}
) } export default function StoryFeatureMosaic({ props, lang }: CustomBlockComponentProps) { const title = readLocalized(props?.title, lang, 'Our Story') const subtitle = readLocalized(props?.subtitle, lang, 'From craft to happiness in every bite') const description = readLocalized(props?.description, lang, '') const buttonText = readLocalized(props?.buttonText, lang, '') const buttonHref = readString(props?.buttonHref, '') const images = readImages(props?.images, lang) const features = readFeatures(props?.features, lang) return (
{subtitle && (

{subtitle}

)}

{title}

{description && (

{description}

)} {buttonText && buttonHref && ( {buttonText} )}
{images.map((image, index) => ( ))}
{features.map((feature, index) => { const Icon = iconMap[feature.icon] ?? CheckCircle return (

{feature.title}

{feature.subtitle && (

{feature.subtitle}

)}
) })}
) }