{{define "results_inner"}}
{{if .Corrections}}
<div class="correction">{{range .Corrections}}{{.}} {{end}}</div>
{{end}}

{{if or .Answers .Infoboxes}}
<div id="answers">
  {{range .Answers}}
  <div class="dialog-error">{{.}}</div>
  {{end}}
</div>
{{end}}

<div class="results-meta">
  {{if .NumberOfResults}}
  <span>{{.NumberOfResults}} results</span>
  {{end}}
</div>

<div id="urls" role="main">
  {{if .Results}}
  {{if .IsImageSearch}}
  <div class="image-grid">
    {{range .Results}}
    {{if eq .Template "images"}}
    {{template "image_item" .}}
    {{end}}
    {{end}}
  </div>
  {{else}}
  {{range .Results}}
  {{if eq .Template "videos"}}
  {{template "video_item" .}}
  {{else if eq .Template "images"}}
  {{template "image_item" .}}
  {{else}}
  {{template "result_item" .}}
  {{end}}
  {{end}}
  {{end}}
  {{else if not .Answers}}
  <div class="no-results">
    <div class="no-results-icon">🔍</div>
    <h2>No results found</h2>
    <p>Try different keywords or check your spelling.</p>
  </div>
  {{end}}
</div>

{{if .Pageno}}
<nav class="pagination" role="navigation">
  {{if gt .Pageno 1}}
  <form method="GET" action="/search" class="prev-next">
    <input type="hidden" name="q" value="{{.Query}}">
    <input type="hidden" name="pageno" value="{{.PrevPage}}">
    <button type="submit">← Prev</button>
  </form>
  {{end}}

  {{range .PageNumbers}}
  {{if .IsCurrent}}
  <span class="page-current">{{.Num}}</span>
  {{else}}
  <form method="GET" action="/search" class="page-link">
    <input type="hidden" name="q" value="{{$.Query}}">
    <input type="hidden" name="pageno" value="{{.Num}}">
    <button type="submit">{{.Num}}</button>
  </form>
  {{end}}
  {{end}}

  {{if .HasNext}}
  <form method="GET" action="/search" class="prev-next">
    <input type="hidden" name="q" value="{{.Query}}">
    <input type="hidden" name="pageno" value="{{.NextPage}}">
    <button type="submit">Next →</button>
  </form>
  {{end}}
</nav>
{{end}}

<div class="back-to-top" id="backToTop">
  <a href="#">↑ Back to top</a>
</div>

<div class="htmx-indicator">Searching…</div>
{{end}}
