<?php
/**
 * Hero renderer — presentation only.
 *
 * @package Kutby
 * @since   2.8.0
 */

declare(strict_types=1);

namespace Kutby\Hero\Services;

use Kutby\Events\Dispatcher;
use Kutby\Hero\Support\HeroContext;

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

/**
 * Class HeroRenderer
 */
final class HeroRenderer {

	/**
	 * Render the active hero layout (no-op if homepage section disabled).
	 *
	 * @return void
	 */
	public static function render(): void {
		$ctx = HeroContext::from_request();
		if ( ! $ctx->section_enabled() ) {
			return;
		}

		$manager = new HeroManager();
		$layout  = $manager->layout();

		$layout->render( $ctx );

		Dispatcher::emit(
			'hero_rendered',
			array(
				'layout' => $layout->id(),
			)
		);
	}
}
