<?php
/**
 * File Path: templates/partials/section-endorsements.php
 *
 * My Book Showroom — Endorsements / Blurbs Section
 *
 * Renders visible endorsements from the mbs_endorsements table.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

if ( ! mbs_is_registered() ) {
	return;
}

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

$endorsements = MBS_Endorsement_DAO::get_by_post( $post_id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global

if ( empty( $endorsements ) ) {
	return;
}
?>

<div class="mbs-wrapper mbs-section mbs-section-endorsements">
	<h2><?php echo esc_html__( 'Endorsements', 'my-book-showroom' ); ?></h2>
	<div class="mbs-endorsements">
		<?php foreach ( $endorsements as $endorsement ) : // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global?>
			<blockquote class="mbs-endorsement">
				<p><?php echo wp_kses_post( $endorsement->quote_text ); ?></p>
				<cite>
					— <?php echo esc_html( $endorsement->attributed_to ); ?>
					<?php if ( ! empty( $endorsement->attribution_title ) ) : ?>
						<span class="mbs-attribution-title"><?php echo esc_html( $endorsement->attribution_title ); ?></span>
					<?php endif; ?>
				</cite>
			</blockquote>
		<?php endforeach; ?>
	</div>
</div>
