{% extends 'base.html' %}
{% block title %} My Courses | Learning management system{% endblock title %}
{% load static %}

{% block content %}

<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/">Home</a></li>
        <li class="breadcrumb-item active" aria-current="page">My Courses</li>
    </ol>
</nav>

{% if request.user.is_student %}
    <div class="title-1">{{ student.program.title }}</div>
    {% if student.program.summary %}
        <p>{{ student.program.summary }}</p>
    {% endif %}
{% endif %}

{% if request.user.is_lecturer %}
    <div class="title-1">My Courses</div>
{% endif %}

{% if messages %}
    {% for message in messages %}
        {% if message.tags == 'error' %}
            <div class="alert alert-danger">
                <i class="fas fa-exclamation-circle"></i>{{ message }}
            </div>
        {% else %}
            <div class="alert alert-success">
                <i class="fas fa-check-circle"></i>{{ message }}
            </div>
        {% endif %}
    {% endfor %}
{% endif %}

{% if request.user.is_student %}
<div class="table-responsive p-3 mt-3">
    <h6 class="fw-bold text-primary"><u>Taken Courses:</u></h6>
    <div class="table-shadow">
        <table class="table table-light">
            <thead>
                <tr>
                    <th>#</th>
                    <th> Course Name </th>
                    <th> Course Code </th>
                    <th> Cr.Hr </th>
                    <th> Year </th>
                    <th> Semester </th>
                    <th> Current Semester </th>
                    <th> Taken </th>
                </tr>
            </thead>
            <tbody>
                {% for course in taken_courses %}
                <tr>
                    <td>{{ forloop.counter }}.</td> 
                    <td><a href="{{ course.get_absolute_url }}">
                        {{ course.course.title }}</a></td>
                    <td>{{ course.course.code }}</td>
                    <td>{{ course.course.credit }}</td>
                    <td>{{ course.course.year }}</td>
                    <td>{{ course.course.semester }}</td>
                    <th>
                        {% if course.course.is_current_semester == False %}
                        <i class="fas fa-times-circle fa-1-5x danger"></i>
                        {% else %}
                        <i class="fas fa-check-circle"></i>
                        {% endif %}
                    </th>
                    <td class="success">
                        <i class="fas fa-check-circle"></i> Taken
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endif %}

<div class="table-responsive p-3">
    <h6 class="fw-bold text-primary"><u>All Courses:</u></h6>
    <div class="table-shadow">
        <table class="table table-light">
            <thead>
                <tr>
                    <th>#</th>
                    <th> Course Name </th>
                    <th> Course Code </th>
                    <th> Cr.Hr </th>
                    <th> Year </th>
                    <th> Semester </th>
                    <th> Current Semester </th>
                </tr>
            </thead>
            <tbody>
                {% for course in courses %}
                <tr>
                    <td>{{ forloop.counter }}.</td> 
                    <td><a href="{{ course.get_absolute_url }}">
                        {{ course.title }}</a></td>
                    <td>{{ course.code }}</td>
                    <td>{{ course.credit }}</td>
                    <td>{{ course.year }}</td>
                    <td>{{ course.semester }}</td>
                    <th>
                        {% if course.is_current_semester == False %}
                        <i class="fas fa-times-circle fa-1-5x danger"></i>
                        {% else %}
                        <i class="fas fa-check-circle"></i>
                        {% endif %}
                    </th>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

{% if courses.paginator.page_range|length > 1 %}
<div class="content-center">
    <div class="pagination">
        <a href="?page=1">&laquo;</a>
        {% for i in courses.paginator.page_range %}
            {% if i == courses.number %}
                <a class="pagination-active" href="?page={{ i }}"><b>{{ i }}</b></a>
            {% else %}
                <a href="?page={{ i }}">{{ i }}</a>
            {% endif %}
        {% endfor %}
        <a href="?page={{ courses.paginator.num_pages }}">&raquo;</a>
    </div>
</div>
{% endif %}

{% endblock content %}
