/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var TooltipWrapper = require('./TooltipWrapper.js');
var amisCore = require('amis-core');
var Spinner = require('./Spinner.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var Button = /** @class */ (function (_super) {
    tslib.__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 = tslib.__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 (_J$X_(Comp, tslib.__assign({ type: Comp === 'input' || Comp === 'button' ? type : undefined }, amisCore.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 && (_J$X_(Spinner["default"], { 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 (_J$X_(TooltipWrapper["default"], { 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["default"].Component));
var Button$1 = amisCore.themeable(Button);

exports.Button = Button;
exports["default"] = Button$1;
