<?php

namespace App\Controllers;

use App\Models\UserModel;
use CodeIgniter\Controller;

class Users extends Controller
{
    public function index()
    {
        $model = new UserModel();
        $search = $this->request->getGet('search');

        $query = $model;

        if (!empty($search)) {
            $query = $query->groupStart()
                ->like('username', $search)
                ->orLike('email', $search)
                ->groupEnd();
        }

        $data = [
            'users' => $query->paginate(10),
            'pager' => $model->pager,
            'search' => $search
        ];

        return view('users/index', $data);
    }
}
