"use client" import { cn } from "@/lib/utils" import { motion } from "framer-motion" import { ArrowLeft, ArrowRight } from "lucide-react" import Image from "next/image" import { useEffect, useRef, useState } from "react" interface CaseStudy { id: string title: string description: string image: string } interface CaseStudiesCarouselProps { title: string description: string caseStudies: CaseStudy[] } export default function CaseStudiesCarousel({ title = "Case Studies", description = "Discover how leading companies and developers are leveraging modern web technologies to build exceptional digital experiences. These case studies showcase real-world applications and success stories.", caseStudies = [ { id: "shadcn", title: "shadcn/ui: Building a Modern Component Library", description: "Explore how shadcn/ui revolutionized React component development", image: "/blocks/case-studies-1/image-1.jpg", }, { id: "tailwind", title: "Tailwind CSS: The Utility-First Revolution", description: "Discover how Tailwind CSS transformed the way developers style applications", image: "/blocks/case-studies-1/image-2.jpg", }, { id: "astro", title: "Astro: The All-in-One Web Framework", description: "Learn how Astro's innovative 'Islands Architecture' and zero-JS approach", image: "/blocks/case-studies-1/image-3.jpg", }, { id: "react", title: "React: Pioneering Component-Based UI", description: "See how React continues to shape modern web development with its component model", image: "/blocks/case-studies-1/image-4.jpg", }, { id: "nextjs", title: "Next.js: The React Framework", description: "Explore how Next.js has become the go-to framework for React applications", image: "/blocks/case-studies-1/image-5.jpg", }, ], }: CaseStudiesCarouselProps) { const carouselRef = useRef(null) const [activeIndex, setActiveIndex] = useState(0) const [canScrollLeft, setCanScrollLeft] = useState(false) const [canScrollRight, setCanScrollRight] = useState(true) const checkScrollAbility = () => { if (carouselRef.current) { const { scrollLeft, scrollWidth, clientWidth } = carouselRef.current setCanScrollLeft(scrollLeft > 0) setCanScrollRight(scrollLeft < scrollWidth - clientWidth - 10) } } useEffect(() => { checkScrollAbility() window.addEventListener("resize", checkScrollAbility) return () => window.removeEventListener("resize", checkScrollAbility) }, []) const scroll = (direction: "left" | "right") => { if (carouselRef.current) { const cardWidth = carouselRef.current.querySelector("div[data-card]")?.clientWidth || 300 const scrollAmount = direction === "left" ? -cardWidth : cardWidth carouselRef.current.scrollBy({ left: scrollAmount, behavior: "smooth", }) if (direction === "left" && activeIndex > 0) { setActiveIndex(activeIndex - 1) } else if ( direction === "right" && activeIndex < caseStudies.length - 1 ) { setActiveIndex(activeIndex + 1) } } } const scrollToIndex = (index: number) => { if (carouselRef.current) { const cards = carouselRef.current.querySelectorAll("div[data-card]") if (cards[index]) { cards[index].scrollIntoView({ behavior: "smooth", block: "nearest", inline: "start", }) setActiveIndex(index) } } } return (

{title}

{description}

{ checkScrollAbility() if (carouselRef.current) { const scrollLeft = carouselRef.current.scrollLeft const cardWidth = carouselRef.current.querySelector("div[data-card]") ?.clientWidth || 300 const newIndex = Math.round(scrollLeft / cardWidth) if ( newIndex !== activeIndex && newIndex >= 0 && newIndex < caseStudies.length ) { setActiveIndex(newIndex) } } }} > {caseStudies.map((study, index) => (
{study.title}

{study.title}

{study.description}

))}
{caseStudies.map((_, index) => (
) }