@extends('layouts.app')

@section('title', 'Dashboard Guru')

@section('content')
            <!-- Header -->
            <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap">
                <div class="mb-2 mb-md-0">
                    <h3 class="mb-1">Dashboard Guru</h3>
                    <p class="text-muted mb-0">Selamat datang, <strong>{{ $user->name }}</strong></p>
                    @if($data['school'])
                    <small class="text-muted"><i class="bi bi-building"></i> {{ $data['school']->name }}</small>
                    @endif
                </div>
                <div class="text-end">
                    <small class="text-muted d-none d-md-block">{{ now()->isoFormat('dddd, D MMMM Y') }}</small>
                    <small class="text-muted d-md-none">{{ now()->isoFormat('D MMM Y') }}</small>
                </div>
            </div>

            <!-- Academic Year Info -->
            @if($activeAcademicYear)
            <div class="alert alert-info border-0 shadow-sm mb-4" role="alert">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0">
                        <i class="bi bi-calendar-check-fill fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="alert-heading mb-1">
                            <i class="bi bi-star-fill text-warning me-1"></i>
                            Tahun Ajaran Aktif: <strong>{{ $activeAcademicYear->name }}</strong>
                        </h6>
                        <p class="mb-0 small">
                            <i class="bi bi-calendar-event me-1"></i>
                            Periode: {{ $activeAcademicYear->start_date->format('d M Y') }} - {{ $activeAcademicYear->end_date->format('d M Y') }}
                        </p>
                    </div>
                </div>
            </div>
            @endif

            <!-- Statistics Cards -->
            <div class="row mb-4">
                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Evaluasi Selesai</h6>
                                    <h3 class="mb-0 text-success">{{ $data['evaluasi_selesai'] }}</h3>
                                    <small class="text-muted">Completed</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-check-circle text-success opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Evaluasi Pending</h6>
                                    <h3 class="mb-0 text-warning">{{ $data['evaluasi_pending'] }}</h3>
                                    <small class="text-muted">Belum Selesai</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-hourglass-split text-warning opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Total Form</h6>
                                    <h3 class="mb-0 text-primary">{{ $data['total_forms'] }}</h3>
                                    <small class="text-muted">Semua Form</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-file-earmark-text text-primary opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Form Aktif</h6>
                                    <h3 class="mb-0 text-info">{{ $data['active_forms'] }}</h3>
                                    <small class="text-muted">Tersedia</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-file-text text-info opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Recent Activities & Quick Actions -->
            <div class="row">
                <div class="col-lg-8 mb-4">
                    <div class="card border-0 shadow-sm">
                        <div class="card-header bg-white border-bottom">
                            <h5 class="card-title mb-0">
                                <i class="bi bi-clock-history text-info"></i> Aktivitas Terbaru
                            </h5>
                        </div>
                        <div class="card-body">
                            @if($data['recent_activities']->count() > 0)
                                <div class="list-group list-group-flush">
                                    @foreach($data['recent_activities'] as $activity)
                                    <div class="list-group-item px-0 py-3">
                                        <div class="d-flex align-items-start">
                                            <div class="flex-shrink-0">
                                                <span class="badge bg-{{ $activity['color'] }} rounded-circle p-2">
                                                    <i class="bi bi-{{ $activity['icon'] }}"></i>
                                                </span>
                                            </div>
                                            <div class="flex-grow-1 ms-3">
                                                <div class="d-flex w-100 justify-content-between flex-wrap">
                                                    <h6 class="mb-1">{{ $activity['message'] }}</h6>
                                                    <small class="text-muted">{{ $activity['time'] }}</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    @endforeach
                                </div>
                            @else
                                <div class="text-center py-4">
                                    <i class="bi bi-inbox text-muted" style="font-size: 3rem;"></i>
                                    <p class="text-muted mt-2 mb-0">Belum ada aktivitas terbaru</p>
                                </div>
                            @endif
                        </div>
                    </div>

                    <!-- Progress Chart -->
                    <div class="card border-0 shadow-sm mt-3">
                        <div class="card-header bg-white border-bottom">
                            <h5 class="card-title mb-0">
                                <i class="bi bi-graph-up text-success"></i> Progress Evaluasi
                            </h5>
                        </div>
                        <div class="card-body">
                            <div class="mb-3">
                                <div class="d-flex justify-content-between mb-2">
                                    <span class="fw-bold">Tingkat Penyelesaian</span>
                                    <span class="fw-bold text-success">
                                        {{ $data['active_forms'] > 0 ? round(($data['evaluasi_selesai'] / $data['active_forms']) * 100) : 0 }}%
                                    </span>
                                </div>
                                <div class="progress" style="height: 20px;">
                                    <div class="progress-bar bg-success progress-bar-striped progress-bar-animated" 
                                         role="progressbar" 
                                         style="width: {{ $data['active_forms'] > 0 ? ($data['evaluasi_selesai'] / $data['active_forms']) * 100 : 0 }}%" 
                                         aria-valuenow="{{ $data['evaluasi_selesai'] }}" 
                                         aria-valuemin="0" 
                                         aria-valuemax="{{ $data['active_forms'] }}">
                                        {{ $data['evaluasi_selesai'] }}/{{ $data['active_forms'] }}
                                    </div>
                                </div>
                            </div>
                            <div class="row text-center mt-4">
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded">
                                        <h4 class="mb-1 text-success">{{ $data['evaluasi_selesai'] }}</h4>
                                        <small class="text-muted">Selesai</small>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="p-3 bg-light rounded">
                                        <h4 class="mb-1 text-warning">{{ $data['evaluasi_pending'] }}</h4>
                                        <small class="text-muted">Pending</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 mb-4">
                    <div class="card border-0 shadow-sm">
                        <div class="card-header bg-white border-bottom">
                            <h5 class="card-title mb-0">
                                <i class="bi bi-lightning-fill text-warning"></i> Aksi Cepat
                            </h5>
                        </div>
                        <div class="card-body">
                            <div class="d-grid gap-2">
                                <a href="#" class="btn btn-primary btn-sm">
                                    <i class="bi bi-file-earmark-check"></i> Isi Evaluasi
                                </a>
                                <a href="#" class="btn btn-outline-info btn-sm">
                                    <i class="bi bi-graph-up"></i> Lihat Progress
                                </a>
                                <a href="#" class="btn btn-outline-success btn-sm">
                                    <i class="bi bi-award"></i> Kompetensi Saya
                                </a>
                                <a href="#" class="btn btn-outline-secondary btn-sm">
                                    <i class="bi bi-download"></i> Download Sertifikat
                                </a>
                            </div>
                        </div>
                    </div>

                    <!-- Personal Info -->
                    @if($data['school'])
                    <div class="card border-0 shadow-sm mt-3">
                        <div class="card-header bg-white border-bottom">
                            <h6 class="card-title mb-0">
                                <i class="bi bi-person-badge text-primary"></i> Info Profil
                            </h6>
                        </div>
                        <div class="card-body">
                            <table class="table table-sm table-borderless mb-0">
                                <tr>
                                    <td class="text-muted"><small><strong>Nama</strong></small></td>
                                    <td><small>{{ $user->name }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Email</strong></small></td>
                                    <td><small>{{ $user->email }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Sekolah</strong></small></td>
                                    <td><small>{{ $data['school']->name }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>NPSN</strong></small></td>
                                    <td><small>{{ $data['school']->npsn }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Status</strong></small></td>
                                    <td>
                                        @if($user->is_active)
                                            <span class="badge bg-success">Aktif</span>
                                        @else
                                            <span class="badge bg-secondary">Nonaktif</span>
                                        @endif
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    @endif

                    <!-- Motivational Card -->
                    <div class="card border-0 shadow-sm mt-3 bg-gradient" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
                        <div class="card-body text-white">
                            <div class="text-center">
                                <i class="bi bi-trophy" style="font-size: 2.5rem;"></i>
                                <h6 class="mt-2 mb-1">Terus Berkembang!</h6>
                                <p class="small mb-0">Selesaikan evaluasi untuk meningkatkan kompetensi Anda</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Info Alert -->
            <div class="row">
                <div class="col-12">
                    <div class="alert alert-info border-0 shadow-sm" role="alert">
                        <div class="d-flex align-items-center">
                            <i class="bi bi-lightbulb me-2" style="font-size: 1.5rem;"></i>
                            <div>
                                <strong>Tips:</strong> Lengkapi evaluasi secara berkala untuk mendapatkan feedback yang berguna 
                                dalam pengembangan kompetensi Anda. Evaluasi yang diselesaikan akan membantu meningkatkan kualitas pembelajaran.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
@endsection
