"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { IconCheck, IconCircleDashed, IconChevronLeft, IconChevronRight, } from "@tabler/icons-react"; import { cn } from "@kandev/ui/lib/utils"; import { getTaskStateIcon } from "@/lib/ui/state-icons"; import { linkToTask } from "@/lib/links"; import type { Task } from "@/components/kanban-card"; import type { WorkflowStep } from "@/components/kanban-column"; import { useTaskPendingClarification } from "@/hooks/use-task-pending-clarification"; type StepPhase = "past" | "current" | "future"; function isRunningState(state?: string): boolean { return state === "IN_PROGRESS" || state === "SCHEDULING"; } export type Graph2StepNodeProps = { step: WorkflowStep; phase: StepPhase; task: Task; hasPrev: boolean; hasNext: boolean; onMoveTask: (task: Task, targetStepId: string) => void; onPreviewTask: (task: Task) => void; prevStepId?: string; nextStepId?: string; isMoving?: boolean; }; const NODE_CLASS = "w-[130px] h-[36px] rounded-lg shrink-0 px-2.5 flex flex-col items-start justify-center"; function PastNode({ step }: { step: WorkflowStep }) { return (
{step.title}
); } function FutureNode({ step }: { step: WorkflowStep }) { return (
{step.title}
); } function MoveButton({ direction, isMoving, onClick, }: { direction: "left" | "right"; isMoving?: boolean; onClick: (e: React.MouseEvent) => void; }) { const posClass = direction === "left" ? "-left-3" : "-right-3"; const Icon = direction === "left" ? IconChevronLeft : IconChevronRight; return ( ); } export function Graph2StepNode({ step, phase, task, hasPrev, hasNext, onMoveTask, prevStepId, nextStepId, isMoving, }: Graph2StepNodeProps) { const router = useRouter(); const [isHovered, setIsHovered] = useState(false); const hasPendingClarificationRequest = useTaskPendingClarification(task.primarySessionId); if (phase === "past") return ; if (phase === "future") return ; // Current phase const running = isRunningState(task.state); const handleClick = () => { router.push(linkToTask(task.id)); }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {isHovered && hasPrev && prevStepId && ( { e.stopPropagation(); onMoveTask(task, prevStepId); }} /> )} {isHovered && hasNext && nextStepId && ( { e.stopPropagation(); onMoveTask(task, nextStepId); }} /> )}
); }