<x-app-layout>
    <x-slot name="header">
        <div>
            <p class="text-sm font-semibold uppercase tracking-wide text-blue-600 dark:text-blue-400">Mentor Academy</p>
            <h2 class="mt-1 text-2xl font-bold text-slate-950 dark:text-white">Mentor Dashboard</h2>
        </div>
    </x-slot>

    <div class="space-y-6">
        <section class="grid gap-4 md:grid-cols-3">
            <div class="rounded-lg border border-blue-100 bg-white p-5 shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
                <p class="text-sm text-slate-500 dark:text-slate-400">Active Students</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $totalStudents }}</p>
            </div>
            <div class="rounded-lg border border-blue-100 bg-white p-5 shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
                <p class="text-sm text-slate-500 dark:text-slate-400">Pending Invites</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $pendingInvites }}</p>
            </div>
            <div class="rounded-lg border border-blue-100 bg-white p-5 shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
                <p class="text-sm text-slate-500 dark:text-slate-400">Trades Awaiting Review</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $submittedTrades }}</p>
            </div>
        </section>

        <section class="rounded-lg border border-blue-100 bg-white p-6 shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
            <h3 class="text-lg font-bold text-slate-950 dark:text-white">Invite Student</h3>
            <form method="POST" action="{{ route('mentor.students.invite') }}" class="mt-4 flex flex-col gap-3 sm:flex-row">
                @csrf
                <input name="student_email" type="email" placeholder="Student email optional" class="block w-full rounded-lg border-blue-100 bg-white px-3 py-2 text-sm text-slate-900 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-blue-900 dark:bg-slate-950 dark:text-white">
                <button class="rounded-lg bg-blue-600 px-5 py-2 text-sm font-bold text-white hover:bg-blue-700">Create Invite Code</button>
            </form>
            @error('student_email') <p class="mt-2 text-sm text-red-600 dark:text-red-300">{{ $message }}</p> @enderror
        </section>

        <section class="rounded-lg border border-blue-100 bg-white shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
            <div class="border-b border-blue-100 p-6 dark:border-blue-900/50">
                <h3 class="text-lg font-bold text-slate-950 dark:text-white">Students & Invites</h3>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-blue-100 dark:divide-blue-900/50">
                    <thead class="bg-blue-50 dark:bg-blue-950/40">
                        <tr>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Student</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Invite Code</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Status</th>
                            <th class="px-4 py-3 text-right text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Action</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-blue-50 dark:divide-blue-900/40">
                        @forelse ($students as $link)
                            <tr>
                                <td class="px-4 py-4 text-sm font-bold text-slate-950 dark:text-white">{{ $link->student?->name ?? $link->student_email ?? 'Waiting for student' }}</td>
                                <td class="px-4 py-4 text-sm font-mono text-slate-600 dark:text-slate-300">{{ $link->invite_code }}</td>
                                <td class="px-4 py-4 text-sm capitalize text-slate-600 dark:text-slate-300">{{ $link->status }}</td>
                                <td class="px-4 py-4 text-right text-sm">
                                    @if ($link->student)
                                        <a href="{{ route('mentor.students.show', $link->student) }}" class="font-bold text-blue-700 dark:text-blue-300">View Journal</a>
                                    @else
                                        <span class="text-slate-400">Not joined</span>
                                    @endif
                                </td>
                            </tr>
                        @empty
                            <tr><td colspan="4" class="px-4 py-10 text-center text-sm text-slate-500 dark:text-slate-400">No invites yet.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </section>
    </div>
</x-app-layout>
