"use client"; import { memo, useMemo } from "react"; import { Handle, Position, NodeProps } from "@xyflow/react"; import { Badge } from "@/components/ui/badge"; export interface PageNodeData { title: string; status: "draft" | "ready" | "review"; content?: string; notes?: string; hasAttachments?: boolean; hasLinks?: boolean; [key: string]: unknown; } const statusConfig = { draft: { label: "Szkic", className: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30", }, ready: { label: "Gotowe", className: "bg-green-500/20 text-green-400 border-green-500/30", }, review: { label: "Do poprawki", className: "bg-red-500/20 text-red-400 border-red-500/30", }, }; // Different styles for node types const nodeTypeConfig = { page: { bgClass: "bg-slate-800/90", borderClass: "border-slate-600", selectedBorderClass: "border-blue-500", accentColor: "blue", icon: ( ), label: "Strona", }, note: { bgClass: "bg-amber-900/40", borderClass: "border-amber-600/50", selectedBorderClass: "border-amber-400", accentColor: "amber", icon: ( ), label: "Notatka", }, section: { bgClass: "bg-purple-900/40", borderClass: "border-purple-600/50", selectedBorderClass: "border-purple-400", accentColor: "purple", icon: ( ), label: "Sekcja", }, }; function CustomNode({ data, selected, type }: NodeProps) { const nodeData = data as PageNodeData; const status = statusConfig[nodeData.status] || statusConfig.draft; const nodeType = nodeTypeConfig[type as keyof typeof nodeTypeConfig] || nodeTypeConfig.page; const hasContent = useMemo(() => { return nodeData.hasAttachments || nodeData.hasLinks; }, [nodeData.hasAttachments, nodeData.hasLinks]); const handleColorClass = nodeType.accentColor === "amber" ? "!bg-amber-500" : nodeType.accentColor === "purple" ? "!bg-purple-500" : "!bg-blue-500"; return (
{/* Top Handle */} {/* Type indicator */}
{nodeType.icon} {nodeType.label}
{/* Content */}

{nodeData.title || "Nowa strona"}

{hasContent && (
)}
{status.label}
{/* Bottom Handle */}
); } export default memo(CustomNode);