import type { Goal } from "@paperclip/shared"; import { StatusBadge } from "./StatusBadge"; import { ChevronRight } from "lucide-react"; import { cn } from "../lib/utils"; import { useState } from "react"; interface GoalTreeProps { goals: Goal[]; onSelect?: (goal: Goal) => void; } interface GoalNodeProps { goal: Goal; children: Goal[]; allGoals: Goal[]; depth: number; onSelect?: (goal: Goal) => void; } function GoalNode({ goal, children, allGoals, depth, onSelect }: GoalNodeProps) { const [expanded, setExpanded] = useState(true); const hasChildren = children.length > 0; return (
onSelect?.(goal)} > {hasChildren ? ( ) : ( )} {goal.level} {goal.title}
{hasChildren && expanded && (
{children.map((child) => ( g.parentId === child.id)} allGoals={allGoals} depth={depth + 1} onSelect={onSelect} /> ))}
)}
); } export function GoalTree({ goals, onSelect }: GoalTreeProps) { const roots = goals.filter((g) => !g.parentId); if (goals.length === 0) { return

No goals.

; } return (
{roots.map((goal) => ( g.parentId === goal.id)} allGoals={goals} depth={0} onSelect={onSelect} /> ))}
); }