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 React, { useContext } from "react";
import { ThoughtChainList } from "../ThoughtChainList";
import { BubbleConfigContext } from "./BubbleConfigProvide";
var DEFAULT_TASK_LIST = [
    {
        info: '理解问题'
    }
];
var getTaskList = function(whiteBoxProcess) {
    return [
        whiteBoxProcess
    ].flat(2).filter(function(item) {
        return item === null || item === void 0 ? void 0 : item.info;
    });
};
var canRenderThoughtChain = function(placement, role, thoughtChainEnabled) {
    if (placement !== 'left') return false;
    if (role === 'bot') return false;
    if (thoughtChainEnabled === false) return false;
    return true;
};
/**
 * BubbleBeforeNode 组件
 *
 * 在聊天气泡之前渲染思维链或任务列表，显示AI的思考过程
 *
 * @example
 * ```tsx
 * <BubbleBeforeNode bubble={bubbleData} />
 * ```
 */ export var BubbleBeforeNode = function(param) {
    var bubble = param.bubble, className = param.className, style = param.style;
    var _context_thoughtChain, _originData_extra, _context_thoughtChain1, _context_thoughtChain2;
    var context = useContext(BubbleConfigContext);
    var placement = bubble.placement, originData = bubble.originData;
    if (!canRenderThoughtChain(placement, originData === null || originData === void 0 ? void 0 : originData.role, context === null || context === void 0 ? void 0 : (_context_thoughtChain = context.thoughtChain) === null || _context_thoughtChain === void 0 ? void 0 : _context_thoughtChain.enable)) {
        return null;
    }
    var taskList = getTaskList(originData === null || originData === void 0 ? void 0 : (_originData_extra = originData.extra) === null || _originData_extra === void 0 ? void 0 : _originData_extra.white_box_process);
    if (taskList.length < 1 && !(context === null || context === void 0 ? void 0 : (_context_thoughtChain1 = context.thoughtChain) === null || _context_thoughtChain1 === void 0 ? void 0 : _context_thoughtChain1.alwaysRender)) {
        return null;
    }
    if (context === null || context === void 0 ? void 0 : (_context_thoughtChain2 = context.thoughtChain) === null || _context_thoughtChain2 === void 0 ? void 0 : _context_thoughtChain2.render) {
        return context.thoughtChain.render(bubble, taskList.join(','));
    }
    var isFinished = (originData === null || originData === void 0 ? void 0 : originData.isFinished) || (originData === null || originData === void 0 ? void 0 : originData.isAborted);
    var isLoading = (originData === null || originData === void 0 ? void 0 : originData.content) === '...';
    return /*#__PURE__*/ React.createElement(ThoughtChainList, _object_spread_props(_object_spread({}, context === null || context === void 0 ? void 0 : context.thoughtChain), {
        className: className,
        style: style,
        bubble: _object_spread_props(_object_spread({}, originData), {
            isFinished: isFinished
        }),
        finishAutoCollapse: true,
        thoughtChainList: taskList.length ? taskList : DEFAULT_TASK_LIST,
        loading: isLoading
    }));
};
