import React, { useMemo, useState } from 'react'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; import { Widget } from '@/hooks/Mapper/components/mapInterface/components'; import { SystemKillsContent } from './SystemKillsContent/SystemKillsContent'; import { KillsHeader } from './components/SystemKillsHeader'; import { useKillsWidgetSettings } from './hooks/useKillsWidgetSettings'; import { useSystemKills } from './hooks/useSystemKills'; import { KillsSettingsDialog } from './components/SystemKillsSettingsDialog'; import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormholeSpace'; export const SystemKills: React.FC = () => { const { data: { selectedSystems, systems, isSubscriptionActive }, outCommand, } = useMapRootState(); const [systemId] = selectedSystems || []; const [settingsDialogVisible, setSettingsDialogVisible] = useState(false); const systemNameMap = useMemo(() => { const map: Record = {}; systems.forEach(sys => { map[sys.id] = sys.temporary_name || sys.name || '???'; }); return map; }, [systems]); const [settings] = useKillsWidgetSettings(); const visible = settings.showAll; const { kills, isLoading, error } = useSystemKills({ systemId, outCommand, showAllVisible: visible, }); const isNothingSelected = !systemId && !visible; const showLoading = isLoading && kills.length === 0; const filteredKills = useMemo(() => { if (!settings.whOnly) return kills; return kills.filter(kill => { const system = systems.find(sys => sys.system_static_info.solar_system_id === kill.solar_system_id); if (!system) { console.warn(`System with id ${kill.solar_system_id} not found.`); return false; } return isWormholeSpace(system.system_static_info.system_class); }); }, [kills, settings.whOnly, systems]); return (
setSettingsDialogVisible(true)} /> } > {!isSubscriptionActive && (
Kills available with 'Active' map subscription only (contact map administrators)
)} {isSubscriptionActive && ( <> {isNothingSelected && (
No system selected (or toggle “Show all systems”)
)} {!isNothingSelected && showLoading && (
Loading Kills...
)} {!isNothingSelected && !showLoading && error && (
{error}
)} {!isNothingSelected && !showLoading && !error && (!filteredKills || filteredKills.length === 0) && (
No kills found
)} {!isNothingSelected && !showLoading && !error && (
)} )}
); };