{% extends "base.html" %}
{% load i18n staticfiles wger_extras django_bootstrap_breadcrumbs %}


{#           #}
{# Opengraph #}
{#           #}
{% block opengraph %}
    {{ block.super }}
    <meta property="og:title" content="{% trans 'Weight log' %}">
    <meta property="og:description" content="{% trans 'Weight log' %} / {{ workout }} / {{ owner_user.username }}">
{% endblock %}


{#             #}
{# Breadcrumbs #}
{#             #}
{% block breadcrumbs %}
    {{ block.super }}

    {% breadcrumb workout "manager:workout:view" workout.pk %}
    {% breadcrumb "Weight log" "manager:log:log" workout.pk %}
{% endblock %}


{#       #}
{# Title #}
{#       #}
{% block title %}{% trans "Weight log for workout" %}{% endblock %}


{#        #}
{# Header #}
{#        #}
{% block header %}
<script>
$(document).ready(function() {
    toggle_weight_log_table();
});
</script>
{% endblock %}


{#         #}
{# Content #}
{#         #}
{% block content %}
{% if workout.comment %}
<p>
    <strong>{% trans "Goal" %}:</strong> {{workout.comment}}
</p>
{% endif %}

{% for day in workout.canonical_representation.day_list %}
    <h4>{{ day.obj.description }}</h4>

    {% if is_owner %}
    <p>
    <a href="{% url 'manager:day:log' day.obj.id %}"
       title="{% trans 'Add weight log to this day' %}"
       {% auto_link_css flavour %}>
           <img src="{% static 'images/icons/statistics.svg' %}"
                width="32"
                height="32"
                alt="{% trans 'Add weight log to this day' %}">
        {% trans 'Add weight log to this day' %}
    </a>
    </p>
    {% endif %}

    {% for set in day.set_list %}
    {% for exercise in set.exercise_list %}

        {% with day_list=workout_log|get_item:day.obj.id %}
        {% with exercise_list=day_list|get_item:exercise.obj.id %}

            <div class="alert alert-info" style="text-align: center;margin-top:1em;">
                <a href="{{ exercise.obj.get_absolute_url }}">{{ exercise.obj.name }}</a>
            </div>

            {% if exercise_list.log_by_date %}
                {% with list=exercise_list.log_by_date %}
                    {% render_weight_log list exercise_list.div_uuid owner_user %}

                    <script>
                    $(document).ready(function() {
                    weight_log_chart({{exercise_list.chart_data|safe}},
                                    "{{exercise_list.div_uuid}}",
                                    "{{reps}}",
                                    $('#content').width());
                    });
                    </script>
                {% endwith %}
            {% else %}
                <p><em>{% trans "No weight entries here." %}</em></p>
            {% endif %}

        {% endwith %}
        {% endwith %}

    {% empty%}
    <p>
        <em>{% trans "No exercises for this day." %}</em>
    </p>
    {% endfor %}
    {% endfor %}
{% endfor %}
{% endblock %}


{#          #}
{# Side bar #}
{#          #}
{% block sidebar %}
<h4>{% trans "Notes" %}</h4>
<p>{% blocktrans %}This page shows the weight logs belonging to this workout
only. Click on an exercise to see all the historical data for
it.{% endblocktrans %}</p>

<p>{% blocktrans %}Click on a value on a chart to edit the log
entry.{% endblocktrans %}</p>

<p>{% blocktrans %}If on a single day there is more than one entry with the
same number of repetitions, but different weights, only the entry with the
higher weight is shown in the diagram.{% endblocktrans %}</p>

{% endblock %}
