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 { memo, useMemo } from "react";
import React from "react";
import { debugInfo } from "../Utils/debugUtils";
import { AIBubble } from "./AIBubble";
import { bubblePropsAreEqual } from "./bubblePropsAreEqual";
import { useSchemaEditorBridge } from "./schema-editor";
import { UserBubble } from "./UserBubble";
/**
 * Bubble 组件 - 聊天气泡组件（智能分发器）
 *
 * 该组件是聊天气泡的智能分发器，根据消息角色自动选择合适的子组件进行渲染。
 * - 用户消息（role: 'user'）使用 UserBubble 组件，采用右侧布局
 * - AI消息（其他角色）使用 AIBubble 组件，采用左侧布局，支持完整交互功能
 *
 * @component
 * @description 聊天气泡智能分发组件，根据消息角色自动选择渲染方式
 * @param {BubbleProps & {deps?: any[], bubbleRef?: MutableRefObject<any>}} props - 组件属性
 * @param {string} [props.placement] - 气泡位置，会被自动覆盖
 * @param {BubbleAvatarProps} [props.avatar] - 头像配置
 * @param {string | number | Date} [props.time] - 消息时间
 * @param {React.ReactNode} [props.children] - 消息内容
 * @param {string} [props.className] - 自定义CSS类名
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {BubbleRenderConfig} [props.bubbleRenderConfig] - 气泡渲染配置
 * @param {BubbleClassNames} [props.classNames] - 自定义类名配置
 * @param {BubbleStyles} [props.styles] - 自定义样式配置
 * @param {Function} [props.onAvatarClick] - 头像点击回调
 * @param {any[]} [props.deps] - 依赖数组
 * @param {MutableRefObject} [props.bubbleRef] - 气泡引用
 * @param {MessageBubbleData} [props.originData] - 消息数据，包含角色信息
 * @example
 * ```tsx
 * // 用户消息会自动使用 UserBubble
 * <Bubble
 *   originData={{ role: 'user', content: '你好' }}
 *   avatar={{ avatar: "user.jpg", title: "用户" }}
 * />
 *
 * // AI消息会自动使用 AIBubble
 * <Bubble
 *   originData={{ role: 'assistant', content: '你好！有什么可以帮助你的吗？' }}
 *   avatar={{ avatar: "ai.jpg", title: "AI助手" }}
 * />
 *
 * // Schema Editor 在开发环境下自动启用
 * // 需要传入 id 以支持插件识别
 * <Bubble
 *   id="msg-1"
 *   originData={{ id: 'msg-1', role: 'assistant', originContent: '# Hello' }}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的聊天气泡组件
 */ var BubbleComponent = function BubbleComponent(props) {
    var originData = props.originData;
    var isStringContent = typeof (originData === null || originData === void 0 ? void 0 : originData.content) === 'string';
    // Schema Editor Bridge - 开发环境自动启用
    var content = useSchemaEditorBridge(props.id, isStringContent ? originData.content : '').content;
    debugInfo('useSchemaEditorBridge', content);
    // 根据角色自动选择组件
    var isUserMessage = props.placement === undefined ? (originData === null || originData === void 0 ? void 0 : originData.role) === 'user' : props.placement === 'right';
    // 稳定 originData 引用
    var memoizedOriginData = useMemo(function() {
        return originData ? _object_spread({}, originData, isStringContent && {
            content: content
        }) : undefined;
    }, [
        originData,
        isStringContent,
        originData === null || originData === void 0 ? void 0 : originData.isLast,
        content
    ]);
    // 计算 placement
    var placement = props.placement || (isUserMessage ? 'right' : 'left');
    // 构建传递给子组件的 props（避免使用 useMemo，因为 props 对象每次都会变化）
    var bubbleProps = _object_spread_props(_object_spread({}, props), {
        placement: placement,
        originData: memoizedOriginData
    });
    debugInfo('bubbleProps', {
        isUserMessage: isUserMessage,
        bubbleProps: bubbleProps
    });
    // 使用提前返回优化
    if (isUserMessage) {
        return /*#__PURE__*/ React.createElement(UserBubble, _object_spread(_object_spread_props(_object_spread({}, bubbleProps), {
            pure: false
        }), props.userBubbleProps));
    }
    return /*#__PURE__*/ React.createElement(AIBubble, _object_spread({}, bubbleProps, props.aIBubbleProps));
};
BubbleComponent.displayName = 'Bubble';
// 自定义比较：列表侧常传入新的 styles / avatar 对象引用；扩展 props 时同步 bubblePropsAreEqual
export var Bubble = /*#__PURE__*/ memo(BubbleComponent, bubblePropsAreEqual);
