{% extends "orga/cfp/base.html" %}
{% load bootstrap4 %}
{% load compress %}
{% load i18n %}
{% load static %}
{% load times %}

{% block stylesheets %}
    <link rel="stylesheet" type="text/css" href="{% static "vendored/nvd3/nv.d3.min.css" %}" />
{% endblock %}

{% block scripts %}
    {% compress js %}
        <script defer src="{% static "vendored/nvd3/d3.min.js" %}"></script>
        <script defer src="{% static "vendored/nvd3/nv.d3.min.js" %}"></script>
        <script defer src="{% static "orga/js/question_stats.js" %}"></script>
    {% endcompress %}
{% endblock %}

{% block cfp_content %}
<h4>
    {{ quotation_open }}{{ question.question }}{{ qutoation_close }}
    <small>({{ question.get_variant_display }})</small>
    <a href="{{ question.urls.edit }}" class="btn btn-sm btn-outline-info">
        <i class="fa fa-edit"></i>
    </a>
</h4>

{% if question.active %}
  <div class="alert alert-info">
    <span>
    {% trans "This question is currently active, it will be asked during submission." %}
    <a class="btn btn-sm btn-danger" href="{{ question.urls.toggle }}">{% trans "Hide question" %}</a>
    </span>
  </div>
{% else %}
  <div class="alert alert-info">
    <span>
    {% trans "This question is currently inactive, and will not be asked during submission." %}
    <a class="btn btn-sm btn-success" href="{{ question.urls.toggle }}">{% trans "Activate question" %}</a>
    </span>
  </div>
{% endif %}

<div class="pb-2">
  <form class="form-inline">
    {% bootstrap_form filter_form layout='inline' %}
    <button class="btn btn-info" type="submit">{% trans "Filter" %}</button>
  </form>
</div>

{% if not answer_count %}
    {% trans "Nobody has answered this question at the moment." %}
{% else %}
    {% if missing_answers %}
        {% blocktrans with count=question.answers.count|times missing=missing_answers trimmed %}
            This question has been answered <strong>{{ count }}</strong>, <strong>{{ missing }}</strong> answers are still missing.
        {% endblocktrans %}
    {% else %}
        {% blocktrans with count=question.answers.count|times trimmed %}
            This question has been answered <strong>{{ count }}</strong>, and no answers are missing.
        {% endblocktrans %}
    {% endif %}
  <div id="question-stats" class="d-flex">
    {% if question.variant != "file" and question.grouped_answers|length < 50 %}
    <div class="card">
        <div class="card-header">{% trans "Answers" %}</div>
      <div id="question-data" class="d-none" data-states='{{ question.grouped_answers_json }}'></div>
      <div id="question-answers" class="pie card-body"><svg></svg></div>
    </div>
    {% endif %}
    <table class="table table-responsive">
      <thead>
        <th>{% trans "Answer" %}</th>
        <th>{% trans "Amount" %}</th>
      </thead>
      <tbody>
        {% for answer in question.grouped_answers %}
          <tr>
            <td>
                {% if question.variant == "file" %}
                    {% if answer.answer.answer_file %}
                        <i class="fa fa-file-o"></i>
                        <a href="{{ answer.answer.answer_file.url }}">
                            {{ answer.answer.answer }}
                        </a>
                    {% else %}
                        <i class="fa fa-file-o"></i>
                        {{ answer.answer.answer }} ({% trans "lost file" %})
                    {% endif %}
                {% else %}
                    {% if answer.answer %}
                        {% if question.variant == 'boolean' %}
                            {% if answer.answer == "True" %}
                                {{ quotation_open }}{% trans "Yes" %}{{ quotation_close }}
                            {% else %}
                                {{ quotation_open }}{% trans "No" %}{{ quotation_close }}
                            {% endif %}
                        {% else %}
                            {{ quotation_open }}{{ answer.answer }}{{ quotation_close }}
                        {% endif %}
                    {% elif answer.options %}
                        {{ quotation_open }}{{ answer.options__answer }}{{ quotation_close }}
                    {% else %}
                        {% trans "Empty answer" %}
                    {% endif %}
                {% endif %}
                </td>
                <td>
                    {{ answer.count|times }}
                </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% endif %}
{% endblock %}
