<?php
/**
 * "Compare Link" block — compact header badge with a live count.
 *
 * Delegates to `CompareHandler::renderHeaderLink()` so the block, the
 * Elementor widget, and the `[trx_ad_compare_link]` shortcode all emit
 * identical markup. The count badge uses `.trx-ad-compare-count`, which
 * `Compare.updateCount()` in frontend.js already keeps in sync with
 * localStorage on every add/remove — no extra JS plumbing.
 *
 * @package ThemeREX\AutoDealer
 * @version 1.0.0
 */

declare(strict_types=1);

namespace ThemeREX\AutoDealer\Blocks;

use ThemeREX\AutoDealer\Frontend\CompareHandler;

class CompareLinkBlock extends AbstractBlock {

	protected string $slug = 'compare-link';

	public function render( array $attributes, string $content = '', $block = null ): string {
		$class = '';
		if ( ! empty( $attributes['className'] ) ) {
			$class = sanitize_html_class( (string) $attributes['className'] );
		}

		return CompareHandler::renderHeaderLink(
			array(
				'show_label'    => isset( $attributes['showLabel'] ) ? (bool) $attributes['showLabel'] : true,
				'show_icon'     => isset( $attributes['showIcon'] ) ? (bool) $attributes['showIcon'] : true,
				'hide_if_empty' => isset( $attributes['hideIfEmpty'] ) ? (bool) $attributes['hideIfEmpty'] : false,
				'label'         => isset( $attributes['label'] ) && '' !== (string) $attributes['label']
					? (string) $attributes['label']
					: __( 'Compare', 'trx-auto-dealer' ),
				'class'         => $class,
			)
		);
	}
}
