import { useMemo } from "react";
import { useTelemetryStream } from "./useTelemetryStream";
import { toChartVariable } from "../types/telemetryCatalog";

export function useTelemetryCatalog() {
    const telemetry = useTelemetryStream();

    const variables = useMemo(
        () => telemetry.snapshots.map(toChartVariable),
        [telemetry.snapshots],
    );

    const chartableVariables = useMemo(
        () => variables.filter((variable) => variable.chartable),
        [variables],
    );

    return {
        ...telemetry,
        variables,
        chartableVariables,
    };
}