{% extends "base_wide.html" %}
{% load i18n static wger_extras %}

{% block title %}{% trans "Dashboard" %}{% endblock %}

{#        #}
{# Header #}
{#        #}
{% block header %}
<script src="{% static 'js/weight.js' %}"></script>
{% endblock %}



{% block content %}
{% if current_workout %}
<div class="modal fade" id="calendar-day-select-popup">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">{% trans 'Add log to day' %}</h4>
            </div>
            <div class="modal-body">
                <p>{% blocktrans %}Click to add weight logs to a training
day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</strong></p>

                {% for day in current_workout.day_set.all %}
                    <a href="{% url 'manager:day:log' day.pk %}" class="btn btn-block btn-default">{{day.description}}</a>
                {% endfor %}
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
            </div>
        </div>
    </div>
</div>
{% endif %}

<div class="row">
    <div class="col-sm-4">
        <h4>{% trans "Workout"%}</h4>
            {% if current_workout %}
                <p>
                    <a href="{{ current_workout.get_absolute_url }}">
                        {% if current_workout.comment %}
                            {{ current_workout.comment }}
                        {% else %}
                            {% trans "Workout" %}
                        {% endif %}
                    </a>
                </p>
                <p>
                     – {{ current_workout.creation_date }}
                <p>
            {% endif %}

            <table class="table table-hover table-condensed">
                {% for day, exercise, is_workout in weekdays %}
                <tr>
                    <td>
                        {{ day }}
                     </td>
                    <td>
                        {% if not is_workout %}<span class="text-muted">{% endif%}
                        {{ exercise }}
                        {% if not is_workout %}</span>{% endif%}
                    </td>
                </tr>
                {% endfor %}
            </table>
    </div>
    <div class="col-sm-4">
        <h4>{% trans "Nutrition plan"%}</h4>

        {% if plan %}
            <p>
                <a href="{{ plan.get_absolute_url }}">{{ plan }}</a>
            </p>
            <p>
                 – {{ plan.creation_date }}
            </p>
        {% endif %}
        <table class="table table-hover table-condensed">
            <tr>
                <td>{% trans "Energy" %}</td>
                <td>
                    {{nutritional_info.total.energy|floatformat|default:"-/-"}} {% trans "kcal" %}
                </td>
            </tr>
            <tr>
                <td>{% trans "Protein" %}</td>
                <td>
                    {{nutritional_info.total.protein|floatformat|default:"-/-"}} {% trans_weight_unit 'g' user %}
                </td>
            </tr>
            <tr>
                <td>{% trans "Carbohydrates" %}</td>
                <td>
                    {{nutritional_info.total.carbohydrates|floatformat|default:"-/-"}} {% trans_weight_unit 'g' user %}
                </td>
            </tr>
            <tr>
                <td>{% trans "Fat" %}</td>
                <td>
                    {{nutritional_info.total.fat|floatformat|default:"-/-"}} {% trans_weight_unit 'g' user %}
                </td>
            </tr>
        </table>
    </div>
    <div class="col-sm-4">
        <h4>{% trans "Weight"%}</h4>
        <p>
            <a href="{% url 'weight:overview' user.username %}">{% trans "Overview" %}</a>
        </p>

        {% if weight %}
        <p>
            {% trans "Your current weight is: "%}
            {{weight.weight|floatformat}} {% trans_weight_unit 'kg' user %}
        </p>
        <table class="table table-hover table-condensed">
            {% for entry_detail in last_weight_entries %}
            <tr>
                <td>
                    {{ entry_detail.0.date }}
                </td>
                <td>
                    {{ entry_detail.0.weight }}
                </td>
                <td>
                    {% if entry_detail.1 > 0 %}
                        +
                    {% endif %}
                    {% if entry_detail.1 %}
                        {{ entry_detail.1 }}
                    {% else %}
                        -/-
                    {% endif %}
                <td>
            </tr>
            {% endfor %}
        </table>
        {% endif %}
    </div>
</div>


<div class="row">
    <div class="col-sm-4">
        {% if schedule %}
            <p>
                → {% trans "This workout is part of a schedule:" %}
                <a href="{{schedule.get_absolute_url}}">{{schedule.name}}</a>
            </p>
        {% endif %}
        <p><em>{% blocktrans %}The current workout is selected from your active schedule
or, if you don't have one, simply by date.{% endblocktrans %}</em></p>
    </div>
    <div class="col-sm-4">
        <div id="nutrition_diary_chart"></div>
    </div>
    <div class="col-sm-4">
        <div id="current-username" data-current-username="{{ owner_user.username }}"></div>
        <div id="weight_diagram"></div>
    </div>
</div>

<div class="row">
    <div class="col-sm-4">
        {% if current_workout %}
            {% if current_workout.day_set.all %}
                <a href="#" id="logging-popup-link" data-toggle="modal" data-target="#calendar-day-select-popup" class="btn btn-success btn-sm">
                    {% trans "Add new log" %}
                </a>
            {% endif %}
        {% else %}
            <a href="{% url 'manager:workout:add' %}" class="btn btn-sm btn-success">
                {% trans "No workouts found." %} {% trans "Add one now." %}
            </a>
        {% endif %}
    </div>
    <div class="col-sm-4">
        {% if not plan %}
                <a href="{% url 'nutrition:plan:add' %}" class="btn btn-sm  btn-success">
                    {% trans "No nutrition plans." %} {% trans "Add one now." %}
                </a>
        {% endif %}
        <p>
            <!--
            <a href="{% url 'nutrition:plan:add' %}" class="btn btn-success btn-sm">
                {% trans "Add nutrition plan" %}
            </a>
            -->
        </p>
    </div>
    <div class="col-sm-4">
        <a href="{% url 'weight:add' %}" class="btn btn-success btn-sm wger-modal-dialog">
            {% trans "Add weight entry" %}
        </a>
    </div>
</div>
{% endblock %}



{% block sidebar %}
<h4>{% trans "Info" %}</h4>
<p>{% blocktrans %}The current workout is selected from your active schedule
or, if you don't have one, simply by date.{% endblocktrans %}</p>

<p>{% trans "After adding a workout or a nutritional plan, you can edit them to set a goal." %}</p>
{% endblock %}
