"use strict";
/**
 * @file 角标组件
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.withBadge = exports.Badge = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var hoist_non_react_statics_1 = (0, tslib_1.__importDefault)(require("hoist-non-react-statics"));
var tpl_1 = require("../utils/tpl");
var tpl_builtin_1 = require("../utils/tpl-builtin");
var Badge = /** @class */ (function (_super) {
    (0, tslib_1.__extends)(Badge, _super);
    function Badge(props) {
        return _super.call(this, props) || this;
    }
    Badge.prototype.render = function () {
        var badge = this.props.badge;
        if (!badge) {
            return this.props.children;
        }
        var _a = this.props, children = _a.children, cx = _a.classnames, data = _a.data;
        var isDisplay = true;
        if (typeof badge === 'string') {
            isDisplay = (0, tpl_1.evalExpression)(badge, data) === true;
        }
        var _b = badge.mode, mode = _b === void 0 ? 'dot' : _b, text = badge.text, size = badge.size, style = badge.style, _c = badge.position, position = _c === void 0 ? 'top-right' : _c, visibleOn = badge.visibleOn, className = badge.className, animation = badge.animation;
        if (visibleOn) {
            isDisplay = (0, tpl_1.evalExpression)(visibleOn, data) === true;
        }
        if (typeof text === 'string' && text[0] === '$') {
            text = (0, tpl_builtin_1.resolveVariable)(text, data);
        }
        // 设置默认值
        if (typeof size === 'undefined') {
            if (mode === 'dot') {
                size = 6;
            }
            else {
                size = 16;
            }
        }
        var sizeStyle = {};
        if (mode === 'text') {
            sizeStyle = {
                borderRadius: size / 2,
                height: size,
                lineHeight: size + 'px'
            };
            if (!text) {
                isDisplay = false;
            }
        }
        if (mode === 'dot') {
            sizeStyle = { width: size, height: size };
        }
        var animationBackground = 'var(--danger)';
        if (style && style.background) {
            animationBackground = style.background;
        }
        var animationElement = animation ? (react_1.default.createElement("div", { style: {
                position: 'absolute',
                top: 0,
                left: 0,
                width: '100%',
                height: '100%',
                border: "1px solid " + animationBackground,
                borderRadius: '50%',
                animation: 'badgeDotAnimation 1.2s infinite ease-in-out'
            } })) : null;
        return (react_1.default.createElement("div", { className: cx('Badge', className) },
            children,
            isDisplay ? (mode === 'dot' ? (react_1.default.createElement("span", { className: cx('Badge-dot', "Badge--" + position), style: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, sizeStyle), style) }, animationElement)) : (react_1.default.createElement("span", { className: cx('Badge-text', "Badge--" + position), style: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, sizeStyle), style) },
                text,
                animationElement))) : null));
    };
    Badge.propsList = ['body', 'className', 'children'];
    return Badge;
}(react_1.default.Component));
exports.Badge = Badge;
function withBadge(Component) {
    var _a;
    return (0, hoist_non_react_statics_1.default)((_a = /** @class */ (function (_super) {
            (0, tslib_1.__extends)(WithBadge, _super);
            function WithBadge() {
                return _super !== null && _super.apply(this, arguments) || this;
            }
            WithBadge.prototype.render = function () {
                var badge = this.props.badge;
                if (!badge) {
                    return react_1.default.createElement(Component, (0, tslib_1.__assign)({}, this.props));
                }
                return (react_1.default.createElement(Badge, (0, tslib_1.__assign)({}, this.props),
                    react_1.default.createElement(Component, (0, tslib_1.__assign)({}, this.props))));
            };
            return WithBadge;
        }(react_1.default.Component)),
        _a.displayName = "WithBadge(" + (Component.displayName || Component.name) + ")",
        _a), Component);
}
exports.withBadge = withBadge;
//# sourceMappingURL=./components/Badge.js.map
