import { useState, useEffect, useRef } from "react"; import { cls } from "@/lib/utils"; import TextAnimation from "@/components/ui/TextAnimation"; import ImageOrVideo from "@/components/ui/ImageOrVideo"; import Transition from "@/components/ui/Transition"; import Button from "@/components/ui/Button"; type FeatureItem = { title: string; description: string; } & ({ imageSrc: string; videoSrc?: never } | { videoSrc: string; imageSrc?: never }); interface FeaturesTimelineCardsProps { tag: string; title: string; description: string; primaryButton?: { text: string; href: string }; secondaryButton?: { text: string; href: string }; items: FeatureItem[]; } const FeaturesTimelineCards = ({ tag, title, description, primaryButton, secondaryButton, items, }: FeaturesTimelineCardsProps) => { const [activeIndex, setActiveIndex] = useState(0); const [progress, setProgress] = useState(0); const intervalRef = useRef | null>(null); useEffect(() => { setProgress(0); if (intervalRef.current) clearInterval(intervalRef.current); intervalRef.current = setInterval(() => { setProgress((prev) => (prev >= 100 ? 0 : prev + 1)); }, 50); return () => { if (intervalRef.current) clearInterval(intervalRef.current); }; }, [activeIndex]); useEffect(() => { if (progress === 100) { setActiveIndex((i) => (i + 1) % items.length); } }, [progress, items.length]); const handleCardClick = (index: number) => { if (index !== activeIndex) setActiveIndex(index); }; return (
{tag} {(primaryButton || secondaryButton) && (
{primaryButton &&
)}
= 4 && "md:grid-cols-4" )}> {items.map((item, index) => (
handleCardClick(index)} className="flex flex-col justify-between gap-5 p-5 card rounded transition-opacity duration-300 opacity-50 data-[active=true]:opacity-100 cursor-pointer data-[active=true]:cursor-default hover:opacity-75 data-[active=true]:hover:opacity-100" >
{index + 1}

{item.title}

{item.description}

))}
); }; export default FeaturesTimelineCards;