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 classNames from "clsx";
import React, { memo, useCallback } from "react";
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, onClick = param.onClick, onIconClick = param.onIconClick, className = param.className, icon = param.icon, _param_prefixCls = param.prefixCls, prefixCls = _param_prefixCls === void 0 ? 'md-editor-button-tab' : _param_prefixCls;
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    // 使用 useCallback 优化事件处理函数
    var handleClick = useCallback(function() {
        onClick === null || onClick === void 0 ? void 0 : onClick();
    }, [
        onClick
    ]);
    var handleIconClick = useCallback(function(e) {
        e.stopPropagation();
        onIconClick === null || onIconClick === void 0 ? void 0 : onIconClick();
    }, [
        onIconClick
    ]);
    var handleKeyDown = useCallback(function(e) {
        if (e.key === 'Enter' || e.key === ' ') {
            e.preventDefault();
            onClick === null || onClick === void 0 ? void 0 : onClick();
        }
    }, [
        onClick
    ]);
    var buttonClassName = classNames(prefixCls, _define_property({}, "".concat(prefixCls, "-selected"), selected), className, hashId);
    var iconClassName = classNames("".concat(prefixCls, "-icon"), _define_property({}, "".concat(prefixCls, "-icon-clickable"), !!onIconClick), hashId);
    return wrapSSR(/*#__PURE__*/ React.createElement("button", {
        type: "button",
        className: buttonClassName,
        "data-testid": prefixCls,
        onClick: handleClick,
        onKeyDown: handleKeyDown,
        tabIndex: 0
    }, children && /*#__PURE__*/ React.createElement("span", {
        className: classNames("".concat(prefixCls, "-text"), hashId)
    }, children), icon && /*#__PURE__*/ React.createElement("span", {
        className: iconClassName,
        onClick: onIconClick ? handleIconClick : undefined
    }, icon)));
};
ButtonTabComponent.displayName = 'ButtonTab';
// 使用 React.memo 优化性能，避免不必要的重新渲染
var ButtonTab = /*#__PURE__*/ memo(ButtonTabComponent);
export default ButtonTab;
