"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { WorkspaceWriteBackPhase } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/writeback_pb";
import { cn } from "@stigmer/theme";
/**
 * Renders a single workspace write-back outcome as a compact card.
 *
 * Shows the workspace entry name, branch, diff summary, phase
 * indicator, and a "View PR" link when the pull request was
 * successfully created. On failure, displays the error message.
 *
 * Themed via standard semantic tokens — no hardcoded colors, no
 * Console dependencies. Embedders can theme this card through
 * their Tailwind/CSS configuration.
 *
 * @example
 * ```tsx
 * const { writeBacks } = useWorkspaceWriteBacks(execution);
 *
 * {writeBacks.map((wb) => (
 *   <WriteBackCard
 *     key={wb.workspaceEntryName}
 *     writeBack={wb}
 *   />
 * ))}
 * ```
 *
 * @see useWorkspaceWriteBacks — extracts write-back data from an execution
 */
export function WriteBackCard({ writeBack, className }) {
    const isFailed = writeBack.phase === WorkspaceWriteBackPhase.WORKSPACE_WRITE_BACK_FAILED;
    const hasPR = !!writeBack.pullRequestUrl;
    return (_jsxs("div", { role: "article", "aria-label": `Write-back: ${writeBack.workspaceEntryName}`, className: cn("rounded-md border p-3", isFailed ? "border-destructive/40" : "border-border", className), children: [_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "mt-0.5 shrink-0 text-muted-foreground", children: _jsx(GitBranchIcon, {}) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "truncate text-sm font-medium text-foreground", children: writeBack.workspaceEntryName }), _jsx(PhaseBadge, { phase: writeBack.phase })] }), writeBack.branchName && (_jsxs("div", { className: "mt-0.5 truncate font-mono text-xs text-muted-foreground", children: [writeBack.branchName, writeBack.baseBranch && (_jsxs("span", { className: "text-muted-foreground-subtle", children: [" \u2190 ", writeBack.baseBranch] }))] }))] })] }), writeBack.diffSummary && (_jsx("div", { className: "mt-1.5 whitespace-pre-wrap font-mono text-xs text-muted-foreground", children: writeBack.diffSummary })), isFailed && writeBack.error && (_jsx("div", { className: "mt-1.5 rounded bg-destructive-subtle px-2 py-1 text-xs text-destructive", children: writeBack.error })), hasPR && (_jsx("div", { className: "mt-2", children: _jsxs("a", { href: writeBack.pullRequestUrl, target: "_blank", rel: "noopener noreferrer", className: cn("inline-flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:text-primary-muted", FOCUS_RING_CLASSES), children: [_jsx(ExternalLinkIcon, {}), "View PR #", writeBack.pullRequestNumber] }) }))] }));
}
// ---------------------------------------------------------------------------
// Phase badge
// ---------------------------------------------------------------------------
const PHASE_CONFIG = {
    [WorkspaceWriteBackPhase.WORKSPACE_WRITE_BACK_COMMITTED]: {
        label: "Committed",
        className: "bg-muted text-muted-foreground",
    },
    [WorkspaceWriteBackPhase.WORKSPACE_WRITE_BACK_PUSHED]: {
        label: "Pushed",
        className: "bg-muted text-muted-foreground",
    },
    [WorkspaceWriteBackPhase.WORKSPACE_WRITE_BACK_PR_CREATED]: {
        label: "PR Created",
        className: "bg-primary-subtle text-primary",
    },
    [WorkspaceWriteBackPhase.WORKSPACE_WRITE_BACK_FAILED]: {
        label: "Failed",
        className: "bg-destructive-subtle text-destructive",
    },
};
function PhaseBadge({ phase }) {
    const config = PHASE_CONFIG[phase];
    if (!config)
        return null;
    return (_jsx("span", { className: cn("inline-flex shrink-0 items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium leading-none", config.className), children: config.label }));
}
// ---------------------------------------------------------------------------
// Shared style constants
// ---------------------------------------------------------------------------
const FOCUS_RING_CLASSES = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:rounded-sm";
// ---------------------------------------------------------------------------
// Inline SVG icons
// ---------------------------------------------------------------------------
function GitBranchIcon() {
    return (_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "4", cy: "3.5", r: "1.5" }), _jsx("circle", { cx: "4", cy: "10.5", r: "1.5" }), _jsx("circle", { cx: "10", cy: "5.5", r: "1.5" }), _jsx("path", { d: "M4 5V9" }), _jsx("path", { d: "M10 7V5.5" }), _jsx("path", { d: "M4 5C4 5 4 7 7 7C10 7 10 5.5 10 5.5" })] }));
}
function ExternalLinkIcon() {
    return (_jsxs("svg", { width: "10", height: "10", viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", className: "shrink-0", "aria-hidden": "true", children: [_jsx("path", { d: "M9 3L3 9" }), _jsx("path", { d: "M5 3H9V7" }), _jsx("path", { d: "M9 8V10H2V3H4" })] }));
}
//# sourceMappingURL=WriteBackCard.js.map