"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// One rendered terminal session: the `$ command` prompt line followed by its
// output, as a single block. Rendered on the same `bg-muted-subtle` surface as
// every other code/output block (CollapsibleCode, search, list) — not a
// bespoke dark box — so it tracks the host theme, preset, and color mode.
import { cn } from "@stigmer/theme";
import { CollapsiblePre } from "./tool-rendering-primitives.js";
import { useSandboxNormalize } from "./SandboxContext.js";
/**
 * Renders a shell tool call as a single, cohesive terminal session — the
 * command prompt line immediately followed by its output — instead of a
 * separate command box and output box.
 *
 * Used by {@link ResultView} (full session) and the approval gate's
 * {@link ToolArgsView} (command-only, pre-execution). Importable on its own by
 * platform builders composing custom tool UIs.
 *
 * @example
 * ```tsx
 * <TerminalSession command="ls -la" stdout="total 8\n..." exitCode={0} />
 * <TerminalSession command="npm test" /> // gate: command only
 * ```
 */
export function TerminalSession({ command, stdout, stderr, exitCode, className, }) {
    const normalize = useSandboxNormalize();
    const failed = exitCode !== undefined && exitCode !== 0;
    return (_jsxs("div", { "data-cursor-target": "terminal-session", className: cn("space-y-1 rounded-md border border-border bg-muted-subtle p-2.5 font-mono text-xs", className), children: [command && (
            // A plain <pre> (not CollapsiblePre): the command is the user's intent
            // and renders in full — even a multi-line heredoc — without a second
            // truncation toggle competing with stdout's.
            _jsxs("pre", { className: "whitespace-pre-wrap break-words text-foreground", children: [_jsx("span", { className: "select-none text-muted-foreground", children: "$ " }), normalize(command)] })), stdout && (_jsx(CollapsiblePre, { content: normalize(stdout), className: "text-foreground" })), stderr && (_jsx(CollapsiblePre, { content: normalize(stderr), className: "text-destructive" })), failed && (_jsxs("div", { children: [_jsxs("span", { className: "sr-only", children: ["Command exited with code ", exitCode] }), _jsxs("span", { "aria-hidden": "true", className: "inline-block rounded bg-destructive-subtle px-1 py-0.5 text-[10px] font-medium leading-none tabular-nums text-destructive", children: ["exit ", exitCode] })] }))] }));
}
//# sourceMappingURL=TerminalSession.js.map