<?php

namespace App\Livewire\Admin\Blogs;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Blog;

class BlogList extends Component
{
    use WithPagination;

    protected $paginationTheme = 'tailwind';

    public $search = '';

    // reset page on search
    public function updatedSearch()
    {
        $this->resetPage();
    }

    public function render()
    {
        return view('livewire.admin.blogs.blog-list', [
            'blogs' => Blog::where('title', 'like', '%' . $this->search . '%')
                ->latest()
                ->paginate(10) // ✅ 10 per page
        ])->layout('layouts.admin');
    }
}
