{% autoescape false %}

{% if data is not empty %}
{% set tutor =  is_granted('ROLE_TEACHER') %}
<div id="course-progress" class="thematic">
    <div class="row">
        <div class="col-md-12">
            <div class="bar-progress">
                <div class="float-right">
                    <div class="score-progress">
                        <h3>{{ 'Progress' | get_lang }}: <span id="div_result">{{ score_progress }}</span> %</h3>
                    </div>
                </div>
            </div>
            <div class="table-responsive">
                <table width="100%" class="table">
                    <thead>
                        <tr>
                            <th scope="col" style="width: 35%">{{ 'Thematic' | get_lang }}</th>
                            <th scope="col" style="width: 40%">{{ 'ThematicPlan' | get_lang }}</th>
                            <th scope="col" style="width: 25%">{{ 'ThematicAdvance' | get_lang }}</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for item in data %}
                        <tr>
                            <td id="id-thematic-{{ item.id }}">
                                {% if session_star is empty %}
                                    <h5>{{ item.title }}</h5>
                                {% else %}
                                    <h5>{{ item.title }} {{ session_star }}</h5>
                                {% endif %}
                                {{ item.content }}
                                <div class="btn-group btn-group-sm">
                                    {{ item.toolbar }}
                                </div>
                            </td>
                            <td>

                                {% if tutor %}
                                <div class="float-right">
                                    <a title="{{ 'EditThematicPlan' | get_lang }}" href="index.php?{{ _p.web_cid_query }}&origin=thematic_details&action=thematic_plan_list&thematic_id={{ item.id }}&width=700&height=500'" class="btn btn-outline-secondary btn-sm">
                                        <i class="fas fa-pencil-alt"></i>
                                    </a>
                                </div>
                                {% endif %}

                                <div class="thematic_plan_{{ item.id }}">
                                    {% if item.thematic_plan is empty %}
                                    <div class="alert-thematic">
                                        <div class="alert alert-info" role="alert">{{ 'StillDoNotHaveAThematicPlan' | get_lang }}</div>
                                    </div>
                                    {% else %}
                                        {% for subitem in item.thematic_plan %}
                                        <h5>{{ subitem.title }}</h5>
                                        {{ subitem.description }}
                                        {% endfor %}
                                    {% endif %}
                                </div>
                            </td>
                            <td>
                                {% if tutor %}
                                <div class="float-right">
                                    <a title="{{ 'NewThematicAdvance' | get_lang }}" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_add&thematic_id={{ item.id }}" class="btn btn-outline-secondary btn-sm">
                                        <i class="fa fa-plus-circle" aria-hidden="true"></i>
                                    </a>
                                </div>
                                {% endif %}
                                <div class="thematic-advance">
                                <table width="100%" class="table">
                                {% if item.thematic_advance is not empty %}
                                {% for advance in item.thematic_advance %}
                                <tr>
                                    <td style="width: 90%" class="thematic_advance_content" id="thematic_advance_content_id_{{ advance.id }}">
                                        <div id="thematic_advance_{{ advance.id }}">
                                        <strong>{{ advance.start_date | format_date }}</strong>
                                        {{ advance.content }}
                                        </div>
                                        {% if tutor %}
                                            <div class="toolbar-actions">
                                                <div id="thematic_advance_tools_{{ advance.id }}" class="thematic_advance_actions">
                                                    <div class="btn-group btn-group-sm">
                                                        <a class="btn btn-default btn-sm" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_edit&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Edit' |get_lang }}">
                                                            <i class="fa fa-pencil" aria-hidden="true"></i>
                                                        </a>
                                                        <a class="btn btn-default btn-sm" onclick="javascript:if(!confirm('{{ 'AreYouSureToDelete' | get_lang }}')) return false;" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_delete&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Delete' |get_lang }}">
                                                            <i class="fa fa-trash" aria-hidden="true"></i>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        {% endif %}
                                        </div>
                                    </td>
                                    {% if advance.done_advance == 1 %}
                                        {% set color = "background-color:#E5EDF9;" %}
                                    {% else %}
                                        {% set color = "background-color:#FFFFFF;" %}
                                    {% endif %}
                                    {% if tutor %}
                                        <td style="width: 10%; {{ color }}" id="td_done_thematic_{{ advance.id }}">
                                        {% set check = ""  %}
                                        {% if item.last_done == advance.id %}
                                            {% set check = "checked"  %}
                                        {% endif %}
                                            <input type="radio" class="done_thematic" id="done_thematic_{{ advance.id }}" name="done_thematic" value="{{ advance.id }}" {{ check }} onclick="update_done_thematic_advance(this.value)">
                                    {% else %}
                                        </td>
                                    {% endif %}
                                </tr>
                                {% endfor %}
                                {% else %}
                                    <div class="alert alert-info" role="alert">{{ 'ThereIsNoAThematicAdvance' | get_lang }}</div>
                                {% endif %}
                                </table>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% else %}
    <div class="alert alert-info" role="alert">{{ 'There is no thematic section' | get_lang }}</div>
    {% if is_allowed_to_edit %}
        <div id="no-data-view" class="tool-view">
            <h2>{{ "Educational programming"|trans }}</h2>
            <img src="{{ "course_progress.png"|icon(64) }}" width="64" height="64">
            <div class="controls">
                <a href="{{ _p.web_self }}?{{ _p.web_cid_query ~ "&action=thematic_add" ~ token }}" class="btn btn-outline-primary">
                    {{ "Add thematic"|trans }}
                </a>
            </div>
        </div>
    {% endif %}
{% endif %}
{% endautoescape %}