<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php $url = $block->getReviewsUrl() . '#reviews'; ?>
<?php $urlForm = $block->getReviewsUrl() . '#review-form'; ?>
<?php if ($block->getReviewsCount()): ?>
<?php $rating = $block->getRatingSummary(); ?>
<div class="product-reviews-summary<?php echo !$rating ? ' no-rating' : ''?>" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <?php if ($rating):?>
    <div class="rating-summary">
         <span class="label"><span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span></span>
         <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $rating; ?>%">

             <div class="rating-result__stars">
                 <?php
                 $half_star_id = round( (int)$rating / 20 );
                 for($i = 0; $i < 5; $i++){
                     if( $i < $half_star_id ) {
                         echo '<span class="fa fa-star"></span>';
                     }
                     if( $i == $half_star_id ) {
                         echo '<span class="fa fa-star-half-o"></span>';
                     }
                     if( $i > $half_star_id ) {
                         echo '<span class="fa fa-star-o"></span>';
                     }
                 } ?>
             </div>

             <div class="rating-result__text">
                 <span itemprop="ratingValue"><?php /* @escapeNotVerified */ echo $rating; ?></span>% of <span itemprop="bestRating">100</span></span></span>
             </div>

         </div>
     </div>
    <?php endif;?>
    <div class="reviews-actions">
        <a class="action view" href="<?php /* @escapeNotVerified */ echo $url ?>"><span itemprop="reviewCount"><?php /* @escapeNotVerified */ echo $block->getReviewsCount() ?></span>&nbsp;<span><?php /* @escapeNotVerified */ echo($block->getReviewsCount() == 1) ? __('Review') : __('Reviews') ?></span></a>
        <a class="action add" href="<?php /* @escapeNotVerified */ echo $urlForm ?>"><?php /* @escapeNotVerified */ echo __('Add Your Review') ?></a>
    </div>
</div>
<?php elseif ($block->getDisplayIfEmpty()): ?>
<div class="product-reviews-summary empty">
    <div class="reviews-actions">
        <a class="action add" href="<?php /* @escapeNotVerified */ echo $urlForm; ?>">
            <?php /* @escapeNotVerified */ echo __('Be the first to review this product') ?>
        </a>
    </div>
</div>
<?php endif; ?>
