<?php
/**
 *  UABB Star Ratting Module front-end CSS php file
 *
 *  @package UABB Star Ratting Module
 */

$rating_title = $settings->rating_title;
$rating       = ! empty( $settings->rating ) ? $settings->rating : 0;
$layout       = 0;
?>
<div class="uabb-rating-content">

<?php
if ( 'bottom' === $settings->star_position ) {
	?>
	<div class="uabb-rating-title"><?php echo $rating_title; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
	<?php
}
	$rating_scale   = (int) $settings->rating_scale;
	$rating         = (float) $rating > $rating_scale ? $rating_scale : $rating;
	$txt_rating     = $rating . '/' . $rating_scale;
	$floored_rating = (int) $rating;
	$stars_html     = '';
?>
	<div class="uabb-rating" title="<?php echo( $txt_rating ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" itemtype="http://schema.org/Rating" itemscope="" itemprop="reviewRating">
	<?php
	$icon = '&#9733;';

	if ( 'outline' === $settings->star_style ) {
		$icon = '&#9734;';
	}
	for ( $stars = 1; $stars <= $settings->rating_scale; $stars++ ) {
		if ( $stars <= $floored_rating ) {
			$stars_html .= '<i class="uabb-star-full">' . $icon . '</i>';
		} elseif ( $floored_rating + 1 === $stars && $rating !== $floored_rating ) {
			$stars_html .= '<i class="uabb-star-' . ( $rating - $floored_rating ) * 10 . '">' . $icon . '</i>';

		} else {
			$stars_html .= '<i class="uabb-star-empty">' . $icon . '</i>';
		}
	}

		echo $stars_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	?>
	<span itemprop="ratingValue" class="uabb-hidden"><?php echo( $txt_rating ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
	</div>

<?php
if ( 'top' === $settings->star_position ) {
	?>
	<div class="uabb-rating-title"><?php echo $rating_title; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
	<?php
}
?>
</div>
