<?php

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

use Prodigy\Includes\Helpers\Prodigy_Formatting;
use Prodigy\Includes\Helpers\Prodigy_Widget_Options;

if ( $rating_count > 0 ) : ?>
	<div class="prodigy-product__rating prodigy-custom-template">
		<?php if ( get_option( 'pg_product_rating' ) ) : ?>
			<?php echo wp_kses( pg_get_rating_html( $average ), Prodigy_Formatting::get_allowed_html() ); ?>
		<?php endif; ?>
		<?php if ( isset( $args['prg_style_rating_separator'] ) ) : ?>
			<?php if ( Prodigy_Widget_Options::$bool_mapper[ $args['prg_style_rating_separator'] ] ) : ?>
				<div class="prodigy-product__rating-divider" aria-hidden="true" role="presentation"></div>
			<?php endif; ?>
		<?php else : ?>
			<div class="prodigy-product__rating-divider" aria-hidden="true" role="presentation"></div>
		<?php endif; ?>
		<?php if ( comments_open( $product->get_field( 'ID' ) ) ) : ?>
			<?php if ( get_option( 'pg_product_review' ) && isset( $product_variant_info['attributes']['url'] ) ) : ?>
				<input type="hidden" value="<?php echo esc_attr( $product_variant_info['attributes']['url'] ); ?>"
						class="product-url-js" aria-hidden="true">
				<?php if ( isset( $settings['prg_style_rating_icon_align'] ) ) : ?>
					<a
							class="prodigy-product__rating-link prodigy-review-link-js"
							rel="nofollow"
							style="cursor: pointer"
							href="<?php echo esc_url( get_permalink( $product->get_field( 'ID' ) ) ); ?>#tab-reviews"
							<?php /* translators: %s: number of reviews */ ?>
							aria-label="<?php printf( esc_attr__( 'Read %s customer review(s)', 'prodigy-commerce' ), esc_html( $review_count ) ); ?>"
					>
						<?php if ( $icon_type === 'icon' ) : ?>
							<?php if ( $icon_class !== '' ) : ?>
								<i class="<?php echo esc_attr( $icon_class ); ?>" aria-hidden="true" role="presentation"></i>
							<?php endif; ?>
						<?php elseif ( $icon_type === 'svg' ) : ?>
							<img class="<?php echo esc_attr( $icon_svg_class ); ?>"
								src="<?php echo esc_attr( $settings['prg_style_rating_selected_icon']['value']['url'] ); ?>"
								alt="<?php esc_attr_e( 'Icon image', 'prodigy-commerce' ); ?>" aria-hidden="true" role="presentation">
						<?php endif; ?>
						<?php /* translators: %s: number of customer reviews */ ?>
						<span class="count prodigy-product__rating-info">(<?php printf( esc_html( _n( '%s customer review', '%s customer reviews', $review_count, 'prodigy-commerce' ) ), '' . esc_html( $review_count ) ); ?>)</span>
					</a>
				<?php else : ?>
					<a
							class="prodigy-product__rating-link prodigy-review-link-js"
							rel="nofollow"
							style="cursor: pointer"
							href="<?php echo esc_url( get_permalink( $product->get_field( 'ID' ) ) ); ?>#tab-reviews"
							<?php /* translators: %s: number of reviews */ ?>
							aria-label="<?php printf( esc_attr__( 'Read %s customer review(s)', 'prodigy-commerce' ), esc_html( $review_count ) ); ?>"
					>
						<?php if ( $icon_class !== '' ) : ?>
							<i class="<?php echo esc_attr( $icon_class ); ?>" aria-hidden="true" role="presentation"></i>
						<?php endif; ?>
						<?php /* translators: %s: number of customer reviews */ ?>
						<span class="count prodigy-product__rating-info">(<?php printf( esc_html( _n( '%s customer review', '%s customer reviews', $review_count, 'prodigy-commerce' ) ), '' . esc_html( $review_count ) ); ?>)</span>
					</a>
				<?php endif; ?>
			<?php endif ?>
		<?php endif ?>
	</div>
	<?php if ( $is_quick_view && ! empty( $product->get_field( 'post_excerpt' ) ) ) : ?>
		<p class="prodigy-product__description"><?php echo esc_url( $product->get_field( 'post_excerpt' ) ); ?></p>
	<?php endif; ?>
<?php endif; ?>
