"use client"; import { useState, type ReactNode } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { ArrowRight, CheckCircle2, ClipboardCheck, FileText, LockKeyhole, UserCheck } from "lucide-react"; import { StepControls } from "@/components/visualizations/shared/step-controls"; import { useSteppedVisualization } from "@/hooks/useSteppedVisualization"; import { cn } from "@/lib/utils"; type Protocol = "shutdown" | "plan"; const REQUEST_ID = "req_abc"; const SHUTDOWN_STEPS = [ { title: "Agree on a Small Form", desc: "A protocol is just a shared card shape: request type, request_id, and the expected answer.", }, { title: "Leader Files a Request", desc: "The leader writes a shutdown request card instead of force-stopping the teammate.", }, { title: "Teammate Chooses", desc: "The teammate can approve or reject, and the request_id keeps the answer attached to the right request.", }, { title: "Clean Exit", desc: "The approved response returns to the leader, and the teammate exits cleanly.", }, ]; const PLAN_STEPS = [ { title: "Work Is Locked", desc: "In plan mode, implementation stays locked until a plan card is approved.", }, { title: "Submit the Plan Card", desc: "The teammate sends a concrete plan with the same request-response shape.", }, { title: "Approval Unlocks Action", desc: "The leader approves the card, then implementation can begin.", }, ]; const PROTOCOL_STATES: Record = { shutdown: [ { label: "drafted", detail: "Lead creates request_id" }, { label: "pending", detail: "card waits in inbox" }, { label: "deciding", detail: "teammate replies" }, { label: "closed", detail: "Lead matches response" }, ], plan: [ { label: "locked", detail: "work cannot start" }, { label: "submitted", detail: "plan card is sent" }, { label: "approved", detail: "implementation unlocks" }, ], }; function ToggleButton({ active, onClick, children, }: { active: boolean; onClick: () => void; children: ReactNode; }) { return ( ); } function StateRail({ states, currentStep, }: { states: { label: string; detail: string }[]; currentStep: number; }) { return (
Protocol state
request_id: {REQUEST_ID}
{states.map((state, index) => { const active = index === currentStep; const done = index < currentStep; return (
{state.label}
{state.detail}
{index < states.length - 1 && (
)}
); })}
); } function Desk({ title, icon, active, children, }: { title: string; icon: ReactNode; active: boolean; children: ReactNode; }) { return (
{icon} {title}
{children}
); } function ProtocolCard({ title, rows, tone = "blue", }: { title: string; rows: string[]; tone?: "blue" | "amber" | "emerald" | "zinc"; }) { const toneClass = { blue: "border-blue-200 bg-blue-50 text-blue-800 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-200", amber: "border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-200", emerald: "border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-200", zinc: "border-zinc-200 bg-zinc-50 text-zinc-700 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-200", }[tone]; return (
{title}
{rows.map((row) => (
{row}
))}
); } function EmptyTray({ label }: { label: string }) { return (
{label}
); } export default function TeamProtocols({ title }: { title?: string }) { const [protocol, setProtocol] = useState("shutdown"); const steps = protocol === "shutdown" ? SHUTDOWN_STEPS : PLAN_STEPS; const vis = useSteppedVisualization({ totalSteps: steps.length, autoPlayInterval: 2500 }); const step = vis.currentStep; const switchProtocol = (value: Protocol) => { setProtocol(value); vis.reset(); }; const isPlan = protocol === "plan"; return (

{title || "Team Protocol Cards"}

switchProtocol("shutdown")}> Shutdown switchProtocol("plan")}> Plan Approval
} active={(!isPlan && (step === 1 || step === 3)) || (isPlan && step === 2)} >
{!isPlan && step >= 1 && ( = 3 ? "zinc" : "blue"} /> )} {!isPlan && step >= 3 && ( )} {isPlan && step >= 2 && ( )} {((!isPlan && step === 0) || (isPlan && step < 2)) && ( )}
} active={(!isPlan && step === 0) || (isPlan && step === 0)} >
The key idea is correlation, not ceremony.
{isPlan && (
implementation locked until approval
)}
: } active={(!isPlan && step === 2) || (isPlan && step === 1)} >
{!isPlan && step >= 2 && ( = 3 ? "state: exited" : "state: deciding"]} tone={step >= 3 ? "emerald" : "amber"} /> )} {isPlan && step >= 1 && ( = 2 ? "emerald" : "blue"} /> )} {((!isPlan && step < 2) || (isPlan && step === 0)) && ( )}
); }