import React, { useState, useEffect, useCallback, useRef } from 'react'; import type { IndicatorConfig } from '../types'; import { getIndicatorDef, enrichIndicatorConfig } from '../utils/indicatorRegistry'; import IndicatorSettingsForm from './IndicatorSettingsForm'; import { resetConfigToDefaults } from '../utils/indicatorSettingsEditor'; import { useDraggablePanel } from '../hooks/useDraggablePanel'; interface IndicatorSettingsModalProps { config: IndicatorConfig; chartMarket?: string; onSave: (updated: IndicatorConfig) => void; onCancel: () => void; } /** 차트·설정 화면 공통 — 입력·스타일·가시성 단일 화면 (탭 없음) */ const IndicatorSettingsModal: React.FC = ({ config, chartMarket = '', onSave, onCancel, }) => { const def = getIndicatorDef(config.type); const draftRef = useRef(enrichIndicatorConfig(config)); const [formRevision, setFormRevision] = useState(0); const [chartHidden, setChartHidden] = useState(() => draftRef.current.hidden ?? false); const { panelRef, dragging, onHeaderPointerDown, headerTouchStyle, panelStyle, headerCursor, } = useDraggablePanel({ centerOnMount: true }); const openedIdRef = React.useRef(null); useEffect(() => { if (openedIdRef.current !== config.id) { openedIdRef.current = config.id; draftRef.current = enrichIndicatorConfig(config); setChartHidden(draftRef.current.hidden ?? false); setFormRevision(r => r + 1); } }, [config]); const title = def ? `${def.koreanName} (${def.name})` : config.type; const handleSave = useCallback(() => { onSave(enrichIndicatorConfig(draftRef.current)); }, [onSave]); const handleDefaults = useCallback(() => { draftRef.current = resetConfigToDefaults(draftRef.current); setChartHidden(draftRef.current.hidden ?? false); setFormRevision(r => r + 1); }, []); const handleHidden = useCallback((showOnChart: boolean) => { draftRef.current = { ...draftRef.current, hidden: !showOnChart }; setChartHidden(!showOnChart); }, []); const handleDraftRef = useCallback((updated: IndicatorConfig) => { draftRef.current = updated; }, []); return (
{ if (e.target === e.currentTarget) onCancel(); }} >
e.stopPropagation()} onPointerDown={e => e.stopPropagation()} >
{title}
e.stopPropagation()} onPointerDown={e => e.stopPropagation()} >
); }; export default IndicatorSettingsModal;