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 { PlusOutlined } from "@ant-design/icons";
import { Button, ConfigProvider, Tooltip, Typography } from "antd";
import classNames from "clsx";
import { motion } from "framer-motion";
import React, { memo, useContext, useMemo } from "react";
import { I18nContext } from "../I18n";
import { PauseIcon, PlayIcon, SimplePauseIcon, SimplePlayIcon, SimpleStopIcon, StopIcon } from "./icons";
import Robot from "./Robot";
import { useStyle } from "./style";
import { AGENT_RUN_BAR_TEST_ID } from "./testIds";
export * from "./Robot";
export { AGENT_RUN_BAR_TEST_ID } from "./testIds";
/**
 * 控制按钮 Tooltip 的展示延迟（秒）。
 * 抽出为模块级常量，避免在多处复用 magic number；如需全局调整悬浮提示
 * 灵敏度，仅修改此常量即可。
 */ var TOOLTIP_DELAY_SECONDS = 0.3;
/**
 * 任务状态可选值列表
 *
 * @remarks
 * - `running`：任务正在运行中
 * - `success`：任务已成功完成
 * - `error`：任务执行出错
 * - `pause`：任务已暂停
 * - `stopped`：任务已停止
 * - `cancelled`：任务已取消
 */ export var TaskStatusList = [
    'running',
    'success',
    'error',
    'pause',
    'stopped',
    'cancelled'
];
/**
 * 任务运行状态可选值列表
 *
 * @remarks
 * - `running`：正在运行中
 * - `complete`：已完成
 * - `pause`：已暂停
 */ export var TaskRunningStatusList = [
    'running',
    'complete',
    'pause'
];
/**
 * 任务状态常量对象（向后兼容）
 *
 * 推荐直接使用字符串字面量（如 `'running'`），可获得更好的 tree-shaking 与类型推导。
 * 该对象保留以兼容旧代码 `TASK_STATUS.RUNNING` 的写法。
 */ export var TASK_STATUS = {
    RUNNING: 'running',
    SUCCESS: 'success',
    ERROR: 'error',
    PAUSE: 'pause',
    STOPPED: 'stopped',
    CANCELLED: 'cancelled'
};
/**
 * 任务运行状态常量对象（向后兼容）
 *
 * 推荐直接使用字符串字面量（如 `'running'`），可获得更好的 tree-shaking 与类型推导。
 * 该对象保留以兼容旧代码 `TASK_RUNNING_STATUS.RUNNING` 的写法。
 */ export var TASK_RUNNING_STATUS = {
    RUNNING: 'running',
    COMPLETE: 'complete',
    PAUSE: 'pause'
};
/**
 * 圆形控制按钮（停止 / 暂停 / 继续）。
 * 抽出以避免在「自定义 actionsRender 分支」与「默认分支」中重复 3 套 Tooltip+div 结构。
 */ var ControlIconButton = function ControlIconButton(param) {
    var kind = param.kind, title = param.title, onClick = param.onClick, icon = param.icon, baseCls = param.baseCls, hashId = param.hashId;
    return /*#__PURE__*/ React.createElement(Tooltip, {
        title: title,
        mouseEnterDelay: TOOLTIP_DELAY_SECONDS
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-").concat(kind), hashId),
        role: "button",
        tabIndex: 0,
        "aria-label": title,
        onClick: onClick
    }, icon));
};
/**
 * 控制按钮组：根据当前是否运行 / 是否暂停状态以及各回调可用性，
 * 决定渲染「停止 / 暂停 / 继续」三个圆形控制按钮的子集。
 */ var ControlButtons = function ControlButtons(param) {
    var isRunning = param.isRunning, isPause = param.isPause, variant = param.variant, onStop = param.onStop, onPause = param.onPause, onResume = param.onResume, locale = param.locale, baseCls = param.baseCls, hashId = param.hashId;
    var _locale_agentRunBar, _locale_agentRunBar1, _locale_agentRunBar2;
    var isSimple = variant === 'simple';
    return /*#__PURE__*/ React.createElement(React.Fragment, null, (isRunning || isPause) && onStop && /*#__PURE__*/ React.createElement(ControlIconButton, {
        kind: "pause",
        title: locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar = locale.agentRunBar) === null || _locale_agentRunBar === void 0 ? void 0 : _locale_agentRunBar.stop,
        onClick: onStop,
        icon: isSimple ? /*#__PURE__*/ React.createElement(SimpleStopIcon, null) : /*#__PURE__*/ React.createElement(StopIcon, null),
        baseCls: baseCls,
        hashId: hashId
    }), isRunning && onPause && /*#__PURE__*/ React.createElement(ControlIconButton, {
        kind: "pause",
        title: locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar1 = locale.agentRunBar) === null || _locale_agentRunBar1 === void 0 ? void 0 : _locale_agentRunBar1.pause,
        onClick: onPause,
        icon: isSimple ? /*#__PURE__*/ React.createElement(SimplePauseIcon, null) : /*#__PURE__*/ React.createElement(PauseIcon, null),
        baseCls: baseCls,
        hashId: hashId
    }), isPause && onResume && /*#__PURE__*/ React.createElement(ControlIconButton, {
        kind: "play",
        title: locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar2 = locale.agentRunBar) === null || _locale_agentRunBar2 === void 0 ? void 0 : _locale_agentRunBar2.play,
        onClick: onResume,
        icon: isSimple ? /*#__PURE__*/ React.createElement(SimplePlayIcon, null) : /*#__PURE__*/ React.createElement(PlayIcon, null),
        baseCls: baseCls,
        hashId: hashId
    }));
};
/**
 * 「actionNode 部分」的状态机配置表。
 *
 * key 为状态匹配名（与下面 {@link resolveActionsKey} 中的判定保持一致），
 * value 为该状态下的按钮列表，按顺序渲染。
 *
 * 注意：本表只决定 actionNode（左侧业务按钮组），不包含 stop/pause/resume 控制按钮。
 */ var STATE_ACTION_CONFIG = {
    pause: [
        {
            kind: 'createNewTask',
            localeKey: 'newTask'
        }
    ],
    stopped: [
        {
            kind: 'viewResult',
            localeKey: 'submitTask'
        },
        {
            kind: 'createNewTask',
            localeKey: 'createNewTask',
            primary: true
        }
    ],
    successComplete: [
        {
            kind: 'replay',
            localeKey: 'replayTask'
        },
        {
            kind: 'viewResult',
            localeKey: 'submitTask'
        },
        {
            kind: 'createNewTask',
            localeKey: 'newTask'
        }
    ],
    error: [
        {
            kind: 'replay',
            localeKey: 'replayTask'
        },
        {
            kind: 'viewResult',
            localeKey: 'submitTask'
        },
        {
            kind: 'createNewTask',
            localeKey: 'newTask'
        }
    ],
    default: [
        {
            kind: 'createNewTask',
            localeKey: 'createNewTask'
        }
    ]
};
/**
 * 把 (taskStatus, taskRunningStatus, isRunning, isPause) 映射到
 * {@link STATE_ACTION_CONFIG} 的 key。
 */ var resolveActionsKey = function resolveActionsKey(taskStatus, taskRunningStatus, isRunning, isPause) {
    if (isPause) return 'pause';
    if (taskStatus === TASK_STATUS.STOPPED || taskStatus === TASK_STATUS.CANCELLED) {
        return 'stopped';
    }
    if (taskStatus === TASK_STATUS.SUCCESS && taskRunningStatus === TASK_RUNNING_STATUS.COMPLETE) {
        return 'successComplete';
    }
    if (taskStatus === TASK_STATUS.ERROR) return 'error';
    if (!isRunning && !isPause) return 'default';
    return null;
};
/* -------------------------------------------------------------------------- */ /*  渲染按钮组                                                                  */ /* -------------------------------------------------------------------------- */ var renderButtonGroup = function renderButtonGroup(param) {
    var taskStatus = param.taskStatus, taskRunningStatus = param.taskRunningStatus, actionsRender = param.actionsRender, baseCls = param.baseCls, hashId = param.hashId, locale = param.locale, onCreateNewTask = param.onCreateNewTask, onReplay = param.onReplay, onViewResult = param.onViewResult, onPause = param.onPause, onResume = param.onResume, onStop = param.onStop, variant = param.variant;
    var resolvedVariant = variant !== null && variant !== void 0 ? variant : 'default';
    // 任务运行中状态
    var isRunning = taskStatus === TASK_STATUS.RUNNING && taskRunningStatus === TASK_RUNNING_STATUS.RUNNING;
    // 任务已暂停状态
    var isPause = taskStatus === TASK_STATUS.PAUSE || taskStatus === TASK_STATUS.RUNNING && taskRunningStatus === TASK_RUNNING_STATUS.PAUSE;
    // 控制按钮组（停止 / 暂停 / 继续），actionsRender 与默认分支共用
    var controls = /*#__PURE__*/ React.createElement(ControlButtons, {
        isRunning: isRunning,
        isPause: isPause,
        variant: resolvedVariant,
        onStop: onStop,
        onPause: onPause,
        onResume: onResume,
        locale: locale,
        baseCls: baseCls,
        hashId: hashId
    });
    // ── 分支 1：调用方自定义 actionsRender（含 false 显式禁用）──────────────────
    if (actionsRender !== undefined) {
        var actionNode = typeof actionsRender === 'function' ? actionsRender({
            status: taskStatus,
            runningStatus: taskRunningStatus
        }) : actionsRender;
        return /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(baseCls, "-button-wrapper"), hashId)
        }, actionNode, controls);
    }
    // ── 分支 2：默认逻辑，按状态映射配置表渲染 ─────────────────────────────────
    var callbackMap = {
        replay: onReplay,
        viewResult: onViewResult,
        createNewTask: onCreateNewTask
    };
    var actionsKey = resolveActionsKey(taskStatus, taskRunningStatus, isRunning, isPause);
    var actionConfigs = actionsKey ? STATE_ACTION_CONFIG[actionsKey] : [];
    var actionNode1 = actionConfigs.map(function(cfg) {
        var _locale_agentRunBar;
        var callback = callbackMap[cfg.kind];
        if (!callback) return null;
        var label = locale === null || locale === void 0 ? void 0 : (_locale_agentRunBar = locale.agentRunBar) === null || _locale_agentRunBar === void 0 ? void 0 : _locale_agentRunBar[cfg.localeKey];
        var isCreateNew = cfg.kind === 'createNewTask';
        return /*#__PURE__*/ React.createElement(Button, _object_spread_props(_object_spread({
            key: cfg.kind
        }, cfg.primary ? {
            type: 'primary'
        } : null), {
            onClick: callback,
            icon: isCreateNew ? /*#__PURE__*/ React.createElement(PlusOutlined, null) : undefined,
            color: "default",
            variant: "solid",
            autoInsertSpace: isCreateNew ? undefined : false
        }), label);
    }).filter(Boolean);
    return /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-button-wrapper"), hashId)
    }, actionNode1, controls);
};
/**
 * AgentRunBar 组件 - 智能体任务运行状态条
 *
 * 该组件以一条横向状态条的形式展示 AI 智能体任务的执行状态，包括运行中 /
 * 已暂停 / 已完成 / 出错等多种状态，并提供对应的操作按钮（暂停、继续、停止、
 * 重试、查看结果、新建任务等）。
 *
 * @component
 * @param {AgentRunBarProps} props - 组件属性
 *
 * @example
 * ```tsx
 * <AgentRunBar
 *   title="正在运行中"
 *   description="任务执行中..."
 *   taskStatus="running"
 *   taskRunningStatus="running"
 *   onPause={() => {}}
 *   onResume={() => {}}
 *   onStop={() => {}}
 *   onReplay={() => {}}
 *   onViewResult={() => {}}
 *   onCreateNewTask={() => {}}
 * />
 * ```
 */ var AgentRunBarComponent = function AgentRunBarComponent(rest) {
    var className = rest.className, taskRunningStatus = rest.taskRunningStatus, taskStatus = rest.taskStatus, onPause = rest.onPause, onResume = rest.onResume, onCreateNewTask = rest.onCreateNewTask, onViewResult = rest.onViewResult, onReplay = rest.onReplay, onStop = rest.onStop, title = rest.title, description = rest.description, icon = rest.icon, iconTooltip = rest.iconTooltip, actionsRender = rest.actionsRender, _rest_variant = rest.variant, variant = _rest_variant === void 0 ? 'default' : _rest_variant;
    var context = useContext(ConfigProvider.ConfigContext);
    var baseCls = context === null || context === void 0 ? void 0 : context.getPrefixCls('agent-run-bar');
    var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    // 从context获取国际化配置
    var locale = useContext(I18nContext).locale;
    // 获取机器人状态
    var robotStatus = useMemo(function() {
        if (taskRunningStatus === TASK_RUNNING_STATUS.COMPLETE) {
            return 'dazing';
        }
        if (taskRunningStatus === TASK_RUNNING_STATUS.PAUSE || taskStatus === TASK_STATUS.PAUSE) {
            return 'pause';
        }
        if (taskStatus === TASK_STATUS.SUCCESS || taskStatus === TASK_STATUS.ERROR) {
            return 'default';
        }
        return 'thinking';
    }, [
        taskRunningStatus,
        taskStatus
    ]);
    var _obj;
    // 这里使用 framer-motion 的 `motion.div` + `layout="size"` 是为了在 AgentRunBar
    // 切换状态（如运行 → 暂停 → 完成）导致按钮组个数变化、整体宽高随之改变时，提供
    // 自动测量并补间宽高的过渡动画。
    //
    // 该能力难以用纯 CSS transition 等价实现：CSS transition 不支持从 `auto` 到具体
    // 像素值之间的过渡，必须先取得元素当前尺寸再设回固定值，等价于自行实现一遍
    // `useLayoutEffect + ResizeObserver + requestAnimationFrame`。
    //
    // 因此当前版本保留 framer-motion 依赖。如未来组件库整体去 framer-motion 化，
    // 可以替换为基于 ResizeObserver 的自定义 hook，逻辑等价但实现成本更高。
    return wrapSSR(/*#__PURE__*/ React.createElement(motion.div, {
        className: classNames(baseCls, hashId, className, "".concat(baseCls, "-").concat(variant), (_obj = {}, _define_property(_obj, "".concat(baseCls, "-with-description"), description), _define_property(_obj, "".concat(baseCls, "-status-").concat(robotStatus), robotStatus), _obj)),
        "data-testid": AGENT_RUN_BAR_TEST_ID,
        layout: "size",
        transition: {
            duration: 0.25,
            ease: 'easeOut'
        },
        style: rest.style
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-border"), hashId)
    }), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-background"), hashId)
    }), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-left"), hashId)
    }, icon !== false && /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-left-icon-wrapper"), hashId)
    }, /*#__PURE__*/ React.createElement(Tooltip, {
        title: iconTooltip
    }, /*#__PURE__*/ React.createElement(Robot, {
        icon: icon,
        status: robotStatus,
        size: 40
    }))), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-left-content"), hashId)
    }, title && /*#__PURE__*/ React.createElement(Typography.Title, {
        className: classNames("".concat(baseCls, "-left-main-text"), hashId),
        ellipsis: {
            tooltip: title,
            rows: description ? 1 : 2
        }
    }, title), variant !== 'simple' && description && /*#__PURE__*/ React.createElement(Typography.Text, {
        className: classNames("".concat(baseCls, "-left-text"), hashId),
        ellipsis: {
            tooltip: description
        }
    }, description))), renderButtonGroup({
        taskStatus: taskStatus,
        taskRunningStatus: taskRunningStatus,
        onCreateNewTask: onCreateNewTask,
        onPause: onPause,
        onResume: onResume,
        onStop: onStop,
        onReplay: onReplay,
        onViewResult: onViewResult,
        actionsRender: actionsRender,
        baseCls: baseCls,
        hashId: hashId,
        locale: locale,
        variant: variant
    })));
};
/**
 * AgentRunBar - 智能体任务运行状态条
 *
 * 使用 React.memo 优化性能，避免不必要的重新渲染。
 */ export var AgentRunBar = /*#__PURE__*/ memo(AgentRunBarComponent);
/**
 * @deprecated 请使用 {@link AgentRunBar}。该别名保留以兼容旧代码，将在未来版本移除。
 */ export var TaskRunning = AgentRunBar;
