<?php
/**
 * Wishlist Icon Widget - Render Methods
 *
 * @package GGM_Commerce
 */

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

/**
 * Render the premium widget content.
 *
 * @param GGM_Commerce_Widget_Wishlist_Icon $widget The widget instance.
 */
function ggmc_wishlist_icon_render_premium_content( $widget ) {
	$settings = $widget->get_settings_for_display();

	// Get wishlist count.
	$wishlist = GGM_Commerce_Wishlist::instance();
	$count    = $wishlist->get_count();

	$tag        = 'div';
	$link_attrs = '';

	if ( 'yes' === $settings['link_to_wishlist'] && ! empty( $settings['wishlist_page']['url'] ) ) {
		$tag        = 'a';
		$link_attrs = ' href="' . esc_url( $settings['wishlist_page']['url'] ) . '"';

		if ( ! empty( $settings['wishlist_page']['is_external'] ) ) {
			$link_attrs .= ' target="_blank"';
		}
		if ( ! empty( $settings['wishlist_page']['nofollow'] ) ) {
			$link_attrs .= ' rel="nofollow"';
		}
	}

	?>
	<<?php echo esc_html( $tag ); ?> class="ggmc-wishlist-icon"<?php echo $link_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
		<?php ggmc_render_icon( $settings['icon'], array( 'aria-hidden' => 'true' ) ); ?>
		<?php if ( 'yes' === $settings['show_count'] ) : ?>
			<span class="ggmc-wishlist-count-badge" <?php echo 0 === $count ? 'style="display:none;"' : ''; ?>>
				<?php echo esc_html( $count ); ?>
			</span>
		<?php endif; ?>
	</<?php echo esc_html( $tag ); ?>>
	<?php
}
