import { useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; interface WaypointContextMenuProps { position: { x: number; y: number }; isFirst: boolean; isLast: boolean; isOvernight: boolean; onDelete: () => void; onToggleOvernight: () => void; onClose: () => void; } export function WaypointContextMenu({ position, isFirst, isLast, isOvernight, onDelete, onToggleOvernight, onClose, }: WaypointContextMenuProps) { const { t } = useTranslation("planner"); const ref = useRef(null); useEffect(() => { const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) onClose(); }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, [onClose]); const canToggleOvernight = !isFirst && !isLast; return (
{canToggleOvernight && ( )}
); }