import { useState, useEffect, useRef } from "react"; import { AnimatePresence, motion, useReducedMotion } from "framer-motion"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { X } from "lucide-react"; import { useBoardStore } from "@/stores/board-store"; import { MarkdownEditor } from "@/components/card-detail/MarkdownEditor"; import { ChecklistSection } from "@/components/card-detail/ChecklistSection"; import { LabelPicker } from "@/components/card-detail/LabelPicker"; import { DueDatePicker } from "@/components/card-detail/DueDatePicker"; import { AttachmentSection } from "@/components/card-detail/AttachmentSection"; import { PriorityPicker } from "@/components/card-detail/PriorityPicker"; import { CommentsSection } from "@/components/card-detail/CommentsSection"; import { springs, staggerContainer, fadeSlideUp } from "@/lib/motion"; interface CardDetailModalProps { cardId: string | null; onClose: () => void; } export function CardDetailModal({ cardId, onClose }: CardDetailModalProps) { const card = useBoardStore((s) => cardId ? s.board?.cards[cardId] ?? null : null ); const boardLabels = useBoardStore((s) => s.board?.labels ?? []); const updateCard = useBoardStore((s) => s.updateCard); const open = cardId != null && card != null; const prefersReducedMotion = useReducedMotion(); const instant = { duration: 0 }; return ( {open && card && cardId && ( <> {/* Backdrop */} {/* Modal */}
e.stopPropagation()} > Card detail editor {/* Header: cover color background + title + close */}
{/* Dashboard grid body */} {/* Row 1: Labels + Due Date */} {/* Row 2: Checklist + Description */} {/* Row 3: Priority + Cover */} {/* Row 4: Attachments (full width) */} {/* Row 5: Comments (full width) */}
)}
); } /* ---------- Escape key handler ---------- */ function EscapeHandler({ onClose }: { onClose: () => void }) { useEffect(() => { function handleKeyDown(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [onClose]); return null; } /* ---------- Inline editable title ---------- */ interface InlineTitleProps { cardId: string; title: string; updateCard: (cardId: string, updates: { title: string }) => void; hasColor: boolean; } function InlineTitle({ cardId, title, updateCard, hasColor }: InlineTitleProps) { const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(title); const inputRef = useRef(null); useEffect(() => { setDraft(title); }, [title]); useEffect(() => { if (editing && inputRef.current) { inputRef.current.focus(); inputRef.current.select(); } }, [editing]); function handleSave() { const trimmed = draft.trim(); if (trimmed && trimmed !== title) { updateCard(cardId, { title: trimmed }); } else { setDraft(title); } setEditing(false); } function handleKeyDown(e: React.KeyboardEvent) { if (e.key === "Enter") { e.preventDefault(); handleSave(); } else if (e.key === "Escape") { setDraft(title); setEditing(false); } } const textColor = hasColor ? "text-white" : "text-pylon-text"; const hoverColor = hasColor ? "hover:text-white/80" : "hover:text-pylon-accent"; if (editing) { return ( setDraft(e.target.value)} onBlur={handleSave} onKeyDown={handleKeyDown} className={`flex-1 font-heading text-xl bg-transparent outline-none border-b pb-0.5 ${ hasColor ? "text-white border-white/50" : "text-pylon-text border-pylon-accent" }`} /> ); } return (

setEditing(true)} className={`flex-1 cursor-pointer font-heading text-xl transition-colors ${textColor} ${hoverColor}`} > {title}

); } /* ---------- Cover color picker ---------- */ function CoverColorPicker({ cardId, coverColor, }: { cardId: string; coverColor: string | null; }) { const updateCard = useBoardStore((s) => s.updateCard); const presets = [ { hue: "160", label: "Teal" }, { hue: "240", label: "Blue" }, { hue: "300", label: "Purple" }, { hue: "350", label: "Pink" }, { hue: "25", label: "Red" }, { hue: "55", label: "Orange" }, { hue: "85", label: "Yellow" }, { hue: "130", label: "Lime" }, { hue: "200", label: "Cyan" }, { hue: "0", label: "Slate" }, ]; return (

Cover

{presets.map(({ hue, label }) => (
); }