<%= @project.name %> - Events

<%= link_to "← Back to Project", @project, class: "btn btn-secondary" %> <%= link_to "Analytics", analytics_project_path(@project), class: "btn btn-info" %>
Filters
<%= form_with url: project_events_path(@project), method: :get, local: true, class: "row g-3" do |form| %>
<%= form.label :ip, "IP Address", class: "form-label" %> <%= form.text_field :ip, value: params[:ip], class: "form-control", placeholder: "Filter by IP" %>
<%= form.label :waf_action, "Action", class: "form-label" %> <%= form.select :waf_action, options_for_select([['All', ''], ['Allow', 'allow'], ['Block', 'block'], ['Challenge', 'challenge']], params[:waf_action]), {}, { class: "form-select" } %>
<%= form.label :country, "Country", class: "form-label" %> <%= form.text_field :country, value: params[:country], class: "form-control", placeholder: "Country code (e.g. US)" %>
<%= form.submit "Apply Filters", class: "btn btn-primary me-2" %> <%= link_to "Clear", project_events_path(@project), class: "btn btn-outline-secondary" %>
<% end %>
Events (<%= @events.count %>)
<% if @events.any? %>
<% @events.each do |event| %> <% end %>
Time IP Address Action Path Method Status Country User Agent
<%= event.timestamp.strftime("%Y-%m-%d %H:%M:%S") %> <%= event.ip_address %> <%= event.waf_action %> <%= event.request_path %> <%= event.request_method %> <%= event.response_status %> <% if event.country_code.present? %> <%= event.country_code %> <% else %> - <% end %> <%= event.user_agent&.truncate(30) || '-' %>
<% if @pagy.pages > 1 %>
<%== pagy_nav(@pagy) %>
Showing <%= @pagy.from %> to <%= @pagy.to %> of <%= @pagy.count %> events
<% end %> <% else %>

<% if params[:ip].present? || params[:waf_action].present? || params[:country].present? %> No events found matching your filters. <% else %> No events have been received yet. <% end %>

<% if params[:ip].present? || params[:waf_action].present? || params[:country].present? %> <%= link_to "Clear Filters", project_events_path(@project), class: "btn btn-outline-primary" %> <% end %>
<% end %>