"use client"; import { useEffect, useRef, useState } from "react"; import { Eye, EyeOff, Gem, Star, MinusCircle, ChevronDown, Tag } from "lucide-react"; import { cn } from "@/lib/utils"; type Action = "watched" | "unwatched" | "vip" | "favorite" | "unmark"; export function MarkAsMenu({ onAction, disabled, }: { onAction: (action: Action) => void; disabled?: boolean; }) { const [open, setOpen] = useState(false); const wrapRef = useRef(null); useEffect(() => { if (!open) return; const onDoc = (e: MouseEvent) => { if (!wrapRef.current?.contains(e.target as Node)) setOpen(false); }; document.addEventListener("mousedown", onDoc); return () => document.removeEventListener("mousedown", onDoc); }, [open]); useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") setOpen(false); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [open]); function pick(action: Action) { setOpen(false); onAction(action); } return (
{open && (
e.stopPropagation()} > pick("watched")} /> pick("unwatched")} />
pick("vip")} /> pick("favorite")} /> pick("unmark")} />
)}
); } function Row({ icon: Icon, label, onClick, colorClass, iconStyle, }: { icon: React.ComponentType<{ className?: string; style?: React.CSSProperties }>; label: string; onClick: () => void; colorClass?: string; iconStyle?: React.CSSProperties; }) { return ( ); }