// (C) 2022-2026 GoodData Corporation
import { useEffect, useMemo } from "react";
import { queryConnectingAttributes, } from "../../../../../../model/queries/connectingAttributes.js";
import { useDashboardSelector } from "../../../../../../model/react/DashboardStoreProvider.js";
import { useDashboardQueryProcessing } from "../../../../../../model/react/useDashboardQueryProcessing.js";
import { selectSupportsSettingConnectingAttributes } from "../../../../../../model/store/backendCapabilities/backendCapabilitiesSelectors.js";
/**
 * @internal
 */
export function useConnectingAttributes(currentFilterDisplayForm, neighborFiltersDisplayForms) {
    const shouldLoadConnectingAttributes = useDashboardSelector(selectSupportsSettingConnectingAttributes);
    const pairs = useMemo(() => neighborFiltersDisplayForms.map((neighborDisplayForm) => [
        currentFilterDisplayForm,
        neighborDisplayForm,
    ]), [neighborFiltersDisplayForms, currentFilterDisplayForm]);
    const { run: getConnectingAttributes, result: connectingAttributes, status: connectingAttributesStatus, error: connectingAttributesError, } = useDashboardQueryProcessing({
        queryCreator: queryConnectingAttributes,
    });
    useEffect(() => {
        // if the backend does not support the parent attributes, we must not run the query, it will end in an error
        if (shouldLoadConnectingAttributes) {
            getConnectingAttributes(pairs);
        }
    }, [pairs, getConnectingAttributes, shouldLoadConnectingAttributes]);
    const connectingAttributesLoading = useMemo(() => {
        return connectingAttributesStatus === "pending" || connectingAttributesStatus === "running";
    }, [connectingAttributesStatus]);
    if (!shouldLoadConnectingAttributes) {
        // if the backend does not support the parent attributes, return en empty response
        return {
            connectingAttributes: [],
            connectingAttributesError: undefined,
            connectingAttributesLoading: false,
        };
    }
    return {
        connectingAttributes,
        connectingAttributesLoading,
        connectingAttributesError,
    };
}
//# sourceMappingURL=useConnectingAttributes.js.map