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

{% block page_title %}{% trans "Available Groups" %}{% endblock page_title %}
{% block extra_css %}{% endblock extra_css %}

{% 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>{% trans "Name" %}</th>
                        <th>{% trans "Description" %}</th>
                        <th></th>
                    </tr>
                </thead>

                <tbody>
                    {% for g in groups %}
                        <tr>
                            <td>{{ g.group.name }}</td>
                            <td>{{ g.group.authgroup.description|linebreaks|urlize }}</td>
                            <td class="text-right">
                                {% 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 %}
