{% extends 'tablepage.html' %}

{%- macro games(slots) -%}
    {%- set gameList = [] -%}
    {%- set maxGamesToShow = 10 -%}

    {%- for slot in (slots|list|sort(attribute="player_id"))[:maxGamesToShow] -%}
        {% set player = "#" + slot["player_id"]|string + " " + slot["player_name"] + " : " + slot["game"] -%}
        {% set _ = gameList.append(player) -%}
    {%- endfor -%}

    {%- if slots|length > maxGamesToShow -%}
        {% set _ = gameList.append("... and " + (slots|length - maxGamesToShow)|string + " more") -%}
    {%- endif -%}

    {{ gameList|join('\n') }}
{%- endmacro -%}

{% block head %}
    {{ super() }}
    <title>User Content</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/userContent.css") }}" />
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/markdown.css") }}" />
    <script type="application/ecmascript" src="{{ url_for('static', filename="assets/userContent.js") }}"></script>
{% endblock %}

{% block body %}
    {% include 'header/oceanHeader.html' %}
    <div id="user-content-wrapper" class="markdown">
        <div id="user-content" class="grass-island">
            <h1>User Content</h1>
            Below is a list of all the content you have generated on this site. Rooms and seeds are listed separately.<br/>
            Sessions can be saved or synced across devices using the <a href="{{url_for('show_session')}}">Sessions Page.</a>

            <h2>Your Rooms</h2>
            {% if rooms %}
                <table id="rooms-table" class="table">
                    <thead>
                        <tr>
                            <th>Seed</th>
                            <th>Room</th>
                            <th class="center">Players</th>
                            <th>Created (UTC)</th>
                            <th>Last Activity (UTC)</th>
                            <th>Mark for deletion</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for room in rooms %}
                            <tr>
                                <td><a href="{{ url_for("view_seed", seed=room.seed.id) }}">{{ room.seed.id|suuid }}</a></td>
                                <td><a href="{{ url_for("host_room", room=room.id) }}">{{ room.id|suuid }}</a></td>
                                <td title="{{ games(room.seed.slots) }}">
                                    {{ room.seed.slots|length }}
                                </td>
                                <td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
                                <td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td>
                                <td><a href="{{ url_for("disown_room", room=room.id) }}">Delete next maintenance.</a></td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            {% else %}
                You have not created any rooms yet!
            {% endif %}

            <h2>Your Seeds</h2>
            {% if seeds %}
                <table id="seeds-table" class="table">
                    <thead>
                        <tr>
                            <th>Seed</th>
                            <th class="center">Players</th>
                            <th>Created (UTC)</th>
                            <th>Mark for deletion</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for seed in seeds %}
                            <tr>
                                <td><a href="{{ url_for("view_seed", seed=seed.id) }}">{{ seed.id|suuid }}</a></td>
                                <td title="{{ games(seed.slots) }}">
                                    {% if seed.multidata %}
                                        {{ seed.slots|length }}
                                    {% else %}
                                        1
                                    {% endif %}
                                </td>
                                <td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
                                <td><a href="{{ url_for("disown_seed", seed=seed.id) }}">Delete next maintenance.</a></td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            {% else %}
                You have not generated any seeds yet!
            {% endif %}
        </div>
    </div>
{% endblock %}
