import React from 'react'; import { Globe, FileText, Image as ImageIcon, File, Eye, MoreVertical, Edit3, Share2, Trash2, Lock, ExternalLink, Download, Clock, AlertCircle } from 'lucide-react'; import type { Asset } from '../../../types/assets'; import type { User } from '../../../types/auth'; interface AssetCardProps { asset: Asset; user: User | null; activeMenuId: string | null; setActiveMenuId: (id: string | null) => void; onViewDetails: (asset: Asset) => void; onEdit: (asset: Asset) => void; onShare: (asset: Asset) => void; onDelete: (assetId: string) => void; onOpenViewer: (asset: Asset) => void; onDownload: (asset: Asset) => void; onRequestDownload: (asset: Asset) => void; isSelected?: boolean; onToggleSelect?: (assetId: string) => void; } export const AssetCard: React.FC = ({ asset, user, activeMenuId, setActiveMenuId, onViewDetails, onEdit, onShare, onDelete, onOpenViewer, onDownload, onRequestDownload, isSelected = false, onToggleSelect }) => { const isMenuOpen = activeMenuId === asset.id; const canDirectDownload = user?.role === 'ADMIN' || asset.isDownloadable || asset.downloadRequests?.[0]?.status === 'APPROVED'; const requestStatus = asset.downloadRequests?.[0]?.status; const formatBytes = (bytes: number, decimals = 2) => { if (bytes === 0) return '0 Bytes'; const k = 1024; const dm = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; }; const getAssetIcon = (type: string) => { if (type === 'url') return Globe; if (type.includes('pdf')) return FileText; if (type.includes('image') || type.includes('png') || type.includes('jpg')) return ImageIcon; return File; }; const isRenderable = (type: string) => { return type === 'url' || type.includes('pdf') || type.includes('image') || type.includes('png') || type.includes('jpg'); }; const Icon = getAssetIcon(asset.type); return (
{user?.role === 'ADMIN' && onToggleSelect && ( onToggleSelect(asset.id)} className="w-3.5 h-3.5 rounded border-ink-300 text-ink-900 focus:ring-ink-900/10 cursor-pointer mr-1" /> )}
{isRenderable(asset.type) && ( )} {isMenuOpen && ( <>
setActiveMenuId(null)} />
{user?.role === 'ADMIN' && ( <> )}
)}
{asset.categoryId || 'General'}
{!asset.isDownloadable && (
Strict View Only
)}

{asset.title}

{asset.type === 'url' ? 'External Link' : formatBytes(asset.size)} • {new Date(asset.createdAt).toLocaleDateString()}

{asset.type === 'url' ? 'Type' : 'Downloads'} {asset.type === 'url' ? 'URL Link' : asset.downloadsCount}
{asset.type === 'url' ? ( ) : canDirectDownload ? ( ) : requestStatus === 'PENDING' ? (
Pending Access
) : requestStatus === 'REJECTED' ? ( ) : ( )}
); };