'use strict';

exports.__esModule = true;
exports.defaultRowRenderer = undefined;

var _helper = require('./helper');

var defaultRowRenderer = function defaultRowRenderer(node, treeOptions) {
    var id = node.id;
    var name = node.name;
    var _node$loadOnDemand = node.loadOnDemand;
    var loadOnDemand = _node$loadOnDemand === undefined ? false : _node$loadOnDemand;
    var children = node.children;
    var state = node.state;

    var droppable = treeOptions.droppable;
    var depth = state.depth;
    var open = state.open;
    var path = state.path;
    var total = state.total;
    var _state$selected = state.selected;
    var selected = _state$selected === undefined ? false : _state$selected;

    var childrenLength = Object.keys(children).length;
    var more = node.hasChildren();

    var togglerContent = '';
    if (!more && loadOnDemand) {
        togglerContent = '►';
    }
    if (more && open) {
        togglerContent = '▼';
    }
    if (more && !open) {
        togglerContent = '►';
    }
    var toggler = (0, _helper.buildHTML)('a', togglerContent, {
        'class': function () {
            if (!more && loadOnDemand) {
                return (0, _helper.classNames)(treeOptions.togglerClass, 'infinite-tree-closed');
            }
            if (more && open) {
                return (0, _helper.classNames)(treeOptions.togglerClass);
            }
            if (more && !open) {
                return (0, _helper.classNames)(treeOptions.togglerClass, 'infinite-tree-closed');
            }
            return '';
        }()
    });
    var title = (0, _helper.buildHTML)('span', (0, _helper.quoteattr)(name), {
        'class': (0, _helper.classNames)('infinite-tree-title')
    });
    var treeNode = (0, _helper.buildHTML)('div', toggler + title, {
        'class': 'infinite-tree-node',
        'style': 'margin-left: ' + depth * 18 + 'px'
    });

    return (0, _helper.buildHTML)('div', treeNode, {
        'data-id': id,
        'data-expanded': more && open,
        'data-depth': depth,
        'data-path': path,
        'data-selected': selected,
        'data-children': childrenLength,
        'data-total': total,
        'class': (0, _helper.classNames)('infinite-tree-item', { 'infinite-tree-selected': selected }),
        'droppable': droppable
    });
};

exports.defaultRowRenderer = defaultRowRenderer;