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

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

<!--
        Title
-->
{% block title %}{% trans "Daily calories calculator" %}{% endblock %}


<!--
        Main Content
-->
{% block content %}

<h3>1 - {%trans "Basal metabolic rate" %}</h3>
<p>{% blocktrans %}The basal metabolic rate is the amount of energy expended daily
at rest. This is the minimum energy needed for the body to function, without any
additional physical activity.{% endblocktrans %}</p>
<form action="{% url 'calories-calculate-bmr' %}"
      method="post"
      class="ym-form calories-autoform"
      id="bmr-form">
{% csrf_token %}

{% if form.non_field_errors %}
<div class="ym-fbox-text ym-error">
    {% for error in form.non_field_errors %}
        <p class="ym-message">{% trans error %}</p>
    {% endfor %}
</div>
{% endif %}

<table>
    {% for current_field in form %}
        {% yaml_form_field current_field %}
    {% endfor %}
</table>
</form>

<div id="bmr-result-container" style="display:hidden;">
    <p>{% trans 'Your basic metabolic rate is: ' %}
    <strong>
        <span id="bmr-result-value">{{user.userprofile.calculate_basal_metabolic_rate|floatformat:2}}</span>
    </strong>
    </p>
</div>




<h3>2 - {%trans "Physical activities" %}</h3>
<p>{% blocktrans %}The physical activity level (PAL) is a factor used to to express
the additional physical activity and is used to calculate the total energy
required per day.{% endblocktrans %}</p>
<form action="{% url 'calories-calculate-activities' %}"
      method="post"
      class="ym-form calories-autoform"
      id="activities-form">
{% csrf_token %}

{% if form.non_field_errors %}
<div class="ym-fbox-text ym-error">
    {% for error in form_activities.non_field_errors %}
        <p class="ym-message">{% trans error %}</p>
    {% endfor %}
</div>
{% endif %}


<table>
    {% yaml_form_field form_activities.sleep_hours %}
    <tr>
        <td class="dimmed">{% trans form_activities.work_hours.help_text %}</td>
        <td class="dimmed">{% trans form_activities.work_intensity.label %}</td>
    </tr>
    <tr>
        <td colspan="2">{% trans form_activities.work_hours.label %}</td>
    </tr>
    <tr>
        <td>{{form_activities.work_hours}}</td>
        <td>{{form_activities.work_intensity}}</td>
    </tr>

    <tr>
        <td colspan="2">{% trans form_activities.sport_hours.label %}</td>
    </tr>
    <tr>
        <td>{{form_activities.sport_hours}}</td>
        <td>{{form_activities.sport_intensity}}</td>
    </tr>

    <tr>
        <td colspan="2">{% trans form_activities.freetime_hours.label %}</td>
    </tr>
    <tr>
        <td>{{form_activities.freetime_hours}}</td>
        <td>{{form_activities.freetime_intensity}}</td>
    </tr>
</table>


</form>

<div id="activities-result-container" style="display:hidden;">
    <p>{% trans 'Factor for daily activities: ' %} <strong><span id="activities-result-value">{{user.userprofile.calculate_activities|floatformat:2}}</span></strong></p>
</div>





<h3>3 - {% trans "Total daily calories" %}</h3>
<p>{% blocktrans %}The base caloric intake is the amount of calories your metabolism
needs based on your level of physical activity.{% endblocktrans %}</p>
<form action=""
      method="post"
      class="ym-form calories-autoform"
      id="base-calories-form">
{% csrf_token %}
<table>
    <tr>
        <td>{% trans "Basic caloric intake" %}</td>
        <td><span id="id_base_calories"></span></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="{% trans 'Calculate basic caloric intake' %}" id="form-calculate-daily-calories">
        </td>
    </tr>
</table>
</form>


<p>{% blocktrans %}The total calories are the actual total calories per day. This
might include e.g. a surplus or deficit if you are bulking or cutting. Alternatively
you might just enter yourself the amount of calories if you know the value.{% endblocktrans %}
</p>
<form action="{% url 'calories-calculate-total' %}"
      method="post"
      class="ym-form"
      id="total-calories-form">
{% csrf_token %}
<table>
     {% yaml_form_field form_calories.additional_calories %}
     {% yaml_form_field form_calories.calories %}
</table>

<input type="submit" value="{% trans 'Transfer basic intake to total daily calories' %}" id="form-transfer-calories">
<input type="submit" value="{% trans 'Add additional calories to total daily calories' %}" id="add-calories-total">
<input type="submit" value="{% trans 'Save total calories to profile' %}" id="form-update-calories">
</form>


{% endblock %}


{#                 #}
{#    Side bar     #}
{#                 #}
{% block sidebar %}
<h3>{% trans "Info" %}</h3>
<p>{% blocktrans %}Please note that these calculations can only be an
approximation. If you base your nutrition plan on these values, observe
yourself for some weeks and change the total amount if needed.{% endblocktrans %}</p>
{% endblock %}
