{% extends 'base.html' %}

{% block title %}Questions{% endblock %}


{% block content %}
    <div class="container">
        {% if message %}
            <div class="col-lg-4">
                {% if msg_err %}
                <div class="alert alert-dismissable alert-danger">
                {% else %}
                <div class="alert alert-dismissable alert-success">
                {% endif %}
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    {{ message }}
                </div>
            </div>

        {% endif %}
        <h2>Questions</h2>
        <br>
        <h4>Please vote (or start a new question)</h4>
        {% for question in questions %}
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">By:{{ question.user.username }}
                    </h3>
                </div>
                <div class="panel-body">
                    {{ question.question }}
                    <ul class="nav nav-pills">
                        {% if question.vote_ids|length > 0 %}
                            <a class="btn btn-lg" >Votes <span class="badge">{{ question.vote_ids|length }}  </span></a>
                        {% endif %}
                        {% if the_user.id in question.vote_ids %}
                            <a class="btn btn-warning" href="/q/un_vote/?q={{ question.id }}">Un-Vote <span class="badge">-1</span></a>
                        {% else %}
                            {% if the_user.id == question.user.id %}
                                <a class="btn btn-danger" href="/q/edit/?q={{ question.id }}">Edit</a>
                            {% else %}
                                <a class="btn btn-success" href="/q/vote/?q={{ question.id }}">Vote <span class="badge">+1</span></a>
                            {% endif %}
                        {% endif %}
                        {% if question.docs.keys|length > 0 %}
                            <a class="btn btn-info" href="/q/review/?q={{ question.id }}">Media <span class="badge">{{ question.docs.keys|length }}</span></a>
                        {% endif %}
                    </ul>
                </div>
            </div>
        {% endfor %}
        <br>
        <a href="/q/edit/" class="btn btn-primary">I have a new question</a>
        <a href="/q/home/" class="btn btn-default">Refresh</a>
    </div>
{% endblock %}