// (C) 2021-2026 GoodData Corporation
import { createSelector } from "@reduxjs/toolkit";
import { areObjRefsEqual } from "@gooddata/sdk-model";
import { createMemoizedSelector } from "../_infra/selectors.js";
import { selectActiveOrDefaultTabLocalIdentifier } from "../tabs/tabsSelectors.js";
const selectSelf = createSelector((state) => state, (state) => state.drill);
/**
 * Returns drillable items for the active tab (when tabs enabled) or default tab (when tabs disabled).
 *
 * @alpha
 */
export const selectDrillableItems = createSelector(selectSelf, selectActiveOrDefaultTabLocalIdentifier, (drillState, activeTabId) => {
    return drillState.drillableItems[activeTabId] ?? [];
});
/**
 * Returns cross filtering items for the active tab (when tabs enabled) or default tab (when tabs disabled).
 *
 * @beta
 */
export const selectCrossFilteringItems = createSelector(selectSelf, selectActiveOrDefaultTabLocalIdentifier, (drillState, activeTabId) => {
    return drillState.crossFiltering[activeTabId] ?? [];
});
/**
 * Returns cross filtering items for all tabs keyed by tab identifier.
 * This selector is useful when processing filters for all tabs at once.
 *
 * @internal
 */
export const selectCrossFilteringItemsByTab = createSelector(selectSelf, (drillState) => {
    return drillState.crossFiltering;
});
/**
 * @beta
 */
export const selectIsCrossFiltering = createSelector(selectCrossFilteringItems, (items) => items.length > 0);
/**
 * @beta
 */
export const selectCrossFilteringItemByWidgetRef = createMemoizedSelector((ref) => createSelector(selectCrossFilteringItems, (items) => items.find((item) => areObjRefsEqual(ref, item.widgetRef))));
/**
 * @beta
 */
export const selectCrossFilteringFiltersLocalIdentifiers = createSelector(selectCrossFilteringItems, (items) => items.flatMap((item) => item.filterLocalIdentifiers));
/**
 * @beta
 */
export const selectIsFilterFromCrossFilteringByLocalIdentifier = createMemoizedSelector((localIdentifier) => createSelector(selectCrossFilteringFiltersLocalIdentifiers, (filterLocalIdentifiers) => filterLocalIdentifiers.some((localId) => localId === localIdentifier)));
/**
 * @beta
 */
export const selectCrossFilteringFiltersLocalIdentifiersByWidgetRef = createMemoizedSelector((ref) => createSelector(selectCrossFilteringItemByWidgetRef(ref), (item) => item?.filterLocalIdentifiers));
/**
 * @beta
 */
export const selectCrossFilteringSelectedPointsByWidgetRef = createMemoizedSelector((ref) => createSelector(selectCrossFilteringItemByWidgetRef(ref), (item) => item?.selectedPoints));
//# sourceMappingURL=drillSelectors.js.map