import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props';
import _extends from 'babel-runtime/helpers/extends';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import { inherit } from '../_utils/functional';
import './index.less';

var svgBaseProps = {
    width: '1em',
    height: '1em',
    fill: 'currentColor',
    'aria-hidden': 'true',
    focusable: 'false'
};

var requireAll = function requireAll(context) {
    return context.keys().map(context);
};
var req = require.context('./svg', false, /\.svg$/);
requireAll(req);

var Icon = {
    functional: true,
    name: 'SnIcon',
    props: {
        type: {
            type: String,
            required: true
        },
        viewBox: String,
        spin: {
            type: Boolean,
            'default': false
        }
    },
    render: function render(h, context) {
        var props = context.props,
            slots = context.slots,
            data = context.data;
        var type = props.type,
            spin = props.spin;

        var children = slots()['default'] || [];
        children = children.length === 0 ? undefined : children;

        var classString = _defineProperty({
            'sn-icon': true
        }, 'sn-icon-' + type, !!type);
        var svgClassString = _defineProperty({}, 'sn-icon-spin', !!spin);

        var innerSvgProps = {
            attrs: _extends({}, svgBaseProps),
            'class': svgClassString
        };
        var useProps = {
            attrs: {
                'xlink:href': '#' + type
            }
        };
        var innerNode = h(
            'svg',
            _mergeJSXProps([innerSvgProps, { 'class': svgClassString }]),
            [h('use', useProps)]
        );

        return h(
            'i',
            _mergeJSXProps([{ 'class': classString }, inherit(context, true)]),
            [innerNode]
        );
    }
};

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

export default Icon;