{% from '@ZikulaUsersModule/UserAdministration/userlist.html.twig' import userStatus as userStatus %}
<h3>
    <span class="fas fa-list"></span>
    {% trans %}Search results{% endtrans %}
    {{ pageSetVar('title', 'Search results'|trans) }}
</h3>

<div>
    <div class="alert alert-warning" role="alert">
        {% trans %}Be advised: If your search resulted in more than 250 records, that display has been limited to 250.{% endtrans %}
    </div>
    {{ form_start(resultsForm) }}
    {{ form_errors(resultsForm) }}
    <table class="table table-bordered table-striped">
        <colgroup>
            {% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
            <col id="cDelete" />
            {% endif %}
            <col id="cUser" />
            <col id="cEmail" />
            <col id="cStatus" />
            <col id="cActions" />
        </colgroup>
        <thead>
            <tr>
                {% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
                <th id="hDelete" scope="col">&nbsp;</th>
                {% endif %}
                <th id="hUser" scope="col">{% trans %}User name{% endtrans %}</th>
                <th id="hEmail" scope="col">{% trans %}Email address{% endtrans %}</th>
                <th id="hStatus" scope="col">{% trans %}Status{% endtrans %}</th>
                <th id="hActions" scope="col" class="text-right">{% trans %}Actions{% endtrans %}</th>
            </tr>
        </thead>
        <tbody>
            {% for user in resultsForm.users %}
                {% set excluded = user.vars.name <= 2 ? true : false %}
                <tr{% if excluded %} class="warning"{% endif %}>
                {% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
                <td headers="hDelete">
                    {{ form_widget(user, {title: 'Delete %n'|trans({'%n': user.vars.label}), disabled:excluded}) }}
                </td>
                {% endif %}
                <td headers="hUser">{{ user.vars.label }}</td>
                <td headers="hEmail">
                    {% if (user.parent.vars.choices[user.vars.name].data.email is defined) %}
                    {{ user.parent.vars.choices[user.vars.name].data.email }}
                    {% endif %}
                </td>
                <td headers="hStatus">
                    {% if (user.parent.vars.choices[user.vars.name].data.activated is defined) %}
                        {{ userStatus(user.parent.vars.choices[user.vars.name].data.activated) }}
                    {% endif %}
                </td>
                <td headers="hActions" class="actions">
                    {% if hasPermission('ZikulaUsersModule', user.vars.label~'::'~user.vars.name, 'ACCESS_EDIT') and user.vars.name > 1 %}
                        <a class="fas fa-pencil-alt tooltips" href="{{ path('zikulausersmodule_useradministration_modify', {user:user.vars.name}) }}" title="{% trans with {"%sub%": user.vars.label} %}Edit %sub%{% endtrans %}"></a>
                    {% endif %}
                    {% if not excluded and currentUser.uid != user.vars.name and hasPermission('ZikulaUsersModule', user.vars.label~'::'~user.vars.name, 'ACCESS_DELETE') %}
                        <a class="fas fa-trash-alt fa-fw tooltips" href="{{ path('zikulausersmodule_useradministration_delete', {user:user.vars.name}) }}" title="{% trans with {"%sub%": user.vars.label} %}Delete %sub%{% endtrans %}"></a>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    {% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
    <p><a href="#" id="select-all">{% trans %}Select all{% endtrans %}</a> / <a href="#" id="deselect-all">{% trans %}De-select all{% endtrans %}</a></p>
    {% endif %}

    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#email-users-form" aria-expanded="false" aria-controls="email-users-form"><i class="fas fa-envelope"></i> {% trans %}Mail selected users{% endtrans %}</button>
            {% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
                {{ form_widget(resultsForm.delete) }}
            {% endif %}
            <a class="btn btn-secondary" href="{{ path('zikulausersmodule_useradministration_list') }}"><i class="fas fa-sync"></i> {% trans %}Return to User Administration{% endtrans %}</a>
        </div>
    </div>
    {{ form_end(resultsForm) }}
</div>

{% form_theme mailForm with [
    '@ZikulaFormExtension/Form/bootstrap_4_zikula_admin_layout.html.twig',
    '@ZikulaFormExtension/Form/form_div_layout.html.twig'
] %}
<div class="collapse" id="email-users-form">
    <hr />
    {{ form_start(mailForm) }}
    {{ form_errors(mailForm) }}
    <div class="container-fluid">
        <div class="row">
            {{ form_row(mailForm.from) }}
            {{ form_row(mailForm.replyto) }}
            {{ form_row(mailForm.subject) }}
            {{ form_row(mailForm.format) }}
            {{ form_row(mailForm.message) }}
            {{ form_row(mailForm.batchsize) }}
            {{ notifyDisplayHooks(constant('Zikula\\UsersModule\\HookSubscriber\\UserManagementUiHooksSubscriber::EDIT_FORM')) }}{# allows admin to hook wysiwyg editor for mail form #}
        </div>
    </div>
    <div class="form-group row">
        <div class="col-md-9 offset-md-3">
            {{ form_widget(mailForm.send) }}
            <button type="button" class="btn btn-secondary" data-toggle="collapse" href="#email-users-form"><i class="fas fa-times"></i> {% trans %}Close{% endtrans %}</button>
        </div>
    </div>
    {{ form_end(mailForm) }}
</div>
{% if hasPermission('ZikulaUsersModule', '::', 'ACCESS_DELETE') %}
    {{ pageAddAsset('javascript', zasset('@ZikulaUsersModule:js/ZikulaUsersModule.Admin.SearchResults.js')) }}
{% endif %}
