<?php
// @codingStandardsIgnoreFile
/** @var \Magento\Review\Block\Customer\ListCustomer $block */
?>
<?php if ($block->getReviews() && count($block->getReviews())): ?>
    <div class="cs-info-block | cs-dashboard__block | reviews">
        <div class="cs-table cs-table--tablet-small">
            <table class="table-reviews" id="my-reviews-table">
                <caption class="cs-visually-hidden"><?php /* @escapeNotVerified */ echo __('Product Reviews') ?></caption>
                <thead class="cs-table__head">
                <tr>
                    <th scope="col" class="cs-table__col-head date"><?php /* @escapeNotVerified */ echo __('Created') ?></th>
                    <th scope="col" class="cs-table__col-head item"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
                    <th scope="col" class="cs-table__col-head summary"><?php /* @escapeNotVerified */ echo __('Rating') ?></th>
                    <th scope="col" class="cs-table__col-head description"><?php /* @escapeNotVerified */ echo __('Review') ?></th>
                    <th scope="col" class="cs-table__col-head actions">&nbsp;</th>
                </tr>
                </thead>
                <tbody>
                <?php $iterator = 0; ?>
                <?php foreach ($block->getReviews() as $review): ?>
                    <tr>
                        <td data-th="<?php echo $block->escapeHtml(__('Created')) ?>" class="cs-table__col date">
                            <?php /* @escapeNotVerified */ echo $block->dateFormat($review->getReviewCreatedAt()); ?>
                        </td>
                        <td data-th="<?php echo $block->escapeHtml(__('Product Name')) ?>" class="cs-table__col item">
                            <strong class="product-name">
                                <a
                                    href="<?php /* @escapeNotVerified */ echo $block->getProductLink() ?>id/<?php /* @escapeNotVerified */ echo $review->getEntityPkValue() ?>"
                                    >
                                    <?php echo $block->escapeHtml($review->getName()) ?>
                                </a>
                            </strong>
                        </td>
                        <td data-th="<?php echo $block->escapeHtml(__('Rating')) ?>" class="cs-table__col summary">
                            <?php if ($review->getSum()): ?>
                                <div class="rating-summary">
                                <span class="cs-visually-hidden">
                                    <span><?php /* @escapeNotVerified */ echo __('Rating') ?>:</span>
                                </span>

                                    <?= $this->getLayout()->createBlock('Creativestyle\FrontendExtension\Block\Twig', 'my-reviews-rating-'.$iterator,
                                        ['data' => [
                                            'namespace' => 'cs-',
                                            'maxStars' => 5,
                                            'activeStars' => $review->getSum()/20,
                                            'text' => ''
                                        ]
                                        ])->setTemplate("star-rating/star-rating.twig")->toHtml(); ?>
                                </div>
                            <?php endif; ?>
                        </td>
                        <td data-th="<?php echo $block->escapeHtml(__('Review')) ?>" class="cs-table__col description">
                            <?php echo $this->helper('Magento\Review\Helper\Data')->getDetailHtml($review->getDetail()) ?>
                        </td>
                        <td data-th="<?php echo $block->escapeHtml(__('Actions')) ?>" class="cs-table__col  cs-table__col--actions actions">
                            <a
                                href="<?php /* @escapeNotVerified */ echo $block->getReviewLink() ?>id/<?php /* @escapeNotVerified */ echo $review->getReviewId() ?>"
                                class="cs-link"
                                >
                                <?php /* @escapeNotVerified */ echo __('See Details') ?>
                            </a>
                        </td>
                    </tr>
                    <?php $iterator ++; ?>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php if ($block->getToolbarHtml()): ?>
            <div class="cs-info-block__toolbar | products-reviews-toolbar">
                <?php echo $block->getToolbarHtml() ?>
            </div>
        <?php endif; ?>
    </div>
<?php else: ?>
    <div class="cs-info-block__line"><?php /* @escapeNotVerified */ echo __('You have submitted no reviews.') ?></div>
<?php endif; ?>

