{% extends 'base.html' %}
{% load static %}

{% block title %}Subjects - Rapha-Bethel BNPS{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">Subjects</h1>
            <p class="text-muted">{{ subjects.count }} subject{{ subjects.count|pluralize }} in the curriculum</p>
        </div>
        <a href="{% url 'academics:subject_add' %}" class="btn btn-primary">
            <i class="fas fa-plus me-2"></i>Add Subject
        </a>
    </div>

    <!-- Group by category -->
    {% regroup subjects by get_category_display as category_list %}
    {% for category in category_list %}
    <div class="card shadow mb-4">
        <div class="card-header py-3 bg-light">
            <h6 class="m-0 font-weight-bold text-primary">
                <i class="fas fa-book-open me-2"></i>{{ category.grouper }}
            </h6>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Code</th>
                            <th>Subject Name (EN)</th>
                            <th>Subject Name (FR)</th>
                            <th>Teachers Assigned</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for subject in category.list %}
                        <tr>
                            <td><span class="badge bg-secondary">{{ subject.code }}</span></td>
                            <td class="fw-bold">{{ subject.name }}</td>
                            <td class="text-muted">{{ subject.name_fr|default:"—" }}</td>
                            <td>
                                <span class="badge bg-info">{{ subject.teachers.count }} teacher{{ subject.teachers.count|pluralize }}</span>
                            </td>
                            <td>
                                <a href="{% url 'academics:subject_detail' subject.pk %}" class="btn btn-sm btn-outline-primary">
                                    <i class="fas fa-eye"></i>
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {% empty %}
    <div class="text-center py-5">
        <i class="fas fa-book fa-3x text-muted mb-3"></i>
        <h4 class="text-muted">No subjects found</h4>
        <a href="{% url 'academics:subject_add' %}" class="btn btn-primary mt-2">Add First Subject</a>
    </div>
    {% endfor %}
</div>
{% endblock %}
