<%
  current_tab = easy_page_context[:page_params][:current_tab]
%>

<% Array(current_tab.settings['filters']).each do |filter| %>
  <% case filter['type'] %>
  <% when 'date_period' %>
    <div class="tab-filter">
      <span class="tab-filter__name"><%= filter['name'] %></span>

      <div class="tab-filter__field">
        <%= select_tag("global_filters[#{filter['uuid']}]", options_for_period_select('in-modules', nil,
                  show_future: false,
                  hide_custom: true,
                  disabled_values: ['all', 'is_not_null', 'is_null'],
                  additional_items: [
                    l(:label_others), [["--- #{l(:label_in_modules)} ---", 'in-modules']]
                  ]),
                style: 'width: 180px') %>
      </div>
    </div>

  <% when 'country_select' %>
    <%
      values = [["--- #{l(:label_in_modules)} ---", 'in-modules']]
      values.concat ISO3166::Country.all_names_with_codes(I18n.locale)
    %>

    <div class="tab-filter">
      <span class="tab-filter__name"><%= filter['name'] %></span>

      <div class="tab-filter__field">
        <%= select_tag("global_filters[#{filter['uuid']}]", options_for_select(values), style: 'width: 180px') %>
      </div>
    </div>

  <% when 'cf_list' %>
    <%
      values = filter['possible_values'].to_s.split("\n")
      values.each(&:chomp!)
      values.prepend(["--- #{l(:label_in_modules)} ---", 'in-modules'])
    %>

    <div class="tab-filter">
      <span class="tab-filter__name"><%= filter['name'] %></span>

      <div class="tab-filter__field">
        <%= select_tag("global_filters[#{filter['uuid']}]", options_for_select(values), style: 'width: 180px') %>
      </div>
    </div>

  <% end %>
<% end %>

<% if current_tab.settings['filters'].present? %>
  <a href="javascript:void(0)" class="tab-filter__apply button-positive icon icon-checked" onclick="EASY.pageTab.applyFilters(this)" data-apply-url="<%= get_content_easy_page_tab_path(current_tab) %>" data-tab-id="<%= current_tab.id %>"><%= l(:button_apply) %></a>
<% end %>
