<?php

/**
 * Olegnax ProductReviewsSummary
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Olegnax.com license that is
 * available through the world-wide-web at this URL:
 * https://www.olegnax.com/license
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Olegnax
 * @package     Olegnax_ProductReviewsSummary
 * @copyright   Copyright (c) 2023 Olegnax (http://www.olegnax.com/)
 * @license     https://www.olegnax.com/license
 */

$settings = $this->helper('Olegnax\ProductReviewsSummary\Helper\Helper')->getConfig('olegnax_productreviewssummary/general');

$enabled = $settings['rating_bystar_rating'];
$show_rating_percent = $settings['show_rating_percent'];
$show_rating_count = $settings['show_rating_count'];
$star_text = $settings['stars_text'] ?: '';
if ($enabled):?>
    <?php if (count($block->getNumberOfRatings()) && $countRatings = array_sum($block->getNumberOfRatings())): ?>
		<div class="number-of-ratings">
            <?php if (0 < $countRatings) {
                foreach ($block->getNumberOfRatings() as $_vote => $_count): ?>
                    <?php $percent = round($_count * 100 / $countRatings, 1); ?>
					<div class="rating-item">
						<span class="rating-number"><span class="count"><?= $block->escapeHtml($_vote) ?></span> <span
									class="label"><?= $block->escapeHtml($star_text) ?></span></span>
						<div class="rating-result"><span style="width:<?= $block->escapeHtml($percent) ?>%"></span>
						</div>
						<div class="rating-percent"><?php if ($show_rating_percent) {
                                echo $block->escapeHtml($percent) . '%';
                            } ?><?php if ($show_rating_count) {
                                echo '(' . $block->escapeHtml($_count) . ')';
                            } ?></div>
					</div>
                <?php endforeach;
            } ?>
		</div>
    <?php endif; ?>
<?php endif; ?>