'use client'; import { useState } from 'react'; interface ImageCarouselProps { images: string[]; /** Per-image alt text, parallel to `images`. Falls back to empty when absent. */ alts?: string[]; } /** * Resolve the alt text for the image at `index`. Returns the author-supplied * description when present, otherwise an empty string so screen readers treat * the image as decorative rather than announcing a meaningless filename. */ function altFor(alts: string[] | undefined, index: number): string { return alts?.[index]?.trim() || ''; } export default function ImageCarousel({ images, alts }: ImageCarouselProps) { const [current, setCurrent] = useState(0); if (!images || images.length === 0) return null; if (images.length === 1) { return {altFor(alts,; } const next = () => setCurrent((i) => (i + 1) % images.length); const prev = () => setCurrent((i) => (i - 1 + images.length) % images.length); return (
{altFor(alts, {current > 0 && ( )} {current < images.length - 1 && ( )}
{images.map((_, i) => (
))}
); }