"use client"; import { useEffect, useRef, useState } from "react"; import CanvasHint, { useCanvasHint } from "@/components/ui/CanvasHint"; /* ────────────────────────────────────────────────────────────────────────── * KanbanBoard — compact, interactive product centrepiece for the * projektmanagement page. Tight columns (subtle light panels), small white * cards, draggable between columns (mouse + touch). * * Card look modelled on a real PM/CRM board (Pipedrive/Linear-style): a tag + * priority-flag row, a prominent title, and a footer with overlapping assignee * avatars and a single prioritised status chip. All in the HiveGrid amber * palette with inline SVG icons — no external icon/theme deps. * ────────────────────────────────────────────────────────────────────────── */ type Priority = "high" | "medium" | "low"; type Card = { id: string; title: string; tag: string; tagColor: string; who: string; initials: string; priority: Priority; /** second, overlapping avatar (e.g. the assigned monteur) */ monteur?: string; monteurInitials?: string; /** status chip, prioritised: overdue › due soon › task count › none */ overdueDays?: number; dueDays?: number; taskCount?: number; }; type Column = { id: string; title: string; accent: string; cards: Card[] }; // Subtle "drag me" wiggle for the top todo card — mostly at rest, a quick nudge // every few seconds. Stops after the first drag; disabled for reduced motion. const NUDGE_CSS = ` @keyframes kanban-nudge{0%,78%,100%{transform:rotate(0deg)}83%{transform:rotate(-2.6deg)}88%{transform:rotate(2.4deg)}93%{transform:rotate(-1.4deg)}97%{transform:rotate(0.6deg)}} .kanban-nudge{animation:kanban-nudge 3.4s ease-in-out infinite;transform-origin:60% 65%} @media (prefers-reduced-motion:reduce){.kanban-nudge{animation:none}} `; const INITIAL: Column[] = [ { id: "todo", title: "Zu erledigen", accent: "#93C5FD", cards: [ { id: "c1", title: "Angebot Sanitär — Müller", tag: "Angebot", tagColor: "#3B82F6", who: "Lena Krause", initials: "LK", priority: "high", dueDays: 1 }, { id: "c2", title: "Baustelle Weber vorbereiten", tag: "Baustelle", tagColor: "#E8A317", who: "Tom Berger", initials: "TB", monteur: "Stefan Müller", monteurInitials: "SM", priority: "medium", taskCount: 3 }, { id: "c3", title: "Material bestellen — Berger", tag: "Material", tagColor: "#F97316", who: "Sara Möller", initials: "SM", priority: "low", overdueDays: 2 }, ], }, { id: "doing", title: "In Arbeit", accent: "#F1B729", cards: [ { id: "c4", title: "Heizungstausch — Schmidt", tag: "Heizung", tagColor: "#E8A317", who: "Tom Berger", initials: "TB", monteur: "Jonas Weiß", monteurInitials: "JW", priority: "high", dueDays: 0 }, { id: "c5", title: "Bad-Renovierung — Fischer", tag: "Sanitär", tagColor: "#0D6E6E", who: "Lena Krause", initials: "LK", priority: "medium", taskCount: 5 }, ], }, { id: "done", title: "Erledigt", accent: "#22C55E", cards: [ { id: "c6", title: "Wartung Anlage Nord", tag: "Wartung", tagColor: "#22C55E", who: "Sara Möller", initials: "SM", priority: "low" }, { id: "c7", title: "Abnahme — Solarcarport", tag: "Abnahme", tagColor: "#22C55E", who: "Jonas Weiß", initials: "JW", priority: "low" }, ], }, ]; /* ─── card sub-parts ──────────────────────────────────────────────────── */ function PriorityFlag({ priority }: { priority: Priority }) { const color = priority === "high" ? "#EF4444" : priority === "medium" ? "#F1B729" : "#CBD5E1"; const tip = priority === "high" ? "Hohe Priorität" : priority === "medium" ? "Mittlere Priorität" : "Niedrige Priorität"; return ( ); } function Avatar({ initials, title, variant = "who", overlap = false }: { initials: string; title: string; variant?: "who" | "monteur"; overlap?: boolean }) { const bg = variant === "monteur" ? "#FFEDD5" : "#E5E7EB"; const fg = variant === "monteur" ? "#C2410C" : "#475569"; return ( {initials} ); } function StatusChip({ card }: { card: Card }) { const base = "inline-flex items-center gap-1 rounded text-[10px] font-semibold px-1.5 py-0.5"; if (card.overdueDays && card.overdueDays > 0) { return ( {card.overdueDays} T überfällig ); } if (card.dueDays !== undefined && card.dueDays <= 3) { const label = card.dueDays === 0 ? "Termin Heute" : card.dueDays === 1 ? "Termin Morgen" : `Termin in ${card.dueDays} T`; return ( {label} ); } if (card.taskCount && card.taskCount > 0) { return ( {card.taskCount} ); } return null; } function CardBody({ card }: { card: Card }) { const hasFooter = !!card.initials || !!card.monteurInitials || card.overdueDays || card.dueDays !== undefined || card.taskCount; return (
{/* Row 1: tag (left) · priority flag (right) */}
{card.tag}
{/* Title */} {card.title} {/* Footer: avatars + single status chip */} {hasFooter && (
{card.monteurInitials && ( )}
)}
); } export default function KanbanBoard({ hideHeader = false }: { hideHeader?: boolean }) { const [columns, setColumns] = useState(INITIAL); const [dragging, setDragging] = useState< { cardId: string; fromCol: string; offX: number; offY: number; w: number } | null >(null); const [pos, setPos] = useState({ x: 0, y: 0 }); const [overCol, setOverCol] = useState(null); const [hinted, setHinted] = useState(false); // true once the user drags anything → stop the nudge const posRef = useRef({ x: 0, y: 0 }); const colRefs = useRef>({}); // Centered onboarding hint — appears when the board scrolls into view, // dismissed on the first drag or via the X. const hint = useCanvasHint(); const draggedCard = dragging ? columns.find((c) => c.id === dragging.fromCol)?.cards.find((k) => k.id === dragging.cardId) ?? null : null; const colUnderPointer = (x: number, y: number): string | null => { for (const [id, el] of Object.entries(colRefs.current)) { if (!el) continue; const r = el.getBoundingClientRect(); if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return id; } return null; }; useEffect(() => { if (!dragging) return; // Stop text from being selected anywhere on the page while dragging. document.body.style.setProperty("user-select", "none"); document.body.style.setProperty("-webkit-user-select", "none"); const onMove = (e: PointerEvent) => { const x = e.clientX; const y = e.clientY; posRef.current = { x, y }; setPos({ x, y }); setOverCol(colUnderPointer(x, y)); }; const onUp = () => { const target = colUnderPointer(posRef.current.x, posRef.current.y); if (target && target !== dragging.fromCol) { setColumns((cols) => { const card = cols.find((c) => c.id === dragging.fromCol)?.cards.find((k) => k.id === dragging.cardId); if (!card) return cols; return cols.map((c) => { if (c.id === dragging.fromCol) return { ...c, cards: c.cards.filter((k) => k.id !== dragging.cardId) }; if (c.id === target) return { ...c, cards: [...c.cards, card] }; return c; }); }); } setDragging(null); setOverCol(null); }; window.addEventListener("pointermove", onMove, { passive: true }); window.addEventListener("pointerup", onUp); window.addEventListener("pointercancel", onUp); return () => { window.removeEventListener("pointermove", onMove); window.removeEventListener("pointerup", onUp); window.removeEventListener("pointercancel", onUp); document.body.style.removeProperty("user-select"); document.body.style.removeProperty("-webkit-user-select"); }; }, [dragging]); const startDrag = (e: React.PointerEvent, colId: string, card: Card) => { if (e.button !== 0 && e.pointerType === "mouse") return; setHinted(true); hint.dismiss(); const rect = (e.currentTarget as HTMLElement).getBoundingClientRect(); posRef.current = { x: e.clientX, y: e.clientY }; setPos({ x: e.clientX, y: e.clientY }); setOverCol(colId); setDragging({ cardId: card.id, fromCol: colId, offX: e.clientX - rect.left, offY: e.clientY - rect.top, w: rect.width }); }; return (