<?php
defined( 'ABSPATH' ) || exit;

class Avision_Page_Template {

    /**
     * Render a complete page with guaranteed header + hero + body + footer.
     * No template can skip any of these — structure is enforced here.
     *
     * @param string   $slug    Page identifier (for logging)
     * @param array    $hero    Args passed to avi_component('hero', ...)
     * @param callable $content Function that outputs the page body HTML
     */
    public static function render(
        string $slug,
        array $hero,
        callable $content
    ): void {

        // Header — always first, contains <!DOCTYPE>, <head>, <body>, <nav>
        avi_get_layout( 'header' );

        // Hero — renders immediately after nav
        if ( ! empty( $hero ) ) {
            avi_component( 'hero', $hero );
        }

        // Page body — all sections between hero and footer
        call_user_func( $content );

        // Footer — always last, contains </body></html>
        $GLOBALS['avi_template_footer_rendered'] = true;
        avi_get_layout( 'footer' );

        error_log( '[AVI] Page rendered: ' . $slug );
    }
}
