import { useState } from 'react' import { Link, useLocation } from 'react-router' import { twMerge } from 'tailwind-merge' import { CarouselNextIcon } from '~/components/icons/carousel-next' import { CarouselPreviousIcon } from '~/components/icons/carousel-previous' import { useNewsContext } from '~/contexts/news' import type { TNews } from '~/types/news' import { Button } from './button' export const Carousel = (properties: TNews) => { const { setIsSuccessOpen } = useNewsContext() const [currentIndex, setCurrentIndex] = useState(0) const { pathname } = useLocation() const hasCategory = pathname.includes('/category/') const { title, description, items, type } = properties const itemsPerPage = type === 'hero' ? 1 : 3 const totalPages = Math.ceil(items.length / itemsPerPage) const nextSlide = () => { setCurrentIndex((previousIndex) => (previousIndex + 1) % totalPages) } const previousSlide = () => { setCurrentIndex( (previousIndex) => (previousIndex - 1 + totalPages) % totalPages, ) } return (
{description}
{content}