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;
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
import React, { useContext } from "react";
import { BubbleConfigContext } from "../../../../Bubble/BubbleConfigProvide";
import { SchemaRenderer } from "../../../../Schema";
import { debugInfo } from "../../../../Utils/debugUtils";
import { useEditorStore } from "../../store";
/**
 * ReadonlySchema 组件 - 只读模式渲染组件
 *
 * 专门针对 readonly 模式优化的模式组件，移除了编辑相关功能。
 * 简化渲染逻辑，提升预览模式性能。
 *
 * @component
 * @description 只读模式预览组件，用于预览模式下的模式渲染
 * @param {RenderElementProps} props - 组件属性
 * @param {any} props.element - 模式节点元素
 * @param {React.ReactNode} props.children - 子组件内容
 * @param {Object} props.attributes - 元素属性
 *
 * @example
 * ```tsx
 * <ReadonlySchema
 *   element={schemaNode}
 *   attributes={attributes}
 * >
 *   模式内容
 * </ReadonlySchema>
 * ```
 *
 * @returns {React.ReactElement} 渲染的只读模式组件
 *
 * @remarks
 * - 移除编辑相关功能
 * - 使用 React.memo 优化性能
 * - 保持预览模式的视觉效果
 */ export var ReadonlySchema = /*#__PURE__*/ React.memo(function(props) {
    debugInfo('ReadonlySchema - 渲染只读 Schema', {
        language: props.element.language,
        valueType: _type_of(props.element.value),
        hasApaasify: !!props.element.apaasify
    });
    var node = props.element;
    var editorProps = useEditorStore().editorProps;
    var apaasify = (editorProps === null || editorProps === void 0 ? void 0 : editorProps.apaasify) || (editorProps === null || editorProps === void 0 ? void 0 : editorProps.apassify);
    var bubble = (useContext(BubbleConfigContext) || {}).bubble;
    if ((apaasify === null || apaasify === void 0 ? void 0 : apaasify.enable) && apaasify.render) {
        debugInfo('ReadonlySchema - 使用自定义 apaasify 渲染');
        var renderedContent = apaasify.render(props, bubble === null || bubble === void 0 ? void 0 : bubble.originData);
        return /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, node.attributes), {
            "data-testid": "schema-container",
            contentEditable: false,
            style: {
                display: 'flex',
                flexDirection: 'column',
                userSelect: 'text',
                WebkitUserSelect: 'text'
            }
        }), renderedContent, /*#__PURE__*/ React.createElement("div", {
            "data-testid": "schema-hidden-json",
            style: {
                height: 1,
                opacity: 0,
                userSelect: 'none',
                pointerEvents: 'none',
                overflow: 'hidden'
            }
        }, JSON.stringify(props.element.value, null, 2)));
    }
    if (node.language === 'agentar-card') {
        var _props_element_value;
        debugInfo('ReadonlySchema - 使用 AgentAR 卡片渲染');
        return /*#__PURE__*/ React.createElement("div", {
            "data-testid": "agentar-card-container",
            style: {
                padding: '0.5em'
            },
            "data-agentar-card": true
        }, /*#__PURE__*/ React.createElement(SchemaRenderer, {
            schema: props.element.value,
            values: ((_props_element_value = props.element.value) === null || _props_element_value === void 0 ? void 0 : _props_element_value.initialValues) || {},
            useDefaultValues: false,
            debug: false,
            fallbackContent: null
        }));
    }
    debugInfo('ReadonlySchema - 使用默认 JSON 渲染');
    return /*#__PURE__*/ React.createElement("pre", _object_spread_props(_object_spread({}, props.attributes), {
        style: {
            background: 'rgb(242, 241, 241)',
            color: 'rgb(27, 27, 27)',
            padding: '1em',
            borderRadius: '0.5em',
            margin: '1em 0',
            fontSize: '0.8em',
            fontFamily: 'monospace',
            lineHeight: '1.5',
            overflowX: 'auto',
            whiteSpace: 'pre-wrap',
            wordBreak: 'break-all',
            wordWrap: 'break-word'
        }
    }), /*#__PURE__*/ React.createElement("code", null, JSON.stringify(props.element.value, null, 2)), /*#__PURE__*/ React.createElement("div", {
        style: {
            display: 'none'
        }
    }, props.children));
});
ReadonlySchema.displayName = 'ReadonlySchema';
