<?php
/**
 * Header / menu wishlist icon with item counter.
 *
 * @package SKYNSMFA_Smart_Favorites
 */

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

$skynsmfa_show_badge = ( 'never' !== $skynsmfa_count_visibility )
	&& ( 'always' === $skynsmfa_count_visibility || $skynsmfa_count > 0 );

$skynsmfa_style_parts = array(
	sprintf( '--skynsmfa-menu-icon-size:%dpx', absint( $skynsmfa_icon_size ) ),
);

if ( ! empty( $skynsmfa_icon_color ) ) {
	$skynsmfa_style_parts[] = sprintf( '--skynsmfa-menu-icon-color:%s', $skynsmfa_icon_color );
}

if ( ! empty( $skynsmfa_badge_color ) ) {
	$skynsmfa_style_parts[] = sprintf( '--skynsmfa-badge-bg:%s', $skynsmfa_badge_color );
}

if ( ! empty( $skynsmfa_badge_text_color ) ) {
	$skynsmfa_style_parts[] = sprintf( '--skynsmfa-badge-color:%s', $skynsmfa_badge_text_color );
}

$skynsmfa_inline_style = implode( ';', $skynsmfa_style_parts );

?>
<a
	href="<?php echo esc_url( $skynsmfa_url ); ?>"
	class="skynsmfa-menu-icon"
	style="<?php echo esc_attr( $skynsmfa_inline_style ); ?>"
	data-count-visibility="<?php echo esc_attr( $skynsmfa_count_visibility ); ?>"
	aria-label="<?php echo esc_attr( $skynsmfa_aria_label ); ?>"
>
	<span class="skynsmfa-menu-icon__quantity">
		<span class="skynsmfa-menu-icon__icon" aria-hidden="true">
			<?php if ( ! empty( $skynsmfa_custom_icon_url ) ) : ?>
				<img
					class="skynsmfa-menu-icon__custom-image"
					src="<?php echo esc_url( $skynsmfa_custom_icon_url ); ?>"
					alt=""
					width="<?php echo esc_attr( (string) absint( $skynsmfa_icon_size ) ); ?>"
					height="<?php echo esc_attr( (string) absint( $skynsmfa_icon_size ) ); ?>"
					loading="lazy"
					decoding="async"
				/>
			<?php else : ?>
				<?php include SKYNSMFA_PATH . 'templates/icon.php'; ?>
			<?php endif; ?>
		</span>
		<span class="skynsmfa-menu-icon__badge"<?php echo $skynsmfa_show_badge ? '' : ' hidden'; ?>><?php echo esc_html( (string) absint( $skynsmfa_count ) ); ?></span>
	</span>
</a>
