<?php
/**
 * Header Template
 *
 * Replica EXACTAMENTE la estructura del template RDash (líneas 54-133)
 * Sin wrappers extra.
 *
 * @package ROI_Theme
 * @since 1.0.0
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo('charset'); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- CLS Prevention: Hide navbar-collapse before Bootstrap loads -->
	<style id="cls-navbar-fix">
	@media (max-width: 991.98px) {
		.navbar-collapse:not(.show) {
			display: none !important;
		}
	}
	</style>
	<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<?php wp_body_open(); ?>

<?php
if (function_exists('roi_render_component')) {
    echo roi_render_component('top-notification-bar');
}
?>

<!-- Navbar (Template líneas 264-320) -->
<?php
// Plan 99.15: Solo renderizar wrapper si navbar debe mostrarse
if (function_exists('roi_should_render_wrapper') && roi_should_render_wrapper('navbar')):
?>
<nav class="navbar navbar-expand-lg navbar-dark py-3" role="navigation" aria-label="<?php esc_attr_e('Primary Navigation', 'roi-theme'); ?>">
	<div class="container">

		<?php
		// Brand/Logo - Leer configuración desde BD
		$show_brand = roi_get_navbar_setting('media', 'show_brand', false);
		if ($show_brand) :
			$use_logo = roi_get_navbar_setting('media', 'use_logo', false);
			$brand_text = roi_get_navbar_setting('media', 'brand_text', get_bloginfo('name'));
			$home_url = home_url('/');

			if ($use_logo) :
				$logo_url = roi_get_navbar_setting('media', 'logo_url', '');
				if (!empty($logo_url)) :
		?>
				<a class="navbar-brand" href="<?php echo esc_url($home_url); ?>">
					<img src="<?php echo esc_url($logo_url); ?>" alt="<?php echo esc_attr($brand_text); ?>" class="roi-navbar-logo">
				</a>
		<?php
				endif;
			else :
		?>
				<a class="navbar-brand roi-navbar-brand" href="<?php echo esc_url($home_url); ?>">
					<?php echo esc_html($brand_text); ?>
				</a>
		<?php
			endif;
		endif;
		?>

		<!-- Hamburger Toggle Button -->
		<button class="navbar-toggler"
				type="button"
				data-bs-toggle="collapse"
				data-bs-target="#navbarSupportedContent"
				aria-controls="navbarSupportedContent"
				aria-expanded="false"
				aria-label="<?php esc_attr_e('Toggle navigation', 'roi-theme'); ?>">
			<span class="navbar-toggler-icon"></span>
		</button>

		<!-- Collapsible Menu -->
		<div class="collapse navbar-collapse" id="navbarSupportedContent">
			<?php
			// Navbar Component - Menu de navegación
			if (function_exists('roi_render_component')) {
				echo roi_render_component('navbar');
			}
			?>

			<?php
			// CTA "Let's Talk" Button Component
			if (function_exists('roi_render_component')) {
				echo roi_render_component('cta-lets-talk');
			}
			?>
		</div>

	</div><!-- .container -->
</nav><!-- .navbar -->
<?php endif; // roi_should_render_wrapper('navbar') ?>