<?php

/**
 * Display single product reviews (comments)
 *
 * @package WooCommerce/Templates
 * @version 9.8.0
 */

defined('ABSPATH') || exit;

global $product;

if (! comments_open()) {
    return;
}

$can_review = get_option('woocommerce_review_rating_verification_required') === 'no' || wc_customer_bought_product('', get_current_user_id(), $product->get_id());
$layout = get_theme_mod('product_layout', 'compact');

// The review section is laid out as two block columns (summary | list). The Compact
// layout stacks them via CSS (body.is-product-layout-compact). The "Write a review" form is a
// modal rendered at the page root via wp_footer (see Product::review_form_modal).
?>
<div id="reviews" class="woocommerce-Reviews rt-reviews is-layout-flow">

    <?php if (have_comments()) : ?>

        <?php if ($layout !== 'compact') : ?>
            <div class="wp-block-columns is-layout-flex md:gap-80">
                <div class="wp-block-column is-layout-flow" style="flex-basis: 420px;">
                <?php endif; ?>

                <div class="rt-reviews__head flex flex-wrap items-center justify-between gap-30">
                    <h2 class="woocommerce-Reviews-title rt-reviews__title my-0"><?php esc_html_e('Customer reviews', 'kubelio'); ?></h2>

                    <?php if ($can_review) : ?>
                        <button type="button" class="wp-element-button alt js-modal" data-target="review_form_modal"><?php esc_html_e('Write a review', 'kubelio'); ?></button>
                    <?php endif; ?>
                </div>

                <?php if (! $can_review) : ?>
                    <p class="woocommerce-verification-required has-meta-color py-20"><?php esc_html_e('Only logged in customers who have purchased this product may leave a review.', 'kubelio'); ?></p>
                <?php endif; ?>

                <?php do_action('kubelio_before_product_review_list'); ?>

                <?php if ($layout !== 'compact') : ?>
                </div>
                <div class="wp-block-column is-layout-flow">
                <?php endif; ?>

                <?php do_action('kubelio_before_product_review_comments'); ?>
                <div id="comments">
                    <ol class="commentlist">
                        <?php wp_list_comments(apply_filters('woocommerce_product_review_list_args', array('callback' => 'woocommerce_comments'))); ?>
                    </ol>

                    <?php
                    if (get_comment_pages_count() > 1 && get_option('page_comments')) :
                        echo '<nav class="woocommerce-pagination">';
                        paginate_comments_links(
                            apply_filters(
                                'woocommerce_comment_pagination_args',
                                array(
                                    'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
                                    'next_text' => is_rtl() ? '&larr;' : '&rarr;',
                                    'type'      => 'list',
                                )
                            )
                        );
                        echo '</nav>';
                    endif;
                    ?>
                </div>
                <?php do_action('kubelio_after_product_review_list'); ?>

                <?php if ($layout !== 'compact') : ?>
                </div>
            </div>
        <?php endif; ?>

    <?php else : ?>

        <div id="comments" class="rt-reviews-empty is-layout-flow border rounded-lg py-40 px-40">

            <div class="rt-reviews-empty__stars flex gap-10 has-outline-color has-large-font-size" aria-hidden="true">
                <?php for ($i = 0; $i < 5; $i++) : ?>
                    <i class="rt-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                            <path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                        </svg>
                    </i>
                <?php endfor; ?>
            </div>

            <h2 class="rt-reviews-empty__title has-medium-font-size mt-20 mb-0"><?php esc_html_e('Be the first to review this product', 'kubelio'); ?></h2>

            <p class="rt-reviews-empty__text has-small-font-size mt-20">
                <?php
                /* translators: %s: product name */
                printf(esc_html__('No reviews have been written yet. Your honest feedback helps other shoppers choose %s with confidence.', 'kubelio'), esc_html($product->get_name()));
                ?>
            </p>

            <?php if ($can_review) : ?>
                <div class="rt-reviews-empty__action mt-40">
                    <button type="button" class="wp-element-button alt js-modal" data-target="review_form_modal"><?php esc_html_e('Write the first review', 'kubelio'); ?></button>
                </div>
            <?php else : ?>
                <p class="woocommerce-verification-required has-meta-color has-x-small-font-size mt-40"><?php esc_html_e('Only logged in customers who have purchased this product may leave a review.', 'kubelio'); ?></p>
            <?php endif; ?>

        </div>

    <?php endif; ?>

</div>