import { useState } from "react"; import type { ContractPhase } from "../../lib/api"; /** Phase configuration for styling */ const phaseConfig: Record< ContractPhase, { label: string; color: string; borderColor: string } > = { research: { label: "Research", color: "text-purple-400", borderColor: "border-purple-400/50", }, specify: { label: "Specify", color: "text-blue-400", borderColor: "border-blue-400/50", }, plan: { label: "Plan", color: "text-cyan-400", borderColor: "border-cyan-400/50", }, execute: { label: "Execute", color: "text-green-400", borderColor: "border-green-400/50", }, review: { label: "Review", color: "text-yellow-400", borderColor: "border-yellow-400/50", }, }; export interface PhaseConfirmationData { questionId: string; contractId: string; contractName?: string; currentPhase: ContractPhase; nextPhase: ContractPhase; summary?: string; deliverables?: Array<{ name: string; completed: boolean; }>; } interface PhaseConfirmationModalProps { data: PhaseConfirmationData; onApprove: (questionId: string) => Promise; onRequestChanges: (questionId: string, feedback: string) => Promise; onDismiss?: () => void; } export function PhaseConfirmationModal({ data, onApprove, onRequestChanges, onDismiss, }: PhaseConfirmationModalProps) { const [mode, setMode] = useState<"choice" | "feedback">("choice"); const [feedback, setFeedback] = useState(""); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const currentConfig = phaseConfig[data.currentPhase]; const nextConfig = phaseConfig[data.nextPhase]; const handleApprove = async () => { setSubmitting(true); setError(null); try { await onApprove(data.questionId); } catch (err) { setError(err instanceof Error ? err.message : "Failed to approve"); } finally { setSubmitting(false); } }; const handleRequestChanges = () => { setMode("feedback"); }; const handleSubmitFeedback = async () => { if (!feedback.trim()) return; setSubmitting(true); setError(null); try { await onRequestChanges(data.questionId, feedback.trim()); } catch (err) { setError(err instanceof Error ? err.message : "Failed to submit feedback"); } finally { setSubmitting(false); } }; const handleBack = () => { setMode("choice"); setFeedback(""); setError(null); }; return (
{/* Header */}
?

Phase Transition Confirmation

{onDismiss && ( )}
{/* Content */}
{/* Contract name */} {data.contractName && (

Contract: {data.contractName}

)} {/* Phase transition indicator */}
{currentConfig.label}
{nextConfig.label}
{/* Summary */} {data.summary && (

Phase Summary

{data.summary}

)} {/* Deliverables checklist */} {data.deliverables && data.deliverables.length > 0 && (

Phase Deliverables

    {data.deliverables.map((d, idx) => (
  • {d.completed ? "+" : "-"} {d.name}
  • ))}
)} {/* Error message */} {error && (
{error}
)} {/* Choice mode */} {mode === "choice" && (

Ready to advance to the {nextConfig.label.toLowerCase()} phase?

)} {/* Feedback mode */} {mode === "feedback" && (