<!-- templates/staff/teacher_dashboard.html -->
{% extends 'base.html' %}
{% load static %}

{% block title %}My Dashboard - Teacher{% endblock %}

{% block content %}
<div class="container-fluid">
    <!-- Welcome Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <h4>Welcome back, {{ user.get_full_name }}!</h4>
                    <p class="mb-0">{{ today|date:"l, F d, Y" }}</p>
                </div>
            </div>
        </div>
    </div>

    <!-- My Classes -->
    <div class="row">
        <div class="col-12 mb-4">
            <div class="card shadow">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0"><i class="fas fa-chalkboard-teacher"></i> My Classes Today</h5>
                </div>
                <div class="card-body">
                    {% if my_classes %}
                    <div class="row">
                        {% for class_data in my_classes %}
                        <div class="col-md-6 col-lg-4 mb-3">
                            <div class="card h-100 border-left-primary">
                                <div class="card-body">
                                    <h5 class="card-title">{{ class_data.class.name }}</h5>
                                    <p class="text-muted small">
                                        <i class="fas fa-book"></i> 
                                        {% for subject in class_data.subjects %}
                                            {{ subject.name }}{% if not forloop.last %}, {% endif %}
                                        {% endfor %}
                                    </p>
                                    <p class="mb-2">
                                        <strong>Students:</strong> {{ class_data.student_count }}
                                    </p>
                                    
                                    {% if class_data.today_attendance_taken %}
                                    <div class="alert alert-success py-2 small">
                                        <i class="fas fa-check-circle"></i> Attendance taken today
                                    </div>
                                    {% else %}
                                    <div class="alert alert-warning py-2 small">
                                        <i class="fas fa-exclamation-triangle"></i> Attendance not taken
                                    </div>
                                    {% endif %}
                                    
                                    <a href="{% url 'attendance:mark_attendance' %}?class={{ class_data.class.id }}" 
                                       class="btn btn-sm btn-primary w-100">
                                        <i class="fas fa-clipboard-check"></i> 
                                        {% if class_data.today_attendance_taken %}Update{% else %}Take{% endif %} Attendance
                                    </a>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <p class="text-muted text-center py-4">No classes assigned to you yet.</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card shadow">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0"><i class="fas fa-bolt"></i> Quick Actions</h5>
                </div>
                <div class="card-body">
                    <div class="list-group">
                        <a href="{% url 'attendance:mark_attendance' %}" class="list-group-item list-group-item-action">
                            <i class="fas fa-clipboard-check text-primary me-2"></i> Mark Attendance
                        </a>
                        <a href="{% url 'students:student_list' %}" class="list-group-item list-group-item-action">
                            <i class="fas fa-users text-success me-2"></i> View All Students
                        </a>
                        <a href="{% url 'reports:attendance_report' %}" class="list-group-item list-group-item-action">
                            <i class="fas fa-chart-bar text-info me-2"></i> View Attendance Reports
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <!-- Recent Activity -->
        <div class="col-md-6 mb-4">
            <div class="card shadow">
                <div class="card-header bg-warning text-dark">
                    <h5 class="mb-0"><i class="fas fa-history"></i> Recent Activity</h5>
                </div>
                <div class="card-body">
                    <div class="list-group">
                        {% for attendance in recent_attendance %}
                        <div class="list-group-item">
                            <div class="d-flex justify-content-between">
                                <small>{{ attendance.date }}</small>
                                <small class="text-muted">{{ attendance.student.first_name }}</small>
                            </div>
                            <span class="badge bg-{% if attendance.status == 'present' %}success{% elif attendance.status == 'absent' %}danger{% else %}warning{% endif %}">
                                {{ attendance.get_status_display }}
                            </span>
                        </div>
                        {% empty %}
                        <p class="text-muted text-center py-3">No recent attendance</p>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}