{% load i18n %}
{% load humanize %}
{% load staticfiles %}

<div id="sidebar">
<div class="well">
    <!-- Status -->
    <h4 class="first">{% trans "Status" %}:</h4>
    {% trans motion.state.name %}

    <!-- vote result -->
    {% with motion.polls.all as polls %}
    {% if polls.exists and polls.0.has_votes %}
        {% for poll in polls reversed %}
            {% if poll.has_votes %}
                {% if polls|length > 1 %}
                    <h4>{{ poll.poll_number|ordinal|safe }} {% trans "Vote" %}:</h4>
                {% else %}
                    <h4>{% trans "Poll result" %}:</h4>
                {% endif %}
                {% with poll.get_options.0 as option %}
                <div class="result">
                    <img src="{% static 'img/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ option.Yes }} <br>
                    <img src="{% static 'img/voting-no.png' %}" title="{% trans 'No' %}"> {{ option.No }} <br>
                    <img src="{% static 'img/voting-abstention.png' %}" title="{% trans 'Abstention' %}"> {{ option.Abstain }}<br>
                    {% if poll.votesvalid != None or poll.votesinvalid != None %}
                        <hr>
                        {% if poll.votesvalid != None %}
                            <img src="{% static 'img/voting-yes-grey.png' %}" title="{% trans 'Valid votes' %}"> {{ poll.print_votesvalid }}<br>
                        {% endif %}
                        {% if poll.votesinvalid != None %}
                            <img src="{% static 'img/voting-invalid.png' %}" title="{% trans 'Invalid votes' %}"> {{ poll.print_votesinvalid }}<br>
                        {% endif %}
                    {% endif %}
                    {% if poll.votescast != None %}
                        <hr>
                        <img src="{% static 'img/voting-total.png' %}" title="{% trans 'Votes cast' %}"> {{ poll.print_votescast }}
                    {% endif %}
                </div>
                {% endwith %}
            {% else %}
                {% if poll|length == 1 %}
                <i>{% trans "No result available." %}</i>
                {% endif %}
            {% endif %}
        {% endfor %}
    {% endif %}
    {% endwith %}

    <!-- Submitter -->
    <h4>{% trans "Submitter" %}:</h4>
    {% for submitter in motion.submitter.all %}
        {{ submitter.person }}{% if not forloop.last %},<br>{% endif %}
    {% empty %}
        -
    {% endfor %}

    <!-- Supporters -->
    {% with motion.supporter.all as supporters %}
    {% if supporters|length > 0 %}
        <h4>{% trans "Supporters" %}:</h4>
        {% for supporter in supporters %}
            {{ supporter.person }}{% if not forloop.last %},<br>{% endif %}
        {% endfor %}
    {% endif %}
    {% endwith %}

    <!-- Category -->
    {% if motion.category %}
        <h4>{% trans "Category" %}:</h4>
        {{ motion.category }}
    {% endif %}
</div>
</div>

<h1>
    {{ motion.active_version.title }}
    <small>
        {% trans "Motion" %} {{ motion.identifier|default:'' }}
        {% if motion.is_amendment %}
            ({% trans "Amendment of" %} {{ motion.parent.identifier|default:motion.parent }})
        {% endif %}
        {% if motion.get_active_version.version_number > 1 %} | {% trans 'Version' %} {{ motion.active_version.version_number }}{% endif %}
    </small>
</h1>

<div class="text">
    {{ motion.active_version.text|safe }}
</div>

{% if motion.active_version.reason %}
    <br>
    <div class="reason">
        <p><b>{% trans "Reason" %}:</b></p>
        {{ motion.active_version.reason|safe }}
    </div>
{% endif %}
