{% extends "base.html" %}
{% load i18n static 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 workout %}
    {% breadcrumb "Weight log" "manager:log:log" workout.pk %}
{% endblock %}


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


{#        #}
{# Header #}
{#        #}
{% block header %}
{% 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 %}" class="btn btn-success btn-sm">
            {% 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="row" style="padding-top: 1em;">
                <div class="col-xs-3">
                    <strong><a href="{{ exercise.obj.get_absolute_url }}">{{ exercise.obj.name }}</a></strong>
                </div>
                <div class="col-xs-9">
                    {% if exercise_list.log_by_date %}
                        {#  TODO: perhaps move the draw_weight_chart function to render_weight_log #}
                        {% with list=exercise_list.log_by_date %}
                            {% render_weight_log list exercise_list.div_uuid owner_user %}
                            <script>
                            $(document).ready(function() {
                            wgerDrawWeightLogChart({{exercise_list.chart_data|safe}},
                                                  "{{exercise_list.div_uuid}}");
                            });
                            </script>
                        {% endwith %}


                    {% else %}
                        <p><em>{% trans "No weight entries here." %}</em></p>
                    {% endif %}
                </div>
            </div>

        {% 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 %}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>

<p>{% blocktrans %}Note that only entries with a weight unit (kg or lb) and
repetitions are charted, other combinations such as time or until failure
are ignored here.{% endblocktrans %}</p>
{% endblock %}
