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


{#           #}
{# Opengraph #}
{#           #}
{% block opengraph %}
    {{ block.super }}
    <meta property="og:title" content="{{ exercise.name }}">
    <meta property="og:description" content="{{ exercise.description_clean }}">
{% endblock %}
{% block opengraphimages %}
    {% for image in exercise.exerciseimage_set.accepted %}
        <meta property="og:image" content="{{ image.image.url }}">
    {% empty %}
        <meta property="og:image" content="{{ image_absolute_path }}">
    {% endfor %}
{% endblock %}


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

    {% breadcrumb "Exercises" "exercise:exercise:overview" %}
    {% breadcrumb exercise exercise.get_absolute_url %}
{% endblock %}


{#       #}
{# Title #}
{#       #}
{% block title %}{{ exercise.name }}{% endblock %}


{#        #}
{# Header #}
{#        #}
{% block header %}{% endblock %}


{#         #}
{# Content #}
{#         #}
{% block content %}

{% if exercise.status == exercise.STATUS_PENDING %}
<div class="alert">
<h4>{% trans "Exercise is pending review" %}</h4>
<p>{% blocktrans %}This user submitted exercise is pending a decision to be
included in the database.{% endblocktrans %}
{% trans "Till then, it will not be shown in the overview or the search."  %}
{% if perms.exercises %}{% trans "Please select one of the options below." %}{% endif %}
</p>

{% if perms.exercises %}
<div class="row">
    <div class="col-sm-6">
        <a href="{% url 'exercise:exercise:accept' exercise.id %}" class="btn btn-default btn-block">
            <img src="{% static 'images/icons/status-on.svg' %}"
                width="32"
                height="32"
                alt="{% trans 'Accept' %}">
            {% trans "Accept" %}
        </a>
    </div>
    <div class="col-sm-6">
        <a href="{% url 'exercise:exercise:decline' exercise.id %}" class="btn btn-default btn-block">
            <img src="{% static 'images/icons/status-off.svg' %}"
                width="32"
                height="32"
                alt="{% trans 'Decline' %}">
            {% trans "Decline" %}
        </a>
    </div>
</div>
{% endif %} {# end check permissions #}

</div>
{% endif %} {# end exercise is pending review #}



{% cache cache_timeout exercise-detail-header exercise.id language.id %}
<p><strong>{% trans "Category" %}:</strong> {% trans exercise.category.name %}</p>

{% if exercise.equipment.all %}
    <p><strong>{% trans "Equipment" %}:</strong>
        {% for equipment in exercise.equipment.all %}
            {% trans equipment.name %}
            {% if not forloop.last %}, {% endif %}
        {% endfor %}
    </p>
{% endif %}

<div>{{ exercise.description|safe }}</div>
{% endcache %}


{# Comments #}
{% with comments=exercise.exercisecomment_set.all %}
{% if comments %}
<h4>{% trans "Comments for this exercise" %}</h4>

<ul>
{% for comment in comments %}
    <li>
        {{ comment }}
        {% if perms.exercises %}
        <span class="editoptions">
            <a href="{% url 'exercise:comment:delete' comment.id %}"
               title="{% trans 'Delete' %}">
               <img src="{% static 'images/icons/trash.svg' %}"
                    width="16"
                    height="16"
                    alt="{% trans 'Delete' %}">
            </a>
            <a href="{% url 'exercise:comment:edit' comment.id %}"
               title="{% trans 'Edit' %}"
               class="wger-modal-dialog">
               <img src="{% static 'images/icons/edit.svg' %}"
                    width="16"
                    height="16"
                    alt="{% trans 'Edit' %}">
            </a>
        </span>
        {% endif %}
    </li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}

{% if perms.exercises %}
<p>
    <a href="{% url 'exercise:comment:add' exercise.id %}"
       title="{% trans 'Add' %}"
       class="wger-modal-dialog">
        <img src="{% static 'images/icons/add.svg' %}"
            width="16"
            height="16"
            alt="{% trans 'Add new comment' %}">
        {% trans "Add new comment" %}</a>
</p>
{% endif %}


{# Images #}
{% with images=exercise.exerciseimage_set.accepted %}
{% if images %}
    <h4>{% trans "Images" %}</h4>

    <div class="image-gallery">
    {% with other_images=images %}
    {% for image in other_images %}
        <div class="image-box">
            <div class="boxInner">
                <img src="{{ image.image|thumbnail_url:'small' }}"
                     alt=""
                     class="gallery-image">

                <div class="titleBox">
                    <a href="{{ image.image.url }}"
                       target="_blank"
                       class=" no-hover">
                         {% trans "Download" %}</a>
                    {% if perms.exercises.change_exerciseimage %}
                    |
                    <a href="{% url 'exercise:image:delete' exercise.pk image.pk %}"
                       class="wger-modal-dialog no-hover">
                         {% trans 'Delete' %}</a> |
                    <a href="{% url 'exercise:image:edit' image.pk %}"
                       class="no-hover">
                         {% trans 'Edit' %}</a>
                    {% endif %}

                    <br>
                    {{image.get_license_display}}
                    {% if image.license_author %}
                         – {{image.license_author}}
                    {% endif %}

                </div>
            </div>
        </div>
    {% endfor %}
    {% endwith %}
    </div>
{% endif %}
{% endwith %}

{% if perms.exercises.change_exerciseimage %}
{% with images=exercise.exerciseimage_set.pending %}
{% if images %}
<h4>{% trans "Pending images" %}</h4>
<div class="list-group">
    {% for image in images %}
        <div class="list-group-item">
            <div class="media">
                <div style="width:60px;height:60px;" class="pull-left">
                    <a href="{{image.image.url}}">
                        <img alt="{{ image.exercise.name }}"
                             class="media-object "
                             style="max-width:100%; max-height:100%;"
                             src="{{ image.image|thumbnail_url:'thumbnail' }}">
                    </a>
                </div>
                <div class="media-body">
                    <h4 class="media-heading">{{ image.image }}</h4>
                    <a href="{% url 'exercise:image:accept' image.pk %}" class="btn btn-default btn-sm">{% trans "Accept" %}</a>
                    <a href="{% url 'exercise:image:decline' image.pk %}" class="btn btn-default btn-sm">{% trans "Decline" %}</a>
                    <a href="{% url 'exercise:image:delete' exercise.pk image.pk %}" class="btn btn-danger btn-sm">{% trans "Delete" %}</a>
                 </div>
            </div>
        </div>
    {% endfor %}
</div>
{% endif %}
{% endwith %}
{% endif %}  {# end check permission #}


{% if perms.exercises %}
<p>
    <a href="{% url 'exercise:image:add' exercise.id %}"
       title="{% trans 'Add' %}">
        <img src="{% static 'images/icons/add.svg' %}"
            width="16"
            height="16"
            alt="{% trans 'Add new image' %}">
        {% trans "Add new image" %}</a>
</p>
{% endif %}




{% cache cache_timeout exercise-detail-muscles exercise.id language.id %}
{% with muscles=exercise.muscles.all %}
{% with muscles_secondary=exercise.muscles_secondary.all %}

{% if muscles %}
<h4>{% trans "Muscles" %}</h4>
<p>
    {% trans "The diagram shows the most used muscles on this exercise" %}
</p>


<div>
    <div style="width:1em;height:1em;background-color:#cc0000;float:left;margin-right:0.5em;"></div>
    {% trans "Main muscles" %}
</div>

<div>
    <div style="width:1em;height:1em;background-color:#f57900;float:left;margin-right:0.5em;"></div>
    {% trans "Secondary muscles" %}
</div>



<div class="row" style="margin-top:1em;">
    <div class="col-md-6 col-xs-6">
        <div id="muscle-front" class="muscle-background center-block" style="background-image: {% for background in muscle_backgrounds_front %}url({% static background %}){% if not forloop.last %},{% endif %}{% endfor %};">
        </div>
        <ul>
            {% for muscle in muscles %}
            {% if muscle.is_front %}
            <li>{{muscle.name}}</li>
            {% endif %}
            {% endfor %}

            {% for muscle in muscles_secondary %}
            {% if muscle.is_front %}
            <li>{{muscle.name}}</li>
            {% endif %}
            {% endfor %}
        </ul>
    </div>
    <div class="col-md-6 col-xs-6">
        <div id="muscle-back" class="muscle-background center-block" style="background-image: {% for background in muscle_backgrounds_back %}url({% static background %}){% if not forloop.last %},{% endif %}{% endfor %};">
        </div>
        <ul>
            {% for muscle in muscles %}
            {% if not muscle.is_front %}
            <li>{{muscle.name}}</li>
            {% endif %}
            {% endfor %}

            {% for muscle in muscles_secondary %}
            {% if not muscle.is_front %}
            <li>{{muscle.name}}</li>
            {% endif %}
            {% endfor %}
        </ul>
    </div>
</div>


{% endif %}
{% endwith %}
{% endwith %} {# end musclelist #}
{% endcache %}

{% if logs %}
<h4>{% trans "Weight log" %}</h4>

{% render_weight_log logs svg_uuid user %}
<script src="{% static 'js/d3.js' %}"></script>

<script>
$(document).ready(function() {
    toggle_weight_log_table();
    weight_log_chart({{json|safe}}, "{{svg_uuid}}", "{{reps}}", $('#content').width());
});
</script>
{% endif %}

{% endblock %}


{#          #}
{# Side bar #}
{#          #}
{% block sidebar %}
{% if user.is_authenticated and not user.userprofile.is_temporary and not perms.exercises %}
<h4>{% trans "Options" %}</h4>
<p>
    <a href="{% url 'exercise:exercise:correct' exercise.id %}" {% auto_link_css flavour %}>
        <img src="{% static 'images/icons/edit.svg' %}"
             width="32"
             height="32"
             alt="{% trans 'Submit a correction' %}">
        {% trans "Submit a correction" %}
    </a>
</p>
{% endif %}


{% if perms.exercises %}
<h4>{% trans "Options" %}</h4>
<p>
    <a href="{% url 'exercise:exercise:edit' exercise.id %}" {% auto_link_css flavour %}>
        <img src="{% static 'images/icons/edit.svg' %}"
             width="32"
             height="32"
             alt="{% trans 'Edit' %}">
        {% trans "Edit" %}
    </a>
</p>
<p>
    <a href="{% url 'exercise:exercise:delete' exercise.id %}"
       {% auto_link_css flavour "wger-modal-dialog" %}>
        <img src="{% static 'images/icons/trash.svg' %}"
             width="32"
             height="32"
             alt="{% trans 'Delete' %}">
            {% trans "Delete" %}
    </a>
</p>
{% endif %}

{% license_sidebar exercise.license exercise.license_author %}

{% endblock %}
