'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _babelHelperVueJsxMergeProps = require('babel-helper-vue-jsx-merge-props');

var _babelHelperVueJsxMergeProps2 = _interopRequireDefault(_babelHelperVueJsxMergeProps);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _functional = require('../_utils/functional');

require('./index.less');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

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 = (0, _defineProperty3['default'])({
            'sn-icon': true
        }, 'sn-icon-' + type, !!type);
        var svgClassString = (0, _defineProperty3['default'])({}, 'sn-icon-spin', !!spin);

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

        return h(
            'i',
            (0, _babelHelperVueJsxMergeProps2['default'])([{ 'class': classString }, (0, _functional.inherit)(context, true)]),
            [innerNode]
        );
    }
};

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

exports['default'] = Icon;
module.exports = exports.default;