<?php


namespace AutoAdmin\Bundle\Seo\Twig;

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

class AutoAdminSeoExtension extends AbstractExtension
{
    private ContentContext $contentContext;

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

    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());
    }
}
