{% extends "tablepage.html" %}
{% block head %}
    {{ super() }}
    <title>Multiworld Tracker</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for("static", filename="styles/tracker.css") }}" />
    <script type="application/ecmascript" src="{{ url_for("static", filename="assets/trackerCommon.js") }}"></script>
{% endblock %}

{% block body %}
    {% include "header/dirtHeader.html" %}
    {% include "multitrackerNavigation.html" %}

    <div id="tracker-wrapper" data-tracker="{{ room.tracker | suuid }}" data-second="{{ saving_second }}">
        <div id="tracker-header-bar">
            <input placeholder="Search" id="search" />

            <div
                id="multi-stream-link"
                class="tracker-navigation-bar"
                {% if not videos %}style="display: none"{% endif %}
            >

                <a
                    class="tracker-navigation-button"
                    href="https://multistream.me/
                        {%- for platform, link in videos.values() | unique(False, 1) -%}
                            {%- if platform == "Twitch" -%}t{%- else -%}yt{%- endif -%}:{{- link -}}/
                        {%- endfor -%}"
                    target="_blank"
                >
                    ► Multistream
                </a>
            </div>

            <div class="info">
                Clicking on a slot&apos;s number will bring up the slot-specific tracker.
                This tracker will automatically update itself periodically.
            </div>
        </div>

        <div id="tables-container">
        {%- for team, players in room_players.items() -%}
            <div class="table-wrapper">
                <table id="checks-table" class="table non-unique-item-table">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            {% if current_tracker == "Generic" %}<th>Game</th>{% endif %}
                            <th>Status</th>
                            {% block custom_table_headers %}
                            {# Implement this block in game-specific multi-trackers. #}
                            {% endblock %}
                            <th class="center-column">Checks</th>
                            <th class="center-column">&percnt;</th>
                            <th class="center-column hours last-activity">Last<br>Activity</th>
                        </tr>
                    </thead>
                    <tbody>
                    {%- for player in players -%}
                        {%- if current_tracker == "Generic" or games[(team, player)] == current_tracker -%}
                            <tr>
                                <td>
                                    <a href="{{ url_for("get_player_tracker", tracker=room.tracker, tracked_team=team, tracked_player=player) }}">
                                        {{ player }}
                                    </a>
                                </td>
                                <td>{{ player_names_with_alias[(team, player)] | e }}</td>
                                {%- if current_tracker == "Generic" -%}
                                    <td>{{ games[(team, player)] }}</td>
                                {%- endif -%}
                                <td>
                                    {{
                                        {
                                            0: "Disconnected",
                                            5: "Connected",
                                            10: "Ready",
                                            20: "Playing",
                                            30: "Goal Completed"
                                        }.get(states[(team, player)], "Unknown State")
                                    }}
                                </td>

                                {% block custom_table_row scoped %}
                                {# Implement this block in game-specific multi-trackers. #}
                                {% endblock %}

                                {% set location_count = locations[(team, player)] | length %}
                                <td class="center-column" data-sort="{{ locations_complete[(team, player)] }}">
                                    {{ locations_complete[(team, player)] }}/{{ location_count }}
                                </td>

                                <td class="center-column">
                                {%- if locations[(team, player)] | length > 0 -%}
                                    {% set percentage_of_completion = locations_complete[(team, player)] / location_count * 100 %}
                                    {{ "{0:.2f}".format(percentage_of_completion) }}
                                {%- else -%}
                                    100.00
                                {%- endif -%}
                                </td>

                                {%- if activity_timers[(team, player)] -%}
                                    <td class="center-column">{{ activity_timers[(team, player)].total_seconds() }}</td>
                                {%- else -%}
                                    <td class="center-column">None</td>
                                {%- endif -%}
                            </tr>
                        {%- endif -%}
                    {%- endfor -%}
                    </tbody>

                    {%- if not self.custom_table_headers() | trim -%}
                        <tfoot>
                            <tr>
                                <td colspan="2" style="text-align: right">Total</td>
                                <td>All Games</td>
                                <td>{{ completed_worlds[team] }}/{{ players | length }} Complete</td>
                                <td class="center-column">
                                    {{ total_team_locations_complete[team] }}/{{ total_team_locations[team] }}
                                </td>
                                <td class="center-column">
                                    {%- if total_team_locations[team] == 0 -%}
                                        100
                                    {%- else -%}
                                        {{ "{0:.2f}".format(total_team_locations_complete[team] / total_team_locations[team] * 100) }}
                                    {%- endif -%}
                                </td>
                                <td class="center-column last-activity"></td>
                            </tr>
                        </tfoot>
                    {%- endif -%}
                </table>
            </div>

        {%- endfor -%}

        {% block custom_tables %}
        {# Implement this block to create custom tables in game-specific multi-trackers. #}
        {% endblock %}

        {% include "multitrackerHintTable.html" with context %}
        </div>
    </div>
{% endblock %}
