"use client"; import { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Feature } from "@/store/app-store"; import { AlertCircle, CheckCircle2, Circle } from "lucide-react"; import { cn } from "@/lib/utils"; interface DependencyTreeDialogProps { open: boolean; onClose: () => void; feature: Feature | null; allFeatures: Feature[]; } export function DependencyTreeDialog({ open, onClose, feature, allFeatures, }: DependencyTreeDialogProps) { const [dependencyTree, setDependencyTree] = useState<{ dependencies: Feature[]; dependents: Feature[]; }>({ dependencies: [], dependents: [] }); useEffect(() => { if (!feature) return; // Find features this depends on const dependencies = (feature.dependencies || []) .map((depId) => allFeatures.find((f) => f.id === depId)) .filter((f): f is Feature => f !== undefined); // Find features that depend on this one const dependents = allFeatures.filter((f) => f.dependencies?.includes(feature.id) ); setDependencyTree({ dependencies, dependents }); }, [feature, allFeatures]); if (!feature) return null; const getStatusIcon = (status: Feature["status"]) => { switch (status) { case "completed": case "verified": return ; case "in_progress": case "waiting_approval": return ; default: return ; } }; const getPriorityBadge = (priority?: number) => { if (!priority) return null; return ( P{priority} ); }; return ( Dependency Tree
{/* Current Feature */}
{getStatusIcon(feature.status)}

Current Feature

{getPriorityBadge(feature.priority)}

{feature.description}

Category: {feature.category}

{/* Dependencies (what this feature needs) */}

Dependencies ({dependencyTree.dependencies.length})

This feature requires:
{dependencyTree.dependencies.length === 0 ? (
No dependencies - this feature can be started independently
) : (
{dependencyTree.dependencies.map((dep) => (
{getStatusIcon(dep.status)} {dep.description.slice(0, 100)} {dep.description.length > 100 && "..."} {getPriorityBadge(dep.priority)}
{dep.category} {dep.status.replace(/_/g, " ")}
))}
)}
{/* Dependents (what depends on this feature) */}

Dependents ({dependencyTree.dependents.length})

Features blocked by this:
{dependencyTree.dependents.length === 0 ? (
No dependents - no other features are waiting on this one
) : (
{dependencyTree.dependents.map((dependent) => (
{getStatusIcon(dependent.status)} {dependent.description.slice(0, 100)} {dependent.description.length > 100 && "..."} {getPriorityBadge(dependent.priority)}
{dependent.category} {dependent.status.replace(/_/g, " ")}
))}
)}
{/* Warning for incomplete dependencies */} {dependencyTree.dependencies.some( (d) => d.status !== "completed" && d.status !== "verified" ) && (

Incomplete Dependencies

This feature has dependencies that aren't completed yet. Consider completing them first for a smoother implementation.

)}
); }