{% load evelinks %}
{% load i18n %}

<div id="corps" class="tab-pane fade panel panel-default">
    <div class="panel-body">
        {% if user_can_see_other_corps %}
            <h4>{% translate "Corporations <small>(Click on an alliance name to see their corporations)</small>" %}</h4>
        {% endif %}

        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" style="margin-bottom: 0;">
            {% if perms.afat.stats_corporation_other or perms.afat.manage_afat %}
                {% for key, value in data.items|dictsort:0 %}
                    {% if value|length > 0 %}
                        <div class="panel panel-default">
                            <div class="panel-heading" role="tab" id="heading{{ value.0 }}">
                                <h4 class="panel-title">
                                    <img src="{{ value.0|alliance_logo_url:32 }}" alt="{{ key }}" style="margin-right: 0.25rem;">

                                    <a role="button" class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#{{ value.0 }}" aria-expanded="false" aria-controls="{{ value.0 }}">
                                        {{ key }}
                                    </a>

                                    {% if key != 'No Alliance' %}
                                        <a class="btn btn-primary btn-sm pull-right" href="{% url 'afat:statistics_alliance' value.0 year %}" role="button">
                                            <span class="glyphicon glyphicon-eye-open" style="color: rgb(255 255 255);"></span>
                                        </a>
                                    {% endif %}
                                </h4>
                            </div>

                            <div id="{{ value.0 }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{ value.0 }}">
                                <div class="panel-body">
                                    <table class="table table-striped table-hover" style="margin-bottom: 0;">
                                        <tbody>
                                            {% for corp in value %}
                                                {% if forloop.first %}
                                                {% else %}
                                                    <tr>
                                                        <td>
                                                            <img src="{{ corp.0|corporation_logo_url:32 }}" alt="{{ corp.1 }}" style="margin-right: 0.25rem;">
                                                            {{ corp.1 }}
                                                        </td>

                                                        <td class="text-right">
                                                            <a class="btn btn-primary btn-sm" href="{% url 'afat:statistics_corporation' corp.0 year %}">
                                                                <span class="glyphicon glyphicon-eye-open"></span>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                {% endif %}
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    {% endif %}
                {% endfor %}
            {% elif perms.afat.stats_corporation_own %}
                <table class="table table-striped table-hover" style="margin-bottom: 0;">
                    <tbody>
                        <tr>
                            <td>
                                <img src="{{ data.0.0|corporation_logo_url:32 }}" alt="{{ data.0.1 }}" style="margin-right: 0.25rem;">
                                {{ data.0.1 }}
                            </td>

                            <td class="text-right">
                                <a class="btn btn-primary btn-sm" href="{% url 'afat:statistics_corporation' data.0.0 year %}">
                                    <span class="glyphicon glyphicon-eye-open"></span>
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            {% endif %}
        </div>
    </div>
</div>
