<?php

namespace Modules\User\Http\Livewire;

use Livewire\Component;
use Modules\Main\Models\Agent\Agent;
use Modules\Contracts\Models\Contract;
use Modules\Contracts\Models\ContractStatus;
use Modules\User\Models\UserRole;
use Modules\User\Models\Role;
use Modules\User\Models\User;
use Modules\Main\Models\Company\CompanyAdmin;

class UserSelectorLivewire extends Component
{
    public $id;
    public $name;
    public $query;
    public $users;
    public function mount()
    {
        $this->query = '';
        $this->users = [];
    }
    public function clearSearch()
    {
        $this->query = '';
    }
    public function setUser($id)
    {
        $user = User::find($id);
        $this->id = $id;
        $this->name = $user->name;
    }
    public function unsetUser()
    {
        unset($this->id);
        unset($this->name);
        $this->query = '';
    }
    public function render()
    {
        if ($this->query)
        {
            $users = User::where('name', 'like', '%' . $this->query . '%')->take(10)->get();
            $this->users = $users->toArray();
        }
        return view('user::livewire.search.selector');
    }
}