import React from 'react'; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Monitor, Laptop, Smartphone, Printer, HardDrive, Eye, Edit, Trash2, User, Calendar, Mouse, MousePointer2, Keyboard, Tablet, Scan, Computer, UserPlus } from 'lucide-react'; import { Asset, AssetWithDetails, AssetCondition } from '@/types/asset-management'; import { format } from 'date-fns'; // Helper function to get badge variant based on asset condition const getConditionBadgeVariant = (condition: AssetCondition) => { switch (condition) { case 'Excellent': return 'default'; case 'Good': return 'secondary'; case 'Fair': return 'outline'; case 'Poor': return 'destructive'; default: return 'outline'; } }; // Helper function to get asset type icon const getAssetTypeIcon = (assetType: string) => { const type = assetType.toLowerCase(); // Exact matches first if (type === 'laptop') return ; if (type === 'desktop') return ; if (type === 'monitor') return ; if (type === 'extended screen') return ; if (type === 'keyboard') return ; if (type === 'mouse') return ; if (type === 'wired mouse') return ; if (type === 'wireless mouse') return ; if (type === 'laptop stand') return ; if (type === 'printer') return ; if (type === 'scanner') return ; if (type === 'tablet') return ; if (type === 'phone') return ; // Fallback for partial matches if (type.includes('laptop')) return ; if (type.includes('monitor') || type.includes('screen')) return ; if (type.includes('mouse')) return ; if (type.includes('keyboard')) return ; if (type.includes('phone')) return ; if (type.includes('tablet')) return ; if (type.includes('printer')) return ; if (type.includes('scanner')) return ; return ; }; interface AssetCardProps { asset: Asset | AssetWithDetails; onView?: (asset: Asset) => void; onEdit?: (asset: Asset) => void; onDelete?: (asset: Asset) => void; onAssign?: (asset: Asset) => void; activeAssignment?: any; showActions?: boolean; compact?: boolean; } const AssetCard: React.FC = ({ asset, onView, onEdit, onDelete, onAssign, activeAssignment, showActions = true, compact = false }) => { const assetWithDetails = asset as AssetWithDetails; const currentAssignment = activeAssignment || assetWithDetails.currentAssignment || (assetWithDetails.assignments && assetWithDetails.assignments.find(a => !a.returnedDate)); const isAvailable = !currentAssignment; return ( {/* Assignment Status Badge - Mobile First */}
{currentAssignment ? ( Assigned to {currentAssignment.employeeName} ) : ( Available )}
{getAssetTypeIcon(asset.assetType)} {asset.assetType} {asset.assetCondition}
Asset Code: {asset.assetCode}
Brand/Model: {asset.brandModel}
Serial Number: {asset.serialNumber}
{/* Assignment Status Details */} {currentAssignment ? (
Assigned
{currentAssignment.assignedDate && ( since {format(new Date(currentAssignment.assignedDate), 'PP')} )}
) : (
Available
)} {/* System Details Preview */} {assetWithDetails.systemDetails && !compact && (
System Details:
{assetWithDetails.systemDetails.systemModel}
{assetWithDetails.systemDetails.processor}
{assetWithDetails.systemDetails.installedRAM} RAM
)}
{showActions && (
{onAssign && isAvailable && ( )} {onView && ( )} {onEdit && ( )} {onDelete && ( )}
)}
); }; export default AssetCard;