<?php
/**
 * The template for displaying experience archive
 *
 * @package DevelopSriLanka
 */

get_header(); ?>

<main id="main" class="site-main">
    <section class="experience-section">
        <div class="container">
            <div class="experience-intro">
                <h1 class="section-title">Why Sri Lanka is a Better Country</h1>
                <p class="section-subtitle">Read inspiring stories from travelers around the world</p>
            </div>
            
            <?php if (have_posts()) : ?>
                
                <div class="experiences-grid">
                    <?php while (have_posts()) : the_post(); ?>
                        
                        <div class="experience-card">
                            <?php if (has_post_thumbnail()) : ?>
                                <a href="<?php the_permalink(); ?>">
                                    <img src="<?php echo get_the_post_thumbnail_url(get_the_ID(), 'experience-thumb'); ?>" alt="<?php the_title(); ?>" class="experience-thumbnail">
                                </a>
                            <?php endif; ?>
                            
                            <div class="experience-details">
                                <div class="experience-meta">
                                    <span>
                                        <?php 
                                        $contributor = get_post_meta(get_the_ID(), '_contributor_name', true);
                                        echo esc_html($contributor ? $contributor : 'Anonymous');
                                        ?>
                                    </span>
                                    <span>
                                        <?php 
                                        $country = get_post_meta(get_the_ID(), '_contributor_country', true);
                                        echo esc_html($country);
                                        ?>
                                    </span>
                                </div>
                                
                                <h3>
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h3>
                                
                                <div class="experience-excerpt">
                                    <?php echo wp_trim_words(get_the_excerpt(), 25); ?>
                                </div>
                                
                                <a href="<?php the_permalink(); ?>" class="read-more">Read Full Story →</a>
                            </div>
                        </div>
                        
                    <?php endwhile; ?>
                </div>
                
                <div class="pagination">
                    <?php
                    the_posts_pagination(array(
                        'prev_text' => '← Previous',
                        'next_text' => 'Next →',
                    ));
                    ?>
                </div>
                
            <?php else : ?>
                
                <div class="no-posts text-center">
                    <h2>No Experiences Yet</h2>
                    <p>Be the first to share your Sri Lanka experience!</p>
                    <a href="<?php echo esc_url(home_url('/submit-experience')); ?>" class="btn btn-primary mt-20">Share Your Story</a>
                </div>
                
            <?php endif; ?>
        </div>
    </section>
</main>

<?php get_footer(); ?>
