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 SkeletonList from "./SkeletonList";
import { useContext, useMemo } from "react";
import { ConfigProvider } from "antd";
import cx from "classnames";
import React from "react";
import { PureAIBubble, PureUserBubble } from "../PureBubble";
import { BubbleConfigContext } from "../BubbleConfigProvide";
import { useStyle } from "./style";
export var PureBubbleList = function(props) {
    var bubbleList = props.bubbleList, bubbleListRef = props.bubbleListRef, bubbleRenderConfig = props.bubbleRenderConfig, className = props.className, classNames = props.classNames, docListProps = props.docListProps, isLoading = props.isLoading, markdownRenderConfig = props.markdownRenderConfig, onAvatarClick = props.onAvatarClick, onCancelLike = props.onCancelLike, onDisLike = props.onDisLike, onDoubleClick = props.onDoubleClick, onLike = props.onLike, onReply = props.onReply, onScroll = props.onScroll, onTouchMove = props.onTouchMove, onWheel = props.onWheel, shouldShowCopy = props.shouldShowCopy, shouldShowVoice = props.shouldShowVoice, style = props.style, styles = props.styles, userMeta = props.userMeta, assistantMeta = props.assistantMeta;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var compact = (useContext(BubbleConfigContext) || {}).compact;
    var prefixClass = getPrefixCls('agentic-bubble-list');
    var _useStyle = useStyle(prefixClass), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var deps = useMemo(function() {
        return [
            props.style
        ];
    }, [
        JSON.stringify(props.style)
    ]);
    var listDom = useMemo(function() {
        return bubbleList.map(function(item, index) {
            var placement = item.role === 'user' ? 'right' : 'left';
            var BubbleComponent = placement === 'right' ? PureUserBubble : PureAIBubble;
            var isLast = index === bubbleList.length - 1;
            item.isLatest = isLast;
            item.isLast = isLast;
            return /*#__PURE__*/ React.createElement(BubbleComponent, {
                key: item.id,
                "data-id": item.id,
                avatar: _object_spread({}, placement === 'right' ? userMeta : assistantMeta, item.meta),
                preMessage: bubbleList[index - 1],
                id: item.id,
                style: _object_spread({}, styles === null || styles === void 0 ? void 0 : styles.bubbleListItemStyle),
                originData: item,
                placement: placement,
                time: item.updateAt || item.createAt,
                deps: deps,
                pure: true,
                bubbleListRef: bubbleListRef,
                bubbleRenderConfig: bubbleRenderConfig,
                classNames: classNames,
                bubbleRef: props.bubbleRef,
                markdownRenderConfig: markdownRenderConfig,
                docListProps: docListProps,
                styles: _object_spread_props(_object_spread({}, styles), {
                    bubbleListItemContentStyle: _object_spread({}, styles === null || styles === void 0 ? void 0 : styles.bubbleListItemContentStyle, placement === 'right' ? styles === null || styles === void 0 ? void 0 : styles.bubbleListRightItemContentStyle : styles === null || styles === void 0 ? void 0 : styles.bubbleListLeftItemContentStyle)
                }),
                readonly: props.readonly,
                onReply: onReply,
                onDisLike: onDisLike,
                onLike: onLike,
                onCancelLike: onCancelLike,
                onAvatarClick: onAvatarClick,
                onDoubleClick: onDoubleClick,
                customConfig: bubbleRenderConfig === null || bubbleRenderConfig === void 0 ? void 0 : bubbleRenderConfig.customConfig,
                shouldShowCopy: shouldShowCopy,
                shouldShowVoice: shouldShowVoice
            });
        });
    }, [
        bubbleList,
        props.style
    ]);
    if (isLoading) {
        return wrapSSR(/*#__PURE__*/ React.createElement("div", {
            className: cx(prefixClass, "".concat(prefixClass, "-loading"), className, hashId),
            ref: bubbleListRef,
            style: {
                padding: 24
            }
        }, /*#__PURE__*/ React.createElement(SkeletonList, null)));
    }
    var _obj;
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: cx("".concat(prefixClass), className, hashId, (_obj = {}, _define_property(_obj, "".concat(prefixClass, "-readonly"), props.readonly), _define_property(_obj, "".concat(prefixClass, "-compact"), compact), _obj)),
        "data-chat-list": bubbleList.length,
        style: style,
        ref: bubbleListRef,
        onScroll: onScroll,
        onWheel: function(event) {
            return onWheel === null || onWheel === void 0 ? void 0 : onWheel(event, (bubbleListRef === null || bubbleListRef === void 0 ? void 0 : bubbleListRef.current) || null);
        },
        onTouchMove: function(event) {
            return onTouchMove === null || onTouchMove === void 0 ? void 0 : onTouchMove(event, (bubbleListRef === null || bubbleListRef === void 0 ? void 0 : bubbleListRef.current) || null);
        }
    }, listDom));
};
export default PureBubbleList;
