/**
* ProbeList component - sidebar showing planets and probes
*/
import { useState } from 'react';
import type { CelestialBody } from '../types';
interface ProbeListProps {
probes: CelestialBody[];
planets: CelestialBody[];
onBodySelect: (body: CelestialBody | null) => void;
selectedBody: CelestialBody | null;
}
export function ProbeList({ probes, planets, onBodySelect, selectedBody }: ProbeListProps) {
const [isExpanded, setIsExpanded] = useState(true);
// Calculate distance for each probe
const probesWithDistance = probes.map((probe) => {
const pos = probe.positions[0];
const distance = Math.sqrt(pos.x ** 2 + pos.y ** 2 + pos.z ** 2);
return { body: probe, distance };
});
// Calculate distance for each planet (exclude Sun)
const planetsWithDistance = planets
.filter((p) => p.type !== 'star') // Exclude Sun
.map((planet) => {
const pos = planet.positions[0];
const distance = Math.sqrt(pos.x ** 2 + pos.y ** 2 + pos.z ** 2);
return { body: planet, distance };
});
// Sort by distance
probesWithDistance.sort((a, b) => a.distance - b.distance);
planetsWithDistance.sort((a, b) => a.distance - b.distance);
const totalCount = probes.length + planets.length - 1; // -1 for Sun
// Collapsed state - show only toggle button
if (!isExpanded) {
return (
);
}
return (
🌍 天体列表
{/* Planets Section */}
行星 ({planetsWithDistance.length})
{planetsWithDistance.length === 0 ? (
加载中...
) : (
{planetsWithDistance.map(({ body, distance }) => (
))}
)}
{/* Probes Section */}
探测器 ({probesWithDistance.length})
{probesWithDistance.length === 0 ? (
加载中...
) : (
{probesWithDistance.map(({ body, distance }) => (
))}
)}
{/* Return button */}
);
}