{% extends 'training_template.html' %}
{% load lessons %}
{% load permissions %}

{% block training_content %}
    <div class="row">
        <div class="col-md-12">
            <h2 id="lesson-title" class="xsd-lesson-title">
                {% if lesson.code %}<span class="code">{{ lesson.code }}</span>{% endif %}
                <span class="title">{{ lesson.title }}</span>
            </h2>
        </div>
    </div>

    <div class="row" id="lesson-body" class="xsd-lesson-body">
        <div class="col-lg-5">
            <p>{{ lesson.description }}</p>
            <p class="mode">This is a {{ lesson.get_mode_display|lower }} lesson.</p>

        </div>
        <div class="col-lg-7">
            <ul class="xsd-pl-list">
                {% for pl in pls %}
                    <li class="pl pl--{{ pl.state.0 }}">
                        <div class="card">
                            <div class="card-header pl-header">
                                {% pl_state_icon pl %}
                                {{ pl.date }}
                                <div class="pl-controls">
                                    {% permission request.user can_edit pl %}
                                        <a class="btn btn-secondary btn-sm"
                                           href="{% url 'xsd_training:TraineePerformedLessonUpdate' t_pk=trainee.pk l_pk=lesson.pk pk=pl.pk %}">
                                            <i class="fa fa-pencil"></i>
                                            Edit
                                        </a>
                                    {% endpermission %}

                                    {% permission request.user can_delete pl %}
                                        <form method="POST"
                                              onsubmit="return confirm('Are you sure you want to delete this performed lesson?');"
                                              action="{% url 'xsd_training:TraineePerformedLessonDelete' t_pk=trainee.pk l_pk=lesson.pk pk=pl.pk %}">
                                            {% csrf_token %}
                                            <button class="btn btn-danger btn-sm">
                                                <i class="fa fa-trash"></i>
                                                Delete
                                            </button>
                                        </form>
                                    {% endpermission %}

                                </div>
                            </div>
                            <div class="card-block pl-body">
                                <dl class="xsd-pl-summary --detail">
                                    <dt class="session"><i class="fa fa-map-marker fa-fw"></i></dt>
                                    <dd>{{ pl.session }}</dd>
                                    <dt class="instructor"><i class="fa fa-user fa-fw"></i></dt>
                                    <dd>{{ pl.instructor }}</dd>
                                    {% if state.0 != "PLANNED" %}
                                        <dt class="notes-public"><i class="fa fa-unlock fa-fw"></i></dt>
                                        <dd>{{ pl.public_notes }}</dd>
                                        {% permission request.user can_view_private pl %}
                                            <dt class="notes-private"><i class="fa fa-lock fa-fw"></i></dt>
                                            <dd>{{ pl.private_notes }}</dd>
                                        {% endpermission %}
                                    {% endif %}
                                </dl>
                            </div>
                        </div>
                    </li>
                    {% empty %}
                    <li>No performed lessons</li>
                {% endfor %}

                {# TODO: This should be something like {% permission request.user can_create_pls %} #}
                {% if is_instructor or is_training %}
                <p>
                    <a class="btn btn-outline-success btn-block"
                       href="{% url 'xsd_training:TraineePerformedLessonCreate' t_pk=trainee.pk l_pk=lesson.pk %}">
                        <i class="fa fa-plus"></i>
                        Add Lesson
                    </a>
                </p>
                {% endif %}
            </ul>
        </div>

    </div>

{% endblock %}
