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

/** @var Magento\Review\Block\Product\View\ListView $block */

$_items = $block->getReviewsCollection()->getItems();
$format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT;
?>
<?php if (count($_items)) : ?>
<div class="block review-list" id="customer-reviews">
    <?php if (!$block->getHideTitle()) : ?>
        <div class="block-title">
            <strong><?= $block->escapeHtml(__('Customer Reviews')) ?></strong>
        </div>
    <?php endif ?>
    <div class="block-content">
        <div class="toolbar review-toolbar">
            <?= $block->getChildHtml('toolbar') ?>
        </div>
        <ol class="items review-items">
        <?php foreach ($_items as $_review) : ?>
            <li class="item review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
                <div class="review-title" itemprop="name" itemtype="https://schema.org/name"><?= $block->escapeHtml($_review->getTitle()) ?></div>
                <?php if (count($_review->getRatingVotes())) : ?>
                    <div class="review-ratings">
                    <?php foreach ($_review->getRatingVotes() as $_vote) : ?>
                    <div class="rating-summary item" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
                        <span class="label rating-label"><span><?= $block->escapeHtml($_vote->getRatingCode()) ?></span></span>
                        <div class="rating-result" title="<?= $block->escapeHtmlAttr($_vote->getPercent()) ?>%">
                            <meta itemprop="worstRating" content = "1" itemtype="https://schema.org/worstRating"/>
                            <span style="width:<?= $block->escapeHtmlAttr($_vote->getPercent()) ?>%">
                            </span>
                        </div>
                    </div>
                    <?php endforeach; ?>
                    </div>
                <?php endif; ?>
                <div class="review-content" itemprop="description" itemtype="https://schema.org/description">
                    <?= /* @noEscape */ nl2br($block->escapeHtml($_review->getDetail())) ?>
                </div>
                <div class="review-details">
                    <p class="review-author">
                        <span class="review-details-label"><?= $block->escapeHtml(__('Review by')) ?></span>
                        <strong class="review-details-value" itemprop="author" itemtype="https://schema.org/author"><?= $block->escapeHtml($_review->getNickname()) ?></strong>
                    </p>
                    <p class="review-date">
                        <span class="review-details-label"><?= $block->escapeHtml(__('Posted on')) ?></span> 
                        <time class="review-details-value" itemprop="datePublished"  itemtype="https://schema.org/author" datetime="<?= $block->escapeHtmlAttr($block->formatDate($_review->getCreatedAt(), $format)) ?>"><?= $block->escapeHtml($block->formatDate($_review->getCreatedAt(), $format)) ?></time>
                    </p>
                </div>
            </li>
        <?php endforeach; ?>
        </ol>
        <div class="toolbar review-toolbar">
            <?= $block->getChildHtml('toolbar') ?>
        </div>
    </div>
</div>
<?php endif;?>
