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;
}
import { ConfigProvider } from "antd";
import classNames from "clsx";
import React, { memo, useContext } from "react";
import { useRefFunction } from "../Hooks/useRefFunction";
import { useStyle } from "./ButtonTabStyle";
var ButtonTabComponent = function ButtonTabComponent(param) {
    var children = param.children, _param_selected = param.selected, selected = _param_selected === void 0 ? false : _param_selected, _param_disabled = param.disabled, disabled = _param_disabled === void 0 ? false : _param_disabled, onClick = param.onClick, onIconClick = param.onIconClick, className = param.className, icon = param.icon, customPrefixCls = param.prefixCls;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    // P0-4：走 ConfigProvider 体系，并将默认前缀从 'md-editor-button-tab' 改为
    // 'agentic-chatboot-button-tab'，使其归属于 ChatBootPage 命名空间，避免冒充
    // markdown-editor 的命名空间；同时支持外层 ConfigProvider 自定义 prefixCls。
    var prefixCls = getPrefixCls('agentic-chatboot-button-tab', customPrefixCls);
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    // P0-3：disabled 时统一短路，避免键盘 Enter/Space 仍能触发 onClick
    var handleClick = useRefFunction(function() {
        if (disabled) return;
        onClick === null || onClick === void 0 ? void 0 : onClick();
    });
    var handleIconClick = useRefFunction(function(e) {
        e.stopPropagation();
        if (disabled) return;
        onIconClick === null || onIconClick === void 0 ? void 0 : onIconClick();
    });
    var _obj;
    // 注意：原生 <button> 已原生处理 Enter/Space 触发 onClick，
    // 无需额外 handleKeyDown，避免同一按键触发两次。
    var buttonClassName = classNames(prefixCls, (_obj = {}, _define_property(_obj, "".concat(prefixCls, "-selected"), selected), _define_property(_obj, "".concat(prefixCls, "-disabled"), disabled), _obj), className, hashId);
    var iconClassName = classNames("".concat(prefixCls, "-icon"), _define_property({}, "".concat(prefixCls, "-icon-clickable"), !!onIconClick && !disabled), hashId);
    // P1-5：当 icon 区域是独立可点的（onIconClick 存在）时，需要让键盘也能触发它。
    // 用 role="button" + tabIndex + 键盘 handler 让 icon span 成为独立 a11y 元素；
    // 同时阻止键盘事件冒泡到外层主按钮，避免一次按键触发两次 onClick。
    var handleIconKeyDown = useRefFunction(function(e) {
        if (disabled || !onIconClick) return;
        if (e.key === 'Enter' || e.key === ' ') {
            e.preventDefault();
            e.stopPropagation();
            onIconClick();
        }
    });
    // P1-9：testid 与 prefixCls 解耦
    var testId = 'agentic-chatboot-button-tab';
    return wrapSSR(/*#__PURE__*/ React.createElement("button", {
        type: "button",
        className: buttonClassName,
        "data-testid": testId,
        onClick: handleClick,
        disabled: disabled,
        "aria-disabled": disabled || undefined,
        tabIndex: disabled ? -1 : 0
    }, children && /*#__PURE__*/ React.createElement("span", {
        className: classNames("".concat(prefixCls, "-text"), hashId)
    }, children), icon && /*#__PURE__*/ React.createElement("span", {
        className: iconClassName,
        onClick: onIconClick && !disabled ? handleIconClick : undefined,
        onKeyDown: onIconClick && !disabled ? handleIconKeyDown : undefined,
        role: onIconClick && !disabled ? 'button' : undefined,
        tabIndex: onIconClick && !disabled ? 0 : undefined,
        "aria-label": onIconClick && !disabled ? 'tab icon action' : undefined
    }, icon)));
};
ButtonTabComponent.displayName = 'ButtonTab';
// 使用 React.memo 优化性能，避免不必要的重新渲染
var ButtonTab = /*#__PURE__*/ memo(ButtonTabComponent);
export default ButtonTab;
