<div class='container'>
  <div class='row'>
    <div class='col-md-12'>
      <div class="page-header">
        <h2>
          Your Events <%= @agent && "from #{@agent.name}" %>
        </h2>
      </div>

      <div class='table-responsive'>
        <table class='table table-striped events'>
          <tr>
            <th>Source</th>
            <th>Created</th>
            <th>Payload</th>
            <th></th>
          </tr>

        <% @events.each do |event| %>
          <% next unless event.agent %>
          <%= content_tag :tr, class: (highlighted?(event.id) ? 'hl' : nil) do %>
            <td><%= link_to event.agent.name, agent_path(event.agent, return: request.fullpath) %></td>
            <td title='<%= event.created_at %>'><%= time_ago_in_words event.created_at %> ago</td>
            <td class='payload'><%= truncate event.payload.to_json, :length => 90, :omission => "" %></td>
            <td>
              <div class="btn-group btn-group-xs">
                <%= link_to 'Show', event_path(event), class: "btn btn-default" %>
                <%= link_to 'Re-emit', reemit_event_path(event), method: :post, data: { confirm: 'Are you sure you want to duplicate this event and emit the new one now?' }, class: "btn btn-default" %>
                <%= link_to 'Delete', event_path(event), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-default" %>
              </div>
            </td>
          <% end %>
        <% end %>
        </table>
      </div>

      <%= paginate @events, params: params.slice(:hl), theme: 'twitter-bootstrap-3' %>

      <br />

      <% if @agent %>
        <div class="btn-group">
          <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, filtered_agent_return_link || agents_path, class: "btn btn-default" %>
          <%= link_to icon_tag('glyphicon-random') + ' See all events'.html_safe, events_path, class: "btn btn-default" %>
        </div>
      <% end %>
    </div>
  </div>
</div>

