@extends('layouts.app')

@section('title', 'Attendance Analytics | Institution Axis')

@section('sidebar-menu')
    @include('schooladmin.partials.sidebar')
@endsection

@section('breadcrumb')
    <span><a href="{{ route('schooladmin.dashboard') }}">Home</a></span> / 
    <span><a href="{{ route('schooladmin.reports.index') }}">Reports</a></span> / 
    <span class="active-page">Attendance Analytics</span>
@endsection

@section('content')
<div class="container-fluid p-0">
    <div class="row g-4 mb-4">
        <div class="col-lg-12">
            <div class="card shadow-sm border-0 rounded-4">
                <div class="card-header bg-white border-0 py-3">
                    <h5 class="mb-0 fw-bold">Student Attendance Trend (Last 30 Days)</h5>
                </div>
                <div class="card-body">
                    <canvas id="studentAttendanceChart" height="250"></canvas>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4 mb-4">
        <div class="col-lg-6">
            <div class="card shadow-sm border-0 rounded-4 h-100">
                <div class="card-header bg-white border-0 py-3">
                    <h5 class="mb-0 fw-bold">Staff Attendance Overview</h5>
                </div>
                <div class="card-body">
                    <canvas id="staffAttendanceChart" height="200"></canvas>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="card shadow-sm border-0 rounded-4 h-100">
                <div class="card-header bg-white border-0 py-3">
                    <h5 class="mb-0 fw-bold">Daily Attendance Average</h5>
                </div>
                <div class="card-body d-flex flex-column justify-content-center align-items-center text-center">
                    <div class="display-1 fw-bold text-primary mb-0">94.2%</div>
                    <p class="text-muted">Overall average for the current term</p>
                    <div class="mt-4 w-100">
                        <div class="d-flex justify-content-between mb-1">
                            <span>Target: 98%</span>
                            <span class="text-danger">-3.8% from target</span>
                        </div>
                        <div class="progress" style="height: 10px;">
                            <div class="progress-bar bg-primary" style="width: 94.2%"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('custom-scripts')
<script>
    // Student Attendance Line Chart
    const studentCtx = document.getElementById('studentAttendanceChart').getContext('2d');
    new Chart(studentCtx, {
        type: 'line',
        data: {
            labels: @json($studentAttendance->pluck('date')),
            datasets: [{
                label: 'Present Students',
                data: @json($studentAttendance->pluck('present_count')),
                borderColor: '#17a2b8',
                backgroundColor: 'rgba(23, 162, 184, 0.1)',
                borderWidth: 2,
                tension: 0.3,
                fill: true
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });

    // Staff Attendance Bar Chart
    const staffCtx = document.getElementById('staffAttendanceChart').getContext('2d');
    new Chart(staffCtx, {
        type: 'bar',
        data: {
            labels: @json($staffAttendance->pluck('date')),
            datasets: [{
                label: 'Present Staff',
                data: @json($staffAttendance->pluck('present_count')),
                backgroundColor: 'rgba(40, 167, 69, 0.6)',
                borderColor: 'rgba(40, 167, 69, 1)',
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });
</script>
@endsection
