{% extends "layout.html" %}
{% block body %}
  {% if query_time %}
    <p class=search_type><b>Time: </b> {{ query_time }} ms</p>
  {% endif %}

  {% if query_text %}
    <button id="query_button">Show query</button>
    <pre id="query_text" style="display: none" class="language-sql">
      <code>
{{ query_text|safe }}
      </code>
    </pre>
    <script>
    $("#query_button").click(function() {
      $("#query_text").toggle("slow");
    });
    </script>
  {% endif %}

  <ul class=entries>
    {% if error %}
      <li><em>{{ error }}</em></li>
    {% else %}
      {% if faceted %}
        {% if entries %}
          {% for key, value in entries.items() %}
            <li>
              <h1>{{ key }}</h1>
              <small><b>Result count: {{ value['count'] }}</b></small>
              <ul class="entries faceted">
                {% for results in value['results'] %}
                <li><h2><a href="{{ url_for('show_apod', apod_id=results['msg_id'], lang=results['lang']) }}">{{ results['title'] }}</a></h2></li>
                {% endfor %}
              </ul>
            </li>
          {% endfor %}
        {% else %}
          {% if hints|length > 0 %}
          <li>
            <em>Maybe you mean:</em>
            <ul class=entries>
              {% for hint in hints %}
              <li><b>{{ hint.word }}</b></li>
              {% endfor %}
            </ul>
          </li>
          {% else %}
          <li><em>No entries here.</em></li>
          {% endif %}
        {% endif %}
      {% else %}
        {% for entry in entries %}
          <li>
            <h2><a href="{{ url_for('show_apod', apod_id=entry.msg_id, lang=entry.lang) }}">{{ entry.title }}</a></h2>
            <small><b>{{ entry.date }}</b></small><br>
            {{ entry.text|safe }}
          </li>
        {% else %}
          {% if hints|length > 0 %}
          <li>
            <em>Maybe you mean:</em>
            <ul class=entries>
              {% for hint in hints %}
              <li><b>{{ hint.word }}</b></li>
              {% endfor %}
            </ul>
          </li>
          {% else %}
          <li><em>No entries here.</em></li>
          {% endif %}
        {% endfor %}
      {% endif %}
    {% endif %}
  </ul>
{% endblock %}
