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

{% block title %}{{schedule.name}}{% endblock %}

{% block header %}
{% endblock %}

{% block content %}
{% for step in schedule.schedulestep_set.select_related %}
<div class="modal fade" id="step-{{step.id}}">
    <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 "Options" %}</h4>
            </div>
            <div class="modal-body">
                <a href="{{ step.workout.get_absolute_url }}"
                   title="{% trans 'Workout' %}"
                   class="btn btn-default btn-block">
                       {% trans 'Workout' %}</a>

                <a href="{% url 'manager:step:edit' step.id %}"
                   title="{% trans 'Edit' %}"
                   class="btn btn-default btn-block wger-modal-dialog">
                       <span class="{% fa_class 'pencil-square-o' %}"></span>
                       {% trans 'Edit' %}</a>
                <a href="{% url 'manager:step:delete' step.id %}"
                   title="{% trans 'Delete' %}"
                   class="btn btn-default btn-block">
                    <span class="{% fa_class 'trash' %}"></span>
                    {% trans 'Delete' %}</a>
                </p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
            </div>
        </div>
    </div>
</div>
{% endfor %}


<table class="table">
    <tr>
        <th style="width: 30%;">{% trans "Start date" %}</th>
        <td>{{schedule.start_date}}</td>
    </tr>
    <tr>
        <th>{% trans "Schedule active" %}</th>
        <td>
            {% if schedule.is_active %}
                <span class="{% fa_class 'check' %}"></span>
            {% else %}
                <span class="{% fa_class 'times' %}"></span>
            {% endif %}
        </td>
    </tr>
    <tr>
        <th>{% trans "Is a loop" %}</th>
        <td>
            {% if schedule.is_loop %}
                <span class="{% fa_class 'check' %}"></span>
                <small>{% trans "This schedule is a loop and will go through the workouts above till you deactivate it" %}</small>
            {% else %}
                <span class="{% fa_class 'times' %}"></span>
            {% endif %}
        </td>
    </tr>
    {% if not schedule.is_active %}
    <tr>
        <td colspan="2">
            <a href="{% url 'manager:schedule:start' schedule.pk %}" class="btn btn-success btn-sm">
                <span class="{% fa_class 'play' %}"></span>
                {% trans "Start schedule" %}
            </a>
        </td>
    </tr>
    {% endif %}
</table>

<div class="list-group">
{% for step in schedule.schedulestep_set.select_related %}
    <a href="#step-{{step.id}}" data-toggle="modal" class="list-group-item wger-list-group-item">
        <span class="glyphicon glyphicon-cog pull-right"></span>

        {% if active_workout == step %}
        <span class="label label-primary pull-right"><em>{% trans "active" %}</em></span>
        {% endif  %}

        <h4 class="list-group-item-heading">{{ forloop.counter }} - {{ step.workout }}</h4>
        <div class="list-group-item-text">
            <p>{{ workout.creation_date }}</p>
            <p>{% trans "Weeks" %}: {{ step.duration }}</p>
        </div>
    </a>
{% empty %}
        <a href="{% url 'manager:step:add' schedule.id %}" class="list-group-item wger-list-group-item wger-modal-dialog">
        {% trans "No workouts found." %}<br>{% trans "Add one now." %}
        </a>
{% endfor %}
        <a href="{% url 'manager:step:add' schedule.id %}" class="list-group-item list-group-item-success wger-modal-dialog">
            <span class="{% fa_class 'plus' %}"></span>
            {% trans "Add workout" %}
        </a>
</div>
<p><small>{% blocktrans %}Add as many workouts to the schedule as you want. You can
edit the order by dragging and dropping them. It's also possible to add one workout more
than once.{% endblocktrans %}</small></p>




