<?php
/**
 * The template for displaying all pages
 *
 * Replica la estructura de single.php para consistencia visual.
 * Grid layout: col-lg-9 (contenido) + col-lg-3 (sidebar)
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-page
 *
 * @package ROI_Theme
 * @since 1.0.0
 */

get_header();
?>

<?php while (have_posts()) : the_post(); ?>

<main id="main-content" class="site-main" role="main">

<!-- Hero Section - Componente dinámico -->
<?php
if (function_exists('roi_render_component')) {
    echo roi_render_component('hero');
}
?>

<!-- Main Content Grid -->
<?php
// Plan 99.15: Determinar si mostrar sidebar basándose en visibilidad de componentes
$sidebar_components = ['table-of-contents', 'cta-box-sidebar'];
$show_sidebar = function_exists('roi_should_render_any_wrapper')
    ? roi_should_render_any_wrapper($sidebar_components)
    : true;
$main_col_class = $show_sidebar ? 'col-lg-9' : 'col-lg-12';
?>
<div class="container">
	<div class="row">

		<!-- Main Content Column -->
		<div class="<?php echo esc_attr($main_col_class); ?>">

			<!-- Featured Image - Componente dinámico -->
			<?php
			if (function_exists('roi_render_component')) {
				echo roi_render_component('featured-image');
			}
			?>

			<!-- Page Content -->
			<article id="post-<?php the_ID(); ?>" <?php post_class('post-content'); ?>>
				<?php
				the_content();

				wp_link_pages(array(
					'before' => '<div class="page-links">' . esc_html__('Pages:', 'roi-theme'),
					'after'  => '</div>',
				));
				?>
			</article>

			<!-- Share Buttons - Componente dinámico -->
			<?php
			if (function_exists('roi_render_component')) {
				echo roi_render_component('social-share');
			}
			?>

			<!-- CTA Post - Componente dinámico -->
			<?php
			if (function_exists('roi_render_component')) {
				echo roi_render_component('cta-post');
			}
			?>

			<!-- Related Posts - Componente dinámico -->
			<?php
			if (function_exists('roi_render_component')) {
				echo roi_render_component('related-post');
			}
			?>

			<!-- Ad After Related Posts -->
			<?php
			if (function_exists('roi_render_ad_slot')) {
				echo roi_render_ad_slot('after-related');
			}
			?>

		</div><!-- .<?php echo esc_attr($main_col_class); ?> -->

		<?php if ($show_sidebar): ?>
		<!-- Sidebar Column (col-lg-3) -->
		<div class="col-lg-3">
			<div class="sidebar-sticky">
				<!-- Table of Contents - Componente dinámico -->
				<?php
				if (function_exists('roi_render_component')) {
					echo roi_render_component('table-of-contents');
				}
				?>

				<!-- CTA Box Sidebar - Componente dinámico -->
				<?php
				if (function_exists('roi_render_component')) {
					echo roi_render_component('cta-box-sidebar');
				}
				?>
			</div>
		</div>
		<?php endif; ?>

	</div><!-- .row -->
</div><!-- .container -->

</main><!-- #main-content -->

<?php endwhile; ?>

<!-- Contact Form Section - Componente dinámico -->
<?php
if (function_exists('roi_render_component')) {
    echo roi_render_component('contact-form');
}
?>

<?php
get_footer();
