{% set chapters = get_chapters(course.name) %}
{% set is_instructor = is_instructor(course.name) %}

{% if chapters | length %}
<div class="course-home-outline">

    {% if not lesson_page %}
    <div class="page-title mb-8" id="outline-heading" data-course="{{ course.name }}">
        {{ _("Course Content") }}
    </div>

    <!-- <div class="mb-2">
        <span>
            {{ chapters | length }} chapters
        </span>
        <span>
            . {{ get_lessons(course.name, None, False) }} lessons
        </span>
    </div> -->
    {% endif %}

    {% if chapters | length %}
    <div>
    {% for chapter in chapters %}
    {% set lessons = get_lessons(course.name, chapter) %}

    <div class="chapter-parent" data-chapter="{{ chapter.name }}">

        <div class="chapter-title" data-toggle="collapse" aria-expanded="false"
        data-target="#{{ get_slugified_chapter_title(chapter.title) }}">

            <img class="chapter-icon" src="/assets/lms/icons/chevron-right.svg">
            <div class="chapter-title-main">
                {{ chapter.title }}
            </div>
            <!-- <div class="small ml-auto">
                {{ lessons | length }} lessons
            </div> -->
        </div>


        <div class="chapter-content collapse navbar-collapse" id="{{ get_slugified_chapter_title(chapter.title) }}">

            {% if chapter.description %}
            <div class="chapter-description">
                {{ chapter.description }}
            </div>
            {% endif %}

            <div class="lessons">

                {% if lessons | length %}

                {% for lesson in lessons %}
                {% set active = membership.current_lesson == lesson.name %}
                <div data-lesson="{{ lesson.name }}" class="lesson-info {% if active %} active-lesson {% endif %}">

                {% if membership or lesson.include_in_preview or is_instructor or has_course_moderator_role() %}
                <a class="lesson-links"
                href="{{ get_lesson_url(course.name, lesson.number) }}{% if classname %}?class={{ classname }}{% endif %}{{course.query_parameter}}"
                {% if is_instructor and not lesson.include_in_preview %}
                title="{{ _('This lesson is not available for preview. As you are the Instructor of the course only you can see it.') }}"
                {% endif %}>

                    <svg class="icon icon-sm mr-2">
                        <use class="" href="#{{ lesson.icon }}">
                    </svg>

                    <span>{{ lesson.title }}</span>

                    {% if membership %}
                    <svg class="icon icon-md lesson-progress-tick ml-auto {{ get_progress(course.name, lesson.name) != 'Complete' and 'hide' }}">
                        <use class="" href="#icon-success">
                    </svg>
                    {% endif %}

                </a>

                {% else %}
                <div class="no-preview" title="This lesson is not available for preview">
                    <div class="lesson-links">
                    <svg class="icon icon-sm mr-2">
                        <use class="" href="#icon-lock-gray">
                    </svg>
                    <div>{{ lesson.title }}</div>
                    </div>
                </div>
                {% endif %}

                </div>
                {% endfor %}

            {% endif %}
            </div>

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

    {% endif %}

</div>
{% endif %}

{% if chapters | length %}
<!-- No Preview Modal -->
{{ widgets.NoPreviewModal(course=course, membership=membership) }}

{% endif %}
