<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Http\Livewire\Components;

use Livewire\Component;
use Illuminate\Contracts\View\View;

/**
 * Class Pracoviska
 *
 * @package Seka\Vzdelavanie\Http\Livewire\Components
 */
final class Pracoviska extends Component
{
    /**
     * @var \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed
     */
    private $pracoviska = [];

    /**
     * @var string
     */
    public string $kod = '';

    /**
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function mount(): void
    {
        $this->pracoviska = app()->make('\App\Models\Pracovisko\Pracovisko')
            ->orderBy('kod', 'ASC')
            ->get();
    }

    /**
     * @return mixed
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function render(): View
    {
        return view('Vzdelavanie::livewire.components.pracoviska');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed
     */
    public function pracoviska()
    {
        return $this->pracoviska;
    }

    /**
     * @param $value
     */
    public function updatedKod($value)
    {
        $this->emitTo(
            'Vzdelavanie::pages.sprava.testovanie.pouzivatelia.components.zoznam',
            'filterByPekCode',
            $value
        );
    }
}
