<%- title @title %>
<%- description @description %>

<div class="sidebarred">
  <div class="sidebarred-main-content">
    <div class="open-sidebar sidebar-collapsed">
      ☰
    </div>

    <% if defined?(@set) and !@set.nil? %>
      <h3>
        <%= @set.display_name %> by <%= link_to @set.user.name, @set.user %>
        <% if user_signed_in? and current_user == @set.user %>
          <%= link_to('Edit', edit_user_script_set_path(current_user, @set)) %>
        <% end %>
      </h3>
      <% if !@set.favorite %>
        <p class="script-list-description"><%= @set.description %></p>
      <% end %>
    <% end %>

    <% if defined?(@page_description) %>
      <p class="script-list-description"><%= @page_description %></p>
    <% end %>

    <% if @current_locale_filter %>
      <% if current_user && !current_user.filter_locale_default %>
        <p class="script-list-description"><%= it('scripts.listing_remove_locale_filter', language: @current_locale_filter.best_name(in_locale: request_locale), remove_filter_link: current_path_with_params(filter_locale: nil)) %></p>
      <% else %>
        <p class="script-list-description"><%= it('scripts.listing_remove_locale_filter', language: @current_locale_filter.best_name(in_locale: request_locale), remove_filter_link: It.link(current_path_with_params(filter_locale: '0'), rel: :nofollow)) %></p>
      <% end %>
    <% elsif @offer_filtered_results_for_locale && @scripts.any? %>
      <% if current_user && !current_user.filter_locale_default %>
        <p class="script-list-description"><%= it('scripts.listing_set_locale_filter', language: @offer_filtered_results_for_locale.best_name(in_locale: request_locale), set_filter_link: It.link(current_path_with_params(filter_locale: '1'), rel: :nofollow)) %></p>
      <% else %>
        <p class="script-list-description"><%= it('scripts.listing_set_locale_filter', language: @offer_filtered_results_for_locale.best_name(in_locale: request_locale), set_filter_link: current_path_with_params(filter_locale: nil)) %></p>
      <% end %>
    <% end %>

    <% # There can be a delay in reindexing scripts that were deleted. Ensure we don't show them to those who shouldn't see them.
      scripts_to_render = if current_user&.moderator?
                            # full list
                            @scripts
                          elsif current_user
                            @scripts.reject{|script| script.deleted? && !script.users.include?(current_user) }
                          else
                            @scripts.reject(&:deleted?)
                          end
    %>

    <% if scripts_to_render.empty? %>
      <% if @ad_method&.ea? %>
        <%= render(partial: 'shared/ea_text_ad', locals: {ad_method: @ad_method, ea_div_id: 'script-list-blank-ea'}) %>
      <% end %>

      <p><%= t('scripts.listing_no_scripts') %></p>
    <% else %>
      <ol id="browse-script-list" class="script-list <%= 'showing-all-languages' if params[:language] == 'all' %>">
        <% if @ad_method&.ea? %>
          <li class="ad-entry">
            <%= render(partial: 'shared/ea_text_ad', locals: {ad_method: @ad_method, ea_div_id: 'script-list-ea'}) %>
          </li>
        <% end %>
        <%= render partial: 'scripts/script', collection: scripts_to_render, cached: overriding_locale? ? false : ->(script) { [script, request_locale] } %>
      </ol>

      <%= render_pagination %>
  <% end %>

    <p class="script-list-description"><%= t('scripts.write_your_own_html', post_a_script_link: link_to(t('scripts.post_a_script_link_text'), new_script_version_path), learn_to_write_scripts_link: link_to(t('scripts.learn_to_write_scripts_link_text'), help_writing_user_scripts_path)) %></p>
  </div>

  <% if !defined?(@skip_search_options) || !@skip_search_options %>
    <div class="sidebar collapsed">
      <div class="close-sidebar">
        <div class="sidebar-title"><%= t('common.listing_options_title') %></div>
        <div>☰</div>
      </div>
      <%= render partial: 'list_options', locals: {by_sites: @by_sites, scripts: @scripts, sort_options: @sort_options, include_script_sets: @include_script_sets.nil? ? true : @include_script_sets, include_search: action_name != 'code_search'} %>
    </div>
  <% end %>
</div>
