"use client"; import React, { useRef, useState, useEffect } from "react"; import { Card, CardAction, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { ChevronLeft, ChevronRight } from "lucide-react"; export type VideoItem = { id: string | number; title: string; duration: string; // formatted like "4:12" thumbnailUrl: string; }; type Props = { categoryTitle: string; videos: VideoItem[]; visibleCount?: number; // defaults to 4 }; export default function VideoCarousel({ categoryTitle, videos, visibleCount = 4, }: Props) { const scrollerRef = useRef(null); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(false); useEffect(() => { const el = scrollerRef.current; if (!el) return; const update = () => { setCanScrollLeft(el.scrollLeft > 0); setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1); }; update(); el.addEventListener("scroll", update, { passive: true }); window.addEventListener("resize", update); return () => { el.removeEventListener("scroll", update); window.removeEventListener("resize", update); }; }, [videos]); const scrollByPage = (direction: "left" | "right") => { const el = scrollerRef.current; if (!el) return; const amount = el.clientWidth; // scroll by visible area so next "page" shows el.scrollBy({ left: direction === "left" ? -amount : amount, behavior: "smooth" }); }; // keyboard navigation useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.key === "ArrowLeft") scrollByPage("left"); if (e.key === "ArrowRight") scrollByPage("right"); }; window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (

{categoryTitle}

{videos.map((v) => (
{v.title} {v.duration}
{v.title} {/* placeholder for action, e.g., menu or save */}
{v.duration}
))}
{/* small gradients on the sides to indicate scrollability */}
); } /* Usage example: import VideoCarousel, { VideoItem } from "./VideoCarousel"; const videos: VideoItem[] = [ { id: 1, title: "Fluffy cat plays with yarn", duration: "3:45", thumbnailUrl: "/thumb1.jpg" }, { id: 2, title: "Cat napping compilation", duration: "2:12", thumbnailUrl: "/thumb2.jpg" }, // ...more ]; Notes: - This file assumes shadcn/ui components exist at the given paths. Replace imports if your project structure differs. - Card widths are responsive: they use a percent width with a min-width to keep thumbnails readable on small screens. - The scroller uses native smooth scrolling so it works well on touch devices and with keyboards. */