<?php
/**
 * Template part: vehicle-recently-viewed
 *
 * Server-renders a hydration shell. Vehicle IDs live in the visitor's
 * localStorage (anonymous tracking, no server logging — see ADR-29 and
 * Phase 4 deliverables list). frontend.js reads `trx_ad_recently_viewed`,
 * fetches each card via REST, and injects the cards into `[data-trx-ad-rv-grid]`.
 *
 * If the visitor has no recently-viewed history, the section stays hidden
 * (the JS toggles `hidden` once a non-empty list resolves).
 *
 * @package ThemeREX\AutoDealer
 * @version 1.0.0
 *
 * @var int $exclude Optional listing ID to exclude (the current single-vehicle page).
 * @var int $limit   Max cards (default 4).
 */

declare(strict_types=1);

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

$exclude = isset( $exclude ) ? (int) $exclude : 0;
$limit   = isset( $limit ) ? max( 1, min( 12, (int) $limit ) ) : 4;
?>
<section
	class="trx-ad-recently-viewed"
	data-trx-ad-recently-viewed
	data-exclude="<?php echo esc_attr( (string) $exclude ); ?>"
	data-limit="<?php echo esc_attr( (string) $limit ); ?>"
	aria-labelledby="trx-ad-rv-heading"
	hidden>
	<h2 id="trx-ad-rv-heading" class="trx-ad-recently-viewed__heading">
		<?php esc_html_e( 'Recently Viewed', 'trx-auto-dealer' ); ?>
	</h2>
	<div class="trx-ad-recently-viewed__grid" data-trx-ad-rv-grid></div>
</section>
