{% load i18n %}
{% load staticfiles %}
{% load wger_extras %}

<script>
$(document).ready(function() {

    // Call the setup function to allow the sets to be sortable again after loading this
    // view via AJAX
    setup_sortable();

    // Init the modal dialog to edit the exercise
    form_modal_dialog();

})
</script>

<table class="bordertable workout-table" id="table-day-{{ day.obj.id }}">
<thead>
    <tr id="day-{{ day.obj.id }}">
        <th colspan="2">

            {{ day.days_of_week.text }} – {{ day.obj.description }}

            <span class="editoptions" style="float: right;">
                <a href="{% url 'day-delete' day.obj.id %}"
                   title="{% trans 'Delete' %}">
                       <img src="{% static 'images/icons/trash.svg' %}"
                            width="22"
                            height="22"
                            alt="{% trans 'Delete' %}">
                </a>
                <a href="{% url 'day-edit' day.obj.id %}"
                   title="{% trans 'Edit' %}"
                   class="modal-dialog">
                       <img src="{% static 'images/icons/edit.svg' %}"
                            width="22"
                            height="22"
                            alt="{% trans 'Edit' %}">
                </a>
                <a href="{% url 'day-log' day.obj.id %}"
                   title="{% trans 'Add weight log to this day' %}">
                       <img src="{% static 'images/icons/statistics.svg' %}"
                            width="22"
                            height="22"
                            alt="{% trans 'Add weight log to this day' %}">
                </a>
            </span>
        </th>
    </tr>
    </thead>
    <tbody>
        {% for set in day.set_list %}
        <tr id="set-{{ set.obj.id }}">
            <td class="ym-g10">{{ forloop.counter }}
                <span class="editoptions">
                {% if day.set_list|length > 1 %}
                <img src="{% static 'images/icons/move.svg' %}"
                     width="22"
                     height="22"
                     alt="{% trans 'Move me' %}"
                     title="{% trans 'Move me' %}"
                     class="dragndrop-handle">
                 <br>
                 {% endif %}
                 <a href="{% url 'set-edit' set.obj.id %}"
                   title="{% trans 'Edit' %}"
                   class="modal-dialog">
                       <img src="{% static 'images/icons/edit.svg' %}"
                            width="22"
                            height="22"
                            alt="{% trans 'Edit' %}">
                </a>
                 <a href="{% url 'wger.manager.views.set.delete' set.obj.id %}"
                    title="{% trans 'Delete' %}">
                        <img src="{% static 'images/icons/trash.svg' %}"
                             width="16"
                             height="16"
                             alt="{% trans 'Delete' %}">
                </a>
                 </span>
            </td>
            <td>
                <div class="exercise-list">
                {% for exercise in set.exercise_list %}
                    <div id="exercise-{{ exercise.obj.id }}" class="ajax-set-edit-target">
                        <a href="{{ exercise.obj.get_absolute_url }}">{{ exercise.obj.name }}</a>:

                        <span class="settings-list">
                        {{exercise.setting_text}}
                        {% if not exercise.setting_text %}
                            <a href="{% url 'set-edit' set.obj.id %}"
                               class="modal-dialog btn btn-block">
                                    {% trans "This exercise has no repetitions." %}
                                    {% trans "Edit them now."%}
                            </a>
                        {% endif %}
                        </span>

                        <div class="exercise-comments dimmed">
                            <ul>
                            {% for comment in exercise.comment_list %}
                                <li>{{comment}}</li>
                            {% endfor %}
                            </ul>
                        </div>
                    </div>
                {% endfor %} <!--for exercise in set-->
                </div>
            </td>
        </tr>
        {% empty %}
        <tr>
            <td colspan="2">
                    <a href="{% url 'set-add' day.obj.id %}"
                       class="modal-dialog btn btn-block">
                       {% trans "No exercises selected for this day." %}
                       {% trans "Add one now." %}
                    </a>
            </td>
        </tr>
        {% endfor %} <!--for set in day-->
        <tr>
            <td colspan="2">
                <a href="{% url 'set-add' day.obj.id %}"
                   class="modal-dialog">{% trans "Add exercises to this workout day" %}</a>
            </td>
        </tr>
    </tbody>
</table>
