<?php
/**
 * Template for displaying testimonial archives
 *
 * @package Nihongo
 */

get_header(); ?>

<main id="main" class="site-main">
    <!-- Archive Hero Section -->
    <section class="archive-hero">
        <div class="archive-hero-background">
            <img src="<?php echo get_template_directory_uri(); ?>/assets/img/r1.jpg" alt="<?php echo nihongo_translate('testimonials'); ?>" class="archive-hero-image">
            <div class="archive-hero-overlay"></div>
        </div>
        <div class="container">
            <div class="archive-hero-content">
                <h1 class="archive-hero-title"><?php echo nihongo_translate('testimonials'); ?></h1>
                <p class="archive-hero-subtitle"><?php echo nihongo_translate('testimonials_subtitle'); ?></p>
            </div>
        </div>
    </section>

    <!-- Testimonials Grid Section -->
    <section class="section testimonials">
        <div class="container">
            <div class="testimonials-grid">
                <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>
                        <?php
                        $name = get_post_meta(get_the_ID(), '_testimonial_name', true);
                        $country = get_post_meta(get_the_ID(), '_testimonial_country', true);
                        $course = get_post_meta(get_the_ID(), '_testimonial_course', true);
                        $rating = get_post_meta(get_the_ID(), '_testimonial_rating', true);
                        ?>
                        
                        <div class="testimonial-card">
                            <div class="testimonial-content">
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="testimonial-image">
                                        <a href="<?php the_permalink(); ?>">
                                            <?php the_post_thumbnail('testimonial-thumbnail'); ?>
                                        </a>
                                    </div>
                                <?php endif; ?>
                                <div class="testimonial-header">
                                    <h3 class="testimonial-title">
                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <?php if ($rating) : ?>
                                        <div class="testimonial-rating">
                                            <?php for ($i = 0; $i < $rating; $i++): ?>
                                                <span class="star">★</span>
                                            <?php endfor; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <p class="testimonial-comment"><?php echo get_the_excerpt(); ?></p>
                                <div class="testimonial-author">
                                    <div class="testimonial-info">
                                        <?php if ($name) : ?>
                                            <h4><?php echo esc_html($name); ?></h4>
                                        <?php endif; ?>
                                        <?php if ($country || $course) : ?>
                                            <p>
                                                <?php if ($country) : ?>
                                                    <?php echo esc_html($country); ?>
                                                <?php endif; ?>
                                                <?php if ($country && $course) : ?> / <?php endif; ?>
                                                <?php if ($course) : ?>
                                                    <?php echo esc_html($course); ?>
                                                <?php endif; ?>
                                            </p>
                                        <?php endif; ?>
                                        <p class="testimonial-date"><?php echo get_the_date(); ?></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endwhile; ?>
                <?php else : ?>
                    <div class="no-testimonials">
                        <h3><?php echo nihongo_translate('no_testimonials_found'); ?></h3>
                        <p><?php echo nihongo_translate('no_testimonials_message'); ?></p>
                    </div>
                <?php endif; ?>
            </div>

            <!-- Pagination -->
            <?php
            the_posts_pagination(array(
                'mid_size' => 2,
                'prev_text' => nihongo_translate('previous'),
                'next_text' => nihongo_translate('next'),
            ));
            ?>
        </div>
    </section>
</main>

<?php get_footer(); ?>
