import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var Button = React.forwardRef(function (props, ref) {
    var _a;
    var _b = props.size, size = _b === void 0 ? 'md' : _b, _c = props.btnType, btnType = _c === void 0 ? 'default' : _c, _d = props.loading, loading = _d === void 0 ? false : _d, _e = props.disabled, disabled = _e === void 0 ? false : _e, _f = props.block, block = _f === void 0 ? false : _f, onClick = props.onClick, icon = props.icon, round = props.round, children = props.children, className = props.className, style = props.style, customisedCls = props.prefixCls, otherProps = __rest(props, ["size", "btnType", "loading", "disabled", "block", "onClick", "icon", "round", "children", "className", "style", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('btn', configContext.prefixCls, customisedCls);
    var btnSize = props.size || configContext.componentSize || size;
    var cls = classNames(prefixCls, className, prefixCls + "_" + btnSize, (_a = {},
        _a[prefixCls + "_" + btnType] = btnType,
        _a[prefixCls + "_block"] = block,
        _a[prefixCls + "_round"] = round,
        _a[prefixCls + "_disabled"] = disabled,
        _a[prefixCls + "_loading"] = loading,
        _a));
    var btnOnClick = function (e) {
        if (disabled || loading) {
            return;
        }
        onClick && onClick(e);
    };
    var renderIcon = function () {
        if (loading) {
            return React.createElement("span", { className: prefixCls + "__loader" });
        }
        else if (icon) {
            return React.createElement("span", { className: prefixCls + "__icon-container" }, icon);
        }
        else {
            return null;
        }
    };
    return (React.createElement("button", __assign({}, otherProps, { ref: ref, role: "button", className: cls, disabled: disabled, onClick: btnOnClick, style: style }),
        renderIcon(),
        children && React.createElement("span", { className: prefixCls + "__children" }, children)));
});
Button.displayName = 'Button';
export default Button;
//# sourceMappingURL=button.js.map