"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = (0, tslib_1.__importStar)(require("react"));
var PropTypes = (0, tslib_1.__importStar)(require("prop-types"));
var tea_component_1 = require("tea-component");
var classnames_1 = (0, tslib_1.__importDefault)(require("../../utils/classnames"));
require("./index.css");
var platform_1 = require("../../utils/platform");
// 不用 react-weui 而直接用底层实现的原因是 react-weui 不能支持表单类型
function Button(_a) {
    var _b;
    var _c = _a.text, text = _c === void 0 ? '按钮' : _c, _d = _a.size, size = _d === void 0 ? 'default' : _d, _e = _a.type, type = _e === void 0 ? 'primary' : _e, contentSlot = _a.contentSlot, formType = _a.formType, _f = _a.loading, loading = _f === void 0 ? false : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.events, events = _h === void 0 ? {} : _h, className = _a.className, style = _a.style, id = _a.id;
    var platform = (0, platform_1.usePlatform)();
    var isH5 = platform === 'h5';
    var cls = (0, classnames_1.default)((_b = {
            'weda-ui': true,
            'weda-button': true,
            'weda-button-mini': size === 'mini',
            'weui-btn': isH5,
            'weui-btn_mini': isH5 && size === 'mini',
            'weui-btn_primary': isH5 && type === 'primary',
            'weui-btn_default': isH5 && type === 'default',
            'weui-btn_warn': isH5 && type === 'warn',
            'weui-btn_disabled': isH5 && disabled
        },
        _b[className] = className,
        _b));
    var onClick = function (e) { return events.tap({}, { originEvent: e }); };
    if (platform === 'h5') {
        return (React.createElement("button", { className: cls, disabled: disabled, type: formType, style: style, id: id, onClick: onClick },
            loading && (React.createElement("span", { className: "weui-btn_loading" },
                React.createElement("i", { className: "weui-loading" }))),
            text ? text : contentSlot));
    }
    var teaType = type;
    if (teaType === 'warn')
        teaType = 'error';
    return (React.createElement(tea_component_1.ConfigProvider, { classPrefix: "wedatea2td" },
        React.createElement(tea_component_1.Button, { loading: loading, onClick: onClick, disabled: disabled, htmlType: formType, type: teaType, style: style, className: cls, id: id }, text ? text : contentSlot)));
}
exports.default = Button;
Button.propTypes = {
    /**
     * 内容
     */
    text: PropTypes.string,
    /**
     * 样式类型
     */
    type: PropTypes.oneOf(['primary', 'warn', 'default']),
    /**
     * 大小
     */
    size: PropTypes.oneOf(['default', 'mini']),
    /**
     * 是否禁用
     */
    disabled: PropTypes.bool,
    /**
     * 加载中
     */
    loading: PropTypes.bool,
    /**
     * 组件事件
     */
    events: PropTypes.objectOf(PropTypes.func),
    /**
     * 用于 form 类型
     */
    formType: PropTypes.oneOf(['button', 'submit', 'reset']),
    className: PropTypes.string,
    contentSlot: PropTypes.string,
    style: PropTypes.object,
    id: PropTypes.string,
};
/**
 * 默认属性
 */
Button.defaultProps = {
    type: 'primary',
    size: 'default',
};
//# sourceMappingURL=index.js.map