import { memo } from "react"; import { createPortal } from "react-dom"; import type { TimelineElement } from "../store/playerStore"; import { canSplitElement } from "../../utils/timelineElementSplit"; import { useContextMenuDismiss } from "../../hooks/useContextMenuDismiss"; interface ClipContextMenuProps { x: number; y: number; element: TimelineElement; currentTime: number; onClose: () => void; onSplit: (element: TimelineElement, splitTime: number) => void; onDelete: (element: TimelineElement) => void; } export const ClipContextMenu = memo(function ClipContextMenu({ x, y, element, currentTime, onClose, onSplit, onDelete, }: ClipContextMenuProps) { const menuRef = useContextMenuDismiss(onClose); const menuWidth = 200; const menuHeight = 80; const overflowY = y + menuHeight - window.innerHeight; const adjustedX = x + menuWidth > window.innerWidth ? x - menuWidth : x; const adjustedY = overflowY > 0 ? y - overflowY - 8 : y; const isSplittable = canSplitElement(element) && ["video", "audio", "img"].includes(element.tag); const canSplit = isSplittable && currentTime > element.start && currentTime < element.start + element.duration; const splitLabel = !isSplittable ? null : canSplit ? `Split at ${currentTime.toFixed(2)}s` : "Split (move playhead inside clip)"; return createPortal(
{splitLabel && ( <>
)}
, document.body, ); });