'use client'; import React, { useEffect, useRef, useState } from 'react'; import Image from 'next/image'; const cardData = [ { imgSrc: '/gems-world-card.webp', title: 'Detail 1', points: ['Cashback up to 5%', 'No Annual Fee', 'Airport Lounge Access'], id: 1, }, { imgSrc: '/du-titanium-credit-card-2.webp', title: 'Detail 2', points: ['Earn Reward Points', 'Fuel Discounts', 'Dining Offers'], id: 2, }, { imgSrc: '/fab-cashback-credit-card.webp', title: 'Detail 3', points: ['1% Cashback on All Purchases', 'Low Interest Rate', 'Free Movie Tickets'], id: 3, }, { imgSrc: '/fab-low-rate-credit-card.webp', title: 'Detail 4', points: ['0% Balance Transfer', 'No Foreign Transaction Fee', 'Bonus Points on Signup'], id: 4, }, { imgSrc: '/du-titanium-credit-card-2.webp', title: 'Detail 5', points: ['Exclusive Travel Benefits', 'Hotel Discounts', 'Priority Customer Support'], id: 5, }, { imgSrc: '/fab-cashback-credit-card.webp', title: 'Detail 3', points: ['1% Cashback on All Purchases', 'Low Interest Rate', 'Free Movie Tickets'], id: 6, }, { imgSrc: '/fab-low-rate-credit-card.webp', title: 'Detail 4', points: ['0% Balance Transfer', 'No Foreign Transaction Fee', 'Bonus Points on Signup'], id: 7, }, { imgSrc: '/du-titanium-credit-card-2.webp', title: 'Detail 5', points: ['Exclusive Travel Benefits', 'Hotel Discounts', 'Priority Customer Support'], id: 8, }, { imgSrc: '/gems-world-card.webp', title: 'Detail 1', points: ['Cashback up to 5%', 'No Annual Fee', 'Airport Lounge Access'], id: 9, }, { imgSrc: '/du-titanium-credit-card-2.webp', title: 'Detail 2', points: ['Earn Reward Points', 'Fuel Discounts', 'Dining Offers'], id: 10, }, ]; const CardOfferFirst: React.FC = () => { const carouselRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); const [cardsPerSlide, setCardsPerSlide] = useState(5); // Default for desktop // Function to determine number of cards per slide const updateCardsPerSlide = () => { if (window.innerWidth <= 640) { setCardsPerSlide(1); // Mobile - 1 card } else if (window.innerWidth <= 1024) { setCardsPerSlide(1); // Tablet - 1 card } else { setCardsPerSlide(5); // Desktop - 5 cards } }; useEffect(() => { updateCardsPerSlide(); // Set on load window.addEventListener('resize', updateCardsPerSlide); return () => window.removeEventListener('resize', updateCardsPerSlide); }, []); const totalSlides = Math.ceil(cardData.length / cardsPerSlide); // Auto-scroll logic (moves forward, loops back) useEffect(() => { const interval = setInterval(() => { setActiveIndex((prev) => (prev + 1) % totalSlides); }, 10000); // 10 seconds delay before moving return () => clearInterval(interval); }, [totalSlides]); // Scroll effect useEffect(() => { if (carouselRef.current) { carouselRef.current.scrollTo({ left: activeIndex * carouselRef.current.clientWidth, behavior: 'smooth', }); } }, [activeIndex]); return (

Best Cash Back Card

{/* ✅ Carousel Wrapper */}
{cardData.map((card, index) => (
{/* ✅ Image */} {/* {card.title} */} {card.title} {/* ✅ Title */}
{card.title}
{/* ✅ Bulleted List */}
    {card.points.map((point, i) => (
  • {point}
  • ))}
{/* ✅ Buttons */}
Know More Apply Now
))}
{/* ✅ Dots Navigation */}
{Array.from({ length: totalSlides }).map((_, i) => ( ))}
); }; export default CardOfferFirst;