import { ActionSubitem, ActionSubItemPrivate, } from '../components/ActionControl'; export interface UseBulkActionMobileGroupsParams { primaryActionItems: ActionSubitem[]; secondaryActionItems: ActionSubitem[][]; moreActionsLabel: string; } /** * Hook to build mobile action groups for the bulk action toolbar. * Combines primary and secondary bulk actions into grouped sections for mobile view. */ export function useBulkActionMobileGroups({ primaryActionItems, secondaryActionItems, moreActionsLabel, }: UseBulkActionMobileGroupsParams): ActionSubItemPrivate['subItems'] { const primaryGroup = primaryActionItems.flatMap((actionItem) => { if (!actionItem.subItems) { return [actionItem]; } return [{ sectionTitle: actionItem.label! }, ...actionItem.subItems.flat()]; }); const secondaryFlat = [ { sectionTitle: moreActionsLabel }, ...secondaryActionItems.flat(), ]; const groups: ActionSubItemPrivate['subItems'] = []; if (primaryGroup.length > 0) { groups.push(primaryGroup); } // array is at least of size 1 because of the hardcoded moreActionsLabel if (secondaryFlat.length > 1) { groups.push(secondaryFlat); } return groups; }