function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
import DOMPurify from "dompurify";
import React from "react";
import { debugInfo } from "../../../../Utils/debugUtils";
/**
 * ReadonlyCode 组件 - 只读代码块预览组件
 *
 * 专门针对 readonly 模式优化的代码块组件，移除了编辑相关功能。
 * 简化渲染逻辑，提升预览模式性能。
 *
 * @component
 * @description 只读代码块预览组件，用于预览模式下的代码块渲染
 * @param {RenderElementProps} props - 组件属性
 * @param {any} props.element - 代码块节点元素
 * @param {React.ReactNode} props.children - 子组件内容
 * @param {Object} props.attributes - 元素属性
 *
 * @example
 * ```tsx
 * <ReadonlyCode
 *   element={codeNode}
 *   attributes={attributes}
 * >
 *   代码内容
 * </ReadonlyCode>
 * ```
 *
 * @returns {React.ReactElement} 渲染的只读代码块组件
 *
 * @remarks
 * - 简化渲染逻辑，移除编辑相关功能
 * - 使用 React.memo 优化性能
 * - 保持预览模式的视觉效果
 */ export var ReadonlyCode = /*#__PURE__*/ React.memo(function(param) {
    var attributes = param.attributes, children = param.children, element = param.element;
    var _element_value, _element_otherProps, _element_otherProps1, _element_otherProps2, _element_value1, _element_otherProps3, _element_value2;
    debugInfo('ReadonlyCode - 渲染只读代码块', {
        language: element === null || element === void 0 ? void 0 : element.language,
        valueLength: element === null || element === void 0 ? void 0 : (_element_value = element.value) === null || _element_value === void 0 ? void 0 : _element_value.length,
        isConfig: element === null || element === void 0 ? void 0 : (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.isConfig,
        finished: element === null || element === void 0 ? void 0 : (_element_otherProps1 = element.otherProps) === null || _element_otherProps1 === void 0 ? void 0 : _element_otherProps1.finished
    });
    // HTML 代码块处理
    if ((element === null || element === void 0 ? void 0 : element.language) === 'html') {
        var _element_otherProps4, _element_otherProps5, _element_otherProps6, _element_value3;
        debugInfo('ReadonlyCode - HTML 代码块', {
            isConfig: element === null || element === void 0 ? void 0 : (_element_otherProps4 = element.otherProps) === null || _element_otherProps4 === void 0 ? void 0 : _element_otherProps4.isConfig
        });
        return /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, attributes), {
            style: {
                display: (element === null || element === void 0 ? void 0 : (_element_otherProps5 = element.otherProps) === null || _element_otherProps5 === void 0 ? void 0 : _element_otherProps5.isConfig) ? 'none' : 'block'
            }
        }), (element === null || element === void 0 ? void 0 : (_element_otherProps6 = element.otherProps) === null || _element_otherProps6 === void 0 ? void 0 : _element_otherProps6.isConfig) ? '' : DOMPurify.sanitize(element === null || element === void 0 ? void 0 : (_element_value3 = element.value) === null || _element_value3 === void 0 ? void 0 : _element_value3.trim()));
    }
    // 检查代码块是否未闭合
    var isUnclosed = (element === null || element === void 0 ? void 0 : (_element_otherProps2 = element.otherProps) === null || _element_otherProps2 === void 0 ? void 0 : _element_otherProps2.finished) === false;
    debugInfo('ReadonlyCode - 普通代码块', {
        language: element === null || element === void 0 ? void 0 : element.language,
        isUnclosed: isUnclosed,
        valueLength: element === null || element === void 0 ? void 0 : (_element_value1 = element.value) === null || _element_value1 === void 0 ? void 0 : _element_value1.length
    });
    return /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, attributes), {
        "data-is-unclosed": isUnclosed,
        "data-language": element === null || element === void 0 ? void 0 : element.language,
        style: (element === null || element === void 0 ? void 0 : element.language) === 'html' ? {
            display: (element === null || element === void 0 ? void 0 : (_element_otherProps3 = element.otherProps) === null || _element_otherProps3 === void 0 ? void 0 : _element_otherProps3.isConfig) ? 'none' : 'block'
        } : {
            height: '240px',
            minWidth: '398px',
            maxWidth: '800px',
            minHeight: '240px',
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            alignSelf: 'stretch',
            zIndex: 5,
            color: 'rgb(27, 27, 27)',
            padding: '1em',
            margin: '1em 0',
            fontSize: '0.8em',
            lineHeight: '1.5',
            overflowX: 'auto',
            whiteSpace: 'pre-wrap',
            wordBreak: 'break-all',
            fontFamily: "'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace",
            wordWrap: 'break-word',
            borderRadius: '12px',
            background: '#FFFFFF',
            boxShadow: 'var(--shadow-control-base)',
            position: 'relative'
        }
    }), (element === null || element === void 0 ? void 0 : (_element_value2 = element.value) === null || _element_value2 === void 0 ? void 0 : _element_value2.trim()) || children);
});
ReadonlyCode.displayName = 'ReadonlyCode';
