<table class="hardware_profiles_table table-content-crud table table-hover table-striped">
  <thead>
  <tr>

    <% @columns_selected.each do |column| %>
      <th class="<%= "selected" if @order == column %> order-table-head" data-order="<%= column %>" data-orientation="<%= ((@order == column)?  ((@order_orientation == "ASC")? 'DESC' : 'ASC') : 'ASC') %>">
        <%= Traccar::Device.human_attribute_name(column) %>
      </th>
    <% end %>
    <th><%= Traccar::Position.human_attribute_name('servertime') %> <%= _("Last position") %></th>
  </tr>
  </thead>
  <tbody>

  <% @devices.each do |device| %>
    <tr>
      <% @columns_selected.each do |column| %>
        <td>
          <% begin %>
            <%= eval("device." + column) %>
          <% rescue %>
          <% end %>
        </td>
      <% end %>
      <td>
        <% last_position = Traccar::Position.find_by(id: device.positionid) %>
        <%=  last_position.servertime if last_position%></td>
    </tr>
  <% end %>

  </tbody>
  <tfoot>
  <tr>
    <td colspan="100%" style="padding-top: 10px;">
      <div class="row" style="max-height: 40px;padding-top: 1px;">
        <div class="col-md-6" style="display: flex">
          <%= paginate @devices, :remote => true %>

        </div>
        <div class="col-md-6" align="right">
          <%= t("count") %>: <%= @devices.count %> &nbsp;&nbsp;&nbsp;
        </div>
      </div>
    </td>
  </tr>
  </tfoot>
</table>
<script>
    $(".select_number_by_register").change(function() {
        showLoadingImg();
        $.get("<%= site_manager_report_assign_devices_path %>.js?<%= request.query_parameters.to_query %>&limit=" + this.value, function(){
            hideLoadingImg();
            loadHideColumnSelectorTable();
        });
    });

<!--    $(".order-table-head").click(function () {-->
<!--        let column_ref = $(this);-->
<!--        let column_order = column_ref.attr("data-order");-->
<!--        let column_orientation = column_ref.attr("data-orientation");-->

<!--        showLoadingImg();-->
<!--        $.get("<%= site_manager_report_assign_devices_path %>.js?<%= request.query_parameters.to_query %>&order=" + column_order + "&order_orientation=" + column_orientation, function(){-->
<!--            hideLoadingImg();-->
<!--            loadHideColumnSelectorTable();-->
<!--        });-->
<!--    });-->
    <% if @add_button %>
    $(".btn-create").attr('href', '<%= @add_button.name.underscore.pluralize + "/new?" + request.query_parameters.to_query %>');
    <% end %>

    $(".button-edit").click(function(){
        showLoadingImg();
    });

</script>
