<?php
/**
 * Template part: compare-bar
 *
 * Floating "X selected — Compare" bar at the bottom of any plugin page.
 * Server-rendered as a hidden shell; frontend.js shows it once the
 * sessionStorage compare bag is non-empty and updates the count.
 *
 * @package ThemeREX\AutoDealer
 * @version 1.0.0
 *
 * @var string $compare_url Optional URL of the public compare page.
 */

declare(strict_types=1);

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

if ( ! isset( $compare_url ) || '' === (string) $compare_url ) {
	$compare_page_id = (int) get_option( 'trx_ad_compare_page_id', 0 );
	$compare_url     = $compare_page_id > 0
		? (string) get_permalink( $compare_page_id )
		: home_url( '/?trx_ad_compare=1' );
}
$compare_url = (string) $compare_url;
?>
<div class="trx-ad-compare-bar" data-trx-ad-compare-bar hidden>
	<span class="trx-ad-compare-bar__count">
		<span class="trx-ad-compare-count" aria-live="polite">0</span>
		<?php esc_html_e( 'selected', 'trx-auto-dealer' ); ?>
	</span>
	<a class="trx-ad-btn trx-ad-btn--primary trx-ad-compare-bar__cta" href="<?php echo esc_url( $compare_url ); ?>">
		<span class="trx-ad-compare-bar__cta-label"><?php esc_html_e( 'Compare', 'trx-auto-dealer' ); ?></span>
		<span class="trx-ad-compare-bar__cta-suffix"> <?php esc_html_e( 'now', 'trx-auto-dealer' ); ?></span>
	</a>
	<button
		type="button"
		class="trx-ad-compare-bar__close"
		data-trx-ad-compare-clear
		aria-label="<?php esc_attr_e( 'Clear compare list', 'trx-auto-dealer' ); ?>"
		title="<?php esc_attr_e( 'Clear compare list', 'trx-auto-dealer' ); ?>">
		&times;
	</button>
</div>
