<?php
/**
 * File Path: templates/partials/section-look-inside.php
 *
 * My Book Showroom — Look Inside Section Content
 *
 * Renders the Look Inside sample text inside a section wrapper (for use in section order).
 * PRO-only Amazon "Continue Reading" link placeholder.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

if ( ! mbs_is_registered() ) {
	return;
}

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

$look_inside_text   = (string) get_post_meta( $post_id, 'mbs_look_inside_text', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global
$amazon_look_inside = ''; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; Future PA-API integration placeholder

// GP-UI-1: suppress section entirely when there is nothing to show.
if ( empty( $look_inside_text ) && empty( $amazon_look_inside ) ) {
	return;
}
?>

<div class="mbs-wrapper mbs-section mbs-section-look-inside">
	<?php echo wp_kses_post( wpautop( $look_inside_text ) ); ?>

	<?php if ( mbs_is_pro() && ! empty( $amazon_look_inside ) ) : ?>
		<a href="<?php echo esc_url( $amazon_look_inside ); ?>" class="button" target="_blank" rel="noopener">
			<?php echo esc_html__( 'Continue Reading on Amazon →', 'my-book-showroom' ); ?>
		</a>
	<?php endif; ?>
</div>
