<?php

namespace App\Components\Contact\BulkEmail;

use App\Models\Contact\BulkEmailCampaign;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
use Livewire\WithPagination;

class History extends Component
{
    use WithPagination, AuthorizesRequests;

    public int $perPage = 20;

    public function mount(): void
    {
        $this->authorize('communications.send.bulk');
    }

    public function render()
    {
        $campaigns = BulkEmailCampaign::with(['template', 'creator'])
            ->latest()
            ->paginate($this->perPage);

        return view('components.contact.bulk-email.history', [
            'campaigns' => $campaigns,
        ]);
    }
}
