import { useState, useEffect, useCallback } from "react"; import type { ContractWithRelations, ContractPhase, ContractStatus, ContractRepository, FileSummary, TaskSummary, TemplateSummary, } from "../../lib/api"; import { listTemplates, getTemplate, createFile, } from "../../lib/api"; import { PhaseProgressBar } from "./PhaseProgressBar"; import { PhaseHint } from "./PhaseHint"; import { RepositoryPanel } from "./RepositoryPanel"; import { ContractCliInput } from "./ContractCliInput"; import { PhaseDeliverablesPanel } from "./PhaseDeliverablesPanel"; import { CommandModePanel } from "./CommandModePanel"; import { TaskTree } from "../mesh/TaskTree"; type Tab = "overview" | "repos" | "files" | "tasks"; interface ContractDetailProps { contract: ContractWithRelations; loading: boolean; onBack: () => void; onUpdate: (name: string, description: string) => void; onDelete: () => void; onPhaseChange: (phase: ContractPhase) => void; onStatusChange: (status: ContractStatus) => void; onFileSelect: (id: string) => void; onTaskSelect: (id: string) => void; onTaskCreate: (name: string, plan: string, repositoryUrl?: string) => void; onRefresh: () => void; // Repository callbacks onAddRemoteRepo: (name: string, url: string, isPrimary: boolean) => void; onAddLocalRepo: (name: string, path: string, isPrimary: boolean) => void; onCreateManagedRepo: (name: string, isPrimary: boolean) => void; onDeleteRepo: (repoId: string) => void; onSetRepoPrimary: (repoId: string) => void; // File creation callback for phase deliverables onCreateFileFromTemplate?: (templateId: string, suggestedName: string) => void; } const statusConfig: Record = { active: { label: "Active", color: "text-green-400" }, completed: { label: "Completed", color: "text-blue-400" }, archived: { label: "Archived", color: "text-[#555]" }, }; export function ContractDetail({ contract, loading, onBack, onUpdate, onDelete, onPhaseChange, onStatusChange, onFileSelect, onTaskSelect, onTaskCreate, onRefresh, onAddRemoteRepo, onAddLocalRepo, onCreateManagedRepo, onDeleteRepo, onSetRepoPrimary, onCreateFileFromTemplate, }: ContractDetailProps) { const [activeTab, setActiveTab] = useState("overview"); const [isEditing, setIsEditing] = useState(false); const [name, setName] = useState(contract.name); const [description, setDescription] = useState(contract.description || ""); const handleSave = () => { onUpdate(name, description); setIsEditing(false); }; const handleCancel = () => { setName(contract.name); setDescription(contract.description || ""); setIsEditing(false); }; if (loading) { return (
Loading...
); } const tabs: { key: Tab; label: string; count?: number }[] = [ { key: "overview", label: "Overview" }, { key: "repos", label: "Repositories", count: contract.repositories.length }, { key: "files", label: "Files", count: contract.files.length }, { key: "tasks", label: "Tasks", count: contract.tasks.length }, ]; return (
{/* Header */}
{isEditing ? ( <> ) : ( <> )}
{isEditing ? (
setName(e.target.value)} className="w-full px-3 py-2 bg-[#0d1b2d] border border-[#3f6fb3] text-[#dbe7ff] font-mono text-sm focus:outline-none focus:border-[#75aafc]" placeholder="Contract name" />