<div class="bulk-email-history">
    <x-title>
        Bulk Email History
        <x-slot:buttons>
            <a wire:navigate href="{{ route('communications.bulk-email') }}"
               class="btn btn-primary waves-effect waves-light">
                <i class="mdi mdi-email-multiple-outline me-1"></i> New campaign
            </a>
        </x-slot:buttons>
    </x-title>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-centered table-hover table-striped mb-0">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Sent</th>
                        <th>Template</th>
                        <th>Status</th>
                        <th class="text-end">Targeted</th>
                        <th class="text-end">Queued</th>
                        <th class="text-end">Opted-out</th>
                        <th class="text-end">Skipped</th>
                        <th class="text-end">Failed</th>
                        <th>By</th>
                    </tr>
                    </thead>
                    <tbody>
                    @forelse($campaigns as $campaign)
                        <tr>
                            <td>{{ $campaign->id }}</td>
                            <td class="text-muted small">{{ $campaign->created_at->format('d/m/y H:i') }}</td>
                            <td>{{ $campaign->template?->name ?? '—' }}</td>
                            <td>
                                <span class="badge bg-{{ $campaign->status->color() }}">
                                    {{ $campaign->status->label() }}
                                </span>
                            </td>
                            <td class="text-end">{{ number_format($campaign->total_recipients) }}</td>
                            <td class="text-end text-success">{{ number_format($campaign->queued_count) }}</td>
                            <td class="text-end">{{ number_format($campaign->suppressed_count) }}</td>
                            <td class="text-end">
                                {{ number_format($campaign->deduped_count + $campaign->rate_limited_count) }}
                            </td>
                            <td class="text-end text-danger">{{ number_format($campaign->failed_count) }}</td>
                            <td class="text-muted small">
                                {{ $campaign->creator
                                    ? $campaign->creator->name_first . ' ' . $campaign->creator->name_last
                                    : '—' }}
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="10" class="text-center">No campaigns yet.</td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>
            </div>

            <div class="mt-3">
                {{ $campaigns->links() }}
            </div>
        </div>
    </div>
</div>
