"use client"; import { useState, useEffect } from "react"; import { Initiative, FileTreeNode } from "@/core/types"; import { MarkdownContent } from "./MarkdownContent"; import { FileTree } from "./FileTree"; import { FileViewer } from "./FileViewer"; interface InitiativeViewProps { initiative: Initiative; onDelete: () => void; onMove: (targetState: "active" | "backlog" | "completed") => void; onRefresh: () => void; } type TabId = "overview" | "tracker" | "sessions" | "decisions" | "plans" | "files"; export function InitiativeView({ initiative, onDelete, onMove, onRefresh }: InitiativeViewProps) { const [activeTab, setActiveTab] = useState("overview"); const [fileTree, setFileTree] = useState([]); const [selectedFilePath, setSelectedFilePath] = useState(null); const [loadingFiles, setLoadingFiles] = useState(false); // Fetch file tree when Files tab is selected useEffect(() => { if (activeTab === "files" && fileTree.length === 0) { setLoadingFiles(true); fetch(`/api/initiatives/${initiative.state}/${initiative.name}/files`) .then((res) => res.json()) .then((data) => { if (data.success) { setFileTree(data.data); } }) .catch(console.error) .finally(() => setLoadingFiles(false)); } }, [activeTab, initiative.state, initiative.name, fileTree.length]); const tabs: { id: TabId; label: string; count?: number; badge?: string }[] = [ { id: "overview", label: "Overview" }, { id: "tracker", label: "Tracker", badge: initiative.tracker?.phase }, { id: "sessions", label: "Sessions", count: initiative.sessions.length }, { id: "decisions", label: "Decisions", count: initiative.decisions.length }, { id: "plans", label: "Plans", count: initiative.plans.length }, { id: "files", label: "Files" }, ]; const stateColors = { active: "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300", backlog: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300", completed: "bg-gray-100 text-gray-700 dark:bg-gray-700/50 dark:text-gray-300", }; return (
{/* Header */}
{initiative.state.charAt(0).toUpperCase() + initiative.state.slice(1)} {initiative.frontmatter.created}

{initiative.frontmatter.title}

{initiative.frontmatter.tags && initiative.frontmatter.tags.length > 0 && (
{initiative.frontmatter.tags.map((tag) => ( {tag} ))}
)}
{/* Actions */}
{/* Tab Bar */}
{/* Tab Content */}
{/* Overview Tab */} {activeTab === "overview" && ( )} {/* Tracker Tab */} {activeTab === "tracker" && ( initiative.tracker ? (
{initiative.tracker.phase && (
Phase: {initiative.tracker.phase} {initiative.tracker.updated && ( ยท Updated: {initiative.tracker.updated} )}
)}
) : ( ) )} {/* Sessions Tab */} {activeTab === "sessions" && ( initiative.sessions.length > 0 ? (
{initiative.sessions.map((session) => ( ))}
) : ( ) )} {/* Decisions Tab */} {activeTab === "decisions" && ( initiative.decisions.length > 0 ? (
{initiative.decisions.map((decision) => ( ))}
) : ( ) )} {/* Plans Tab */} {activeTab === "plans" && ( initiative.plans.length > 0 ? (
{initiative.plans.map((plan) => ( ))}
) : ( ) )}
{/* Files Tab - Full width with two-column layout */} {activeTab === "files" && (
{/* File Tree */}
{loadingFiles ? (
Loading files...
) : fileTree.length > 0 ? (
) : (
No files found
)}
{/* File Viewer */}
{selectedFilePath ? ( ) : (
Select a file to view
)}
)}
); } // Move dropdown interface MoveDropdownProps { currentState: "active" | "backlog" | "completed"; onMove: (targetState: "active" | "backlog" | "completed") => void; } function MoveDropdown({ currentState, onMove }: MoveDropdownProps) { const states = ["active", "backlog", "completed"] as const; const availableStates = states.filter((s) => s !== currentState); return (
{availableStates.map((state) => ( ))}
); } // Session card interface SessionCardProps { session: { name: string; date: string; branch?: string; content: string }; } function SessionCard({ session }: SessionCardProps) { return (
{session.date} {session.branch && ( {session.branch} )}
); } // Decision card interface DecisionCardProps { decision: { name: string; date: string; status: string; content: string }; } function DecisionCard({ decision }: DecisionCardProps) { const statusColors: Record = { proposed: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-300", accepted: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300", superseded: "bg-gray-100 text-gray-700 dark:bg-gray-700/50 dark:text-gray-300", deprecated: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300", }; return (
{decision.name} {decision.status} {decision.date}
); } // Plan card interface PlanCardProps { plan: { name: string; content: string }; } function PlanCard({ plan }: PlanCardProps) { return (
{plan.name}
); } // Empty state function EmptyState({ message }: { message: string }) { return (
{message}
); }