import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props';
// Utils
import { isDef } from '../utils/commonUtil';
import { inherit } from '../_utils/functional';
import './index.less';

var Badge = {
    functional: true,
    name: 'SnBadge',
    render: function render(h, context) {
        var props = context.props;
        var dot = props.dot,
            info = props.info;

        var showInfo = isDef(info) && info !== '';

        if (!dot && !showInfo) {
            return;
        }

        return h(
            'div',
            _mergeJSXProps([{
                'class': {
                    'sn-badge': true,
                    'sn-badge-dot': dot
                }
            }, inherit(context)]),
            [dot ? '' : props.info]
        );
    }
};

Badge.install = function (Vue) {
    Vue.component(Badge.name, Badge);
};

export default Badge;