'use strict';

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

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

var _babelHelperVueJsxMergeProps2 = _interopRequireDefault(_babelHelperVueJsxMergeProps);

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

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _icon = require('../icon');

var _icon2 = _interopRequireDefault(_icon);

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

var _classnames = require('../_utils/classnames');

var _classnames2 = _interopRequireDefault(_classnames);

require('./index.less');

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

var Button = {
    functional: true,
    name: 'SnButton',
    props: {
        loading: {
            type: Boolean,
            'default': false
        },
        type: {
            type: String,
            'default': 'default',
            validator: function validator(value) {
                return ['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(value) > -1;
            }
        },
        size: {
            type: String,
            validator: function validator(value) {
                return ['medium', 'small'].indexOf(value) > -1;
            }
        },
        inline: {
            type: Boolean,
            'default': false
        },
        ghost: {
            type: Boolean,
            'default': false
        },
        disabled: {
            type: Boolean,
            'default': false
        },
        icon: String,
        shape: {
            type: String,
            validator: function validator(value) {
                return ['square', 'round'].indexOf(value) > -1;
            }
        }
    },
    render: function render(h, context) {
        var _classNames;

        var props = context.props,
            slots = context.slots,
            data = context.data;
        var loading = props.loading,
            type = props.type,
            size = props.size,
            inline = props.inline,
            ghost = props.ghost,
            disabled = props.disabled,
            icon = props.icon,
            shape = props.shape;

        var $slots = slots();
        var className = (0, _classnames2['default'])((_classNames = {
            'sn-button': true,
            'sn-button-loading': loading,
            'sn-button-inline': inline,
            'sn-button-ghost': ghost,
            'sn-button-disabled': disabled || loading
        }, (0, _defineProperty3['default'])(_classNames, 'sn-button-' + type, true), (0, _defineProperty3['default'])(_classNames, 'sn-button-' + size, size === 'medium' || size === 'small'), (0, _defineProperty3['default'])(_classNames, 'sn-button-' + shape, shape === 'square' || shape === 'round'), _classNames));

        var btnIcon = loading ? h(_icon2['default'], {
            attrs: { type: 'loading' },
            'class': 'sn-button-icon' }) : $slots.icon ? $slots.icon : icon && h(_icon2['default'], {
            attrs: { type: icon },
            'class': 'sn-button-icon' });

        function onClick(event) {
            if (!loading && !disabled) {
                (0, _functional.emit)(context, 'click', event);
            } else {
                event.stopPropagation();
            }
        }

        return h(
            'button',
            (0, _babelHelperVueJsxMergeProps2['default'])([{
                'class': className,
                attrs: { disabled: disabled
                },
                on: {
                    'click': onClick
                }
            }, (0, _functional.inherit)(context)]),
            [btnIcon, $slots['default'] ? h('span', [$slots['default']]) : null]
        );
    }
};

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

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