<?php

namespace AutoAdmin\Bundle\Admin\Twig\Extension;

use AutoAdmin\Bundle\Admin\Helper\EntityPrevNextHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class EntityExtension extends AbstractExtension
{
    public function __construct(
        private EntityPrevNextHelper $prevNextHelper,
    ) {
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('aa_admin_prev_next_links', [$this, 'prevNextLinks'], ['is_safe' => ['html'],]),
        ];
    }

    public function prevNextLinks($currentEntity)
    {
        if (empty($currentEntity)) {
            return null;
        }

        return $this->prevNextHelper->getPrevNextLinks($currentEntity);
    }
}
