<?php
/**
 * Single FluentCart product template.
 *
 * FluentCart's TemplateLoader::loadTemplate() looks for this exact filename
 * (single-fluent-products.php) once the theme declares add_theme_support(
 * 'fluent_cart' ) -- see core/setup.php. Without it, WordPress falls back to
 * single.php (built for blog posts), and FluentCart's own content-injection
 * fallback (filterSingleProductContent) only runs for themes that do NOT
 * declare support, so the page would render with no product content at all.
 *
 * The banner shown here is just the breadcrumb strip (template-parts/
 * banner/banner-page.php -> edify_breadcrumb_func()), not a title, so it
 * doesn't duplicate [fluent_cart_single_product]'s own <h1
 * id="fct-product-summary-title">. Toggle it via Customizer > Theme
 * Settings > Shop Page > "Show Page Header (FluentCart Single Product)"
 * ('fct_single_show_page_header' theme_mod, default on).
 */

get_header();

if ( 'off' !== get_theme_mod( 'fct_single_show_page_header', 'on' ) ) {
	get_template_part( 'template-parts/banner/banner-page' );
}
?>

<div class="page-wrapper">
	<main id="main" class="site-main">
		<div class="container">
			<div class="row justify-content-center">
				<div class="col-lg-12">
					<?php
					while ( have_posts() ) :
						the_post();

						echo do_shortcode( '[fluent_cart_single_product productid="' . absint( get_the_ID() ) . '"]' );

						// ProductRenderer::render() (used by the shortcode above) only
						// outputs the short excerpt via renderExcerpt(). The full
						// long-form description (post_content) has its own method,
						// renderDescription(), which the plugin never calls anywhere
						// by default -- themes are expected to call it explicitly.
						$fct_product = \FluentCart\App\Models\Product::query()->find( get_the_ID() );
						if ( $fct_product && ! empty( get_post( $fct_product->ID )->post_content ) ) {
							?>
							<div class="fct-single-product-description-section">
								<h2 class="fct-product-description-title"><?php esc_html_e( 'Description', 'edify' ); ?></h2>
								<?php ( new \FluentCart\App\Services\Renderer\ProductRenderer( $fct_product ) )->renderDescription(); ?>
							</div>
							<?php
						}

						if ( comments_open() || get_comments_number() ) :
							comments_template();
						endif;

					endwhile;
					?>
				</div>
			</div>
		</div>
	</main>
</div>

<?php
get_footer();
