"use client"; import { IconBookmark, IconCheck, IconPlayerPlay, IconPlus, IconX, } from "@tabler/icons-react"; import { AnimatePresence, motion } from "motion/react"; import { useEffect, useRef, useState } from "react"; const statuses = [ { value: "watchlist", label: "Watchlist", icon: IconBookmark, colorClass: "border-status-watchlist/30 bg-status-watchlist/10 text-status-watchlist hover:bg-status-watchlist/15", }, { value: "in_progress", label: "Watching", icon: IconPlayerPlay, colorClass: "border-status-watching/30 bg-status-watching/10 text-status-watching hover:bg-status-watching/15", }, { value: "completed", label: "Completed", icon: IconCheck, colorClass: "border-status-completed/30 bg-status-completed/10 text-status-completed hover:bg-status-completed/15", }, ] as const; interface StatusButtonProps { currentStatus: string | null; onChange: (status: string | null) => void; } export function StatusButton({ currentStatus, onChange }: StatusButtonProps) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { function handleClick(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener("mousedown", handleClick); return () => document.removeEventListener("mousedown", handleClick); }, []); const current = statuses.find((s) => s.value === currentStatus); const CurrentIcon = current?.icon ?? IconPlus; return (
{open && ( {statuses.map((s) => { const Icon = s.icon; return ( ); })} {currentStatus && ( <>
)} )}
); }