'use client'; import { ChevronLeft, ChevronRight} from 'lucide-react'; import Image from 'next/image'; import { useEffect, useState } from 'react'; import { Button } from '@/shared/shadcn-ui/button'; import { Card, CardContent } from '@/shared/shadcn-ui/card'; import Link from 'next/link'; import { useLanguage } from '../language'; const promotions = [ { id: 1, title: 'Скидка 10% на премиум топливо', description: 'Получите скидку 10% на премиум топливо при заправке от 30 литров', image: '/placeholder.svg?height=200&width=400&text=Promotion 1', validUntil: '31.12.2023', }, { id: 2, title: 'Кофе в подарок', description: 'Получите бесплатный кофе при заправке от 20 литров', image: '/placeholder.svg?height=200&width=400&text=Promotion 2', validUntil: '15.11.2023', }, { id: 3, title: 'Двойные баллы по карте лояльности', description: 'Получайте в 2 раза больше баллов при заправке в выходные дни', image: '/placeholder.svg?height=200&width=400&text=Promotion 3', validUntil: '30.11.2023', }, { id: 4, title: 'Скидка на автомойку', description: 'Скидка 20% на автомойку при заправке от 40 литров', image: '/placeholder.svg?height=200&width=400&text=Promotion 4', validUntil: '31.12.2023', }, ]; export default function PromotionSlider() { const [currentIndex, setCurrentIndex] = useState(0); const [visibleItems, setVisibleItems] = useState(3); const { t } = useLanguage() useEffect(() => { const handleResize = () => { if (window.innerWidth < 640) { setVisibleItems(1); } else if (window.innerWidth < 1024) { setVisibleItems(2); } else { setVisibleItems(3); } }; handleResize(); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); const nextSlide = () => { setCurrentIndex((prevIndex) => prevIndex + visibleItems >= promotions.length ? 0 : prevIndex + 1, ); }; const prevSlide = () => { setCurrentIndex((prevIndex) => prevIndex === 0 ? Math.max(0, promotions.length - visibleItems) : prevIndex - 1, ); }; return (
{promotions.map((promo) => (
{promo.title}

{promo.title}

{promo.description}

Действует до: {promo.validUntil}
))}
); }