"use client"; import React, { useEffect, useState, } from "react"; import { IconArrowNarrowLeft, IconArrowNarrowRight, IconChevronRight, } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; import { Link } from "react-router-dom"; import { motion } from "motion/react"; interface CarouselProps { items: JSX.Element[]; initialScroll?: number; } type Card = { src: string; title: string; category: string; description: string; link: string; bg: any; }; export const Carousel = ({ items, initialScroll = 0 }: CarouselProps) => { const carouselRef = React.useRef(null); const [canScrollLeft, setCanScrollLeft] = React.useState(false); const [canScrollRight, setCanScrollRight] = React.useState(true); useEffect(() => { if (carouselRef.current) { carouselRef.current.scrollLeft = initialScroll; checkScrollability(); } }, [initialScroll]); const checkScrollability = () => { if (carouselRef.current) { const { scrollLeft, scrollWidth, clientWidth } = carouselRef.current; setCanScrollLeft(scrollLeft > 0); setCanScrollRight(scrollLeft < scrollWidth - clientWidth); } }; const scrollLeft = () => { if (carouselRef.current) { carouselRef.current.scrollBy({ left: -300, behavior: "smooth" }); } }; const scrollRight = () => { if (carouselRef.current) { carouselRef.current.scrollBy({ left: 300, behavior: "smooth" }); } }; const isMobile = () => { return window && window.innerWidth < 768; }; return (
{items.map((item, index) => ( {item} ))}
); }; export const Card = ({ card, layout = false, }: { card: Card; layout?: boolean; }) => { return (
{card.category} {card.title}
{card.description}
); }; export const BlurImage = ({ src, className, width, height, alt, ...rest }: React.ImgHTMLAttributes) => { const [isLoading, setLoading] = useState(true); return ( setLoading(false)} src={src as string} width={width} height={height} loading="lazy" decoding="async" alt={alt ? alt : "Background of a beautiful view"} {...rest} /> ); };