@extends('layouts.app')

@section('title', 'Campaign History')

@section('content')
<div class="container py-5">
    <h2 class="mb-4">Campaign History</h2>

    <div class="card shadow-sm">
        <div class="card-body">
            @if($campaigns->count() > 0)
            <div class="table-responsive">
                <table class="table table-bordered table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Campaign Name</th>
                            <th>Total Emails</th>
                            <th>Sent</th>
                            <th>Failed</th>
                            <th>Pending</th>
                            <th>Date</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($campaigns as $campaign)
                        <tr>
                            <td>{{ $campaign->name }}</td>
                            <td>{{ $campaign->total_emails }}</td>
                            <td>{{ $campaign->sent_count }}</td>
                            <td>{{ $campaign->failed_count }}</td>
                            <td>{{ $campaign->pending_count }}</td>
                            <td>{{ $campaign->created_at->format('Y-m-d H:i') }}</td>
                            <td>
                                <a href="{{ route('campaigns.history.show', $campaign->id) }}" class="btn btn-sm btn-primary">
                                    View Emails
                                </a>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

            <div class="mt-3">
                {{ $campaigns->links('pagination::bootstrap-5') }}
            </div>
            @else
            <p class="text-center text-muted">No campaigns found.</p>
            @endif
        </div>
    </div>
</div>
@endsection