/**
 * amis-ui v6.11.0-beta.7
 * Copyright 2018-2025 fex
 */

import { __extends, __rest, __assign } from 'tslib';
import React__default from 'react';
import TooltipWrapper from './TooltipWrapper.js';
import { pickEventsProps, themeable } from 'amis-core';
import Spinner from './Spinner.js';

/**
 * @file Button
 * @author fex
 */
var Button = /** @class */ (function (_super) {
    __extends(Button, _super);
    function Button() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Button.prototype.renderButton = function () {
        var _a, _b;
        var _c = this.props, level = _c.level, _d = _c.size, size = _d === void 0 ? 'default' : _d, disabled = _c.disabled, className = _c.className, style = _c.style, title = _c.title, Comp = _c.componentClass, cx = _c.classnames, children = _c.children; _c.disabledTip; var block = _c.block, type = _c.type, active = _c.active, iconOnly = _c.iconOnly, href = _c.href, loading = _c.loading, loadingClassName = _c.loadingClassName, overrideClassName = _c.overrideClassName, loadingConfig = _c.loadingConfig, testIdBuilder = _c.testIdBuilder, tabIndex = _c.tabIndex, rest = __rest(_c, ["level", "size", "disabled", "className", "style", "title", "componentClass", "classnames", "children", "disabledTip", "block", "type", "active", "iconOnly", "href", "loading", "loadingClassName", "overrideClassName", "loadingConfig", "testIdBuilder", "tabIndex"]);
        if (href) {
            Comp = 'a';
        }
        else if ((Comp === 'button' && disabled) || loading) {
            Comp = 'div';
        }
        return (React__default.createElement(Comp, __assign({ type: Comp === 'input' || Comp === 'button' ? type : undefined }, pickEventsProps(rest), { onClick: rest.onClick && disabled ? function () { } : rest.onClick, href: href }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId(), { className: cx(overrideClassName
                ? ''
                : (_a = {
                        'Button': true
                    },
                    _a["Button--".concat(level)] = level,
                    _a["Button--size-".concat(size)] = size,
                    _a["Button--block"] = block,
                    _a["Button--iconOnly"] = iconOnly,
                    _a['is-disabled'] = disabled,
                    _a['is-active'] = active,
                    _a), className), style: style, title: title, disabled: disabled, tabIndex: tabIndex }),
            loading && !disabled && (React__default.createElement(Spinner, { loadingConfig: loadingConfig, size: "sm", show: true, icon: "loading-outline", className: cx(overrideClassName
                    ? ''
                    : (_b = {}, _b["Button--loading Button--loading--".concat(level)] = level, _b), loadingClassName) })),
            children));
    };
    Button.prototype.render = function () {
        var _a = this.props, tooltip = _a.tooltip, tooltipPlacement = _a.tooltipPlacement, tooltipContainer = _a.tooltipContainer, tooltipTrigger = _a.tooltipTrigger, tooltipRootClose = _a.tooltipRootClose, disabled = _a.disabled, disabledTip = _a.disabledTip; _a.classnames;
        return (React__default.createElement(TooltipWrapper, { placement: tooltipPlacement, tooltip: disabled ? disabledTip : tooltip, container: tooltipContainer, trigger: tooltipTrigger, rootClose: tooltipRootClose }, this.renderButton()));
    };
    Button.defaultProps = {
        componentClass: 'button',
        level: 'default',
        type: 'button',
        tooltipPlacement: 'top',
        tooltipTrigger: ['hover', 'focus'],
        tooltipRootClose: false
    };
    return Button;
}(React__default.Component));
var Button$1 = themeable(Button);

export { Button, Button$1 as default };
