<?php
/**
 * Standalone classic-theme fallback for AmbassadorHub block templates.
 *
 * This file is a last resort, reached only when the active classic theme has
 * no page.php, single.php, or index.php at all (extremely rare). Under normal
 * conditions BlockTemplateLoader injects blocks via the_content filter into
 * the theme's own page.php/single.php so the theme's sidebar, wrappers, and
 * post classes all render correctly.
 *
 * Never reference this file directly — always go through BlockTemplateLoader.
 *
 * @package AmbassadorHub\Frontend
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$ambh_config = \AmbassadorHub\Frontend\BlockTemplateLoader::get_current();

if ( ! $ambh_config || ! file_exists( $ambh_config['path'] ) ) {
	global $wp_query;
	$wp_query->set_404();
	status_header( 404 );
	get_template_part( '404' );
	exit;
}

// Load the post into the loop so post-title / post-content blocks resolve correctly.
// Archive templates own their own query loop block, so the_post() is not needed.
if ( is_singular() ) {
	the_post();
}

// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- reading local plugin file.
$ambh_content = (string) file_get_contents( $ambh_config['path'] );

get_header();
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- do_blocks() output is safe; blocks handle their own escaping.
echo do_blocks( $ambh_content );
get_footer();
