'use client'; import { useCallback, useEffect, useState, type ReactNode } from 'react'; import useEmblaCarousel from 'embla-carousel-react'; import Autoplay from 'embla-carousel-autoplay'; import { usePrefersReducedMotion } from '@/lib/motion'; // Thin Embla wrapper shared by the hero's pain-point rotator and the mobile // row of inflection points. Autoplay pauses on hover/focus/interaction, and // never runs at all for users who asked for less motion — it's still a fully // usable carousel (drag, dots, keyboard) with it off, just static. export function Carrusel({ slides, autoplayMs, className = '', slideClassName = '', ariaLabel, mostrarContador = false, }: { slides: ReactNode[]; autoplayMs?: number; className?: string; slideClassName?: string; ariaLabel: string; // "01 / 06" + flechas prev/next, en vez de puntos — el patrón de // en-ti.com ("desliza para explorar") para carruseles con más peso. mostrarContador?: boolean; }) { const reduced = usePrefersReducedMotion(); const plugins = autoplayMs && !reduced ? [Autoplay({ delay: autoplayMs, stopOnInteraction: false, stopOnMouseEnter: true })] : []; const [emblaRef, embla] = useEmblaCarousel({ loop: true }, plugins); const [selected, setSelected] = useState(0); useEffect(() => { if (!embla) return; const onSelect = () => setSelected(embla.selectedScrollSnap()); embla.on('select', onSelect); onSelect(); return () => { embla.off('select', onSelect); }; }, [embla]); const scrollTo = useCallback((i: number) => embla?.scrollTo(i), [embla]); const scrollPrev = useCallback(() => embla?.scrollPrev(), [embla]); const scrollNext = useCallback(() => embla?.scrollNext(), [embla]); return (
{slides.map((slide, i) => (
{slide}
))}
{slides.length > 1 && mostrarContador && (

{String(selected + 1).padStart(2, '0')} / {String(slides.length).padStart(2, '0')}

)} {slides.length > 1 && !mostrarContador && (
{slides.map((_, i) => (
)}
); }