/* @oracle/oraclejet-preact: undefined */
import { useCallback } from 'preact/hooks';
import { g as getInfo } from './eventsUtils-e5fc62d5.js';
import './accUtils-ce2d6588.js';
import { u as useVisDrill } from './useVisDrill-21902134.js';

const isDrillable = (info, drilling, groups, getDataItem) => {
    const { seriesIndex, groupIndex } = info;
    if (groupIndex === undefined) {
        return false;
    }
    if (seriesIndex != null) {
        const itemDrilling = getDataItem(seriesIndex, groupIndex)?.drilling != 'off';
        return drilling === 'on' && itemDrilling;
    }
    else {
        return groups[groupIndex].drilling != 'off';
    }
};
/**
 * Returns the event handlers for drill support.
 */
function useChartDrill({ rootRef, focusedItemInfo, focusedGroupInfo, groups, selectionMode, drilling, getDataItem, onItemDrill, onGroupDrill }) {
    const processDrill = useCallback((info) => {
        if (!info ||
            info.groupIndex == undefined ||
            !isDrillable(info, drilling, groups, getDataItem)) {
            return;
        }
        const { seriesIndex, groupIndex } = info;
        if (seriesIndex != null) {
            const data = getDataItem(seriesIndex, groupIndex);
            if (data) {
                onItemDrill?.({
                    groupIndex,
                    seriesIndex,
                    data,
                    id: data?.id
                });
            }
        }
        else {
            onGroupDrill?.({
                groupIndex,
                group: groups[groupIndex],
                id: groups[groupIndex].id
            });
        }
    }, [drilling, getDataItem, groups, onGroupDrill, onItemDrill]);
    const onDrill = useCallback((event) => {
        if (event.type === 'keydown') {
            const focusedInfo = focusedItemInfo.isCurrent ? focusedItemInfo : focusedGroupInfo;
            processDrill(focusedInfo);
        }
        else {
            processDrill(getInfo(rootRef, event.target));
        }
    }, [rootRef, focusedItemInfo, focusedGroupInfo, processDrill]);
    return useVisDrill(selectionMode, onDrill);
}

export { useChartDrill as u };
//# sourceMappingURL=useChartDrill-676e05ad.js.map
