<?php

namespace App\Livewire\Supports;

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

class Index extends Component
{
    use WithPagination;

    public string $search = '';

    protected $queryString = ['search'];

    public function updatingSearch()
    {
        $this->resetPage();
    }

    public function render()
    {
        $supports = Support::query()
            ->when($this->search, function ($query) {
                $query->where('name', 'like', "%{$this->search}%")
                    ->orWhere('shortname', 'like', "%{$this->search}%");
            })
            ->orderBy('name')
            ->paginate(20);

        return view('livewire.supports.index', [
            'supports' => $supports,
        ])->layout('layouts.app');
    }
}

