import { useState, useRef, useEffect } from 'react'; import { ComboBox } from '@common/components/ui/ComboBox'; export interface RecalcParams { substance: string; releaseType: '연속 유출' | '순간 유출' | '밀도가스 유출'; emissionRate: number; totalRelease: number; algorithm: string; predictionTime: string; } interface HNSRecalcModalProps { isOpen: boolean; onClose: () => void; onSubmit: (params: RecalcParams) => void; currentParams?: Partial | null; } export function HNSRecalcModal({ isOpen, onClose, onSubmit, currentParams }: HNSRecalcModalProps) { const backdropRef = useRef(null); const [substance, setSubstance] = useState('톨루엔 (Toluene)'); const [releaseType, setReleaseType] = useState('연속 유출'); const [amount, setAmount] = useState('10'); const [algorithm, setAlgorithm] = useState('ALOHA (EPA)'); const [predictionTime, setPredictionTime] = useState('24시간'); // 모달 열릴 때 현재 파라미터로 초기화 useEffect(() => { if (!isOpen || !currentParams) return; queueMicrotask(() => { if (currentParams.substance) setSubstance(currentParams.substance); if (currentParams.releaseType) setReleaseType(currentParams.releaseType); if (currentParams.releaseType === '순간 유출') { setAmount(String(currentParams.totalRelease ?? '')); } else { setAmount(String(currentParams.emissionRate ?? '')); } if (currentParams.algorithm) setAlgorithm(currentParams.algorithm); if (currentParams.predictionTime) setPredictionTime(currentParams.predictionTime); }); }, [isOpen, currentParams]); // 배경 클릭으로 닫기 useEffect(() => { const handler = (e: MouseEvent) => { if (e.target === backdropRef.current) onClose(); }; if (isOpen) document.addEventListener('mousedown', handler); return () => document.removeEventListener('mousedown', handler); }, [isOpen, onClose]); const handleRun = () => { const numAmount = parseFloat(amount) || 10; onSubmit({ substance, releaseType, emissionRate: releaseType !== '순간 유출' ? numAmount : 10, totalRelease: releaseType === '순간 유출' ? numAmount : 5000, algorithm, predictionTime, }); onClose(); }; if (!isOpen) return null; const amountLabel = releaseType === '순간 유출' ? '총 누출량' : '배출률'; const amountUnit = releaseType === '순간 유출' ? 'g' : 'g/s'; return (
{/* Header */}
🔄

대기확산 재계산

조건을 변경하여 재계산합니다
{/* Content */}
{/* HNS 물질 */} {/* 유출 유형 + 유출량 */}
setReleaseType(v as RecalcParams['releaseType'])} options={[ { value: '연속 유출', label: '연속 유출' }, { value: '순간 유출', label: '순간 유출' }, { value: '밀도가스 유출', label: '밀도가스 유출' }, ]} /> setAmount(e.target.value)} placeholder={amountUnit} />
{/* 확산 모델 + 예측 시간 */}
{/* Footer */}
); } function FG({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); }