<?php
/**
 * File Path: templates/partials/section-about-the-book.php
 *
 * My Book Showroom — About the Book Section
 *
 * Renders the full book synopsis / description.
 *
 * Content priority (mirrors the hero):
 *   1. mbs_synopsis (PRO) — full back-cover / flap copy.
 *   2. mbs_teaser          — short description / tagline.
 *   3. post_content        — fallback for books using the native WP editor.
 *
 * GP-UI-1: returns with zero output when all three sources are empty.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variables injected by mbs_get_template_part(); not global vars

if ( ! mbs_is_registered() ) {
	return;
}

if ( ! isset( $post_id ) ) {
	$post_id = get_the_ID();
}

// Resolve description from meta fields first (MBS stores description in meta,
// not post_content). Fall back to post_content for books using the WP editor.
$_mbs_about_text = '';
if ( mbs_is_pro() ) {
	$_mbs_about_text = trim( (string) get_post_meta( $post_id, 'mbs_synopsis', true ) );
}
if ( '' === $_mbs_about_text ) {
	$_mbs_about_text = trim( (string) get_post_meta( $post_id, 'mbs_teaser', true ) );
}
if ( '' === $_mbs_about_text ) {
	$_mbs_about_text = trim( wp_strip_all_tags( get_the_content( null, false, $post_id ) ) );
}

// GP-UI-1: suppress section when nothing is available.
if ( '' === $_mbs_about_text ) {
	return;
}
?>

<div class="mbs-wrapper mbs-section mbs-section-about">
	<h2><?php echo esc_html__( 'About the Book', 'my-book-showroom' ); ?></h2>
	<div class="mbs-synopsis">
		<?php echo wp_kses_post( wpautop( $_mbs_about_text ) ); ?>
	</div>
</div>
