{% set page_title = _("Groups") %}

{% extends theme("management/management_layout.html") %}

{% block breadcrumb %}
<ol class="breadcrumb flaskbb-breadcrumb">
    <li class="breadcrumb-item"><a href="{{ url_for('forum.index') }}">{% trans %}Forum{% endtrans %}</a></li>
    <li class="breadcrumb-item"><a href="{{ url_for('management.overview') }}">{% trans %}Management{% endtrans %}</a></li>
    <li class="breadcrumb-item active">{% trans %}Manage Groups{% endtrans %}</li>
</ol>
{% endblock %}

{% block management_content %}
{%- from theme('_macros/pagination.html') import render_pagination -%}
{%- from theme('_macros/navigation.html') import navlink with context -%}
{%- from theme('_macros/form.html') import action_confirm -%}

<div class="col-md-3 settings-col">
    <div class="nav-sidebar">
        <ul class="nav">
            {{ navlink('management.groups', _("Manage Groups")) }}
            {{ navlink('management.add_group', _("Add Group")) }}
        </ul>
    </div>
</div>

<div class="col-md-9 settings-col with-left-border">
    <div class="card settings">
        <div class="card-header settings-header">
            <span class="fa fa-users"></span> {% trans %}Groups{% endtrans %}
        </div>
        <div class="card-body settings-body">
            <div class="settings-content">
                <div class="settings-meta row">
                    <div class="col-md-1 col-sm-1 col-1 meta-item"><input type="checkbox" name="rowtoggle" class="action-checkall" title="Select All"/></div>
                    <div class="col-md-4 col-sm-4 col-5 meta-item">{% trans %}Group Name{% endtrans %}</div>
                    <div class="col-md-5 col-sm-5 d-none d-sm-block meta-item">{% trans %}Description{% endtrans %}</div>
                    <div class="col-md-2 col-sm-2 col-5">
                        <div class="dropdown">
                            <a class="dropdown-toggle text-dark text-decoration-none fw-bold" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">
                                <span class="fa fa-fw fa-cog"></span>
                                {% trans %}Actions{% endtrans %}
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <button class="dropdown-item btn btn-sm" onclick="return bulk_actions.execute('{{ url_for('management.delete_group') }}')">
                                        <span class="far fa-fw fa-trash-alt text-danger"></span>
                                        {% trans %}Delete selected Groups{% endtrans %}
                                    </button>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

            {% for group in groups.items %}
                <div class="row settings-row hover">
                    <div class="col-md-1 col-sm-1 col-1"><input type="checkbox" name="rowid" class="action-checkbox" value="{{ group.id }}" title="Select Group"/></div>
                    <div class="col-md-4 col-sm-4 col-5">{{ group.name }}</div>
                    <div class="col-md-5 col-sm-5 d-none d-sm-block">{{ group.description }}</div>
                    <div class="col-md-2 col-sm-2 col-5">
                        <a href="{{ url_for('management.edit_group', group_id = group.id) }}" class="btn btn-icon">
                            <span class="fas fa-edit text-primary" data-bs-toggle="tooltip" title="{% trans %}Edit{% endtrans %}"></span>
                        </a>
                        {# only display "Delete" if group is not part of the standard groups. #}
                        {% if group.id > 6 %}
                            {{
                                action_confirm(
                                    id="delete-" ~ group.id,
                                    url=url_for('management.delete_group', group_id=group.id),
                                    title=_("Delete"),
                                    icon="far fa-trash-alt text-danger"
                                )
                            }}
                        {% endif %}
                    </div>
                </div>
            {% else %}
                <div class="row settings-row">
                    <div class="col-12">{% trans %}No groups found.{% endtrans %}</div>
                </div>
            {% endfor %}
            </div>
        </div>
        <div class="card-footer settings-footer">
            {{ render_pagination(groups, url_for('management.groups')) }}
        </div>
    </div>
</div>
{% include theme('_partials/confirm_dialog.html') %}
{% endblock %}

{% block scripts %}
    <script>
    var bulk_actions = new window.app.BulkActions();
    </script>
{% endblock %}
