{% extends "allianceauth/base.html" %}
{% load static %}
{% load i18n %}

{% block page_title %}{% trans "Available Groups" %}{% endblock page_title %}
{% block extra_css %}{% endblock extra_css %}
url
{% block content %}
    <div class="col-lg-12">
        <h1 class="page-header text-center">{% trans "Available Groups" %}</h1>
        {% if groups %}
            <table class="table table-aa">
                <thead>
                    <tr>
                        <th class="text-center">{% trans "Name" %}</th>
                        <th class="text-center">{% trans "Description" %}</th>
                        <th class="text-center">{% trans "Action" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for g in groups %}
                        <tr>
                            <td class="text-center">{{ g.group.name }}</td>
                            <td class="text-center">{{ g.group.authgroup.description|urlize }}</td>
                            <td class="text-center">
                                {% if g.group in user.groups.all %}
                                    {% if not g.request %}
                                        <a href="{% url 'groupmanagement:request_leave' g.group.id %}" class="btn btn-danger">
                                            {% trans "Leave" %}
                                        </a>
                                    {% else %}
                                        <button type="button" class="btn btn-primary" disabled>
                                            {{ g.request.status }}
                                        </button>
                                    {% endif %}
                                {% elif not g.request %}
                                    {% if g.group.authgroup.open %}
                                        <a href="{% url 'groupmanagement:request_add' g.group.id %}" class="btn btn-success">
                                            {% trans "Join" %}
                                        </a>
                                    {% else %}
                                        <a href="{% url 'groupmanagement:request_add' g.group.id %}" class="btn btn-primary">
                                            {% trans "Request" %}
                                        </a>
                                    {% endif %}
                                {% else %}
                                    <button type="button" class="btn btn-primary" disabled>
                                        {{ g.request.status }}
                                    </button>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            <div class="alert alert-warning text-center">
                {% trans "No groups available." %}
            </div>
        {% endif %}
    </div>

{% endblock content %}
