import React, { useRef } from 'react'; import { NodeResizer, Handle, Position, useUpdateNodeInternals } from '@xyflow/react'; import { Settings, StickyNote, Pin } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { useTheme } from '../../../../context/ThemeContext'; const getInitials = (displayName, email) => { if (displayName && displayName.trim()) { const parts = displayName.trim().split(/\s+/); if (parts.length >= 2) { return (parts[0][0] + parts[1][0]).toUpperCase(); } return parts[0].substring(0, 2).toUpperCase(); } if (email && email.trim()) { return email.substring(0, 2).toUpperCase(); } return 'U'; }; const PASTEL_COLORS = { yellow: { light: '#fef9c3', dark: '#2e2b14', borderLight: '#eab308', borderDark: '#ca8a04' }, blue: { light: '#dbeafe', dark: '#111827', borderLight: '#3b82f6', borderDark: '#2563eb' }, green: { light: '#dcfce7', dark: '#062f17', borderLight: '#22c55e', borderDark: '#16a34a' }, pink: { light: '#fce7f3', dark: '#37061d', borderLight: '#ec4899', borderDark: '#db2777' }, purple: { light: '#f3e8ff', dark: '#210638', borderLight: '#a855f7', borderDark: '#9333ea' }, orange: { light: '#ffedd5', dark: '#2e1208', borderLight: '#f97316', borderDark: '#ea580c' }, white: { light: '#f5f5f4', dark: '#1c1917', borderLight: '#d6d3d1', borderDark: '#44403c' } }; const CommentNode = ({ id, data, selected }) => { const { t } = useTranslation(); const { isDarkMode } = useTheme(); const updateNodeInternals = useUpdateNodeInternals(); // Re-calculate handles when node size might change React.useEffect(() => { updateNodeInternals(id); }, [id, data.label, data.description, updateNodeInternals]); // Create a slight premium dynamic rotation based on node ID to make it look like a physical sticky note const rotateAngle = useRef(((parseInt(id.slice(0, 2), 16) % 3) - 1.5).toFixed(1)); const openConfigureModal = (e) => { e.stopPropagation(); window.dispatchEvent(new CustomEvent('configure-sketch-node', { detail: { nodeId: id } })); }; const togglePin = (e) => { e.stopPropagation(); e.preventDefault(); if (data.updateNodeData) { data.updateNodeData(id, { isPinned: !data.isPinned }); } }; // Background and border style resolution based on selected color or default to yellow const colorKey = data.color && data.color !== 'default' ? data.color : 'yellow'; const selectedColor = PASTEL_COLORS[colorKey]; const nodeBg = isDarkMode ? selectedColor.dark : selectedColor.light; const nodeBorder = isDarkMode ? selectedColor.borderDark : selectedColor.borderLight; return (
{data.description || t('canvas.comment_placeholder', 'Двоклацніть, щоб додати коментар...')}