import { useState } from 'react' import { Link } from '@tanstack/react-router' import { Button } from '@/ui/components/ui/button' import { Separator } from '@/ui/components/ui/separator' import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar' import { m } from '@/ui/paraglide/messages.js' import type { KanbanTaskAssetInfo } from '@shumai/dtos' import { AssetPickerDialog } from './asset-picker-dialog' import { Plus, X, Folder, File, Files } from 'lucide-react' import { cn } from '@/ui/lib/utils' interface TaskRelatedAssetsProps { teamId: string projectId?: string | null assets: KanbanTaskAssetInfo[] onAddAssets: (newAssets: KanbanTaskAssetInfo[]) => void onRemoveAsset: (assetId: string) => void disabled?: boolean /** Make each row a link to the asset in its project. Off by default so unsaved drafts are not discarded. */ linkable?: boolean } export function TaskRelatedAssets({ teamId, projectId, assets, onAddAssets, onRemoveAsset, disabled = false, linkable = false, }: TaskRelatedAssetsProps) { const [isPickerOpen, setIsPickerOpen] = useState(false) const handleConfirmPicker = (selectedAssets: KanbanTaskAssetInfo[]) => { // Filter out already linked assets const existingIds = new Set(assets.map((a) => a.id)) const toAdd = selectedAssets.filter((a) => !existingIds.has(a.id)) if (toAdd.length > 0) { onAddAssets(toAdd) } } return (
{/* Title + Plus Button */}
{m.related_assets()} {assets.length > 0 && ( ({assets.length}) )}
{!disabled && ( )}
{/* Assets List Rows */} {assets.length === 0 ? (

{m.no_related_assets()}

) : (
{assets.map((asset) => { const isFolder = asset.type === 'folder' const assetProjectId = asset.projectId || projectId const assetHref = linkable && assetProjectId ? `/projects/${assetProjectId}/${isFolder ? 'folders' : 'files'}/${asset.id}` : null const body = ( <> {/* Thumbnail / Icon */}
{asset.thumbnailUrl ? ( {asset.name} ) : isFolder ? ( ) : ( )}
{/* Name & Path */}

{asset.name}

{asset.path || '/'}

) return (
{/* Left: Thumbnail & Names (links to the asset when linkable) */} {assetHref ? ( {body} ) : (
{body}
)} {/* Right: Creator & Remove Button */}
{asset.creator && (
{asset.creator.name.slice(0, 1).toUpperCase()} {asset.creator.name}
)} {!disabled && ( )}
) })}
)} {/* Asset Picker Dialog */} {isPickerOpen && ( a.id)} isOpen={isPickerOpen} onClose={() => setIsPickerOpen(false)} onConfirm={handleConfirmPicker} /> )}
) }