{% load i18n %} 
{% load url from future %}
{% load staticfiles %}
{% load manager_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.id }}">
<thead>
    <tr id="day-{{ day.id }}">
        <th colspan="2">
            {% for day_of_week in day.day.select_related %}
                {% trans day_of_week.day_of_week %}
                {% if not forloop.last %}, {% endif %}
                {% if forloop.last %}–{% endif %}
            {% endfor %}

            {{ day.description }}

            <span class="editoptions" style="float: right;">
                <a href="{% url 'wger.manager.views.day.delete' workout.id day.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.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.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_set.select_related %}
        <tr id="set-{{ set.id }}">
            <td class="ym-g10">{{ forloop.counter }}
                <span class="editoptions">
                <img src="{% static 'images/icons/move.svg' %}"
                     width="22"
                     height="22"
                     alt="{% trans 'Move me' %}"
                     title="{% trans 'Move me' %}"
                     class="dragndrop-handle">
                 <br>
                 <a href="{% url 'set-edit' set.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.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.exercises.select_related %}
                    <div id="exercise-{{ exercise.id }}" class="ajax-set-edit-target">
                        <a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>:

                        {% comment %}
                            If there are more than 1 settings, don't output the repetitions
                            e.g. "4 x 8 8 10 10" is shown only as "8 8 10 10", after all
                            those 4 sets are not done four times! But "3 x 12" is stil shown
                            like that.
                        {% endcomment %}
                        {% if exercise|get_current_settings:set.id|length == 1 %}
                            {{ set.sets }} ×
                        {% endif %}

                        {% comment %}
                            get_current_settings only does a exercise.setting_set.filter(set_id=set_id)
                        {% endcomment %}
                        
                        <span class="settings-list">
                        {% for setting in exercise|get_current_settings:set.id %}
                            <span id="setting-{{setting.id}}">
                            
                            
                            {% if setting.reps == 99 %}
                                 ∞
                            {%else%}
                                {{setting.reps}}
                            {%endif%}
                            {% if not forloop.last %} – {% endif %}
                            </span>
                        {% empty %}
                                <a href="{% url 'set-edit' set.id %}"
                                   class="modal-dialog btn btn-block">
                                {% trans "This exercise has no repetitions." %} 
                                {% trans "Edit them now."%}
                            </a>
                        {% endfor %} <!--for setting in exercise-->
                        </span>
                        
                        <div class="exercise-comments dimmed">
                            <ul>
                            {% for comment in exercise.exercisecomment_set.all %}
                                <li>{{comment}}</li>
                            {% endfor %}
                            </ul>
                        </div>
                        
                        
                        
                    </div>
                {% endfor %} <!--for exercise in set-->
                </div>
        {% empty %}
        <tr>
            <td colspan="2">
                    <a href="{% url 'set-add' day.id %}"
                       class="modal-dialog btn btn-block">
                       {% trans "No exercises selected for this day." %}
                       {% trans "Add one now." %}
                    </a>
                
        {% endfor %} <!--for set in day-->
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <a href="{% url 'set-add' day.id %}"
                   class="modal-dialog">{% trans "Add exercises to this workout day" %}</a>
            </td>
        </tr>
    </tbody>
</table>
