"use client"; import { useState } from "react"; import Link from "next/link"; import { AlertTriangle, Check, EllipsisVertical, X } from "lucide-react"; import { Button, buttonVariants } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { DueChip } from "@/components/task-status"; import { captureHref, INTENT_ICONS } from "@/lib/suggestions/labels"; import type { Suggestion } from "@/lib/suggestions/types"; import { TASK_PRIORITY_LABELS } from "@/lib/tasks/labels"; import { dueState } from "@/lib/tasks/today"; import { todayLocalIsoDate } from "@/lib/dates"; import { DueDateSheet } from "./due-date-sheet"; export interface SuggestionCardProps { suggestion: Suggestion; /** A decision for this very suggestion is running. */ busy?: boolean; /** tasks:create - needed for „Übernehmen“ and every way to plan a task. */ canAccept?: boolean; /** tasks:update - needed for „Verwerfen“. */ canDismiss?: boolean; /** `dueDate` is undefined for the suggestion's own day, else YYYY-MM-DD. */ onAccept: (suggestion: Suggestion, dueDate?: string) => void; onDismiss: (suggestion: Suggestion) => void; /** „Aufräumen“ for a CLEANUP suggestion; without a handler the button is not offered. */ onCleanup?: (suggestion: Suggestion) => void; } type MenuAction = { label: string; sheetTitle: string; confirmLabel: string }; function menuActionOf(suggestion: Suggestion): MenuAction | null { if (suggestion.mode === "PLAN") { return { label: "Termin ändern", sheetTitle: "Termin ändern", confirmLabel: "Übernehmen" }; } if (suggestion.intent === "CLEANUP") return null; return { label: "Als Aufgabe planen", sheetTitle: "Als Aufgabe planen", confirmLabel: "Aufgabe anlegen" }; } function MainAction({ suggestion, busy, canAccept = true, onAccept, onCleanup }: SuggestionCardProps) { if (suggestion.intent === "CLEANUP") { if (!onCleanup) return null; return ( ); } if (suggestion.mode === "DO") { return ( Erfassen ); } if (!canAccept) return null; return ( ); } export function SuggestionCard(props: SuggestionCardProps) { const { suggestion, busy, canAccept = true, canDismiss = true, onAccept, onDismiss } = props; const [now] = useState(() => new Date()); const [isSheetOpen, setIsSheetOpen] = useState(false); const Icon = INTENT_ICONS[suggestion.intent]; const menuAction = canAccept ? menuActionOf(suggestion) : null; const isUrgent = suggestion.priority === "HIGH" || suggestion.priority === "URGENT"; return (

{suggestion.title}

{suggestion.colonyCode ? ( {suggestion.colonyCode} ) : null}
{suggestion.reasons.length > 0 ? (
    {suggestion.reasons.map((reason) => (
  • {reason}
  • ))}
) : null}
{isUrgent ? ( {TASK_PRIORITY_LABELS[suggestion.priority]} ) : null}
{canDismiss ? ( ) : null} {menuAction ? ( } > setIsSheetOpen(true)}> {menuAction.label} ) : null}
{menuAction ? ( { setIsSheetOpen(false); onAccept(suggestion, dueDate); }} /> ) : null}
); }