<x-app-layout>
    <x-slot name="header">
        <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
            <div>
                <p class="text-sm font-semibold uppercase tracking-wide text-blue-600 dark:text-blue-400">Challenge Participants</p>
                <h2 class="mt-1 text-2xl font-bold text-slate-950 dark:text-white">{{ $challenge->title }}</h2>
            </div>
            <a href="{{ route('admin.challenges.edit', $challenge) }}" class="rounded-lg bg-blue-600 px-4 py-2 text-sm font-bold text-white hover:bg-blue-700">Edit Challenge</a>
        </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">Participants</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $challenge->participants_count }}</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">Duration</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $challenge->duration_days }} days</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">Status</p>
                <p class="mt-2 text-3xl font-black text-slate-950 dark:text-white">{{ $challenge->is_active ? 'Active' : 'Inactive' }}</p>
            </div>
        </section>

        <section class="rounded-lg border border-blue-100 bg-white shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
            <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">Days</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Streak</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase text-blue-700 dark:text-blue-300">Completion</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-blue-50 dark:divide-blue-900/40">
                        @forelse ($participants as $participant)
                            <tr>
                                <td class="px-4 py-4 text-sm font-bold text-slate-950 dark:text-white">{{ $participant->user?->name ?? 'Deleted user' }}</td>
                                <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ $participant->days_completed }}</td>
                                <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ $participant->current_streak }}</td>
                                <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ number_format((float) $participant->completion_percentage, 0) }}%</td>
                            </tr>
                        @empty
                            <tr><td colspan="4" class="px-4 py-10 text-center text-sm text-slate-500 dark:text-slate-400">No participants yet.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="p-4">{{ $participants->links() }}</div>
        </section>
    </div>
</x-app-layout>
