{% set isIndex = tmpl == 'index' ? true : false %}
{% set tmpl = 'list' %}

{% extends isIndex ? '@MauticCore/Default/content.html.twig' : '@MauticCore/Default/raw_output.html.twig' %}
{% block mauticContent %}role{% endblock %}
{% block headerTitle %}{% trans %}mautic.user.roles{% endtrans %}{% endblock %}
{% block actions %}
{{- include('@MauticCore/Helper/page_actions.html.twig',
    {
        'templateButtons' : {
            'new' : permissions['create'],
        },
        'routeBase' : 'role',
        'langVar'   : 'user.role',
    }
) -}}
{% endblock %}

{% block content %}
    {% if isIndex %}
        {{- include('@MauticCore/Helper/list_toolbar.html.twig',
            {
                'searchValue' : searchValue,
                'searchHelp'  : 'mautic.user.role.help.searchcommands',
                'action'      : currentRoute,
            }
        ) -}}
        <div class="page-list">
            {{ block('listResults') }}
        </div>
    {% else %}
        {{ block('listResults') }}
    {% endif %}
{% endblock %}

{% block listResults %}
<div class="table-responsive">
    <table class="table table-hover table-striped table-bordered role-list" id="roleTable">
        <thead>
        <tr>
            {{- include('@MauticCore/Helper/tableheader.html.twig',
                {
                    'checkall'        : 'true',
                    'target'          : '#roleTable',
                    'langVar'         : 'user.role',
                    'routeBase'       : 'role',
                    'templateButtons' : {
                        'delete' : permissions['delete'],
                    },
                }
            ) -}}

            {{- include(
                '@MauticCore/Helper/tableheader.html.twig',
                {
                    'sessionVar' : 'role',
                    'orderBy'    : 'r.name',
                    'text'       : 'mautic.core.name',
                    'class'      : 'col-role-name',
                    'default'    : true,
                }
            ) -}}

            {{- include(
                '@MauticCore/Helper/tableheader.html.twig',
                {
                    'sessionVar' : 'role',
                    'orderBy'    : 'r.description',
                    'text'       : 'mautic.core.description',
                    'class'      : 'visible-md visible-lg col-role-desc',
                }
            ) -}}
            <th class="visible-md visible-lg col-rolelist-usercount">
                {% trans %}mautic.user.role.list.thead.usercount{% endtrans %}
            </th>
            {{- include('@MauticCore/Helper/tableheader.html.twig',
                {
                    'sessionVar' : 'role',
                    'orderBy'    : 'r.id',
                    'text'       : 'mautic.core.id',
                    'class'      : 'visible-md visible-lg col-role-id',
                }
            ) -}}
        </tr>
        </thead>
        <tbody>
        {% for item in items %}
            <tr>
                <td>
                    {{- include('@MauticCore/Helper/list_actions.html.twig',
                        {
                            'item'            : item,
                            'templateButtons' : {
                                'edit'   : permissions['edit'],
                                'delete' : permissions['delete'],
                            },
                            'routeBase' : 'role',
                            'langVar'   : 'user.role',
                            'pull'      : 'left',
                        }) -}}
                </td>
                <td>
                    {% if permissions['edit'] %}
                        <a href="{{ path('mautic_role_action',
                            {'objectAction' : 'edit', 'objectId' : item.getId()}) }}" data-toggle="ajax">
                            {{ item.getName() }}
                        </a>
                    {% else %}
                        {{ item.getName() }}
                    
                    {% endif %}
                </td>
                <td class="visible-md visible-lg">
                    {{ item.getDescription()|purify }}
                </td>
                <td class="visible-md visible-lg">
                    <a class="label label-primary" href="{{ path('mautic_user_index',
                        {'search' : ('mautic.user.user.searchcommand.role'|trans) ~ ':&quot;' ~ item.getName() ~ '&quot;'}) }}" data-toggle="ajax"{{ userCounts[item.getId()] == 0 ? 'disabled=disabled' : '' }}>
                        {{ 'mautic.user.role.list.viewusers_count'|trans(
                            {'%count%' : userCounts[item.getId()]}
                        ) }}
                    </a>
                </td>
                <td class="visible-md visible-lg">
                    {{ item.getId() }}
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
<div class="panel-footer">
    {{- include('@MauticCore/Helper/pagination.html.twig',
        {
            'totalItems' : items|length,
            'page'       : page,
            'limit'      : limit,
            'baseUrl'    : path('mautic_role_index'),
            'sessionVar' : 'role',
        }
    ) -}}
</div>
{% endblock %}