<% provide :title do %><%= t("proposals.index.title") %><% end %>
<% content_for :header_addon do %>
  <%= render "shared/search_form",
             search_path: proposals_path(page: 1),
             i18n_namespace: "proposals.index.search_form" %>
<% end %>
<% content_for :canonical do %>
  <%= render "shared/canonical", href: proposals_url %>
<% end %>

<main>
  <% if @search_terms || @advanced_search_terms || @tag_filter || params[:retired].present? %>
    <div class="highlight no-margin-top padding margin-bottom">
      <div class="row">
        <div class="small-12 column">
          <% if @search_terms || @advanced_search_terms %>
            <h2><%= t("shared.search_results") %></h2>
            <p>
              <%= page_entries_info @proposals %>
              <% if !@advanced_search_terms %>
                <%= t("proposals.index.search_results_html", count: @proposals.size, search_term: @search_terms) %>
              <% end %>
            <p>
          <% elsif @tag_filter %>
            <h2><%= t("shared.search_results") %></h2>
            <p>
              <%= page_entries_info @proposals %>
              <%= t("proposals.index.filter_topic", count: @proposals.size, topic: @tag_filter) %>
            </p>
          <% elsif params[:retired].present? %>
            <h2><%= t("proposals.index.retired_proposals") %></h2>
          <% end %>
        </div>
      </div>
    </div>
  <% else %>
    <%= render "shared/section_header", i18n_namespace: "proposals.index.section_header", image: "proposals" %>
  <% end %>

  <% if feature?('user.recommendations') && @recommended_proposals.present? %>
    <%= render "shared/recommended_index", recommended: @recommended_proposals,
                                           disable_recommendations_path: recommendations_disable_proposals_path,
                                           namespace: "proposals" %>
  <% end %>

  <div class="row">
    <div id="proposals" class="proposals-list small-12 medium-9 column">

      <% if has_banners? %>
        <%= render "shared/banner" %>
      <% end %>

      <% if @featured_proposals.present? %>
        <div id="featured-proposals" class="row featured-proposals">
          <div class="small-12 column">
            <h2>
              <%= t("proposals.index.featured_proposals") %>
            </h2>
          </div>
          <% @featured_proposals.each do |featured_proposal| %>
            <%= render "featured_proposal", proposal: featured_proposal %>
          <% end %>
        </div>
      <% end %>

      <div class="row">
        <div class="small-12 column">
          <%= render "view_mode" %>
        </div>
      </div>

      <%= render("shared/advanced_search", search_path: proposals_path(page: 1)) unless params[:retired].present? %>

      <%= render 'shared/order_links', i18n_namespace: "proposals.index" %>

      <% if @proposals.any? %>
        <div class="show-for-small-only">
          <%= link_to t("proposals.index.start_proposal"),
                      new_proposal_path,
                      class: 'button expanded' %>
        </div>
      <% end %>

      <div id="proposals-list">
        <% if @proposals.any? || current_user.blank? %>
          <% if proposals_default_view? %>
            <%= render partial: 'proposals/proposal', collection: @proposals %>
          <% else %>
            <% @proposals.each do |proposal| %>
              <%= render partial: '/proposals/proposal_minimal', locals: { proposal: proposal } %>
            <% end %>
          <% end %>
        <% else %>
          <%= empty_recommended_proposals_message_text(current_user) %>
        <% end %>
        <%= paginate @proposals %>

        <% unless @search_terms || @advanced_search_terms || @tag_filter %>
          <div id="section_help" class="margin" data-magellan-target="section_help">
            <p class="lead">
              <strong><%= t("proposals.index.section_footer.title") %></strong>
            </p>
            <p><%= t("proposals.index.section_footer.description") %></p>
          </div>
        <% end %>
      </div>
    </div>

    <div class="small-12 medium-3 column">
      <aside class="margin-bottom">
        <%= link_to t("proposals.index.start_proposal"),
                    new_proposal_path,
                    class: 'button expanded' %>
        <% if params[:retired].blank? %>
          <%= render 'categories' %>
          <%= render "shared/tag_cloud", taggable: 'proposal' %>
          <%= render 'geozones' %>
          <%= render 'popular' %>
        <% end %>
        <%= render 'retired' %>
      </aside>
    </div>

  </div>
</main>
