/** StreamSelector — checkbox list of all streams grouped by subprocess. */ import { useEffect, useCallback } from 'react'; import { useProjectStore } from '../../store/projectStore'; import { useAnalysisStore } from '../../store/analysisStore'; import { getStreamInfo } from '../../utils/streamUtils'; import type { Stream } from '../../types/stream'; import ChartHelpButton from '../ui/ChartHelpButton'; import { useTranslation } from 'react-i18next'; export default function StreamSelector() { const { t } = useTranslation(); const processes = useProjectStore((s) => s.state.processes); const selectedStreams = useAnalysisStore((s) => s.selectedStreams); const setSelectedStream = useAnalysisStore((s) => s.setSelectedStream); // Initialize any streams that haven't been seen yet as "selected" by default useEffect(() => { const keysToEnable: string[] = []; processes.forEach((proc, pi) => { (proc.streams ?? []).forEach((_s: Stream, si: number) => { const key = `stream_${pi}_${si}`; // If it's not even in the map yet, we mark it as "to be enabled" if (selectedStreams[key] === undefined) { keysToEnable.push(key); } }); }); if (keysToEnable.length > 0) { // Direct merge into store to avoid overwriting existing selections const next = { ...selectedStreams }; keysToEnable.forEach(k => next[k] = true); useAnalysisStore.setState({ selectedStreams: next }); } }, [processes, selectedStreams]); const handleToggle = useCallback( (key: string) => { setSelectedStream(key, !selectedStreams[key]); }, [selectedStreams, setSelectedStream], ); if (!processes.length) { return