<?php
/**
 * Search Template
 *
 * @package Rifeng_Weifang
 */

get_header();
?>

<div class="page-header">
    <div class="container">
        <h1>搜索结果: <?php echo get_search_query(); ?></h1>
        <?php rf_breadcrumb(); ?>
    </div>
</div>

<section class="page-content">
    <div class="container">
        <?php if ( have_posts() ) : ?>
            <p style="margin-bottom:24px;color:#666;">共找到 <?php echo $wp_query->found_posts; ?> 个结果</p>
            
            <div class="news-grid">
                <?php while ( have_posts() ) : the_post(); ?>
                    <article class="news-card">
                        <a href="<?php the_permalink(); ?>">
                            <?php if ( has_post_thumbnail() ) : ?>
                                <div class="card-image">
                                    <?php the_post_thumbnail( 'news-thumb' ); ?>
                                </div>
                            <?php else : ?>
                                <div class="card-image" style="background:linear-gradient(135deg,#0281cc 0%,#0066b3 100%);display:flex;align-items:center;justify-content:center;color:#fff;font-size:48px;height:200px;">
                                    🔍
                                </div>
                            <?php endif; ?>
                            <div class="card-body">
                                <div class="card-date"><?php echo get_the_date( 'Y-m-d' ); ?></div>
                                <h3><?php the_title(); ?></h3>
                                <p><?php echo wp_trim_words( get_the_excerpt(), 25 ); ?></p>
                                <span class="read-more">查看详情 →</span>
                            </div>
                        </a>
                    </article>
                <?php endwhile; ?>
            </div>
            
            <div style="text-align:center;margin-top:40px;">
                <?php
                the_posts_pagination( array(
                    'mid_size'  => 2,
                    'prev_text' => '← 上一页',
                    'next_text' => '下一页 →',
                ) );
                ?>
            </div>
        <?php else : ?>
            <div style="text-align:center;padding:60px 0;">
                <h2>未找到相关内容</h2>
                <p style="color:#999;margin:16px 0 24px;">抱歉，没有找到与 "<?php echo get_search_query(); ?>" 相关的内容。</p>
                <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" style="max-width:400px;margin:0 auto;display:flex;gap:8px;">
                    <input type="search" name="s" value="<?php echo get_search_query(); ?>" placeholder="重新搜索..." style="flex:1;padding:12px 16px;border:1px solid #e5e7eb;border-radius:6px;font-size:15px;">
                    <button type="submit" class="btn btn-primary">搜索</button>
                </form>
            </div>
        <?php endif; ?>
    </div>
</section>

<?php get_footer();
