@php
$sidebarNav = [
    ['label'=>'Dashboard',     'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z'],
    ['label'=>'Lesson Recaps', 'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M15 10l4.553-2.069A1 1 0 0121 8.82v6.36a1 1 0 01-1.447.894L15 14M3 8a2 2 0 012-2h10a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V8z'],
    ['label'=>'Quizzes & Marks','route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2'],
    ['label'=>'My Students',   'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z'],
];
$mobileNav = [
    ['label'=>'Home',     'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z'],
    ['label'=>'Recaps',   'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M15 10l4.553-2.069A1 1 0 0121 8.82v6.36a1 1 0 01-1.447.894L15 14M3 8a2 2 0 012-2h10a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V8z'],
    ['label'=>'Marks',    'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2'],
    ['label'=>'Students', 'route'=>route('teacher.dashboard'), 'active'=>'teacher.dashboard', 'icon'=>'M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857'],
];
@endphp

<x-app-layout title="Teacher Dashboard – SMART Academy">

{{-- Welcome --}}
<div class="mb-6">
    <p class="text-sm text-gray-500">Welcome back,</p>
    <h1 class="text-2xl font-black text-gray-900">{{ $teacher->name }} 📋</h1>
    <p class="text-sm text-gray-500">{{ $subject?->name }} Teacher</p>
</div>

{{-- Stat cards --}}
<div class="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-7">
    @foreach([
        ['n'=>$students->count(),  'label'=>'Students', 'icon'=>'👨‍🎓', 'color'=>'#ED1C24'],
        ['n'=>$lessons->count(),   'label'=>'Lessons',  'icon'=>'📚',   'color'=>'#2563EB'],
        ['n'=>$quizzes->count(),   'label'=>'Quizzes',  'icon'=>'📝',   'color'=>'#059669'],
        ['n'=>$announcements->count(),'label'=>'Posts', 'icon'=>'📢',   'color'=>'#D97706'],
    ] as $stat)
        <div class="bg-white rounded-2xl p-5 shadow-sm border-t-[3px]" style="border-top-color: {{ $stat['color'] }}">
            <div class="text-2xl mb-2">{{ $stat['icon'] }}</div>
            <div class="text-3xl font-black" style="color: {{ $stat['color'] }}">{{ $stat['n'] }}</div>
            <div class="text-xs text-gray-500 mt-1">{{ $stat['label'] }}</div>
        </div>
    @endforeach
</div>

<div class="grid lg:grid-cols-2 gap-6">
    {{-- Add Lesson (Livewire continuous entry) --}}
    <div>
        <h2 class="font-bold text-base text-gray-900 mb-4">Lesson Recaps</h2>
        @livewire('teacher.add-lesson')

        {{-- Existing lessons --}}
        <div class="mt-4 space-y-3">
            @foreach($lessons->take(6) as $lesson)
                <div class="bg-white rounded-xl px-5 py-4 flex items-center gap-4 shadow-sm border-l-4"
                     style="border-left-color: {{ $subject?->color ?? '#ED1C24' }}">
                    <div class="flex-1 min-w-0">
                        <div class="text-sm font-bold text-gray-900 truncate">{{ $lesson->title }}</div>
                        <div class="text-xs text-gray-500 mt-1">{{ $lesson->lesson_date->format('M j, Y') }} · {{ $lesson->hasVideo() ? '📹 Video' : '📄 Text' }}</div>
                    </div>
                    <button class="text-xs font-semibold text-gray-500 bg-gray-100 rounded-lg px-3 py-1.5 hover:bg-gray-200 transition">Edit</button>
                </div>
            @endforeach
        </div>
    </div>

    <div class="space-y-6">
        {{-- Add Mark (Livewire) --}}
        <div>
            <h2 class="font-bold text-base text-gray-900 mb-4">Enter Quiz Marks</h2>
            @livewire('teacher.add-mark')
        </div>

        {{-- Post Announcement (Livewire) --}}
        <div>
            <h2 class="font-bold text-base text-gray-900 mb-4">Post Announcement</h2>
            @livewire('teacher.post-announcement')
        </div>

        {{-- Students list --}}
        <div>
            <h2 class="font-bold text-base text-gray-900 mb-4">My Students ({{ $students->count() }})</h2>
            <div class="space-y-2">
                @foreach($students->take(8) as $student)
                    @php $avgScore = $student->marks->avg('score'); @endphp
                    <div class="bg-white rounded-xl px-4 py-3 flex items-center gap-3 shadow-sm">
                        <div class="w-10 h-10 rounded-full flex items-center justify-center text-white font-black text-sm shrink-0"
                             style="background: linear-gradient(135deg, #ED1C24, #991B1B)">
                            {{ strtoupper(substr($student->name, 0, 1)) }}
                        </div>
                        <div class="flex-1">
                            <div class="text-sm font-bold text-gray-900">{{ $student->name }}</div>
                            <div class="text-xs text-gray-500">{{ $student->studentProfile?->grade?->name }}</div>
                        </div>
                        <div class="text-right">
                            <div class="text-lg font-black {{ $avgScore >= 75 ? 'text-emerald-600' : ($avgScore >= 50 ? 'text-amber-500' : 'text-red-600') }}">
                                {{ $avgScore ? round($avgScore) : '–' }}
                            </div>
                            <div class="text-[10px] text-gray-400">Avg</div>
                        </div>
                    </div>
                @endforeach
            </div>
        </div>
    </div>
</div>

</x-app-layout>
