<?php

namespace BookStack\View\ViewBlocks;

use BookStack\Entities\Queries\BookQueries;
use BookStack\View\SimpleViewBlock;

class BooksIndexRecents extends SimpleViewBlock
{
    protected static string $id = 'builtin_books-index-recents';
    protected static string $view = 'books.parts.index-sidebar-section-recents';
    protected static string $labelTranslationKey = 'entities.recently_viewed';

    public function __construct(
        protected BookQueries $queries,
    ) {
    }

    public function getViewData(array $viewData): array
    {
        $recents = null;
        if (!user()->isGuest()) {
            $recents = $this->queries->recentlyViewedForCurrentUser()->take(4)->get();
        }

        return [
            'recents' => $recents,
        ];
    }
}
