<?php
/**
 * File Path: templates/partials/buy-links.php
 *
 * My Book Showroom — Buy Links Partial
 *
 * Renders the Order Now button and retailer links for the currently selected format.
 * Uses MBS_Buy_Link_Renderer for all rendering logic and respects PRO affiliate rewriting.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

if ( ! mbs_is_registered() ) {
	return;
}

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

if ( ! isset( $format_row ) ) {
	$format_rows = MBS_Format_Row_DAO::get_by_post( $post_id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global
	$format_row  = $format_rows[0] ?? null; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global
}

echo MBS_Buy_Link_Renderer::render_order_now( $post_id, $format_row ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted renderer returns pre-escaped HTML

mbs_get_template_part( 'partials/section-wc-product', array( 'post_id' => $post_id ) );
?>
