import { format, formatDistanceToNow, isPast, isToday } from "date-fns"; import { Button } from "@/components/ui/button"; import { useBoardStore } from "@/stores/board-store"; interface DueDatePickerProps { cardId: string; dueDate: string | null; } export function DueDatePicker({ cardId, dueDate }: DueDatePickerProps) { const updateCard = useBoardStore((s) => s.updateCard); const dateObj = dueDate ? new Date(dueDate) : null; const overdue = dateObj != null && isPast(dateObj) && !isToday(dateObj); function handleChange(e: React.ChangeEvent) { const val = e.target.value; updateCard(cardId, { dueDate: val || null }); } function handleClear() { updateCard(cardId, { dueDate: null }); } // Format the date value for the HTML date input (YYYY-MM-DD) const inputValue = dateObj ? format(dateObj, "yyyy-MM-dd") : ""; return (
{/* Header */}

Due Date

{/* Current date display */} {dateObj && (
{format(dateObj, "MMM d, yyyy")} {overdue ? `overdue by ${formatDistanceToNow(dateObj)}` : isToday(dateObj) ? "today" : `in ${formatDistanceToNow(dateObj)}`}
)} {/* Date input + clear */}
{dueDate && ( )}
); }