import React, { useEffect, useRef } from 'react'; import type { Drawing } from '../types'; // 도구별 한국어 이름 const DRAWING_LABELS: Record = { hline: '수평선', vline: '수직선', trendline: '추세선', ray: '레이', fib: '피보나치', fibtz: '피보나치 타임존', measure: '가격 측정', rect: '사각형', channel: '채널', pencil: '자유 드로잉', text: '텍스트', }; /* ── SVG Icons (IndicatorContextToolbar 와 동일 스타일) ── */ const IcEye = ({ visible }: { visible: boolean }) => visible ? ( ) : ( ); const IcGear = () => ( ); const IcTrash = () => ( ); interface DrawingContextToolbarProps { drawing: Drawing; screenX: number; screenY: number; onSettings: () => void; onToggleVisible: () => void; onRemove: () => void; onClose: () => void; } const DrawingContextToolbar: React.FC = ({ drawing, screenX, screenY, onSettings, onToggleVisible, onRemove, onClose, }) => { const ref = useRef(null); // 외부 클릭 시 닫기 useEffect(() => { const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) { onClose(); } }; const tid = setTimeout(() => document.addEventListener('mousedown', handler), 100); return () => { clearTimeout(tid); document.removeEventListener('mousedown', handler); }; }, [onClose]); const W = 220; let left = screenX + 8; let top = screenY + 8; if (left + W > window.innerWidth - 8) left = window.innerWidth - W - 8; if (top + 50 > window.innerHeight - 8) top = screenY - 58; const label = DRAWING_LABELS[drawing.type] ?? drawing.type; const isHidden = drawing.visible === false; return (
e.stopPropagation()} > {/* 색상 닷 + 이름 */} {label} {/* 가시성 토글 */} {/* 설정 */} {/* 삭제 */}
); }; export default DrawingContextToolbar;