{% extends 'allianceauth/base.html' %}

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

{% block page_title %}{% trans 'Fleet Activity' %}{% endblock %}

{% block content %}
    <div class="col-lg-12">
        <br>
        {% include "afat/menu.html" %}

        <h2>{% trans "Statistics" %}</h2>

        {% if msg %}
            <div class="alert alert-{{ msg.0 }} alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="close">
                    <span aria-hidden="true">&times</span>
                </button>
                <h4>
                    {% if msg.0 == 'danger' %}
                        {% trans "Oh No!" %}
                    {% elif msg.0 == 'success' %}
                        {% trans "Success!" %}
                    {% endif %}
                </h4>
                <p>{{ msg.1 }}</p>
            </div>
        {% endif %}

        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#mine">{% trans "My Stats" %}</a></li>
            {% if perms.afat.stats_corp_own or perms.afat.stats_corp_other %}
                <li><a data-toggle="tab" href="#corps">{% trans "Corps" %}</a></li>
            {% endif %}
        </ul>

        <div class="tab-content">
            <div id="mine" class="tab-pane fade in active panel-default">
                <div class="panel-body">
                    <h4>{% trans "Months" %}</h4>

                    <p>{% trans "Only months with FAT data in the last 12 months are shown." %}</p>

                    <ul class="nav nav-pills">
                        {% for char in charstats %}
                            {% if forloop.first %}
                                <li class="active"><a data-toggle="tab" href="#{{ char.2 }}"><img class="img-circle" src="{{ char.2|character_portrait_url:32 }}"/>  {{ char.0 }}</a></li>
                            {% else %}
                                <li><a data-toggle="tab" href="#{{ char.2 }}"><img class="img-circle" src="{{ char.2|character_portrait_url:32 }}"/>  {{ char.0 }}</a></li>
                            {% endif %}
                        {% endfor %}
                    </ul>

                    <div class="tab-content">
                        {% for char in charstats %}
                            {% if forloop.first %}
                            <div id="{{ char.2 }}" class="tab-pane fade in active panel-default">
                            {% else %}
                            <div id="{{ char.2 }}" class="tab-pane fade panel-default">
                            {% endif %}
                                <div class="panel-body">
                                {% if char.1|length > 0 %}
                                    <table class="table">
                                        <thead>
                                            <th>{% trans "Month" %}</th>
                                            <th>{% trans "FAT Count" %}</th>
                                            <th></th>
                                        </thead>

                                        <tbody>
                                            {% for key, value in char.1.items %}
                                                <tr>
                                                    <td>{{ key|month }}</td>
                                                    <td>{{ value }}</td>
                                                    <td>
                                                        <a href="/afat/stats/char/{{ char.2 }}/{{ key }}/{{ year }}/" class="btn btn-primary">
                                                            <span class="glyphicon glyphicon-eye-open"></span>
                                                        </a>
                                                    </td>
                                                </tr>
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                {% else %}
                                    <div class="alert alert-warning" role="alert">
                                        <p>{% trans "No FATs for" %} {{ char.0 }}</p>
                                    </div>
                                {% endif %}
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>

            {% if perms.afat.stats_corp_own or perms.afat.stats_corp_other %}
            <div id="corps" class="tab-pane fade panel-default">
                <div class="panel-body">
                    <h4>{% trans "Corporations (Click Alliance Name to See Corps)" %}</h4>
                    {% if perms.afat.stats_corp_other %}
                        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                            {% for key, value in data.items %}
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="heading{% if key == 'No Alliance' %}0000{% else %}{{ value.0 }}{% endif %}">
                                        <h4 class="panel-title">
                                            {% if key == 'No Alliance' %}
                                                <img src="{{ 1|alliance_logo_url:32 }}" />
                                            {% else %}
                                                <img src="{{ value.0|alliance_logo_url:32 }}" />
                                            {% endif %}

                                            <a role="button" class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#{% if key == 'No Alliance' %}0000{% else %}{{ value.0 }}{% endif %}" aria-expanded="false" aria-controls="{% if key == 'No Alliance' %}0000{% else %}{{ value.0 }}{% endif %}">
                                                {{ key }}
                                            </a>

                                            <a class="btn btn-primary btn-sm pull-right" href="/afat/stats/ally/{% if key == 'No Alliance' %}000{% else %}{{ value.0 }}{% endif %}/" role="button">
                                                <span class="glyphicon glyphicon-eye-open" style="color: white"></span>
                                            </a>
                                        </h4>
                                    </div>

                                    <div id="{% if key == 'No Alliance' %}0000{% else %}{{ value.0 }}{% endif %}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{% if key == 'No Alliance' %}0000{% else %}{{ value.0 }}{% endif %}">
                                        <div class="panel-body">
                                            <table class="table">
                                                <tbody>
                                                {% for corp in value %}
                                                    {% if forloop.first %}
                                                    {% else %}
                                                    <tr>
                                                        <td><img src="{{ corp.0|corporation_logo_url:32 }}" /></td>
                                                        <td>{{ corp.1 }}</td>
                                                        <td>
                                                            <a class="btn btn-primary" href="/afat/stats/corp/{{ corp.0 }}/">
                                                                <span class="glyphicon glyphicon-eye-open"></span>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                    {% endif %}
                                                {% endfor %}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                        {% endfor %}
                    {% elif perms.afat.stats_corp_own %}
                        <table class="table">
                            <tbody>
                                <tr>
                                    <td><img src="{{ data.0.0|corporation_logo_url:32 }}" /> </td>
                                    <td>{{ data.0.1 }}</td>
                                    <td>
                                        <a class="btn btn-primary" href="/afat/stats/corp/{{ data.0.0 }}/">
                                            <span class="glyphicon glyphicon-eye-open"></span>
                                        </a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    {% endif %}
                </div>
            </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
