"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useMemo } from "react";
import { Streamdown } from "streamdown";
import { cn } from "@stigmer/theme";
import { PLAN_DOCUMENT_MARKDOWN_COMPONENTS, extractLeadingH1, unwrapEnclosingMarkdownFence, } from "../internal/markdown-components.js";
/**
 * Renders a Plan-mode turn's plan as a first-class document instead of a chat
 * bubble: a bordered card with a title header (the plan's leading `# H1`,
 * lifted out of the prose) and document-grade typography
 * ({@link PLAN_DOCUMENT_MARKDOWN_COMPONENTS}).
 *
 * This is the thread's NO-ARTIFACT fallback: a completed Plan turn that never
 * published `plan.md` (older executions, a failed upload) keeps its plan
 * inline via this component — the message is the only copy of the plan, so it
 * must stay readable in place. A turn that DID publish the artifact collapses
 * its plan message into the compact `PlanArtifactCard` instead, and the
 * document renders in the session panel's plan tab (`PlanEditor`) with the
 * same typography.
 *
 * Fence handling is plan-scoped: a plan wrapped in a whole-body fence is
 * unwrapped even when the fence carries no language tag (`allowBareFence`) —
 * a Plan turn's output is a markdown document by contract, so an enclosing
 * bare fence is wrapping, not code. Render-time only; the transcript and the
 * published artifact stay byte-faithful.
 *
 * Purely presentational — no data fetching, no state.
 * All visual properties flow through `--stgm-*` tokens.
 */
export const PlanDocumentMessage = memo(function PlanDocumentMessage({ content, className, }) {
    const { title, body } = useMemo(() => extractLeadingH1(unwrapEnclosingMarkdownFence(content, true)), [content]);
    return (_jsx("div", { role: "article", "aria-label": "Plan document", className: cn("mx-4", className), children: _jsxs("div", { className: "overflow-hidden rounded-lg border border-border-muted bg-card", children: [_jsxs("header", { className: "flex items-center gap-2 border-b border-border-muted bg-muted-faint px-4 py-2.5", children: [_jsx(PlanDocIcon, {}), _jsx("span", { className: "min-w-0 flex-1 truncate text-sm font-semibold text-foreground", children: title ?? "Plan" })] }), _jsx("div", { className: "stgm-prose px-4 py-4", children: _jsx(Streamdown, { components: PLAN_DOCUMENT_MARKDOWN_COMPONENTS, isAnimating: false, children: body }) })] }) }));
});
function PlanDocIcon() {
    return (_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", className: "shrink-0 text-muted-foreground", "aria-hidden": "true", children: [_jsx("path", { d: "M3 4h10M3 8h7M3 12h8" }), _jsx("path", { d: "M12.5 10.5l1.5 1.5-1.5 1.5" })] }));
}
//# sourceMappingURL=PlanDocumentMessage.js.map