// components/ThreeDCarousel.tsx "use client"; import React, { useRef, useEffect, useState, TouchEvent, } from "react"; import { ChevronLeft, ChevronRight, ArrowRight } from "lucide-react"; import { Card, CardContent } from "@/app/component2/ui/card"; import { useIsMobile } from "../hooks/use-mobile"; import Link from "next/link"; export interface ThreeDCarouselItem { id: number; title: string; brand: string; description: string; tags: string[]; imageUrl: string; link: string; } interface ThreeDCarouselProps { items: ThreeDCarouselItem[]; autoRotate?: boolean; rotateInterval?: number; cardHeight?: number; title?: string; subtitle?: string; tagline?: string; isMobileSwipe?: boolean; } const ThreeDCarousel = ({ items, autoRotate = true, rotateInterval = 4000, cardHeight = 500, title = "From Textile to Intelligence", subtitle = "Customer Cases", tagline = "Explore how our textile sensor technology is revolutionizing multiple industries with intelligent fabric solutions tailored to specific needs.", isMobileSwipe = true, }: ThreeDCarouselProps) => { const [active, setActive] = useState(0); const carouselRef = useRef(null); const [isInView, setIsInView] = useState(false); const [isHovering, setIsHovering] = useState(false); const [touchStart, setTouchStart] = useState(null); const [touchEnd, setTouchEnd] = useState(null); const isMobile = useIsMobile(); const minSwipeDistance = 50; useEffect(() => { if (autoRotate && isInView && !isHovering) { const interval = setInterval(() => { setActive((prev) => (prev + 1) % items.length); }, rotateInterval); return () => clearInterval(interval); } }, [isInView, isHovering, autoRotate, rotateInterval, items.length]); useEffect(() => { const observer = new IntersectionObserver( ([entry]) => setIsInView(entry.isIntersecting), { threshold: 0.2 } ); return () => observer.disconnect(); }, []); const onTouchStart = (e: TouchEvent) => { setTouchStart(e.targetTouches[0].clientX); setTouchEnd(null); }; const onTouchMove = (e: TouchEvent) => { setTouchEnd(e.targetTouches[0].clientX); }; const onTouchEnd = () => { if (!touchStart || !touchEnd) return; const distance = touchStart - touchEnd; if (distance > minSwipeDistance) { setActive((prev) => (prev + 1) % items.length); } else if (distance < -minSwipeDistance) { setActive((prev) => (prev - 1 + items.length) % items.length); } }; const getCardAnimationClass = (index: number) => { if (index === active) return "scale-100 opacity-100 z-20"; if (index === (active + 1) % items.length) return "translate-x-[40%] scale-95 opacity-60 z-10"; if (index === (active - 1 + items.length) % items.length) return "translate-x-[-40%] scale-95 opacity-60 z-10"; return "scale-90 opacity-0"; }; return (
setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} onTouchStart={onTouchStart} onTouchMove={onTouchMove} onTouchEnd={onTouchEnd} ref={carouselRef} >
{items.map((item, index) => (

{item.brand.toUpperCase()}

{item.title}

{item.title}

{item.brand}

{item.description}

))}
{!isMobile && ( <> )}
{items.map((_, idx) => (
); }; export default ThreeDCarousel;