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

{% block title %}{{ student.get_full_name }} — Attendance{% 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">Attendance</h1>
            <p class="text-muted">{{ student.get_full_name }} &bull; {{ student.current_class|default:"No class" }}</p>
        </div>
        <a href="{% url 'parents:parent_student_detail' student.pk %}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left me-2"></i>Back
        </a>
    </div>

    <!-- Month Filter -->
    <div class="card shadow mb-4">
        <div class="card-body">
            <form method="get" class="row g-3 align-items-end">
                <div class="col-md-4">
                    <label class="form-label">Month</label>
                    <select name="month" class="form-select">
                        {% for num, name in months %}
                        <option value="{{ num }}" {% if selected_month|stringformat:"s" == num|stringformat:"s" %}selected{% endif %}>{{ name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Year</label>
                    <select name="year" class="form-select">
                        {% for yr in years %}
                        <option value="{{ yr }}" {% if selected_year|stringformat:"s" == yr|stringformat:"s" %}selected{% endif %}>{{ yr }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-4">
                    <button type="submit" class="btn btn-primary w-100"><i class="fas fa-filter me-1"></i>View</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Records -->
    <div class="card shadow">
        <div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">Attendance Records</h6></div>
        <div class="card-body p-0">
            <table class="table table-hover mb-0">
                <thead class="table-dark">
                    <tr><th>Date</th><th>Day</th><th>Status</th></tr>
                </thead>
                <tbody>
                    {% for att in attendances %}
                    <tr>
                        <td class="fw-bold">{{ att.date|date:"d M Y" }}</td>
                        <td class="text-muted">{{ att.date|date:"l" }}</td>
                        <td>
                            <span class="badge bg-{% if att.status == 'present' %}success{% elif att.status == 'absent' %}danger{% elif att.status == 'late' %}warning{% elif att.status == 'excused' %}info{% else %}secondary{% endif %}">
                                {{ att.get_status_display }}
                            </span>
                        </td>
                    </tr>
                    {% empty %}
                    <tr><td colspan="3" class="text-center py-4 text-muted">No attendance records for this period.</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
