{% extends "base.html" %}
{% import "bootstrap/form.html" as wtf %}

{% block app_content %}

<div class="row">
    <div class="col-md-5">
        <h3>Create a room</h3>
        {{ wtf.render_form(form_create, id="create-room-form") }}
    </div>
    <div class="col-md-2">
    </div>
    <div class="col-md-5">
        <h3>Join a room</h3>
        <div class="list-group">
        {% if not public_rooms|length %}
            No rooms are available
        {% endif %}
        {% for room in public_rooms %}
            {% if room.password_hash is none %}
            <a id="room-link-{{ room.id }}" href={{ url_for('chat_create') + '/' + room.id }} class="list-group-item boldlink">
                    <h4>{{ room.name }}</h4>
                    <p>Participants: {{ room.clients|length }} / {{ room.guest_limit if room.guest_limit is not none else "Unlimited" }}</p>
                    <p>Last active: {{ room.active_ago }} minutes ago</p>
                </a>
            {% else %}
            <div class="list-group-item">
                    <h4>{{ room.name }}</h4>
                    <p>Participants: {{ room.clients|length }} / {{ room.guest_limit if room.guest_limit is not none else "Unlimited" }}</p>
                    <p>Last active: {{ room.active_ago }} minutes ago</p>
                <form class="form form-inline" method="post" role="form" action="{{ url_for('chat_create') + '/' + room.id }}">
                    {{ form_join.csrf_token }}
                    <input id="room_id-{{ room.id }}" name="room_id" type="hidden" value="{{ room.id }}">
                    {{ wtf.form_errors(form_join, hiddens="only") }}
                    {{ wtf.render_field(form_join.password) }}
                    {{ wtf.render_field(form_join.submit) }}
                </form>

            </div>
            {% endif %}
        {% endfor %}
        </div>
    </div>
</div>

{% endblock %}
