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

{% load i18n %}
{% load humanize %}
{% load corp_tags %}
{% load evelinks %}

{% block member_data %}
    <div>
        <div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-title">{% translate "Corporation Stats" %}</div>
                </div>

                <div class="panel-body">
                    <div class="tab-pane fade in active" id="mains">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover" id="table-mains">
                                <thead>
                                    <tr>
                                        <th>{% translate "Corporation" %}</th>
                                        <th>{% translate "Members" %}</th>
                                        <th>{% translate "Mains" %}</th>
                                        <th>{% translate "Ratio" %}</th>
                                        <th>{% translate "Auth'd" %}</th>
                                        <th>{% translate "Orphans" %}</th>
                                        {% for corp in stats %}
                                            {% if forloop.first %}
                                                {% for k, v in corp.data.service_percent.items %}
                                                    <th>{{ k|title }}</th>
                                                {% endfor %}
                                            {% endif %}
                                        {% endfor %}
                                        <th>{% translate "Last Update" %}</th>
                                    </tr>
                                </thead>

                                <tbody>
                                    {% for corp in stats %}
                                        <tr>
                                            <td class="valign-middle">
                                                {{ corp.data.corp_name }}
                                            </td>
                                            <td class="text-right valign-middle">{{ corp.data.total_members }}</td>
                                            <td class="text-right valign-middle">{{ corp.data.total_mains }}</td>
                                            <td class="text-center">{{ corp.data.alt_ratio|floatformat:2|intcomma }}</td>
                                            <td class="text-center" style="color: var(--white); background-color: {% if corp.data.auth_percent >= 95 %}rgb(0 170 51){% elif corp.data.auth_percent >= 80 %}rgb(255 144 0){% else %}rgb(170 0 0){% endif %};">
                                                {{ corp.data.auth_percent|floatformat:0|intcomma }}% ({{ corp.data.authd_members }}/{{ corp.data.total_members }})
                                            </td>
                                            <td class="text-center" style="color: var(--white); background-color: {% if corp.data.orphan_count == 0 %}rgb(0 170 51){% else %}rgb(170 0 0){% endif %};">
                                                {{ corp.data.orphan_count }}
                                            </td>
                                            {% for k, v in corp.data.service_percent.items %}
                                                <td class="text-center" style="color: var(--white); background-color: {% if v.percent >= 95 %}rgb(0 170 51){% elif v.percent >= 80 %}rgb(255 144 0){% else %}rgb(170 0 0){% endif %};">
                                                    {{ v.percent|floatformat:0|intcomma }}% ({{ v.cnt }}/{{ corp.data.total_mains }})
                                                </td>
                                            {% endfor%}
                                            <td class="text-center valign-middle">{{ corp.date|str2date|naturaltime }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block extra_css %}
    {% include 'bundles/datatables-css.html' %}
{% endblock %}

{% block extra_javascript %}
    {% include 'bundles/datatables-js.html' %}

    <script>
        $(document).ready(function(){
            $('#table-mains').DataTable({
                lengthMenu: [
                    [-1, 25, 50],
                    ['All', 25, 50]
                ],
            });
        });
    </script>
{% endblock %}
