<?php

declare(strict_types=1);

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

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

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

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

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

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

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

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

        return view('Terminy::livewire.backend.moznosti-udalosti.components.zoznam')
            ->withMoznostiUdalosti($moznostiUdalosti)
            ->withCreatePath($this->createPath)
            ->withEditPath($this->editPath);
    }
}
