<x-app-layout>
    <x-slot name="header">
        <div class="flex flex-col gap-3 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-300">Admin</p>
                <h2 class="text-2xl font-bold text-slate-950 dark:text-white">Email Broadcasts</h2>
            </div>
            <a href="{{ route('admin.email-broadcasts.create') }}" class="inline-flex items-center justify-center rounded-lg bg-blue-600 px-4 py-2 text-sm font-black text-white transition hover:bg-blue-700">
                New Broadcast
            </a>
        </div>
    </x-slot>

    <div class="overflow-hidden 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-black uppercase text-blue-700 dark:text-blue-300">Subject</th>
                        <th class="px-4 py-3 text-left text-xs font-black uppercase text-blue-700 dark:text-blue-300">Group</th>
                        <th class="px-4 py-3 text-left text-xs font-black uppercase text-blue-700 dark:text-blue-300">Status</th>
                        <th class="px-4 py-3 text-left text-xs font-black uppercase text-blue-700 dark:text-blue-300">Sent</th>
                        <th class="px-4 py-3 text-left text-xs font-black uppercase text-blue-700 dark:text-blue-300">Created</th>
                        <th class="px-4 py-3 text-left text-xs font-black uppercase text-blue-700 dark:text-blue-300">Action</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-blue-100 dark:divide-blue-900/50">
                    @forelse ($broadcasts as $broadcast)
                        <tr>
                            <td class="px-4 py-4 text-sm font-bold text-slate-950 dark:text-white">{{ $broadcast->subject }}</td>
                            <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ \App\Models\EmailBroadcast::recipientGroups()[$broadcast->recipient_group] ?? $broadcast->recipient_group }}</td>
                            <td class="px-4 py-4 text-sm font-bold text-slate-700 dark:text-slate-200">{{ ucfirst($broadcast->status) }}</td>
                            <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ $broadcast->sent_count }}/{{ $broadcast->total_recipients }} sent, {{ $broadcast->failed_count }} failed</td>
                            <td class="px-4 py-4 text-sm text-slate-600 dark:text-slate-300">{{ $broadcast->created_at->format('M d, Y H:i') }}</td>
                            <td class="px-4 py-4">
                                <a href="{{ route('admin.email-broadcasts.show', $broadcast) }}" class="text-sm font-black text-blue-700 dark:text-blue-300">View</a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="px-4 py-8 text-center text-sm font-semibold text-slate-500 dark:text-slate-400">No email broadcasts yet.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

    <div class="mt-6">{{ $broadcasts->links() }}</div>
</x-app-layout>
