import { useMemo } from "react";
const useStageTasksByGroups = (allTasks)=>{
    const sequentialTaskGroups = useMemo(()=>allTasks.filter((group)=>group.some((t)=>{
                if (null != t.taskGroupType) return 'sequential' === t.taskGroupType;
                if (null != t.isAdhoc) return !t.isAdhoc;
                return true;
            })), [
        allTasks
    ]);
    const sequentialTasks = useMemo(()=>sequentialTaskGroups.flatMap((group, groupIndex)=>group.map((task, taskIndex)=>({
                    task,
                    groupIndex,
                    taskIndex
                }))), [
        sequentialTaskGroups
    ]);
    const adhocTaskGroups = useMemo(()=>allTasks.filter((group)=>group.every((t)=>{
                if (null != t.taskGroupType) return 'adhoc' === t.taskGroupType;
                if (null != t.isAdhoc) return t.isAdhoc;
                return false;
            })), [
        allTasks
    ]);
    const adhocTasks = useMemo(()=>adhocTaskGroups.flatMap((group, groupIndex)=>group.map((task, taskIndex)=>({
                    task,
                    groupIndex,
                    taskIndex
                }))), [
        adhocTaskGroups
    ]);
    const eventDrivenTaskGroups = useMemo(()=>allTasks.filter((group)=>group.every((t)=>{
                if (null != t.taskGroupType) return 'event-driven' === t.taskGroupType;
                return false;
            })), [
        allTasks
    ]);
    const eventDrivenTasks = useMemo(()=>eventDrivenTaskGroups.flatMap((group, groupIndex)=>group.map((task, taskIndex)=>({
                    task,
                    groupIndex,
                    taskIndex
                }))), [
        eventDrivenTaskGroups
    ]);
    return {
        sequentialTaskGroups,
        sequentialTasks,
        adhocTaskGroups,
        adhocTasks,
        eventDrivenTaskGroups,
        eventDrivenTasks
    };
};
export { useStageTasksByGroups };
