<?php

namespace App\Http\Livewire\Components\Informacia\Components;

use App\Repositories\Eloquent\Criteria\OrderAscCriteria;
use App\Repositories\Eloquent\Criteria\OrderDescCriteria;
use App\Repositories\Eloquent\Criteria\WithTrashedCriteria;
use App\Repositories\InformaciaRepositoryContract;
use Livewire\Component;
use Livewire\WithPagination;
use Prettus\Repository\Exceptions\RepositoryException;

/**
 * Class Zoznam
 */
final class Zoznam extends Component
{
    use WithPagination;

    private const PER_PAGE = 15;

    public int $sort = 0;

    protected string $paginationTheme = 'bootstrap';

    protected InformaciaRepositoryContract $informaciaRepository;

    public function boot(InformaciaRepositoryContract $informaciaRepository): void
    {
        $this->informaciaRepository = $informaciaRepository;
    }

    /**
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     *
     * @throws RepositoryException
     */
    public function render()
    {
        $informacie = $this->informaciaRepository
            ->pushCriteria(WithTrashedCriteria::class)
            ->pushCriteria(($this->sort == 1) ? OrderAscCriteria::class : OrderDescCriteria::class)
            ->paginate(self::PER_PAGE);

        return view('pages.sprava.informacie.livewire.components.zoznam')->withInformacie($informacie);
    }
}
