@extends('layouts.app')

@section('title', 'Search: ' . $query . ' | ' . config('app.name'))
@section('meta_description', 'Search results for "' . $query . '" on ' . config('app.name') . '. Browse matching articles and news stories.')
@section('canonical', route('search') . ($query ? '?q=' . urlencode($query) : ''))
@section('robots', 'noindex, follow')

@section('schema_json')
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "SearchResultsPage",
  "name": "{{ config('app.name', 'The Hindu') }}",
  "url": "{{ url()->current() }}",
  "query": "{{ $query }}"
}
</script>
@endsection

@section('content')
<div class="search-page">
  <div class="search-header">
    <h1 class="search-title">Search results for "<em>{{ $query }}</em>"</h1>
    <p class="search-count">{{ $results->total() }} {{ Str::plural('result', $results->total()) }} found</p>
  </div>
  <form action="{{ route('search') }}" method="GET" class="search-form" role="search">
    <input type="search" name="q" value="{{ $query }}" placeholder="Search The Hindu..." aria-label="Search" required>
    <button type="submit"><i class="fa-solid fa-magnifying-glass"></i></button>
  </form>
  @if($results->isEmpty())
  <div class="no-results">
    <p>No results found for "{{ $query }}". Try different keywords.</p>
  </div>
  @else
  <div class="cat-list">
    @foreach($results as $art)
    <article class="cat-item">
      <a href="{{ $art->canonical_url }}" class="cat-item-img">
        <img src="{{ $art->photo_url }}" alt="{{ $art->news_title }}" loading="lazy" width="200" height="130">
      </a>
      <div class="cat-item-body">
        <span class="cat-item-tag">{{ strtoupper($art->category->category_name ?? 'NEWS') }}</span>
        <h3 class="cat-item-title"><a href="{{ $art->canonical_url }}" title="{{ $art->news_title }}">{{ $art->news_title }}</a></h3>
        <p class="cat-item-summary">{{ Str::limit(strip_tags($art->news_content_short), 150) }}</p>
        <div class="cat-item-meta">
          <span>{{ strtoupper($art->author->name ?? 'THE HINDU BUREAU') }}</span>
          @if($art->published_at)<span> กค {{ $art->published_at->format('M j, Y') }}</span>@endif
        </div>
      </div>
    </article>
    @endforeach
  </div>
  @if($results->hasPages())
  <div class="hindu-pagination">{{ $results->links('partials.pagination') }}</div>
  @endif
  @endif
</div>
@endsection