<% content_for :title, 'Search' %>

<h1>Search</h1>

<%= form_tag search_path, method: :get do %>
  <div class="form-group-horizontal">
    <div class="form-group">
      <%= label_tag :search, 'Search term', class: "form-element" %>
      <%= text_field_tag :search, params[:search], class: 'form-element' %>
    </div>
    <div class="actions has-padding-bottom-1">
      <%= submit_tag 'Search', class: 'button is-medium is-outlined', name: nil %>
    </div>
  </div>
<% end %>

<% if @posts.nil? %>
  <h3>Advanced Search Options</h3>
  <%= raw(sanitize(render_markdown(SiteSetting['JITAdvancedSearchHelp']), scrubber: scrubber)) %>
  <p>Further help with searching is available <%= link_to 'in the help center', help_path('search') %>.</p>

  <p class="has-color-tertiary-500"><em>Search for something to start finding posts.</em></p>
<% else %>
  <div class="button-list is-gutterless has-float-right">
    <%= link_to 'Relevance', query_url(sort: 'relevance'),
                class: "button is-outlined is-muted #{params[:sort] == 'relevance' || params[:sort].nil? ? 'is-active' : ''}" %>
    <%= link_to 'Score', query_url(sort: 'score'), class: "button is-outlined is-muted #{params[:sort] == 'score' ? 'is-active' : ''}" %>
    <%= link_to 'Age', query_url(sort: 'age'), class: "button is-outlined is-muted #{params[:sort] == 'age' ? 'is-active' : ''}" %>
  </div>
  <div class="has-clear-clear">&nbsp;</div>

  <% if @posts.size == 0 %>
    <p class="has-color-tertiary"><em>No results for <strong><%= params[:search] %></strong>. Try using a different search term.</em></p>
  <% end %>

  <div class="item-list has-border-top-width-1 has-border-top-style-solid has-border-color-tertiary-050">
    <% @posts.each do |post| %>
      <%= render 'posts/type_agnostic', post: post, show_type_tag: true, show_category_tag: true %>
    <% end %>
  </div>
<% end %>

<% unless @posts.nil? %>
  <%= will_paginate @posts, renderer: BootstrapPagination::Rails %>
<% end %>
