<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Livewire\Components;

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

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

    /**
     * @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;
    }

    public function updatedKod(string $value): void
    {
        $this->dispatch('filterByPekCode', $value);
    }
}
