?php
function thenepali_setup() {
    add_theme_support('title-tag');
    add_theme_support('post-thumbnails');
    add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
    add_theme_support('automatic-feed-links');

    register_nav_menus(array(
        'primary' => __('Primary Menu', 'thenepali'),
    ));
}
add_action('after_setup_theme', 'thenepali_setup');

function thenepali_enqueue() {
    wp_enqueue_style('thenepali-fonts', 'https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400;1,700&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300;1,8..60,400&family=Barlow:wght@300;400;500;600;700&display=swap', array(), null);
    wp_enqueue_style('thenepali-style', get_stylesheet_uri(), array(), '2.0');
}
add_action('wp_enqueue_scripts', 'thenepali_enqueue');

// Helper: get category name of a post
function thenepali_get_category($post_id) {
    $cats = get_the_category($post_id);
    if (!empty($cats)) {
        return $cats[0]->name;
    }
    return 'News';
}

// Helper: get category link of a post
function thenepali_get_category_link($post_id) {
    $cats = get_the_category($post_id);
    if (!empty($cats)) {
        return get_category_link($cats[0]->term_id);
    }
    return '#';
}

// Helper: human-friendly time ago
function thenepali_time_ago($post_id) {
    return human_time_diff(get_the_time('U', $post_id), current_time('timestamp')) . ' ago';
}
?>
<?php get_header(); ?>

<style>
.tn-container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.tn-search-wrap { padding: 32px 0 60px; }
.tn-search-header { border-top: 3px solid var(--ft-red); padding-top: 10px; margin-bottom: 28px; }
.tn-search-label { font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ft-red); margin-bottom: 4px; }
.tn-search-title { font-family: var(--serif); font-size: 28px; font-weight: 700; color: var(--ft-dark); }
.tn-search-result { padding: 16px 0; border-bottom: 1px solid var(--ft-light-border); display: flex; gap: 16px; }
.tn-search-result-img { width: 100px; height: 70px; object-fit: cover; flex-shrink: 0; background: var(--ft-salmon); display: flex; align-items: center; justify-content: center; font-size: 30px; }
.tn-search-result-text {}
.tn-search-result-cat { font-family: var(--sans); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ft-red); margin-bottom: 4px; }
.tn-search-result-title { font-family: var(--serif); font-size: 19px; font-weight: 700; line-height: 1.25; color: var(--ft-dark); margin-bottom: 6px; }
.tn-search-result-title a { color: inherit; }
.tn-search-result-title a:hover { color: var(--ft-red); }
.tn-search-result-excerpt { font-size: 13px; color: var(--ft-muted); line-height: 1.5; }
.tn-no-results { padding: 40px 0; font-family: var(--body-serif); font-size: 18px; color: var(--ft-muted); }


<div class="tn-container">
<div class="tn-search-wrap">
    <div class="tn-search-header">
        <div class="tn-search-label">Search Results</div>
        <h1 class="tn-search-title">Results for: "<?php echo get_search_query(); ?>"</h1>
    </div>

    <?php if (have_posts()): while (have_posts()): the_post(); ?>
    <div class="tn-search-result">
        <?php if (has_post_thumbnail()): ?>
            <img class="tn-search-result-img" src="<?php the_post_thumbnail_url('thumbnail'); ?>" alt="">
        <?php else: ?>
            <div class="tn-search-result-img">📰</div>
        <?php endif; ?>
        <div class="tn-search-result-text">
            <div class="tn-search-result-cat"><?php echo thenepali_get_category(get_the_ID()); ?></div>
            <h2 class="tn-search-result-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p class="tn-search-result-excerpt"><?php echo wp_trim_words(get_the_excerpt() ?: get_the_content(), 25); ?></p>
        </div>
    </div>
    <?php endwhile;
    else: ?>
    <p class="tn-no-results">No results found for "<?php echo get_search_query(); ?>". Try a different search term.</p>
    <?php endif; ?>
</div>
</div>

<?php get_footer(); ?>
