import { client } from '@/ui/api/client' import { Badge } from '@/ui/components/ui/badge' import { Button } from '@/ui/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from '@/ui/components/ui/dropdown-menu' import { cn } from '@/ui/lib/utils' import { m } from '@/ui/paraglide/messages.js' import { ChevronDown, ChevronLeft, ChevronRight, Download, MoreVertical, Pencil, SquareKanban, Trash2, } from 'lucide-react' import React from 'react' export interface MobileFileHeaderProps { fileName: string folderName?: string version?: number versions?: Array<{ id: string version: number name?: string | null }> activeFileId: string isPublic?: boolean shareId?: string allowDownload?: boolean downloadInfo?: { originalKey?: string videoTranscodes?: Array<{ key: string width: number height: number }> } canEdit?: boolean onBack: () => void onPrevFile?: () => void onNextFile?: () => void hasPrevFile?: boolean hasNextFile?: boolean onSelectVersion?: (versionId: string) => void onRename?: () => void onDelete?: () => void onLinkedTasks?: () => void linkedTaskCount?: number } export function MobileFileHeader({ fileName, folderName, version, versions, activeFileId, isPublic = false, shareId, allowDownload = true, downloadInfo, canEdit = false, onBack, onPrevFile, onNextFile, hasPrevFile = false, hasNextFile = false, onSelectVersion, onRename, onDelete, onLinkedTasks, linkedTaskCount = 0, }: MobileFileHeaderProps) { const handleDownload = async (key: string) => { try { const res = isPublic && shareId ? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({ param: { shareId, fileId: activeFileId }, json: { key }, }) : await client.api.files['download-url'].$post({ json: { key, assetId: activeFileId }, }) if (!res.ok) return const { url } = await res.json() const link = document.createElement('a') link.href = url link.download = '' document.body.appendChild(link) link.click() document.body.removeChild(link) } catch { // silently fail } } const hasVideoTranscodes = (downloadInfo?.videoTranscodes?.length ?? 0) > 0 return (
{/* Left: Back Button */}
{/* Center: Folder / File Title & Prev / Next Arrows */}
{folderName && ( <> {folderName} / )} {versions && versions.length > 1 ? ( {m.switch_version()} {versions.map((v) => ( onSelectVersion?.(v.id)} className={cn( 'flex items-center justify-between text-xs cursor-pointer', v.id === activeFileId ? 'bg-accent font-semibold text-accent-foreground' : '', )} > v{v.version} {v.name || fileName} ))} ) : (
{fileName} {version !== undefined && ( v{version} )}
)}
{/* Prev / Next file navigation buttons */} {(hasPrevFile || hasNextFile) && (
)}
{/* Right: Three-Dot Menu */}
{/* Download */} {allowDownload && (hasVideoTranscodes ? ( {m.download()} {m.download()} {downloadInfo?.videoTranscodes?.map((t) => { const longSide = Math.max(t.width, t.height) let resolution = `${t.height}p` if (longSide >= 3840) resolution = '2160p' else if (longSide >= 1920) resolution = '1080p' else if (longSide >= 1280) resolution = '720p' else if (longSide >= 960) resolution = '540p' else if (longSide >= 640) resolution = '360p' else if (longSide >= 320) resolution = '180p' return ( handleDownload(t.key)} className="flex items-center justify-between text-xs cursor-pointer" > {resolution} MP4 ) })} {downloadInfo?.originalKey && ( <> handleDownload(downloadInfo.originalKey!)} className="flex items-center justify-between text-xs cursor-pointer" > {m.original?.() || 'Original'} {fileName.split('.').pop()?.toUpperCase() || 'RAW'} )} ) : ( downloadInfo?.originalKey && handleDownload(downloadInfo.originalKey) } disabled={!downloadInfo?.originalKey} className="flex items-center gap-2 text-xs cursor-pointer" > {m.download()} ))} {/* Switch Version (if multi-version) */} {versions && versions.length > 1 && onSelectVersion && ( {m.switch_version?.() || 'Switch version'} {m.switch_version?.() || 'Switch version'} {versions.map((v) => ( onSelectVersion(v.id)} className={cn( 'flex items-center justify-between text-xs cursor-pointer', v.id === activeFileId ? 'bg-accent font-semibold text-accent-foreground' : '', )} > v{v.version} {v.name || fileName} ))} )} {/* Linked Tasks */} {onLinkedTasks && ( {m.linked_tasks?.() || 'Linked Tasks'} {linkedTaskCount > 0 && ( {linkedTaskCount} )} )} {/* Rename */} {canEdit && onRename && ( {m.rename()} )} {/* Delete */} {canEdit && onDelete && ( <> {m.delete()} )}
) }