import type { AssetInfo } from '@shumai/dtos' import { m } from '@/ui/paraglide/messages.js' import { ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuItem, ContextMenuSeparator, ContextMenuPortal, } from '@/ui/components/ui/context-menu' import { DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuItem, DropdownMenuSeparator, } from '@/ui/components/ui/dropdown-menu' import { Copy, Image as ImageIcon, FileText, Link, Download, Hash, Code, Table, HardDrive, } from 'lucide-react' import { type CopyKind, type CopyOptionsContext, getCopyOptions } from './copy-options' interface CopyMenuProps { items: AssetInfo[] context: CopyOptionsContext onCopy: (kind: CopyKind, items: AssetInfo[]) => void } function renderCopyIcon(kind: CopyKind) { switch (kind) { case 'image': return case 'name': return case 'link': return case 'download-link': return case 'id': return case 'markdown': return case 'tsv': return case 'storage-path': return } } function renderCopyLabel(kind: CopyKind) { switch (kind) { case 'image': return m.copy_image() case 'name': return m.copy_name() case 'link': return m.copy_app_link() case 'download-link': return m.copy_download_link() case 'id': return m.copy_id() case 'markdown': return m.copy_markdown_link() case 'tsv': return m.copy_as_table() case 'storage-path': return m.copy_storage_path() } } export function CopyContextMenuSub({ items, context, onCopy }: CopyMenuProps) { const options = getCopyOptions(items, context) if (options.length === 0) return null const imageOpt = options.find((o) => o.kind === 'image') const coreOpts = options.filter((o) => ['name', 'link', 'download-link', 'id'].includes(o.kind)) const docOpts = options.filter((o) => ['markdown', 'tsv'].includes(o.kind)) const storageOpt = options.find((o) => o.kind === 'storage-path') return ( {m.copy()} {imageOpt && ( <> onCopy('image', items)}> {renderCopyIcon('image')} {renderCopyLabel('image')} )} {coreOpts.map((opt) => ( onCopy(opt.kind, items)} > {renderCopyIcon(opt.kind)} {renderCopyLabel(opt.kind)} ))} {docOpts.length > 0 && ( <> {docOpts.map((opt) => ( onCopy(opt.kind, items)} > {renderCopyIcon(opt.kind)} {renderCopyLabel(opt.kind)} ))} )} {storageOpt && ( <> onCopy('storage-path', items)} > {renderCopyIcon('storage-path')} {renderCopyLabel('storage-path')} )} ) } export function CopyDropdownMenuSub({ items, context, onCopy }: CopyMenuProps) { const options = getCopyOptions(items, context) if (options.length === 0) return null const imageOpt = options.find((o) => o.kind === 'image') const coreOpts = options.filter((o) => ['name', 'link', 'download-link', 'id'].includes(o.kind)) const docOpts = options.filter((o) => ['markdown', 'tsv'].includes(o.kind)) const storageOpt = options.find((o) => o.kind === 'storage-path') return ( {m.copy()} {imageOpt && ( <> { e.stopPropagation() onCopy('image', items) }} > {renderCopyIcon('image')} {renderCopyLabel('image')} )} {coreOpts.map((opt) => ( { e.stopPropagation() onCopy(opt.kind, items) }} > {renderCopyIcon(opt.kind)} {renderCopyLabel(opt.kind)} ))} {docOpts.length > 0 && ( <> {docOpts.map((opt) => ( { e.stopPropagation() onCopy(opt.kind, items) }} > {renderCopyIcon(opt.kind)} {renderCopyLabel(opt.kind)} ))} )} {storageOpt && ( <> { e.stopPropagation() onCopy('storage-path', items) }} > {renderCopyIcon('storage-path')} {renderCopyLabel('storage-path')} )} ) }