{% extends 'bingo/base.html' %}
{% load i18n %}
{% load staticfiles %}

{% block title %}{% trans 'Startpage' %}{% endblock %}
{% block extra_head %}
    {{ block.super }}
    <script src="{% static 'bingo/js/board_list.js' %}"></script>
{% endblock %}
{% block headline %}{% trans "start page" %}{% endblock %}

{% block extra_content_top %}
<div style="margin-bottom: 1em;float: right" class="cf">
{% if user.is_authenticated %}
    <b>{% trans "logged in as:" %}</b>
    <a href="{% url "bingo.views.profile" username=user.username %}">{{ user.username }}</a>
    <br />
    <a href="{% url "auth_logout" %}?next={% url "bingo.views.main" %}">{% trans "logout" %}</a>
{% else %}
    <a href="{% url "auth_login" %}?next={% url "bingo.views.main" %}">{% trans "login" %}</a>
    /
    <a href="{% url "registration_register" %}?next={% url "bingo.views.main" %}">{% trans "register" %}</a>
{% endif %}
</div>
{{ block.super }}
{% endblock %}

{% block content %}

{% if not my_board %}
    {% if can_start_game %}
        {% include "bingo/forms.html" %}
    {% endif %}
{% endif %}

{% if boards.count > 0 %}
<ul class="game_list">
    <li>
        {% with current_game as game %}
            <table class="current_game">
                <tr>
                    <th>{% trans 'Current game:' %}</th>
                    <td><a href="{% url 'bingo.views.game' game_id=game.game_id %}">{% trans 'Game #' %}{{ game.game_id }}</a> ({{ game.created }})</td>
                </tr>
                <tr>
                    <th>{% trans 'Your board:' %}</th>
                    <td>
                        {% if my_board %}
                            <a href="{% url 'bingo.views.bingo' my_board.board_id %}">
                                {% trans 'Board' %} #{{ my_board.board_id }}
                            </a>
                        {% else %}
                            {% trans 'You seem not to have a bingo board for the current game' %}
                        {% endif %}
                    </td>
                </tr>
                {% if game.description %}
                    <tr>
                        <th>{% trans 'Game Description:' %}</th>
                        <td>{{ game.description }}</td>
                    </tr>
                {% endif %}
            </table>
        {% endwith %}
        {% with all_boards=boards.all %}
        {% with boards=all_boards.all|slice:":12" total_boards=all_boards.count game=current_game %}
            {% include "bingo/board_list.html" %}
        {% endwith %}
        {% endwith %}
    </li>
</ul>
{% endif %}

{% if old_games.count > 0 %}
<p class="gamelist_header">
    {% trans 'View boards from older games:' %}
</p>
<ul class="game_list">
    {% for game in old_games|slice:'0:10' %}
    <li>
        <a href="{% url 'bingo.views.game' game_id=game.game_id %}">{% trans 'Game #' %}{{ game.game_id }}</a> ({{ game.created }})
        {% include "bingo/game_rating.html" %}
        {% if game.description %}
            <br />
            ({{ game.description }})
        {% endif %}
        {% with all_boards=game.bingoboard_set.all %}
        {% with boards=all_boards.all|slice:":12" total_boards=all_boards.count %}
            {% include "bingo/board_list.html" %}
        {% endwith %}
        {% endwith %}
    </li>
    {% endfor %}
    {% if old_games|length > 10 %}
    <li><a href="{% url 'games_list' %}">{% trans 'older games' %}</a></li>
    {% endif %}
</ul>
{% endif %}

{% endblock %}
