import { Children } from "react"; import type { ReactNode } from "react"; import { Link } from "react-router"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Skeleton } from "@/components/ui/skeleton"; import { useCarouselEmbla } from "@/hooks/useCarouselEmbla"; interface MediaCarouselProps { title: string; titleHref?: string; loading?: boolean; children: ReactNode; skeletonCount?: number; skeletonAspect?: string; onViewAll?: () => void; /** Optional actions rendered next to the title (e.g. pin button) */ headerActions?: ReactNode; } export default function MediaCarousel({ title, titleHref, loading = false, children, skeletonCount = 7, skeletonAspect = "aspect-[2/3]", onViewAll, headerActions, }: MediaCarouselProps) { const { emblaRef, canScrollPrev, canScrollNext, scrollPrev, scrollNext } = useCarouselEmbla(); const slideChildren = loading ? Array.from({ length: skeletonCount }).map((_, i) => (
)) : Children.toArray(children); return (
{titleHref ? (

{title} View

) : (

{title}

)} {headerActions}
{onViewAll && ( )}
{/* Left edge gradient */} {canScrollPrev && (
)} {/* Left arrow */} {canScrollPrev && ( )}
{ if (e.key === "ArrowLeft") { scrollPrev(); } else if (e.key === "ArrowRight") { scrollNext(); } }} >
    {slideChildren.map((child, index) => (
  • {child}
  • ))}
{/* Right arrow */} {canScrollNext && ( )}
); }