import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { Card as CardType } from '../../types/kanban'; import MessageSquareIcon from '../icons/MessageSquareIcon'; import CheckSquareIcon from '../icons/CheckSquareIcon'; import { Link } from 'react-router-dom'; interface KanbanCardProps { card: CardType; onOpenModal: () => void; } export function KanbanCard({ card, onOpenModal }: KanbanCardProps) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: `CARD_${card.id}`, }); const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1, }; // Calculate checklist progress const checklists = (card as any).checklists || []; const totalItems = checklists.reduce( (sum: number, checklist: any) => sum + checklist.items.length, 0 ); const completedItems = checklists.reduce( (sum: number, checklist: any) => sum + checklist.items.filter((item: any) => item.state === 'complete').length, 0 ); const hasChecklists = totalItems > 0; // Calculate comment count const comments = (card as any).comments || []; const commentCount = comments.length; const hasComments = commentCount > 0; // Get labels const labels = (card as any).labels || []; const hasLabels = labels.length > 0; return (
{ // Only open modal if not clicking title link if (!(e.target as HTMLElement).closest('a')) { onOpenModal(); } }} className="bg-gray-700 rounded-lg p-4 mb-3 cursor-pointer hover:bg-gray-600 transition-colors border border-gray-600 shadow-sm" > {/* Labels */} {hasLabels && (
{labels.slice(0, 3).map((label: any) => ( {label.name} ))} {labels.length > 3 && ( +{labels.length - 3} )}
)}

e.stopPropagation()} className="hover:underline" > {card.name}

{card.description && (

{card.description}

)} {/* Badges */}
{/* Comments Badge */} {hasComments && (
{commentCount}
)} {/* Checklist Badge */} {hasChecklists && (
{completedItems}/{totalItems}
)} {/* Due Date Badge */} {card.due && ( Due: {new Date(card.due).toLocaleDateString()} )} {/* Card ID */} #{card.id_short}
); }