<?php


namespace AutoAdmin\Bundle\Seo\Twig;

use AutoAdmin\Bundle\Content\Context\ContentContext;
use AutoAdmin\Bundle\Seo\Model\SeoPage;
use AutoAdmin\Bundle\Seo\Renderer\TagRenderer;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class AutoAdminSeoExtension extends AbstractExtension
{
    private ContentContext $contentContext;
    private TagRenderer $tagRenderer;

    public function __construct(ContentContext $contentContext, TagRenderer $tagRenderer)
    {
        $this->contentContext = $contentContext;
        $this->tagRenderer = $tagRenderer;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('aa_seo_has_data', [$this, 'hasSeoData']),
            new TwigFunction('aa_seo_has_title', [$this, 'hasTitle']),
        ];
    }

    public function hasSeoData(): bool
    {
        return ($seo = $this->contentContext->getSeoPage()) && $seo instanceof SeoPage;
    }

    public function hasTitle(): bool
    {
        return ($seo = $this->contentContext->getSeoPage()) && !empty($seo->getTitle());
    }
}