{% for step in schedule.schedulestep_set.select_related %}
{% with step_dates=step.get_dates %}
    <div class="row">
        <div class="col-md-3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        {% blocktrans count weeks=step.duration %}{{ weeks }} Week
                            {% plural %}{{ weeks }} Weeks
                        {% endblocktrans %}
                    </h4>

                        {% if active_workout == step %}
                            <span class="label label-info">{% trans "active" %}</span>
                        {% endif  %}
                </div>
                <div class="panel-body">
                    <span>{{step_dates.0}} <br> {{step_dates.1}}</span>
                </div>
                <div class="panel-footer">
                    <a href="{% url 'manager:workout:view' step.workout.id %}"
                       class="btn btn-default btn-block btn-sm"
                       style="white-space: normal;">
                        <span class="glyphicon glyphicon-chevron-right pull-right"></span>
                        {{ step.workout }}
                    </a>
                </div>
            </div>
        </div>
        <div class="col-md-9">
        {% for day in step.workout.canonical_representation.day_list %}
            <div id="div-day-{{ day.obj.id }}">
                {% render_day day.obj False %}
            </div>
        {% endfor %}
        </div>
    </div>
{% endwith %}
{% endfor %}





{% endblock %}


{% block sidebar %}
<div class="modal fade" id="export-ical-link">
    <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 "Export calendar file" %}</h4>
            </div>
            <div class="modal-body">
                <p>{% trans "Export this schedule as a calendar file." %}</p>
                <p>{% blocktrans %}You can then import the file it into your calendar
application for example google calendar, outlook or iCal. This will create
an appointment for each training day with the appropriate exercises.{% endblocktrans %}</p>
                <p>
                <a href="{% url 'manager:schedule:ical' schedule.id uid token %}" {% auto_link_css request.user_agent.is_mobile %}>
                   {% trans "Export calendar file" %}
                </a>
                </p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="download-pdf-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 "Download as PDF" %}</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div id="pdf-download-info" data-schedule-id="{{ schedule.id }}" data-uid="{{ uid }}" data-token="{{ token }}"></div>
                    <div class="form-group">
                        <div>
                            <label for="id_images" class="col-md-3 control-label">
                                {% trans "Type" %}
                            </label>
                        </div>
                        <div class="col-md-9" style="padding-left: 35px;">
                            <div class="radio">
                                <input type="radio" name="pdf_type" id="id_type_log" value="log" checked>
                                {% trans "Log" %}
                            </div>
                            <div class="radio">
                                <input type="radio" name="pdf_type" id="id_type_table" value="table">
                                {% trans "Table" %}
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div>
                            <label for="id_images" class="col-md-3 control-label">
                                {% trans "with images" %}
                            </label>
                        </div>
                        <div class="col-md-9">
                            <input type="checkbox" class="checkbox" name="images" id="id_images" checked>
                        </div>
                    </div>
                    <div class="form-group">
                        <div>
                            <label for="id_comments" class="col-md-3 control-label">
                                {% trans "with comments" %}
                            </label>
                        </div>
                        <div class="col-md-9">
                            <input type="checkbox" class="checkbox" name="comments" id="id_comments" checked>
                        </div>
                    </div>
                </form>

                <p>
                <a href="" class="btn btn-block btn-default" id="download-pdf-button">
                   {% trans "Download" %}
                </a>
                </p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}



{#         #}
{# Options #}
{#         #}
{% block options %}
    <div class="btn-group">
    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <span class="{% fa_class 'cog' %}"></span>
        {% trans "Options" %}
    </button>
    <ul class="dropdown-menu">
        <li>
            <a href="#" data-toggle="modal" data-target="#export-ical-popup">
                <span class="{% fa_class 'calendar' %}"></span>
                {% trans "Export calendar file" %}
            </a>
        </li>
        <li>
            <a data-toggle="modal" data-target="#download-pdf-popup">
                <span class="{% fa_class 'download' %}"></span>
                {% trans "Download as PDF" %}
            </a>
        </li>
        {% if is_owner %}
        <li>
            <a href="{% url 'manager:schedule:edit' schedule.id %}" class="wger-modal-dialog">
                <span class="{% fa_class 'pencil-square-o' %}"></span>
                {% trans "Edit schedule" %}
            </a>
        </li>
        <li role="separator" class="divider"></li>
        <li>
            <a href="{% url 'manager:schedule:delete' schedule.id %}" class="wger-modal-dialog">
                <span class="{% fa_class 'trash' %}"></span>
                {% trans "Delete schedule" %}
            </a>
        </li>
        {% endif %}
    </ul>
    </div>
{% endblock %}
