<!-- templates/includes/sidebar.html -->
{% load static %}

<div class="sidebar-sticky pt-3">
    <!-- User Info -->
    <div class="user-info text-center mb-4 p-3">
        {% if user.is_authenticated %}
            <div class="user-avatar mb-2">
                <i class="fas fa-user-circle fa-3x text-primary"></i>
            </div>
            <h6>{{ user.get_full_name|default:user.username }}</h6>
            <p class="text-muted small mb-2">
                {% if user.is_superuser %}Super Admin{% elif user.is_staff %}Staff{% else %}User{% endif %}
            </p>
            <a href="{% url 'admin:logout' %}" class="btn btn-sm btn-outline-danger">
                <i class="fas fa-sign-out-alt"></i> Logout
            </a>
        {% else %}
            <a href="{% url 'admin:login' %}" class="btn btn-sm btn-primary">
                <i class="fas fa-sign-in-alt"></i> Login
            </a>
        {% endif %}
    </div>

    <!-- DASHBOARD -->
    <h6 class="sidebar-heading px-3 mb-2 text-muted">Main</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link {% if request.path == '/dashboard/' %}active{% endif %}" 
               href="{% url 'dashboard' %}">
                <i class="fas fa-tachometer-alt me-2"></i> Dashboard
            </a>
        </li>
    </ul>

    <!-- STUDENTS SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Students</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link {% if request.path == '/students/' %}active{% endif %}" 
               href="{% url 'students:student_list' %}">
                <i class="fas fa-list me-2"></i> All Students
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'students:student_add' %}">
                <i class="fas fa-user-plus me-2"></i> Add Student
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'students:import_students_csv' %}">
                <i class="fas fa-upload me-2"></i> Import Students
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'students:export_students' %}">
                <i class="fas fa-download me-2"></i> Export Students
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'students:download_student_sample' %}">
                <i class="fas fa-file-csv me-2"></i> Download Sample
            </a>
        </li>
    </ul>

    <!-- STAFF SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Staff</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link {% if request.path == '/staff/' %}active{% endif %}" 
               href="{% url 'staff:staff_list' %}">
                <i class="fas fa-list me-2"></i> All Staff
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:staff_add' %}">
                <i class="fas fa-user-plus me-2"></i> Add Staff
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:staff_import' %}">
                <i class="fas fa-upload me-2"></i> Import Staff
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:staff_export' %}">
                <i class="fas fa-download me-2"></i> Export Staff
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:staff_dashboard' %}">
                <i class="fas fa-tachometer-alt me-2"></i> Staff Dashboard
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:leave_list' %}">
                <i class="fas fa-calendar-alt me-2"></i> Leave Requests
            </a>
        </li>
        <!-- Staff Attendance - Only for admins -->
        {% if user.is_superuser or user.staff_profile.role in 'admin,head_master,head_mistress' %}
        <li class="nav-item">
            <a class="nav-link" href="{% url 'staff:attendance_list' %}">
                <i class="fas fa-clock me-2"></i> Staff Attendance
            </a>
        </li>
        {% endif %}
    </ul>

    <!-- ACADEMICS SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Academics</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'academics:class_list' %}">
                <i class="fas fa-chalkboard-teacher me-2"></i> Classes
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'academics:subject_list' %}">
                <i class="fas fa-book me-2"></i> Subjects
            </a>
        </li>
        <!-- Student Attendance via Admin -->
        <li class="nav-item">
            <a class="nav-link" href="/admin/academics/attendance/">
                <i class="fas fa-calendar-check me-2"></i> Student Attendance
            </a>
        </li>
    </ul>

    <!-- FINANCE SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Finance</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:invoice_list' %}">
                <i class="fas fa-file-invoice me-2"></i> Invoices
            </a>
        </li>
        <!-- Finance - Create Invoice (check if user has permission) -->
        {% if user.staff_profile.role in 'bursar,admin,proprietor' %}
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:invoice_create' %}">
                <i class="fas fa-plus-circle me-2"></i> Create Invoice
            </a>
        </li>
        {% endif %}
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:invoice_create' %}">
                <i class="fas fa-plus-circle me-2"></i> Create Invoice
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:payment_list' %}">
                <i class="fas fa-credit-card me-2"></i> Payments
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:payment_add' %}">
                <i class="fas fa-plus-circle me-2"></i> Record Payment
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:fee_list' %}">
                <i class="fas fa-tag me-2"></i> Fee Structure
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:bursar_dashboard' %}">
                <i class="fas fa-chart-pie me-2"></i> Bursar Dashboard
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'finance:financial_reports' %}">
                <i class="fas fa-chart-bar me-2"></i> Financial Reports
            </a>
        </li>
    </ul>

    <!-- COMMUNICATION SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Communication</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'communication:announcement_list' %}">
                <i class="fas fa-bullhorn me-2"></i> Announcements
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'communication:sms_list' %}">
                <i class="fas fa-sms me-2"></i> SMS Messages
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'communication:sms_compose' %}">
                <i class="fas fa-edit me-2"></i> Compose SMS
            </a>
        </li>
    </ul>

    <!-- PARENTS SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Parents</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'parents:parent_dashboard' %}">
                <i class="fas fa-users me-2"></i> Parent Dashboard
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'parents:parent_messages' %}">
                <i class="fas fa-envelope me-2"></i> Parent Messages
            </a>
        </li>
    </ul>

    <!-- REPORTS SECTION -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Reports</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'reports:academic_report' %}">
                <i class="fas fa-chart-line me-2"></i> Academic Reports
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'reports:attendance_report' %}">
                <i class="fas fa-calendar-check me-2"></i> Attendance Reports
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{% url 'reports:financial_report' %}">
                <i class="fas fa-chart-pie me-2"></i> Financial Reports
            </a>
        </li>
    </ul>

    <!-- ADMIN SECTION (Superuser only) -->
    {% if user.is_superuser %}
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Administration</h6>
    <ul class="nav flex-column mb-3">
        <li class="nav-item">
            <a class="nav-link" href="{% url 'admin:index' %}">
                <i class="fas fa-cog me-2"></i> Django Admin
            </a>
        </li>
    </ul>
    {% endif %}

    <!-- QUICK ACTIONS -->
    <h6 class="sidebar-heading px-3 mt-3 mb-2 text-muted">Quick Actions</h6>
    <div class="px-3 mb-4">
        <div class="d-grid gap-2">
            <a href="{% url 'students:student_add' %}" class="btn btn-sm btn-outline-primary">
                <i class="fas fa-user-plus"></i> Add Student
            </a>
            <a href="{% url 'staff:staff_add' %}" class="btn btn-sm btn-outline-success">
                <i class="fas fa-user-tie"></i> Add Staff
            </a>
            <a href="{% url 'finance:invoice_create' %}" class="btn btn-sm btn-outline-warning">
                <i class="fas fa-file-invoice"></i> Create Invoice
            </a>
        </div>
    </div>
</div>

<style>
.sidebar-sticky {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding-bottom: 20px;
}
.nav-link {
    color: #333;
    padding: 8px 15px;
    border-radius: 5px;
    margin: 2px 8px;
    transition: all 0.3s;
    font-size: 0.9rem;
}
.nav-link:hover {
    background-color: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
    transform: translateX(5px);
}
.nav-link.active {
    background: linear-gradient(135deg, #4CAF50, #2196F3);
    color: white;
}
.nav-link i {
    width: 20px;
    text-align: center;
}
.sidebar-heading {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    padding-left: 15px;
}
.user-info {
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 15px;
}
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}
</style>