<?php

namespace App\Livewire\Configurations\Environments;

use App\Models\Environments\Type;
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()
    {

        $types = Type::query()
            ->when($this->search, function ($query) {
                $query->where('name', 'like', "%{$this->search}%")
                    ->orWhere('description', 'like', "%{$this->search}%");
            })
            ->orderBy('name')
            ->paginate(20);

        return view('livewire.configurations.environments.index')
        ->with('types', $types)
        ->layout('layouts.app');
    }
}
