<?php
/**
 * Template for displaying news 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/n1.jpg" alt="<?php echo nihongo_translate('news'); ?>" 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('news'); ?></h1>
                <p class="archive-hero-subtitle"><?php echo nihongo_translate('latest_news_and_updates'); ?></p>
            </div>
        </div>
    </section>

    <!-- News Grid Section -->
    <section class="section">
        <div class="container">
            <div class="news-grid">
                <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>
                        <div class="news-card">
                            <div class="news-image">
                                <?php if (has_post_thumbnail()) : ?>
                                    <a href="<?php the_permalink(); ?>">
                                        <?php the_post_thumbnail('news-thumbnail'); ?>
                                    </a>
                                <?php else : ?>
                                    <a href="<?php the_permalink(); ?>">
                                        <img src="<?php echo get_template_directory_uri(); ?>/assets/img/n1.jpg" alt="<?php the_title(); ?>">
                                    </a>
                                <?php endif; ?>
                            </div>
                            <div class="news-content">
                                <div class="news-date"><?php echo get_the_date(); ?></div>
                                <h3 class="news-title">
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h3>
                                <p class="news-excerpt"><?php echo get_the_excerpt(); ?></p>
                                <div class="news-meta">
                                    <span class="news-author"><?php echo get_the_author(); ?></span>
                                    <?php
                                    $tags = get_the_tags();
                                    if ($tags) :
                                    ?>
                                        <div class="news-tags">
                                            <?php foreach ($tags as $tag) : ?>
                                                <span class="tag"><?php echo esc_html($tag->name); ?></span>
                                            <?php endforeach; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endwhile; ?>
                <?php else : ?>
                    <div class="no-news">
                        <h3><?php echo nihongo_translate('no_news_found'); ?></h3>
                        <p><?php echo nihongo_translate('no_news_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(); ?>
