<?php
/**
 * Recently-viewed strip helper.
 *
 * Free tier — anonymous, localStorage-backed (per ADR-29). The browser
 * tracks the last N viewed listing IDs in `trx_ad_recently_viewed`, and
 * frontend.js hydrates the strip by fetching each /vehicles/{id} and
 * appending a card. This class only provides the server-side render
 * helper that emits the hydration shell.
 *
 * @package ThemeREX\AutoDealer
 * @version 1.0.0
 */

declare(strict_types=1);

namespace ThemeREX\AutoDealer\Frontend;

/**
 * Stateless recently-viewed renderer.
 */
final class RecentlyViewedHandler {

	/**
	 * Render the hydration shell. Pass `$exclude` for the current listing
	 * so it doesn't appear in its own "Recently viewed" list.
	 *
	 * @param int $exclude Vehicle ID to skip.
	 * @param int $limit   Max items (default 4).
	 * @return string
	 */
	public static function renderStrip( int $exclude = 0, int $limit = 4 ): string {
		$limit = max( 1, min( 12, $limit ) );

		ob_start();
		TemplateLoader::getTemplatePart(
			'vehicle-recently-viewed',
			array(
				'exclude' => $exclude,
				'limit'   => $limit,
			)
		);
		return (string) ob_get_clean();
	}
}
