<div id="pick-resource" style="display:none;">
    <div id="pick-field-name"><%= @conn.params["pick"] %></div>
</div>

<div class="col-lg-12 grid-margin stretch-card">
  <div class="card shadow mb-4">
    <div class="card-body table-responsive w-100">
      <h4><%= Kaffy.ResourceAdmin.plural_name(@my_resource) %> <small>(~ <%= @filtered_count %> records)</small></h4>
      <div class="card-description">
        <div class="row">
          <div class="col-md-12">
            <input id="kaffy-search-field" type="text" name="search" value="<%= Map.get(@params, "search", "") %>" class="form-control bg-transparent" placeholder="Search <%= Kaffy.ResourceAdmin.plural_name(@my_resource) %>...">
          </div>
        </div>
      </div>

      <%= render KaffyWeb.ResourceView, "_table.html", conn: @conn, fields: @fields, context: @context, resource: @resource, my_resource: @my_resource, entries: @entries, params: @params %>
    </div>

    <div class="btn-group" role="group" aria-label="Basic example">
      <% params = Map.to_list(@params) |> Enum.map(fn {k, v} -> {String.to_existing_atom(k), v} end) %>
      <%= link "Previous", to: Kaffy.Utils.router().kaffy_resource_path(@conn, :index, @context, @resource, Keyword.merge(params, page: @page - 1)), class: "btn btn-outline-primary#{@prev_class}" %>
      <%= link "Next", to: Kaffy.Utils.router().kaffy_resource_path(@conn, :index, @context, @resource, Keyword.merge(params, page: @page + 1)), class: "btn btn-outline-primary#{@next_class}" %>
    </div>
  </div>
</div>

<form id="kaffy-filters-form" method="get" style="display:none;">
  <%= if Kaffy.ResourceSchema.has_field_filters?(@my_resource) do %>
    <%= for field <- @fields do %>
        <% {field, filters} = Kaffy.ResourceSchema.kaffy_field_filters(@my_resource[:schema], field) %>
        <%= if filters do %>
            <input id="custom-filter-<%= field %>" type="hidden" name="<%= field %>" value="<%= Map.get(@params, to_string(field), "") %>" />
        <% end %>
    <% end %>
  <% end %>
  <input id="kaffy-filter-search" type="hidden" name="search" value="<%= Map.get(@params, "search", "") %>" />
  <input id="kaffy-filter-page" type="hidden" name="page" value="<%= Map.get(@params, "page", "1") %>" />
  <input id="kaffy-filter-limit" type="hidden" name="limit" value="<%= Map.get(@params, "limit", "100") %>" />
  <input id="kaffy-c" type="hidden" name="c" value="<%= @conn.params["c"] %>" />
  <input id="kaffy-r" type="hidden" name="r" value="<%= @conn.params["r"] %>" />
  <input id="kaffy-pick" type="hidden" name="pick" value="<%= @conn.params["pick"] %>" />
</form>
