import React, { type RefObject } from 'react' import { Plus, X, RefreshCw, ChevronLeft, ChevronRight, Layers, GitMerge, FolderPlus, Folder, Trash2, FolderOpen, } from 'lucide-react' import type { Asset } from '../../types/project-model' import { COLOR_LABELS } from './video-editor-utils' import { equalAssetBins, selectAssetBins, selectAssets, selectRegenerationState } from './editor-selectors' import { useEditorActions, useEditorStore } from './editor-store' export interface AssetContextMenuProps { asset: Asset targetIds: string[] assetContextMenu: { assetId: string; x: number; y: number } assetContextMenuRef: RefObject addClipToTimeline: (asset: Asset, trackIndex?: number, startTime?: number) => void handleRegenerate: (assetId: string) => void handleCancelRegeneration: () => void canCancelInFlight: boolean setTakesViewAssetId: (assetId: string | null) => void setSelectedAssetIds: React.Dispatch>> setAssetContextMenu: React.Dispatch> createAssetFromTake: (asset: Asset, take: NonNullable[number]) => Asset openCreateBinEditor: (assetIds: string[]) => void } export function AssetContextMenu({ asset, targetIds, assetContextMenu, assetContextMenuRef, addClipToTimeline, handleRegenerate, handleCancelRegeneration, canCancelInFlight, setTakesViewAssetId, setSelectedAssetIds, setAssetContextMenu, createAssetFromTake, openCreateBinEditor, }: AssetContextMenuProps) { const actions = useEditorActions() const assets = useEditorStore(selectAssets) const bins = useEditorStore(selectAssetBins, equalAssetBins) const regenerationState = useEditorStore(selectRegenerationState) const isRegenerating = regenerationState.regeneratingAssetId !== null || regenerationState.regeneratingClipId !== null const regeneratingAssetId = regenerationState.regeneratingAssetId const isMulti = targetIds.length > 1 const closeMenu = () => setAssetContextMenu(null) const clearSelection = () => setSelectedAssetIds(new Set()) const setActiveTake = (assetId: string, takeIndex: number) => { actions.setAssetActiveTake(assetId, takeIndex) } const setColor = (colorLabel?: string) => { for (const id of targetIds) { actions.setAssetColorLabel(id, colorLabel) } closeMenu() } const moveToBin = (binId?: string) => { actions.assignAssetsToBin(targetIds, binId) clearSelection() closeMenu() } const deleteTargetAssets = () => { actions.deleteAssets(targetIds) clearSelection() closeMenu() } return (
e.stopPropagation()} > {isMulti && (
{targetIds.length} assets selected
)} {!isMulti && ( )} {!isMulti && asset.path && ( )} {!isMulti && asset.generationParams && ( <> {isRegenerating && regeneratingAssetId === asset.id && canCancelInFlight ? ( ) : ( )} )} {!isMulti && asset.takes && asset.takes.length > 1 && ( <>
Take: {(asset.activeTakeIndex ?? 0) + 1}/{asset.takes.length}
)}
Label
{COLOR_LABELS.map(cl => (
Move to Bin
{bins.map(bin => ( ))} {isMulti && ( <>
)}
) }