<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Livewire\Backend\Adresar\Components;

use Illuminate\Contracts\View\View;
use Livewire\Component;
use Livewire\WithPagination;
use Seka\Portal\Modul\Terminy\Entities\MiestoKonania\MiestoKonania;

/**
 * Class Zoznam
 *
 * @package Seka\Portal\Modul\Terminy\Livewire\Backend\Adresar\Components
 */
final class Zoznam extends Component
{
    use WithPagination;

    /**
     * @var int
     */
    protected const PER_PAGE = 15;

    /**
     * @var int
     */
    public int $sort = 0;

    /**
     * @var string|null
     */
    public ?string $state = null;

    /**
     * @var string|null
     */
    public ?string $type = null;

    /**
     * @var \Illuminate\Database\Eloquent\Collection|\Illuminate\Contracts\Pagination\Paginator
     */
    protected $miesta;

    /**
     * @var string
     */
    protected string $createPath = 'modul.terminy.backend.adresar.miesto.create';

    /**
     * @var string
     */
    protected string $editPath = 'modul.terminy.backend.adresar.miesto.edit';

    /**
     * @return \Illuminate\Contracts\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function render(): View
    {
        $miesta = MiestoKonania::withTrashed()
            ->with('vytvoril')
            ->orderBy('updated_at', $this->sort ? 'asc' : 'desc')
            ->paginate(self::PER_PAGE);

        return view('Terminy::livewire.backend.adresar.components.zoznam')
            ->withMiesta($miesta)
            ->withCreatePath($this->createPath)
            ->withEditPath($this->editPath);
    }
}
