<?php

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

use App\Http\Livewire\Frontend\Informacia\MAAISEKUserNotificationsCountPushNotification;
use App\Http\Livewire\Frontend\Informacia\Pouzivatel;
use App\Http\Livewire\Frontend\Informacia\UpozornenieStavEnum;
use App\Repositories\Eloquent\Criteria\AnyRolePouzivatelaCriteria;
use App\Repositories\Eloquent\Criteria\OrderAscCriteria;
use App\Repositories\Eloquent\Criteria\OrderDescCriteria;
use App\Repositories\Eloquent\Criteria\ZverejneneCriteria;
use App\Repositories\InformaciaRepositoryContract;
use Livewire\Component;
use Livewire\WithPagination;
use Prettus\Repository\Exceptions\RepositoryException;

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

    /**
     *
     */
    private const PER_PAGE = 15;

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

    /**
     * @var string
     */
    protected string $paginationTheme = 'bootstrap';

    /**
     * @var InformaciaRepositoryContract
     */
    protected InformaciaRepositoryContract $informaciaRepository;

    /**
     * @param InformaciaRepositoryContract $informaciaRepository
     * @return void
     */
    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(ZverejneneCriteria::class)
            ->pushCriteria(AnyRolePouzivatelaCriteria::class)
            ->pushCriteria(($this->sort == 1) ? OrderAscCriteria::class : OrderDescCriteria::class)
            ->paginate(self::PER_PAGE);

        return view('livewire.frontend.informacie.zoznam')->withInformacie($informacie);
    }
}
