<div class="filter-bar">

  <!-- 
  <div class="btn-group card">
    <a href="#" class="btn white black-text"><i class="material-icons">view_module</i></a>
    <a href="#" class="btn white black-text"><i class="material-icons">view_headline</i></a>
    <a href="#" class="btn white black-text"><i class="material-icons">view_stream</i></a>
    <a href="#" class="btn white black-text"><i class="material-icons">grid_on</i></a>
  </div>
  -->

  <% if content_type.new.respond_to?(:universe) %>
    <div class="btn-group card">
      <a
        class='dropdown-trigger btn black-text white tooltipped <%= Universe.color if @universe_scope.present? %> lighten-5'
        href='#'
        data-position="bottom"
        data-delay="500"
        data-tooltip="Filter by universe"
        data-target='universe-filter-dropdown'>
        <i class="material-icons <%= Universe.text_color %>"><%= Universe.icon %></i>
        <%= @universe_scope.try(:name) if @universe_scope %>
      </a>
      <ul id='universe-filter-dropdown' class='dropdown-content'>
        <li>
          <a href="?universe=all" class="<%= Universe.text_color %>">
            <i class="material-icons <%= Universe.text_color %>"><%= Universe.icon %></i>
            All Universes
          </a>
        </li>
        <li class="divider" tabindex="-1"></li>
        <%
          linkable_universes_with_this_kind_of_content = current_user.linkable_universes.select do |universe|
            @current_user_content.fetch(content_type.name, []).any? { |content| content.universe_id == universe.id }
          end
        %>
        <% linkable_universes_with_this_kind_of_content.each do |universe| %>
          <li>
            <a href="?universe=<%= universe.id %>" data-universe-id="<%= universe.id %>" class="<%= Universe.text_color %>">
              <i class="material-icons <%= Universe.text_color %>"><%= Universe.icon %></i>
              <span class="grey-text">in</span>
              <%= universe.name %>
            </a>
          </li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="btn-group card">
    <a
      class='dropdown-trigger btn white <%= content_type.color if @filtered_page_tags.present? %> lighten-4 black-text tooltipped'
      href='#'
      data-target='tag-filter-dropdown'
      data-position="bottom"
      data-delay="500"
      data-tooltip="Filter by tag">
      <i class="material-icons <%= content_type.text_color %>"><%= PageTag.icon %></i>
      <%= @filtered_page_tags.try(:first).try(:tag) %>
    </a>
    <ul id='tag-filter-dropdown' class='dropdown-content'>
      <li>
        <%= link_to params.permit(:tag, :favorite_only).merge({ tag: nil }), class: "#{content_type.text_color}" do %>
          <i class="material-icons"><%= PageTag.icon %></i>
          All <%= content_type.name.downcase.pluralize %>
        <% end %>
      </li>
      <li class="divider" tabindex="-1"></li>
      <% if @page_tags %>
        <% @page_tags.each do |page_tag| %>
          <li>
            <%= link_to params.permit(:tag, :favorite_only).merge({ tag: PageTagService.slug_for(page_tag.tag) }), class: "#{content_type.text_color}" do %>
              <i class="material-icons"><%= PageTag.icon %></i>
              <small class="grey-text">tagged</small>
              <%= page_tag.tag %>
            <% end %>
          </li>
        <% end %>
      <% end %>
    </ul>
  </div>

  <% if content_type.new.respond_to?(:favorite?) %>
    <a class='btn white <%= 'yellow lighten-3' if params.key?(:favorite_only) %> black-text tooltipped'
        href="<%= url_for(params.permit(:tag, :favorite_only).merge({favorite_only: params.key?(:favorite_only) ? nil : 1})) %>"
        data-position="bottom"
        data-delay="500"
        data-tooltip="Filter by favorite">
      <i class="material-icons amber-text">star_outline</i>
      <% if params.key?(:favorite_only) %>Favorites<% end %>
    </a>
  <% end %>

  &nbsp;

  <!-- <div class="btn-group card">
    <a class='btn white grey-text tooltipped'
        href='#'
        data-position="bottom"
        data-delay="500"
        data-tooltip="Standard order">
      <i class="material-icons black-text">playlist_add_check</i>
    </a>

    <a class='btn white grey-text tooltipped'
        href='#'
        data-position="bottom"
        data-delay="500"
        data-tooltip="Alphabetical order">
      <i class="material-icons black-text">sort_by_alpha</i>
    </a>

    <a class='btn white grey-text tooltipped'
        href='#'
        data-position="bottom"
        data-delay="500"
        data-tooltip="Most-recent order">
      <i class="material-icons black-text">access_time</i>
    </a>
  </div> -->

  &nbsp;

  <div class="input-field inline" style="position: relative; top: 5px; min-width: 320px">
    <input id="js-content-name-filter" type="text">
    <label for="js-content-name-filter">Filter <%= content_type.name.downcase.pluralize %> by name...</label>
  </div>

  <div class="btn-group right" style="margin-top: 1.9em;">
    <%
      creation_path = if @folder
        send("new_#{content_type.name.downcase}_path", { folder: @folder.try(:id) })
      else
        send("new_#{content_type.name.downcase}_path")
      end
    %>
    <%= link_to creation_path, class: "btn right #{content_type.color} white-text" do %>
      <i class="material-icons left">add</i>
      New <%= content_type.name %>
    <% end %>
  </div>

</div>
<div class="clearfix"></div>
