<?php

namespace Core\App\Controllers;

use Core\App\Models\Page;
use Core\System\ThemeManager;

class FrontendPageController
{
    public function show($slug)
    {
        $page = (new Page())->findBySlug($slug);

        if (!$page) {
            http_response_code(404);
            $msg = function_exists('__') ? __('error.page_not_found', 'Page not found.') : 'Page not found.';
            echo htmlspecialchars($msg, ENT_QUOTES, 'UTF-8');
            return;
        }

        ThemeManager::render('page', [
            'page' => $page
        ]);
    }
}
