'use client' import React, { useState, useRef, useEffect } from 'react' import type { FDServiceChooserBlock as Props } from '@/payload-types' import { fdCardRadius as cardRadius, fdContainer} from '@/utilities/fdTheme' export const FDServiceChooserBlockComponent: React.FC = ({ heading, description, categories = [], sectionBackground = 'gray', anchorId, }) => { const [activeIndex, setActiveIndex] = useState(0) const [animating, setAnimating] = useState(false) const [prefersReducedMotion, setPrefersReducedMotion] = useState(false) const prevIndex = useRef(0) /* Priority #8: Detect prefers-reduced-motion */ useEffect(() => { const mql = window.matchMedia('(prefers-reduced-motion: reduce)') setPrefersReducedMotion(mql.matches) const handler = (e: MediaQueryListEvent) => setPrefersReducedMotion(e.matches) mql.addEventListener('change', handler) return () => mql.removeEventListener('change', handler) }, []) const isDark = sectionBackground === 'navy' const bgClass = isDark ? 'bg-fd-navy' : sectionBackground === 'gray' ? 'bg-fd-surface-alt dark:bg-fd-navy' : 'bg-white dark:bg-fd-navy' const titleClass = isDark ? 'text-fd-yellow' : 'text-fd-navy dark:text-fd-yellow' const bodyClass = isDark ? 'text-white' : 'text-fd-navy dark:text-white' const cardBg = isDark ? 'bg-white/10 border-[5px] border-white/10' : 'bg-white border-[5px] border-gray-200 dark:bg-white/10 dark:border-white/10' const handleTabChange = (i: number) => { if (i === activeIndex) return if (prefersReducedMotion) { /* Instant switch — no animation */ setActiveIndex(i) return } setAnimating(true) prevIndex.current = activeIndex setTimeout(() => { setActiveIndex(i) setAnimating(false) }, 200) } const activeCategory = (categories ?? [])[activeIndex] return (
{heading && (

{heading}

)} {description && (

{description}

)}
{(categories ?? []).map((cat, i) => ( ))}
{activeCategory?.intro && (

{activeCategory.intro}

)}
{activeCategory?.services?.map((service, i) => (

{service.title}

{service.description && (

{service.description}

)} {service.ctaText && ( )}
))}
) }