import { CloseOutlined } from "@ant-design/icons";
import { ConfigProvider, Divider, Flex } from "antd";
import classNames from "classnames";
import { AnimatePresence, motion } from "framer-motion";
import React, { useContext } from "react";
import { useSkillModeState } from "./hooks";
import { useStyle } from "./style";
/**
 * 技能模式条内部组件
 * @description 包含所有hooks和渲染逻辑的内部实现组件
 * @param props - 组件属性
 * @returns React 组件
 */ var SkillModeBarInner = function(param) {
    var skillMode = param.skillMode, onSkillModeOpenChange = param.onSkillModeOpenChange;
    // 获取样式前缀和配置
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-skill-mode');
    // 注册样式
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    // 使用技能模式状态管理 hook
    var handleInternalSkillModeChange = useSkillModeState(skillMode, onSkillModeOpenChange);
    // 提取常用判断条件，消除重复逻辑
    // 将 rightContent 统一转换为数组处理
    var rightContentArray = React.useMemo(function() {
        if (!(skillMode === null || skillMode === void 0 ? void 0 : skillMode.rightContent)) return [];
        return Array.isArray(skillMode.rightContent) ? skillMode.rightContent : [
            skillMode.rightContent
        ];
    }, [
        skillMode === null || skillMode === void 0 ? void 0 : skillMode.rightContent
    ]);
    var hasRightContent = rightContentArray.length > 0;
    var isClosable = (skillMode === null || skillMode === void 0 ? void 0 : skillMode.closable) !== false;
    var shouldShowDivider = hasRightContent && isClosable;
    var handleCloseClick = function(e) {
        e.stopPropagation();
        // 使用内部状态变化处理函数
        handleInternalSkillModeChange(false);
    };
    return wrapSSR(/*#__PURE__*/ React.createElement(AnimatePresence, null, (skillMode === null || skillMode === void 0 ? void 0 : skillMode.open) && /*#__PURE__*/ React.createElement(motion.div, {
        role: "region",
        "aria-live": "polite",
        "aria-label": "技能模式",
        initial: {
            height: 0,
            opacity: 0
        },
        animate: {
            height: 'auto',
            opacity: 1
        },
        exit: {
            height: 0,
            opacity: 0
        },
        transition: {
            duration: 0.3,
            ease: [
                0.25,
                0.1,
                0.25,
                1
            ]
        },
        className: classNames("".concat(prefixCls, "-container"), hashId),
        "data-testid": "skill-mode-bar"
    }, /*#__PURE__*/ React.createElement(motion.div, {
        initial: {
            padding: '0px',
            backgroundColor: 'transparent',
            borderColor: 'transparent'
        },
        animate: {
            padding: '12px',
            backgroundColor: 'var(--color-gray-bg-page)',
            borderColor: 'rgba(0, 16, 64, 0.0627)'
        },
        exit: {
            padding: '0px',
            backgroundColor: 'transparent',
            borderColor: 'transparent'
        },
        transition: {
            duration: 0.3,
            ease: [
                0.25,
                0.1,
                0.25,
                1
            ]
        },
        style: skillMode === null || skillMode === void 0 ? void 0 : skillMode.style,
        className: classNames("".concat(prefixCls), hashId, skillMode === null || skillMode === void 0 ? void 0 : skillMode.className)
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-title"), hashId)
    }, skillMode === null || skillMode === void 0 ? void 0 : skillMode.title), /*#__PURE__*/ React.createElement(Flex, {
        justify: "flex-end",
        align: "center",
        gap: 8,
        className: classNames("".concat(prefixCls, "-right"), hashId)
    }, rightContentArray.map(function(content, index) {
        // 优先使用React元素的key，fallback到index
        var key = /*#__PURE__*/ React.isValidElement(content) && content.key ? content.key : index;
        return /*#__PURE__*/ React.createElement(React.Fragment, {
            key: key
        }, content);
    }), shouldShowDivider && /*#__PURE__*/ React.createElement(Divider, {
        type: "vertical",
        className: classNames("".concat(prefixCls, "-divider"), hashId)
    }), isClosable && /*#__PURE__*/ React.createElement("button", {
        type: "button",
        "aria-label": "关闭技能模式",
        className: classNames("".concat(prefixCls, "-close"), hashId),
        onClick: handleCloseClick,
        "data-testid": "skill-mode-close"
    }, /*#__PURE__*/ React.createElement(CloseOutlined, null)))))));
};
/**
 * 技能模式条组件
 * @description 用于显示技能模式的标题栏，包含标题、右侧内容和关闭按钮
 * @param props - 组件属性
 * @returns React 组件
 */ export var SkillModeBar = function(param) {
    var skillMode = param.skillMode, onSkillModeOpenChange = param.onSkillModeOpenChange;
    // 早期返回：当 skillMode 不存在或 enable 为 false 时，不渲染任何内容且不执行任何逻辑
    if (!skillMode || skillMode.enable === false) {
        return null;
    }
    // 渲染内部组件，确保 hooks 始终按相同顺序执行
    return /*#__PURE__*/ React.createElement(SkillModeBarInner, {
        skillMode: skillMode,
        onSkillModeOpenChange: onSkillModeOpenChange
    });
};
