// (C) 2025-2026 GoodData Corporation
import { useMemo } from "react";
import { collectReferences } from "../helpers/references.js";
import { useEvaluatedMetricsAndAttributes } from "./useEvaluatedMetricsAndAttributes.js";
export function useEvaluatedReferences(value, filters, config) {
    const isEmptyValue = useMemo(() => !value?.replace(/\s/g, ""), [value]);
    const references = useMemo(() => collectReferences(value), [value]);
    const { loading, result: metrics, error: metricsError, } = useEvaluatedMetricsAndAttributes(references, filters, {
        ...config,
        // Mark filters as loaded when there are no references to resolve to speed up loading.
        // The query that sets this value runs no matter if there are references or not.
        isFiltersLoading: Object.keys(references).length > 0 && !!config.isFiltersLoading,
    });
    return {
        isEmptyValue,
        loading,
        metrics,
        error: metricsError,
    };
}
