<?php
/**
 * Maho
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2023 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>

<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
    <?php if (count($_items)):?>
        <div class="review-heading">
            <h2>
                <?= $this->__('Customer Reviews') ?>
                <span><?= count($_items) ?> item(s)</span>
            </h2>
            <?= $this->getChildHtml('toolbar') ?>
        </div>
        <dl>
        <?php foreach ($_items as $_review):?>
            <dt>
                <?= $this->escapeHtml($_review->getTitle()) ?>
            </dt>
            <dd>
                <?php $_votes = $_review->getRatingVotes(); ?>

                <?= nl2br($this->escapeHtml($_review->getDetail())) ?>

                <?php if (count($_votes)): ?>
                <table class="ratings-table">
                    <colgroup>
                        <col class="review-label" />
                        <col class="review-value" />
                    </colgroup>
                    <tbody>
                        <?php foreach ($_votes as $_vote): ?>
                        <tr>
                            <th><?= $this->escapeHtml($_vote->getRatingCode()) ?></th>
                            <td>
                                <div class="rating-box">
                                    <div class="rating" style="width:<?= $_vote->getPercent() ?>%;"></div>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach ?>
                    </tbody>
                </table>
                <?php endif ?>


                <span class="review-meta">
                    <?= $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
                    /
                   <?= $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
                </span>
            </dd>
        <?php endforeach ?>
        </dl>
    <?php elseif($this->getParentBlock()): ?>
        <?= $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true) ?>
    <?php endif ?>
    <?= $this->getChildHtml('review_form') ?>
</div>
