/**
 * @fileoverview 思考块组件
 * 只读模式下渲染思考类型的代码块
 */ import React, { useContext } from "react";
import { I18nContext } from "../../../I18n";
import { EditorStoreContext } from "../../../MarkdownEditor/editor/store";
import { ToolUseBarThink } from "../../../ToolUseBar";
/**
 * 将特殊标记恢复为代码块格式
 * @param content - 包含特殊标记的内容
 * @returns 恢复后的内容
 */ var restoreCodeBlocks = function(content) {
    var marker = '\u200B'; // 零宽空格
    // 将格式：【CODE_BLOCK:lang】code【/CODE_BLOCK】
    // 恢复为：```lang\ncode\n```
    return content.replace(new RegExp("".concat(marker, "【CODE_BLOCK:([\\w]*)】\\n?([\\s\\S]*?)\\n?【/CODE_BLOCK】").concat(marker), 'g'), function(_, lang, code) {
        return "```".concat(lang, "\n").concat(code, "\n```");
    });
};
export function ThinkBlock(param) {
    var element = param.element;
    var _editorProps_codeProps;
    var locale = useContext(I18nContext).locale;
    var editorProps = (useContext(EditorStoreContext) || {}).editorProps;
    var rawContent = (element === null || element === void 0 ? void 0 : element.value) !== null && (element === null || element === void 0 ? void 0 : element.value) !== undefined ? String(element.value).trim() : '';
    // 恢复内容中被转义的代码块
    var content = restoreCodeBlocks(rawContent);
    var isLoading = content.endsWith('...');
    var toolNameText = isLoading ? (locale === null || locale === void 0 ? void 0 : locale['think.deepThinkingInProgress']) || '深度思考...' : (locale === null || locale === void 0 ? void 0 : locale['think.deepThinking']) || '深度思考';
    return /*#__PURE__*/ React.createElement(ToolUseBarThink, {
        testId: "think-block",
        styles: {
            root: {
                boxSizing: 'border-box',
                maxWidth: '680px'
            }
        },
        expanded: (editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_codeProps = editorProps.codeProps) === null || _editorProps_codeProps === void 0 ? void 0 : _editorProps_codeProps.alwaysExpandedDeepThink) ? true : undefined,
        toolName: toolNameText,
        thinkContent: content,
        status: isLoading ? 'loading' : 'success'
    });
}
