<%= form_tag collections_path, method: :get, class: "narrow-hidden filters",
    id: "collection-filters" do %>
  <h3 class="landmark heading"><%= ts("Filters") %></h3>
  <%= field_set_tag ts("Filter collections:") do %>
    <dl>
      <dt class="landmark"><%= ts("Sort and Filter") %></dt>
      <dd class="submit actions"><%= submit_tag ts("Sort and Filter") %></dd>
      <dt class="sort">
        <%= label_tag :sort_column, ts("Sort by") %>
      </dt>
      <dd class="sort">
        <%= select_tag :sort_column,
            options_for_select({
              ts("Title") => "collections.title",
              ts("Date Created") => "collections.created_at" },
              params[:sort_column]) %>
      </dd>
      <dt class="sort">
        <%= label_tag :sort_direction, ts("Sort direction") %>
      </dt>
      <dd class="sort">
        <%= select_tag :sort_direction,
            options_for_select({
              ts("Ascending") => "ASC",
              ts("Descending") => "DESC" },
              params[:sort_direction]) %>
      </dd>

      <dt class="autocomplete search">
        <%= label_tag "collection_filters_title",
            ts("Filter by title or name") %>
      </dt>
      <dd class="autocomplete search">
        <%= text_field_tag "collection_filters[title]",
            params[:collection_filters][:title],
            autocomplete_options("collection_fullname",
              data: { autocomplete_token_limit: 1 }) %>
      </dd>
      <dt class="autocomplete search">
        <%= label_tag "collection_filters_fandom", ts("Filter by fandom") %>
      </dt>
      <dd class="autocomplete search">
        <%= text_field_tag "collection_filters[fandom]",
            params[:collection_filters][:fandom],
            autocomplete_options("fandom", data: { autocomplete_token_limit: 1 }) %>
      </dd>
      <dt><%= ts("Closed") %></dt>
      <dd>
        <ul>
          <li>
            <%= label_tag "collection_filters_closed_true" do %>
              <%= radio_button_tag "collection_filters[closed]", true,
                  params[:collection_filters][:closed] == "true" %>
              <%= label_indicator_and_text(ts("Yes")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_closed_false" do %>
              <%= radio_button_tag "collection_filters[closed]", false,
                  params[:collection_filters][:closed] == "false" %>
              <%= label_indicator_and_text(ts("No")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_closed_" do %>
              <%= radio_button_tag "collection_filters[closed]", "",
                  params[:collection_filters][:closed] == "" %>
              <%= label_indicator_and_text(ts("Either")) %>
            <% end %>
          </li>
        </ul>
      </dd>
      <dt><%= ts("Moderated") %></dt>
      <dd>
        <ul>
          <li>
            <%= label_tag "collection_filters_moderated_true" do %>
              <%= radio_button_tag "collection_filters[moderated]", true,
                  params[:collection_filters][:moderated] == "true" %>
              <%= label_indicator_and_text(ts("Yes")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_moderated_false" do %>
              <%= radio_button_tag "collection_filters[moderated]", false,
                  params[:collection_filters][:moderated] == "false" %>
              <%= label_indicator_and_text(ts("No")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_moderated_" do %>
              <%= radio_button_tag "collection_filters[moderated]", "",
                  params[:collection_filters][:moderated] == "" %>
              <%= label_indicator_and_text(ts("Either")) %>
            <% end %>
          </li>
        </ul>
      </dd>
      <dt><%= ts("Collection Type") %></dt>
      <dd>
        <ul>
          <li>
            <%= label_tag "collection_filters_challenge_type_gift_exchange" do %>
              <%= radio_button_tag "collection_filters[challenge_type]",
                  "gift_exchange",
                  params[:collection_filters][:challenge_type] == "gift_exchange"
              %>
              <%= label_indicator_and_text(ts("Gift Exchange Challenge")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_challenge_type_prompt_meme" do %>
              <%= radio_button_tag "collection_filters[challenge_type]",
                  "prompt_meme",
                  params[:collection_filters][:challenge_type] == "prompt_meme"
              %>
              <%= label_indicator_and_text(ts("Prompt Meme Challenge")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_challenge_type_no_challenge" do %>
              <%= radio_button_tag "collection_filters[challenge_type]",
                  "no_challenge",
                  params[:collection_filters][:challenge_type] == "no_challenge"
              %>
              <%= label_indicator_and_text(ts("No Challenge")) %>
            <% end %>
          </li>
          <li>
            <%= label_tag "collection_filters_challenge_type_" do %>
              <%= radio_button_tag "collection_filters[challenge_type]", "",
                  params[:collection_filters][:challenge_type] == "" %>
              <%= label_indicator_and_text(ts("Any")) %>
            <% end %>
          </li>
        </ul>
      </dd>
      <dt class="landmark"><%= ts("Submit") %></dt>
      <dd class="submit actions"><%= submit_tag ts("Sort and Filter") %></dd>
    </dl>
    <p class="footnote">
      <%= link_to ts("Clear Filters"), collections_path %>
    </p>
  <% end %>
  <% # On narrow screens, link jumps to top of index when JavaScript is disabled and closes filters when JavaScript is enabled %>
  <p class="narrow-shown hidden">
    <a href="#main" id="leave_filters" class="close">
      <%= ts("Top of Collection Index") %>
    </a>
  </p>
<% end %>
