<?php
declare(strict_types=1);

function render_module(array $module, array $settings): string
{
    $type = $module['type'] ?? '';
    $template = __DIR__ . '/../templates/modules/' . $type . '.php';
    if (!is_file($template)) {
        return '';
    }
    ob_start();
    include $template;
    return (string)ob_get_clean();
}

function render_page(array $page, array $settings): string
{
    $modules = page_modules($page);
    ob_start();
    foreach ($modules as $module) {
        echo render_module($module, $settings);
    }
    return (string)ob_get_clean();
}
