'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 _icon = require('../icon');

var _icon2 = _interopRequireDefault(_icon);

var _listItem = require('../mixins/list-item');

var _listItem2 = _interopRequireDefault(_listItem);

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

var _classnames2 = _interopRequireDefault(_classnames);

var _commonUtil = require('../utils/commonUtil');

require('./index.less');

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

var ListItem = {
    functional: true,
    name: 'SnListItem',
    mixins: [_listItem2['default']],
    render: function render(h, context) {
        var props = context.props,
            slots = context.slots,
            data = context.data;
        var icon = props.icon,
            rightIcon = props.rightIcon,
            title = props.title,
            label = props.label,
            value = props.value,
            labelNumber = props.labelNumber,
            titleClass = props.titleClass,
            titleStyle = props.titleStyle,
            valueClass = props.valueClass,
            valueStyle = props.valueStyle,
            clickable = props.clickable,
            center = props.center,
            required = props.required,
            border = props.border,
            borderIndent = props.borderIndent,
            valuePosition = props.valuePosition;

        var $slots = slots();
        var showTitle = $slots.title || (0, _commonUtil.isDef)(title);
        var showValue = $slots['default'] || (0, _commonUtil.isDef)(value);
        var showLabel = $slots.label || (0, _commonUtil.isDef)(label);

        var Label = showLabel && h(
            'div',
            {
                'class': {
                    'sn-list-item-label': true,
                    '': props.labelClass
                }
            },
            [$slots.label ? $slots.label : label]
        );

        var titleClassName = (0, _classnames2['default'])('sn-list-item-title', labelNumber ? 'sn-list-item-label-number-' + labelNumber : '', titleClass);

        var Title = showTitle && h(
            'div',
            { 'class': titleClassName, style: titleStyle },
            [$slots.title ? $slots.title : h('span', [title]), Label]
        );

        var valueClassName = (0, _classnames2['default'])('sn-list-item-value', valuePosition === 'left' ? 'sn-list-item-value-position-left' : '', valueClass);

        var Value = showValue && h(
            'div',
            { 'class': valueClassName, style: valueStyle },
            [$slots['default'] ? $slots['default'] : h('span', [value])]
        );

        var onLeftIcon = data.on && data.on['icon-click'] && {
            on: { click: data.on['icon-click'] }
        } || {};
        var LeftIcon = $slots.icon ? $slots.icon : icon && h(_icon2['default'], (0, _babelHelperVueJsxMergeProps2['default'])([{
            attrs: {
                type: icon
            }
        }, (0, _extends3['default'])({}, onLeftIcon, {
            'class': 'sn-list-item-left-icon'
        })]));

        var rightIconSlot = $slots['right-icon'];
        var onRightIcon = data.on && data.on['right-icon-click'] && {
            on: { click: data.on['right-icon-click'] }
        } || {};
        var RightIcon = rightIconSlot ? rightIconSlot : rightIcon && h(_icon2['default'], (0, _babelHelperVueJsxMergeProps2['default'])([{
            attrs: {
                type: rightIcon
            }
        }, (0, _extends3['default'])({}, onRightIcon, {
            'class': 'sn-list-item-right-icon'
        })]));

        var classes = (0, _classnames2['default'])({
            'sn-list-item': true,
            'sn-list-item-clickable': clickable,
            'sn-list-item-center': center,
            'sn-list-item-required': required,
            'sn-list-item-borderless': !border,
            'sn-list-item-border-indentless': !borderIndent
        }, data['class']);

        var domProps = (0, _extends3['default'])({}, data, {
            attrs: {
                role: clickable ? 'button' : null,
                tabindex: clickable ? 0 : null
            },
            'class': classes
        });

        return h(
            'div',
            domProps,
            [LeftIcon, Title, Value, RightIcon]
        );
    }
};

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

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