"use client"; import { useId, useState } from "react"; import Link from "next/link"; import { Check, ChevronDown, Play } from "lucide-react"; import { OnlineOnlyHint, useOnlineOnly } from "@/components/offline/stand-note"; import { Button, buttonVariants } from "@/components/ui/button"; import { INTENT_ICONS, INTENT_LABELS } from "@/lib/suggestions/labels"; import { roundTarget, type SuggestionGroupModel } from "@/lib/suggestions/grouping"; import type { Suggestion, SuggestionIntent } from "@/lib/suggestions/types"; import { cn } from "@/lib/utils"; import { SuggestionCard } from "./suggestion-card"; export interface SuggestionGroupProps { group: SuggestionGroupModel; /** Suggestions with a running decision; only their cards wait. */ busyIds?: ReadonlySet; canAccept?: boolean; canDismiss?: boolean; /** False without a signed-in user: „Runde starten“ then only opens the first inspection. */ canStartRound?: boolean; onAccept: (suggestion: Suggestion, dueDate?: string) => void; onDismiss: (suggestion: Suggestion) => void; onAcceptAll: (ids: string[]) => void; /** Called when „Runde starten“ is tapped; the link then opens the first inspection. */ onStartRound: (suggestions: Suggestion[]) => void; onCleanup?: (suggestion: Suggestion) => void; } interface CombinedRowProps extends Omit { intent: SuggestionIntent; suggestions: Suggestion[]; } /** „n Völker“ when the rows belong to colonies, else „n Vorschläge“. */ function countLabel(suggestions: readonly Suggestion[]): string { const colonies = new Set( suggestions.flatMap((suggestion) => (suggestion.colonyId ? [suggestion.colonyId] : [])), ); if (colonies.size === 0) return `${suggestions.length} Vorschläge`; return colonies.size === 1 ? "1 Volk" : `${colonies.size} Völker`; } function CombinedRow({ intent, suggestions, busyIds, canAccept = true, canDismiss = true, canStartRound = true, ...handlers }: CombinedRowProps) { const [isOpen, setIsOpen] = useState(false); const listId = useId(); const Icon = INTENT_ICONS[intent]; const round = intent === "INSPECT" ? roundTarget(suggestions) : null; const canAcceptAll = canAccept && suggestions.every((suggestion) => suggestion.mode === "PLAN"); const { isOffline, hintId, describedBy } = useOnlineOnly(); const isBusy = suggestions.some((suggestion) => busyIds?.has(suggestion.id)); return (

{INTENT_LABELS[intent]} · {countLabel(suggestions)}

{round ? ( { if (canStartRound) handlers.onStartRound(suggestions); }} className={buttonVariants({ size: "touch" })} > Runde starten ) : canAcceptAll ? ( ) : null}
{canAcceptAll && !round ? : null}
); } /** All open suggestions of one stand (or the farm), same intents folded into one row. */ export function SuggestionGroup({ group, ...handlers }: SuggestionGroupProps) { return (

{group.label}

{group.rows.map((row) => row.kind === "single" ? ( ) : ( ), )}
); }