'use client' import { Deadline } from '@/types' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { cn } from '@/lib/utils' import { isDeadlineOverdue, DEADLINE_TYPE_LABELS, PRIORITY_LABELS, parseDate, startOfDay, } from '@/lib/calendar/utils' import { Check, Circle, Trash2, Pencil } from 'lucide-react' interface DeadlineCardProps { deadline: Deadline onToggle: (deadline: Deadline) => void onEdit?: (deadline: Deadline) => void onDelete?: (deadline: Deadline) => void compact?: boolean } function getRelativeDate(dateStr: string): string { const today = startOfDay(new Date()) const target = parseDate(dateStr) const diffMs = target.getTime() - today.getTime() const diffDays = Math.round(diffMs / (1000 * 60 * 60 * 24)) if (diffDays === 0) return 'Idag' if (diffDays === 1) return 'Imorgon' if (diffDays === -1) return 'Igår' if (diffDays < -1) return `${Math.abs(diffDays)}d sedan` if (diffDays <= 14) return `Om ${diffDays}d` return '' } const SWEDISH_MONTHS_SHORT = [ 'jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec', ] export function DeadlineCard({ deadline, onToggle, onEdit, onDelete, compact = false, }: DeadlineCardProps) { const overdue = isDeadlineOverdue(deadline) const completed = deadline.is_completed const relativeDate = getRelativeDate(deadline.due_date) const dueDate = parseDate(deadline.due_date) const dayNum = dueDate.getDate() const monthStr = SWEDISH_MONTHS_SHORT[dueDate.getMonth()] if (compact) { return (
{deadline.title}
{/* Relative date */} {!completed && relativeDate && ( {relativeDate} )}{deadline.title}
{/* Meta line */}{deadline.notes}
)}