{% extends 'assessments/base.html' %}
{% load i18n %}

{% block head %}
    {{ block.super }}
    <script src="{{ STATIC_URL }}common/js/ajax-modal.js"></script>
{% endblock %}

{% block section_title %}
    {% trans 'Certification levels' %}
{% endblock %}

{% block section_actions %}
    {% if competency_tree.can_edit %}
        <a href="{{ competency_tree.get_certification_status_create_url }}" class="btn btn-primary dialog-box">
            <i class="fa fa-plus"></i> {% trans 'New certification level' %}
        </a>
    {% endif %}
{% endblock %}

{% block section_content %}

    <form method="post">{% csrf_token %}

        <table class="table table-hover certification-program">
            <thead>
                <tr>
                    <th></th>
                    {% for status in form.statuses %}
                        <th>
                            <div class="dropdown {% if status.is_reference %}text-primary{% endif %}" style="display:inline-block">
                                {{ status.name }}

                                {% if competency_tree.can_edit %}
                                    <button class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdown-menu-{{ forloop.counter }}" data-toggle="dropdown" aria-expanded="false">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdown-menu-{{ forloop.counter }}">
                                        <li role="presentation">
                                            <a role="menuitem" tabindex="-1" href="{{ status.get_reference_url }}">
                                                <i class="fa fa-flag"></i> {% trans "Flag as reference" %}
                                            </a>
                                        </li>
                                        <li role="presentation">
                                            <a role="menuitem" tabindex="-1" href="{{ status.get_edit_url }}" class="dialog-box">
                                                <i class="fa fa-pencil"></i> {% trans 'Edit' %}
                                            </a>
                                        </li>
                                        <li role="presentation">
                                            <a role="menuitem" tabindex="-1" href="{{ status.get_delete_url }}" class="dialog-box">
                                                <i class="fa fa-trash"></i> {% trans 'Delete' %}
                                            </a>
                                        </li>
                                    </ul>
                                {% endif %}

                            </div>
                        </th>
                    {% endfor %}
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><strong>Global score</strong></td>
                    {% for field in form.global_score_fields %}
                        {% if competency_tree.can_edit %}
                            <td>{% trans "Min. score:" %} {{ field }}</td>
                        {% else %}
                             <td>{% trans "Min. score:" %} {{ field.value }}</td>
                        {% endif %}
                    {% endfor %}
                </tr>

                {% for competency_fields_list in form.threshold_fields_by_competency %}
                    <tr>
                        <td>{{ competency_fields_list.name }}</td>
                        {% for field in competency_fields_list.fields %}
                            {% if competency_tree.can_edit %}
                                <td>{% trans "Min. score:" %} {{ field }}</td>
                            {% else %}
                                <td>{% trans "Min. score:" %} {{ field.value }}</td>
                            {% endif %}
                        {% endfor %}
                    </tr>
                {% endfor %}

            </tbody>
        </table>

        <hr>
        {% if competency_tree.can_edit %}
            <div class="clearfix">
                <div class="pull-right">
                    <input class="btn btn-primary" type="submit" value="{% trans 'Save' %}" />
                </div>
            </div>
        {% endif %}
    </form>

{% endblock %}
