<div class="header-Outro with-columns browse-page">
  <div class="row content">
    <div class="col col-100">
      <% if params[:tag] %>
        <h1><a href="/browse">Websites</a> > <%= params[:tag] %></h1>
        <h4><a href="/activity?tag=<%= params[:tag]%>">Activity</a></h4>
      <% else %>
        <h1>Sites on FemslashCity</h1>
      <% end %>
    </div>

    <form id="search_criteria" action="/browse" method="GET">
      <div class="col col-50 filter">
        <fieldset class="grouping">
          <% unless is_education? %>
            <label class="text-Label" for="sort_by">Sort by:</label>
            <div class="select-Container">
              <select name="sort_by" id="sort_by" class="input-Select">
                <option value="special_sauce" <%= params[:sort_by] == 'special_sauce' ? 'selected' : '' %>>Special Sauce</option>
                <option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
                <option value="most_followed" <%= params[:sort_by] == 'most_followed' ? 'selected' : '' %>>Most Followed</option>
                <option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
                <option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Views</option>
                <option value="tipping_enabled" <%= params[:sort_by] == 'tipping_enabled' ? 'selected' : '' %>>Tipping Enabled</option>
                <% if signed_in? %>
                  <option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
                <% end %>
                <option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option>
                <% if current_site && current_site.is_admin %>
                  <option value="moderation" <%= params[:sort_by] == 'moderation' ? 'selected' : '' %>>Moderation</option>
                <% end %>
                <!-- <option value="robots" <%= params[:sort_by] == 'robots' ? 'selected' : '' %>>Robots</option> -->
              </select>
            </div>

            <!--
              <div>
                <input name="is_nsfw" type="checkbox" value="true" <%= params[:is_nsfw].to_s == 'true' ? 'checked' : '' %>> Show 18+ content
              </div>
            -->
            <input class="btn-Action" type="submit" value="Update">
          <% end %>
        </fieldset>
      </div>
      <div class="col col-50 filter">
        <fieldset class="grouping">
          <% unless is_education? %>
            <label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
            <input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto" oninput="this.value = this.value.replace(/[^a-zA-Z0-9]+/g, '')">
            <input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
          <% else %>
            <% if params[:tag] %>
              <input name="tag" type="hidden" value="<%= params[:tag] %>">
            <% end %>
          <% end %>
        </fieldset>
      </div>
    </div>
  </form>
</div>

<div class="browse-page">

<% if @sites.length == 0 %>
  <div class="row website-Gallery content int-Gall" style="padding-left: 30px;">
    <h3>No active sites found.</h3>
    <p>Try another search, or <a href="/browse">browse all sites</a>!</p>
  </div>
<% else %>
  <ul class="row website-Gallery content int-Gall">
    <% @sites.each_with_index do |site,i| %>
      <li id="username_<%= site.username %>">
        <a href="<%= site.uri %>"
           class="neo-Screen-Shot"
           title="<%= site.title %>"
        >
          <span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
            <img src="/img/placeholder.png" alt="<%= site.title %>" />
          </span>
        </a>
        <div class="title">
          <a href="<%= site.uri %>"
             title="<%= site.title %>"
          ><%= site.title.shorten(30) %></a>&nbsp;
        </div>
        <div class="site-info">
          <div class="username">
            <a href="/site/<%= site.username %>" title="Site Profile">
              <i class="fa fa-user"><% if site.supporter? %><i class="fa fa-heart"></i><% end %></i><%= site.username %>
            </a>
          </div>
          <div class="site-stats hide-on-mobile">
            <a href="/site/<%= site.username %>" title="<% if params[:sort_by] == 'hits' %>Hits<% else %>Visitors<% end %>">
              <span>
                <i class="fa fa-eye"></i>
              </span>
              <% if params[:sort_by] == 'hits' %>
                <%= site.hits.format_large_number %>
              <% else %>
                <%= site.views.format_large_number %>
              <% end %>
            </a>
          </div>
          <div class="site-tags">
            <% if @site_tags[site.id].length > 0 %>
              <i class="fa fa-tag" title="Tags"></i>
              <% @site_tags[site.id].each_with_index do |tag, index| %>
                <a class="" href="/browse?tag=<%= Rack::Utils.escape tag %>"><%= tag %></a><% if index != @site_tags[site.id].length - 1 %>,<% end %>
              <% end %>
            <% end %>
          </div>
          <% if signed_in? && current_site.is_admin %>
            <div class="admin">
              <button onclick="banSite('<%= site.username.gsub('\'', '') %>', '', this); ">Ban</button>
              <button onclick="banSite('<%= site.username.gsub('\'', '') %>', 'spam', this)">Spam</button>
              <button onclick="banSite('<%= site.username.gsub('\'', '') %>', 'phishing', this)">Phishing</button>
              <button onclick="window.open('/admin/site/<%= site.username %>', '_blank')">Info</button>
              <form action="/admin/mark_nsfw" target="_blank" method="POST" onsubmit="return confirm('Confirm NSFW marking of <%= site.username %>');">
                <%== csrf_token_input_html %>
                <input type="hidden" name="username" value="<%= site.username %>">
                <button>NSFW</button>
              </form>
              
              <% if params[:sort_by] == 'moderation' %>
                <form action="/admin/mark_moderated" method="POST" onsubmit="return confirm('Confirm moderation after <%= site.username %>');">
                  <%== csrf_token_input_html %>
                  <input type="hidden" name="site_id" value="<%= site.id %>">
                  <button>Moderated</button>
                </form>
              <% end %>

              <% if params[:sort_by] == 'blocks' %>
              <p>
                Blocks:<br>
                <% site.blocks.each do |block| %>
                  <a href="/site/<%= block.actioning_site.username %>"><%= block.actioning_site.username %></a><br>
                <% end %>
              </p>
              <% end %>
            </div>
          <% end %>
        </div>
      </li>
    <% end %>
  </ul>
<% end %>

<% if params[:sort_by] != 'random' %>
  <%== erb :'_pagination', layout: false %>
<% else %>
  <div class="txt-Center eps pagination" style="margin-top: 0"  >
    <a href="/browse?sort_by=random&tag=<%= Rack::Utils.escape params[:tag] %>" class="btn-Action txt-Center" style="margin: 0 auto;">More</a>
  </div>
<% end %>
  <% if params[:sort_by] != 'moderation' %>
    <% unless is_education? %>
      <%== erb :_browse_tags, layout: false %>
    <% end %>
  <% end %>
</div>

<% if signed_in? && current_site.is_admin %>
  <script>
    function banSite(usernames, classifier, el) {
      $.post('/admin/ban', {
        usernames: usernames,
        classifier: classifier,
        csrf_token: '<%= csrf_token %>'
      }, function(data) {
        $(el).css('color', '#3eff00')
      })
      return false;
    }
  </script>
<% end %>
