import { X, Ruler, Activity, Radar, Eye } from 'lucide-react'; import { useState } from 'react'; import { request } from '../utils/request'; import type { CelestialBody } from '../types'; import { TerminalModal } from './TerminalModal'; import type { ToastContextValue } from '../contexts/ToastContext'; // Import ToastContextValue type interface FocusInfoProps { body: CelestialBody | null; onClose: () => void; toast: ToastContextValue; // Add toast prop onViewDetails?: (body: CelestialBody) => void; // Add onViewDetails prop } export function FocusInfo({ body, onClose, toast, onViewDetails }: FocusInfoProps) { const [showTerminal, setShowTerminal] = useState(false); const [terminalData, setTerminalData] = useState(''); const [loading, setLoading] = useState(false); if (!body) return null; // Calculate distance if position is available const pos = body.positions[0]; const distance = pos ? Math.sqrt(pos.x ** 2 + pos.y ** 2 + pos.z ** 2).toFixed(2) : '---'; const isProbe = body.type === 'probe'; const isActive = body.is_active !== false; const fetchNasaData = async () => { setShowTerminal(true); setLoading(true); try { const { data } = await request.get(`/celestial/${body.id}/nasa-data`); setTerminalData(data.raw_data); } catch (err) { console.error(err); toast.error('连接 NASA Horizons 失败'); // If failed, maybe show error in terminal setTerminalData("CONNECTION FAILED.\n\nError establishing link with JPL Horizons System.\nCheck connection frequencies."); } finally { setLoading(false); } }; const styles = ` @keyframes spin-slow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .animate-spin-slow { animation: spin-slow 3s linear infinite; } `; return ( // Remove fixed positioning, now handled by parent container (Html component in 3D)
{/* Main Info Card */}
{/* Close Button */} {/* Header */}

{body.name_zh || body.name}

{onViewDetails && ( )} {isProbe ? '探测器' : '天体'}

{body.description || '暂无描述'}

{/* Stats and Actions Grid */}
{/* Column 1: Heliocentric Distance Card */}
日心距离
{distance} AU
{/* Column 2: JPL Horizons Button */}
{/* Conditional Probe Status Card (if isProbe is true, this goes in a new row) */} {isProbe && (
状态
{isActive ? '运行中' : '已失效'}
)}
{/* Connecting Line/Triangle pointing down to the body */}
setShowTerminal(false)} title={
JPL/HORIZONS SYSTEM INTERFACE // {body.name.toUpperCase()}
} loading={loading} loadingText="ESTABLISHING SECURE UPLINK..." >
{terminalData}
); }