<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
    <t t-name="encoach_core.Dashboard">
        <Layout display="{ controlPanel: {} }">
            <div class="o_encoach_dashboard">
                <div class="container-fluid py-4">
                    <h2 class="mb-4">EnCoach Dashboard</h2>

                    <t t-if="state.loading">
                        <div class="text-center py-5">
                            <i class="fa fa-spinner fa-spin fa-3x"/>
                            <p class="mt-2">Loading dashboard...</p>
                        </div>
                    </t>

                    <t t-else="">
                        <!-- KPI Cards -->
                        <div class="row g-3 mb-4">
                            <div class="col-lg-3 col-md-6">
                                <div class="card shadow-sm h-100 cursor-pointer" t-on-click="openStudents">
                                    <div class="card-body">
                                        <div class="d-flex align-items-center">
                                            <div class="rounded-circle bg-primary bg-opacity-10 p-3 me-3">
                                                <i class="fa fa-users fa-2x text-primary"/>
                                            </div>
                                            <div>
                                                <h3 class="mb-0" t-esc="state.stats.total_students"/>
                                                <small class="text-muted">Students</small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-md-6">
                                <div class="card shadow-sm h-100 cursor-pointer" t-on-click="openTeachers">
                                    <div class="card-body">
                                        <div class="d-flex align-items-center">
                                            <div class="rounded-circle bg-success bg-opacity-10 p-3 me-3">
                                                <i class="fa fa-chalkboard-teacher fa-2x text-success"/>
                                            </div>
                                            <div>
                                                <h3 class="mb-0" t-esc="state.stats.total_teachers"/>
                                                <small class="text-muted">Teachers</small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-md-6">
                                <div class="card shadow-sm h-100 cursor-pointer" t-on-click="openCourses">
                                    <div class="card-body">
                                        <div class="d-flex align-items-center">
                                            <div class="rounded-circle bg-info bg-opacity-10 p-3 me-3">
                                                <i class="fa fa-book fa-2x text-info"/>
                                            </div>
                                            <div>
                                                <h3 class="mb-0" t-esc="state.stats.total_courses"/>
                                                <small class="text-muted">Courses</small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-md-6">
                                <div class="card shadow-sm h-100 cursor-pointer" t-on-click="openExams">
                                    <div class="card-body">
                                        <div class="d-flex align-items-center">
                                            <div class="rounded-circle bg-warning bg-opacity-10 p-3 me-3">
                                                <i class="fa fa-file-text fa-2x text-warning"/>
                                            </div>
                                            <div>
                                                <h3 class="mb-0" t-esc="state.stats.total_exams"/>
                                                <small class="text-muted">Exams</small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Action Cards -->
                        <div class="row g-3 mb-4">
                            <div class="col-lg-4 col-md-6">
                                <div class="card shadow-sm border-start border-danger border-4 cursor-pointer" t-on-click="openGradingQueue">
                                    <div class="card-body">
                                        <h5>Grading Queue</h5>
                                        <h2 class="text-danger" t-esc="state.stats.pending_grading"/>
                                        <small class="text-muted">Exams awaiting grading</small>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-6">
                                <div class="card shadow-sm border-start border-warning border-4 cursor-pointer" t-on-click="openPendingApproval">
                                    <div class="card-body">
                                        <h5>Pending Approval</h5>
                                        <h2 class="text-warning" t-esc="state.stats.pending_approval"/>
                                        <small class="text-muted">Scores awaiting release</small>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-6">
                                <div class="card shadow-sm border-start border-info border-4 cursor-pointer" t-on-click="openEntities">
                                    <div class="card-body">
                                        <h5>Entities</h5>
                                        <h2 class="text-info" t-esc="state.stats.total_entities"/>
                                        <small class="text-muted">Registered organizations</small>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Recent Attempts Table -->
                        <div class="card shadow-sm">
                            <div class="card-header bg-white">
                                <h5 class="mb-0">Recent Exam Attempts</h5>
                            </div>
                            <div class="card-body p-0">
                                <table class="table table-hover mb-0">
                                    <thead class="table-light">
                                        <tr>
                                            <th>Student</th>
                                            <th>Exam</th>
                                            <th>Status</th>
                                            <th>Band</th>
                                            <th>Date</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <t t-foreach="state.recentAttempts" t-as="attempt" t-key="attempt.id">
                                            <tr>
                                                <td t-esc="attempt.student_id[1]"/>
                                                <td t-esc="attempt.exam_id ? attempt.exam_id[1] : '-'"/>
                                                <td>
                                                    <span class="badge"
                                                          t-att-class="{
                                                              'bg-success': attempt.status === 'released',
                                                              'bg-warning': attempt.status === 'pending_approval',
                                                              'bg-info': attempt.status === 'scoring',
                                                              'bg-secondary': attempt.status === 'in_progress',
                                                              'bg-primary': attempt.status === 'scored'
                                                          }"
                                                          t-esc="attempt.status"/>
                                                </td>
                                                <td t-esc="attempt.overall_band || '-'"/>
                                                <td t-esc="attempt.started_at"/>
                                            </tr>
                                        </t>
                                        <t t-if="!state.recentAttempts.length">
                                            <tr>
                                                <td colspan="5" class="text-center text-muted py-4">No recent attempts</td>
                                            </tr>
                                        </t>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </t>
                </div>
            </div>
        </Layout>
    </t>
</templates>
