{#-
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
-#}
<form method="GET" action=".">
  <div class="grid-10">
    <input type="text" name="q" value="{{q}}" class="search-query" title="Search App"/>
  </div>
  <div class="grid-3">
    <input type="submit" value="Search">
  </div>
  {% if c.help_modal %}
  <div class="grid-6">
    {{ g.icons['help'].render(extra_css='btn search_help_modal', show_title=True) }}
  </div>
  {% endif %}
  <div style="clear:both"></div>
  {% if not hide_app_project_switcher %}
  <div class="grid-10">
    {% set search_project = request.GET['project'] == '1' %}
    <input type="radio" name="project" value="0" id="search-app" {% if not search_project %}checked{% endif %}>
    <label for="search-app">Search {{c.app.config.options.mount_point or 'app'}}</label>
    <input type="radio" name="project" value="1" id="search-project" {% if search_project %}checked{% endif %}>
    <label for="search-project">Search entire project</label>
  </div>
  {% endif %}
  <div class="grid-9">
    {% if not search_comments_disable %}
      {% set comments = request.GET['search_comments'] %}
      <label for="search-comments">Search comments?</label>
      <input id="search-comments" type="checkbox" name="search_comments"{% if comments %} checked{% endif %}>
    {% endif %}
    {% if not search_history_disable %}
      <label for="search-history">Search history?</label>
      <input id="search-history" type="checkbox" name="history"{% if history %} checked{% endif %}>
    {% endif %}
  </div>
</form>
<div style="clear:both">&nbsp;</div>
{% if search_error %}
<div class="grid-19">{{ search_error }}</div>
{% endif %}
<div class="grid-19">
  {{widget.fields['page_list'].display(limit=limit, page=page, count=count)}}
</div>
{% for doc in results %}
  <div class="grid-19">
    <p>
    <a href="{{doc['url_paginated'] or doc['url_s']}}" rel="nofollow">
      {% if doc.title_match %}
        {{ doc.title_match }}
      {% else %}
        {{ h.get_first(doc, 'title') or h.get_first(doc, 'title_s') -}}  {#-  title_s is legacy -#}
      {% endif %}
    </a>
    {% if doc['type_s'] %}<span class="gray"><sup>{{ '(%s)' % doc['type_s'] }}</sup></span>{% endif %}
    <br>
    {% if doc.text_match %}
      <span class="text-match">{{ doc.text_match }}</span><br>
    {% endif %}
    <span class="gray">Last updated: {{ h.ago_string(doc['mod_date_dt']) }}</span>
    </p>
  </div>
{% endfor %}
<div class="grid-19">
  {{widget.fields['page_list'].display(limit=limit, page=page, count=count)}}
  {{widget.fields['page_size'].display(limit=limit, count=count)}}
</div>
<div class="grid-19" style="clear:both">
  <p>
    Sort by
    <a href="{{ sort_score_url }}" class="{{ 'strong' if sort_field == 'score' else '' }}">relevance</a> or
    <a href="{{ sort_date_url }}" class="{{ 'strong' if sort_field == 'mod_date_dt' else '' }}">date</a>
  </p>
</div>
{% if c.help_modal %}{{ c.help_modal.display() }}{% endif %}
