// (C) 2020-2026 GoodData Corporation
import { useMemo } from "react";
import { isDrillFiltersConfigOptionSelected } from "./types.js";
import { useDrillFiltersConfig } from "./useDrillFiltersConfig.js";
import { useDrillFiltersConfigInner } from "./useDrillFiltersConfigInner.js";
export function useDrillFiltersCount(item, onUpdateDrillItem) {
    const { intersectionAttributesOptions, sourceInsightFiltersOptions, sourceMeasureFiltersOptions, dashboardFiltersOptions, drillIntersectionIgnoredAttributes, includedSourceInsightFiltersObjRefs, ignoredDashboardFilters, includedSourceMeasureFiltersObjRefs, isLoading, onDrillFiltersChange, } = useDrillFiltersConfig({
        item,
        onUpdateDrillItem,
    });
    const { intersectionSelection, sourceInsightSelection, sourceMeasureSelection, dashboardSelection } = useDrillFiltersConfigInner({
        intersectionAttributesOptions,
        sourceInsightFiltersOptions,
        sourceMeasureFiltersOptions,
        dashboardFiltersOptions,
        drillIntersectionIgnoredAttributes,
        includedSourceInsightFiltersObjRefs,
        ignoredDashboardFilters,
        includedSourceMeasureFiltersObjRefs,
        onDrillFiltersChange,
    });
    const count = useMemo(() => intersectionAttributesOptions.filter((option) => isDrillFiltersConfigOptionSelected(option, intersectionSelection)).length +
        dashboardFiltersOptions.filter((option) => isDrillFiltersConfigOptionSelected(option, dashboardSelection)).length +
        sourceInsightFiltersOptions.filter((option) => isDrillFiltersConfigOptionSelected(option, sourceInsightSelection)).length +
        sourceMeasureFiltersOptions.filter((option) => isDrillFiltersConfigOptionSelected(option, sourceMeasureSelection)).length, [
        intersectionAttributesOptions,
        intersectionSelection,
        dashboardFiltersOptions,
        dashboardSelection,
        sourceInsightFiltersOptions,
        sourceInsightSelection,
        sourceMeasureFiltersOptions,
        sourceMeasureSelection,
    ]);
    return {
        count,
        isLoading,
    };
}
