"use client"; import { IconArrowUpRight, IconSubtask } from "@tabler/icons-react"; import { ContextMenuItem, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, } from "@kandev/ui/context-menu"; import { useNestTask } from "@/hooks/use-nest-task"; import { computeNestCandidates } from "@/lib/sidebar/nest-candidates"; import type { TaskSwitcherItem } from "./task-switcher"; import { useTranslation } from "react-i18next"; type TaskNestContextMenuItemsProps = { task: TaskSwitcherItem; nestCandidateTasks?: TaskSwitcherItem[]; nestHierarchyTasks?: TaskSwitcherItem[]; disabled?: boolean; }; /** * "Nest" sub-menu: nest a task under another task (make it a sub-task), * re-parent it, or un-nest it back to the root. Candidate parents are the * other tasks in the same workflow, excluding the task's own descendants * (which would create a cycle) and its current parent. */ export function TaskNestContextMenuItems({ task, nestCandidateTasks = [], nestHierarchyTasks, disabled, }: TaskNestContextMenuItemsProps) { const { t } = useTranslation(); const workflowId = task.workflowId; const nestTask = useNestTask(); if (!workflowId || task.isArchived) return null; const candidates = computeNestCandidates( nestCandidateTasks.filter((candidate) => candidate.workflowId === workflowId), task.id, nestHierarchyTasks ?? nestCandidateTasks, ); const hasParent = Boolean(task.parentTaskId); return ( {t("task:nestUnder")} {hasParent && ( <> void nestTask(task.id, workflowId, null)} > {t("task:unNestRemoveParent")} )} {candidates.length === 0 ? ( {t("task:noOtherTasks")} ) : ( candidates.map((candidate) => ( void nestTask(task.id, workflowId, candidate.id)} > {candidate.title} )) )} ); }