'use client' import { memo, useState, useCallback, useMemo } from 'react' import { Handle, Position } from '@xyflow/react' import type { NodeProps } from '@xyflow/react' import type { OutcomeNodeData } from '@/lib/types' import { useConnectionState } from '../ConnectionContext' function OutcomeNode({ data, selected, id }: NodeProps) { const nodeData = data as OutcomeNodeData const { label, description, fundingReceived, fundingTarget, status } = nodeData const [isExpanded, setIsExpanded] = useState(false) const connectingFrom = useConnectionState() const progress = fundingTarget > 0 ? Math.min(100, (fundingReceived / fundingTarget) * 100) : 0 const isFunded = fundingReceived >= fundingTarget const isPartial = fundingReceived > 0 && fundingReceived < fundingTarget // Handle highlighting: outcome targets glow when dragging from spending or stream handles const isTargetHighlighted = useMemo(() => { if (!connectingFrom || connectingFrom.nodeId === id) return false const handleId = connectingFrom.handleId if (handleId === 'spending-out') return true if (handleId === 'stream-out') return true return false }, [connectingFrom, id]) const statusColors = { 'not-started': { bg: 'bg-slate-100', text: 'text-slate-600', border: 'border-slate-300' }, 'in-progress': { bg: 'bg-blue-100', text: 'text-blue-700', border: 'border-blue-300' }, 'completed': { bg: 'bg-emerald-100', text: 'text-emerald-700', border: 'border-emerald-300' }, 'blocked': { bg: 'bg-red-100', text: 'text-red-700', border: 'border-red-300' }, } const colors = statusColors[status] || statusColors['not-started'] const handleDoubleClick = useCallback((e: React.MouseEvent) => { e.stopPropagation() setIsExpanded(true) }, []) const handleCloseExpanded = useCallback(() => { setIsExpanded(false) }, []) return ( <>
{description}
)}{description}