<?php


namespace AutoAdmin\Bundle\Seo\Controller;


use AutoAdmin\Bundle\Content\Controller\AbstractContentController;
use AutoAdmin\Bundle\Seo\Sitemap\SitemapRenderer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class SitemapController extends AbstractContentController
{
    private SitemapRenderer $renderer;

    public function __construct(SitemapRenderer $renderer)
    {
        $this->renderer = $renderer;
    }

    public function index(Request $request): Response
    {
        $section = $request->get('section', 'default');
        // todo: find a way to differentiate empty section and non-existent section
        $host = $request->getSchemeAndHttpHost();
        $output = $this->renderer->render($host, $section);

        return new Response($output, 200, ['content-type' => 'text/xml;charset=UTF-8']);
    }
}