{% load i18n static wger_extras thumbnail %}

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

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

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

})
</script>

<table class="table table-bordered workout-table" id="table-day-{{ day.obj.id }}" data-id="{{ day.obj.id }}">
<thead>
    <tr id="day-{{ day.obj.id }}">
        <th colspan="2" style="background: none repeat scroll 0% 0% #F5F5F5;">

            {{ day.days_of_week.text }} – {{ day.obj.description }}
            {% if editable %}
            <span class="editoptions" style="float: right;">
                <a href="{% url 'manager:day:delete' day.obj.id %}"
                   title="{% trans 'Delete' %}">
                    <span class="{% fa_class 'trash' %}"></span></a>
                <a href="{% url 'manager:day:edit' day.obj.id %}"
                   title="{% trans 'Edit' %}"
                   class="wger-modal-dialog">
                    <span class="{% fa_class 'pencil-square-o' %}"></span></a>
                <a href="{% url 'manager:day:log' day.obj.id %}"
                   title="{% trans 'Add weight log to this day' %}">
                    <span class="{% fa_class 'line-chart' %}"></span></a>
            </span>
            {% endif %}
        </th>
    </tr>
    </thead>
    <tbody>
        {% for set in day.set_list %}
        <tr data-id="{{ set.obj.id }}" id="set-{{ set.obj.id }}">
            <td style="width: 15%;border-right-width: 0px;">
                <h5><strong>{{ forloop.counter }}</strong></h5>

                {% if editable %}
                    <span class="editoptions">
                    {% if day.set_list|length > 1 %}
                        <span class="{% fa_class 'bars' %} dragndrop-handle"></span>
                        <br>
                    {% endif %}
                    <a href="{% url 'manager:set:edit' set.obj.id %}"
                       title="{% trans 'Edit' %}"
                       class="wger-modal-dialog">
                           <span class="{% fa_class 'pencil-square-o' %}"></span></a>
                        <br>
                    <a href="{% url 'manager:set:delete' set.obj.id %}"
                       title="{% trans 'Delete' %}">
                            <span class="{% fa_class 'trash' %}"></span></a>
                    </span>
                {% endif %}
            </td>
            <td style="border-left-width: 0px;">
                <div class="exercise-list">
                {% for exercise in set.exercise_list %}
                <div id="exercise-{{ exercise.obj.id }}" class="ajax-set-edit-target">
                    <div class="media">


                        <div class="media-left">
                            <a href="{{exercise.obj.get_absolute_url}}" >
                            <div style="width: 64px; height: 64px;">
                            {% if exercise.obj.main_image %}
                            <img class="img-responsive"
                                 src="{{ exercise.obj.main_image.image|thumbnail_url:'small' }}"
                                 alt="{{exercise.obj}}"
                                 style="max-width: 100%; max-height: 100%;">
                            {% else %}
                            <img class="img-responsive"
                                 src="{% static 'images/icons/image-placeholder.svg' %}"
                                 alt="{% trans 'Placeholder image for exercise' %}"
                                 style="opacity: 0.4;">
                            {% endif %}
                            </div>
                            </a>
                        </div>



                        <div class="media-body">
                            <h4 class="media-heading">
                                {{ exercise.obj.name }}
                            </h4>
                            <p>{{exercise.setting_text}}</p>

                            {% if editable %}
                            {% if not exercise.setting_list %}
                            <p>
                                {% trans "This exercise has no repetitions." %}<br>
                                <a href="{% url 'manager:set:edit' set.obj.id %}" class="wger-modal-dialog">
                                {% trans "Edit them now."%}
                                </a>
                            </p>
                            {% endif %}

                            {% if exercise.comment_list %}
                            <p class="text-muted exercise-comments">
                                {% for comment in exercise.comment_list %}
                                    {{comment}}<br>
                                {% endfor %}
                            </p>
                            {% endif %}
                            {% endif %}
                        </div>
                    </div>
                </div>
                {% endfor %} <!--for exercise in set-->
                </div>
            </td>
        </tr>
        {% empty %}
        {% if editable %}
        <tr>
            <td colspan="2">
                    <a href="{% url 'manager:set:add' day.obj.id %}"
                       class="wger-modal-dialog btn btn-default btn-block wger-modal-dialog">
                       {% trans "No exercises selected for this day." %}
                       {% trans "Add one now." %}
                    </a>
            </td>
        </tr>
        {% endif %}
        {% endfor %} <!--for set in day-->
        {% if editable %}
        <tr>
            <td colspan="2">
                <a href="{% url 'manager:set:add' day.obj.id %}"
                   class="wger-modal-dialog">{% trans "Add exercises to this workout day" %}</a>
            </td>
        </tr>
        {% endif %}
    </tbody>
</table>
