<h2>Listing</h2>

<!-- <div id="react-table"></div> -->

<!-- <script type="text/javascript">
<% {_, json} = JSON.encode(@columns) %>
window.__columns__ = <%= raw json %>;
<% {_, json} = JSON.encode(@entries) %>
window.__entries__ = <%= raw json %>;
</script> -->

<table class="table table-hover table-va table-scaffold table-sm">
  <thead class="thead-default">
    <tr>
      <%
        if @direction == "asc" do
          new_direction = "desc"
        else
          new_direction = "asc"
        end
      %>
      <%= for {id, column} <- @columns do %>
        <%= if column.type == :integer || column.type == :string || column.type == :boolean || column.type == :datetime do %>
          <th>
            <%
              if id == @sort do
                local_direction = new_direction
              else
                local_direction = @direction
              end
            %>
            <a href="<%= admin_path(@conn, :index, @resource, sort: id, direction: local_direction) %>"
               class="<%= if id == @sort do %><%= if @direction == "asc" do %>down<% else %>up<% end %><% end %>">
              <%= column[:label] %>
            </a>
          </th>
        <% end %>
      <% end %>
      <th></th>
    </tr>
  </thead>
  <tbody>
<%= for entry <- @entries do %>
    <tr>
      <%= for {id, column} <- @columns do %>
        <%= if column.type == :integer || column.type == :string || column.type == :boolean || column.type == :datetime do %>
          <td><%= Map.get(entry, id, nil) %></td>
        <% end %>
      <% end %>
      <td class="text-right nowrap">
        <%= link "Edit", to: admin_path(@conn, :edit, @resource, entry), class: "btn btn-default btn-xs" %>
        <%= link "Delete", to: admin_path(@conn, :delete, @resource, entry), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>
      </td>
    </tr>
<% end %>
  </tbody>
</table>

<%= link "New", to: admin_path(@conn, :new, @resource) %>
