import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { createContext, useContext } from "react";
import { Text, Box } from "ink";
import { NoSelect } from "./NoSelect.js";
import { Ratchet } from "./Ratchet.js";
import { RETURN_SYMBOL } from "../constants/figures.js";
/**
 * Context that prevents nested MessageResponse components from rendering
 * duplicate ⎿ brackets — child MessageResponses check the context and
 * return just their children without the bracket wrapper.
 */
const MessageResponseContext = createContext(false);
/**
 * Tool result bracket wrapper.
 *
 * Renders the `⎿` bracket pattern used by claude-code to visually
 * distinguish tool output from regular text:
 *
 * ```
 *   ⎿  [content]
 * ```
 *
 * - Left gutter: 2 spaces + bracket + 2 spaces (6 chars), dimColor,
 *   wrapped in NoSelect so terminal copy-paste skips the bracket.
 * - React Context prevents nested brackets when a tool result contains
 *   another tool result (e.g. subagent output).
 * - Wrapped in Ratchet (lock="offscreen") to prevent height shrinking
 *   during streaming re-parses, unless an explicit height is provided.
 */
export function MessageResponse({ children, height, accentColor }) {
    const isNested = useContext(MessageResponseContext);
    // Prevent double brackets in nested tool results
    if (isNested) {
        return _jsx(_Fragment, { children: children });
    }
    const content = (_jsx(MessageResponseContext, { value: true, children: _jsxs(Box, { flexDirection: "row", height: height, overflowY: "hidden", children: [_jsx(NoSelect, { fromLeftEdge: true, flexShrink: 0, children: _jsxs(Text, { color: accentColor, dimColor: true, children: ["  ", RETURN_SYMBOL, "  "] }) }), _jsx(Box, { flexShrink: 1, flexGrow: 1, children: children })] }) }));
    if (height !== undefined) {
        return content;
    }
    return _jsx(Ratchet, { lock: "offscreen", children: content });
}
//# sourceMappingURL=MessageResponse.js.map