"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const tslib_1 = require("tslib");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const react_1 = tslib_1.__importDefault(require("react"));
const dropdown_1 = require("../dropdown");
const icon_1 = require("../icon");
require("./style.less");
const LoadingCircle = () => (react_1.default.createElement("svg", { viewBox: '0 0 1024 1024', focusable: 'false', className: 'kt-button-anticon-spin', "data-icon": 'loading', width: '1em', height: '1em', fill: 'currentColor', "aria-hidden": 'true' },
    react_1.default.createElement("path", { d: 'M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 0 0-94.3-139.9 437.71 437.71 0 0 0-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z' })));
function noop() { }
/**
 * @example
 * ```ts
 * <Button type='primary' | 'secondary' | 'ghost' | 'danger' | 'link' | 'icon'>click</Button>
 * // icon
 * <Button type='primary' icon='share'>click</Button>
 *
 * // or
 * <Button type='primary' iconClass=`${customPrefix} iconkey`>click</Button>
 *
 * // size
 * <Button size='large' | 'default' | 'small' type='primary' iconClass=`${customPrefix} iconkey`>click</Button>
 *
 * // more 点击后展开一个 dropdown
 * <Button more menu={(<div>
 *  <p>item1</p>
 *  <p>item1</p>
 *  </div>)}>click</Button>
 *
 * // 使用自定义 icon
 * <Button<'icon1' | 'icon2'> icon='icon1' type='icon' />
 * <Button<'icon1' | 'icon2'> iconClass=`${customPrefix} icon1` type='icon' />
 * ```
 */
exports.Button = react_1.default.memo((_a) => {
    var { children, loading, className, type = 'primary', htmlType, size, ghost = false, onClick, disabled, block, iconClass, icon, more, moreIconClass, menu, moreVisible, placement, title, onVisibleChange } = _a, otherProps = tslib_1.__rest(_a, ["children", "loading", "className", "type", "htmlType", "size", "ghost", "onClick", "disabled", "block", "iconClass", "icon", "more", "moreIconClass", "menu", "moreVisible", "placement", "title", "onVisibleChange"]);
    const classes = (0, classnames_1.default)('kt-button', className, {
        [`kt-${type}-button-loading`]: loading,
        [`ghost-${type}-button`]: ghost && !loading && type !== 'link',
        [`${type}-button`]: type,
        [`${size}-button-size`]: size,
        ['ghost-button']: ghost && type !== 'link',
        ['block-button']: block,
    });
    const iconClasses = (0, classnames_1.default)(className, {
        ['kt-clickable-icon']: !!onClick,
    });
    if (type === 'icon') {
        return (react_1.default.createElement(icon_1.Icon, Object.assign({ tooltip: title, disabled: disabled, icon: icon, onClick: loading || disabled ? noop : onClick, className: iconClasses, iconClass: iconClass }, otherProps)));
    }
    const iconNode = iconClass ? react_1.default.createElement(icon_1.Icon, { iconClass: iconClass, disabled: disabled }) : null;
    if (menu) {
        return (react_1.default.createElement(dropdown_1.Dropdown, { visible: moreVisible, className: 'kt-menu', overlay: menu, trigger: ['click'], onVisibleChange: onVisibleChange, placement: placement },
            react_1.default.createElement("button", Object.assign({}, otherProps, { disabled: disabled, className: classes, type: htmlType, onClick: loading || disabled ? noop : onClick }),
                loading && type !== 'link' && react_1.default.createElement(LoadingCircle, null),
                iconNode && iconNode,
                children,
                more && (react_1.default.createElement(icon_1.Icon, { iconClass: moreIconClass ? moreIconClass : (0, icon_1.getIcon)('down'), className: 'kt-button-secondary-more' })))));
    }
    return (react_1.default.createElement("button", Object.assign({}, otherProps, { disabled: disabled, className: classes, type: htmlType, onClick: loading || disabled ? noop : onClick }),
        loading && type !== 'link' && react_1.default.createElement(LoadingCircle, null),
        iconNode && iconNode,
        children));
});
//# sourceMappingURL=index.js.map