<?php

declare(strict_types=1);

namespace App\Controller\Frontend;

use App\Entity\Tenant\Page;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class PageController extends AbstractController
{
    public function __construct(
        private readonly EntityManagerInterface $entityManager,
    ) {}

    #[Route('/sayfa/{slug}', name: 'frontend_page')]
    public function show(string $slug): Response
    {
        $page = $this->entityManager->getRepository(Page::class)
            ->findOneBy([
                'slug' => $slug,
                'status' => 'published',
            ]);

        if (!$page) {
            throw $this->createNotFoundException('Sayfa bulunamadi.');
        }

        return $this->render('frontend/page/detail.html.twig', [
            'page' => $page,
        ]);
    }
}
