<?php

namespace App\Http\Livewire\Buscador\Panel;

use Illuminate\Support\Facades\DB;
use Livewire\WithPagination;
use Livewire\Component;
use App\Models\Anestesiologo;

class Anestesiologos extends Component
{
    use WithPagination;
    /*****************************/
    /*** ATRIBUTOS              **/
    /*****************************/
    protected $paginationTheme = 'bootstrap';
    public $numeroregistros = 10;
    public $buscador_anestesiologo;
    public $anestesiologo_seleccionado;
    public $anestesiologo_id;
    public $display = "d-none";

    /*****************************/
    /*** SELECCIONAR            **/
    /*****************************/
    public function selecionar_anestesiologo($id)
    {
        $anestesiologo = Anestesiologo::find($id);
        $this->anestesiologo_seleccionado =  $anestesiologo->nombre;
        $this->emit('ev_seleccionar_anestesiologo', $anestesiologo->id);
        $this->display = 'd-none';
    }
    /*****************************/
    /*** MOSTAR                 **/
    /*****************************/
    public function montar_lista()
    {
        $this->display = 'd-block';
    }
    /*****************************/
    /*** RENDER                 **/
    /*****************************/
    public function render()
    {
        $anestesiologos = DB::table('anestesiologos')
            ->where('anestesiologos.activo', '!=', '0')
            ->select(
                'anestesiologos.id',
                'anestesiologos.documento',
                'anestesiologos.nombre',
                'anestesiologos.activo',
            )
            ->where(function ($query) {
                $query->where('anestesiologos.nombre', 'like', '%' . $this->buscador_anestesiologo . '%');
            })->orderBy('nombre', 'desc')
            ->paginate($this->numeroregistros);

        $count_anestesiologos_busqueda = $anestesiologos->count();
        return view('livewire.buscador.panel.anestesiologos',compact('anestesiologos','count_anestesiologos_busqueda'));
    }
}