<%= @project.name %> - Analytics

<%= link_to "← Back to Project", project_path(@project), class: "btn btn-secondary" %>
Time Range
<%= form_with url: analytics_project_path(@project), method: :get, local: true do |form| %>
<%= form.label :time_range, "Time Range", class: "form-label" %> <%= form.select :time_range, options_for_select([ ["Last Hour", 1], ["Last 6 Hours", 6], ["Last 24 Hours", 24], ["Last 7 Days", 168], ["Last 30 Days", 720] ], @time_range), {}, class: "form-select" %>
<%= form.submit "Update", class: "btn btn-primary" %>
<% end %>

<%= number_with_delimiter(@total_events) %>

Total Events

<%= number_with_delimiter(@allowed_events) %>

Allowed

<%= number_with_delimiter(@blocked_events) %>

Blocked

Top Blocked IPs
<% if @top_blocked_ips.any? %>
<% @top_blocked_ips.each do |stat| %> <% end %>
IP Address Blocked Count
<%= stat.ip_address %> <%= number_with_delimiter(stat.count) %>
<% else %>

No blocked events in this time range.

<% end %>
Top Countries
<% if @country_stats.any? %>
<% @country_stats.each do |stat| %> <% end %>
Country Events
<%= stat.country_code || 'Unknown' %> <%= number_with_delimiter(stat.count) %>
<% else %>

No country data available.

<% end %>
Action Distribution
<% if @action_stats.any? %>
<% @action_stats.each do |stat| %>

<%= stat.action.upcase %>

<%= number_with_delimiter(stat.count) %>

<% end %>
<% else %>

No action data available.

<% end %>
<% if @total_events > 0 %>
Block Rate
<% blocked_percentage = (@blocked_events.to_f / @total_events * 100).round(1) %> <% allowed_percentage = (@allowed_events.to_f / @total_events * 100).round(1) %>
<%= allowed_percentage %>% Allowed
<%= blocked_percentage %>% Blocked
<% end %>
<%= link_to "View Events", events_project_path(@project), class: "btn btn-primary" %> <%= link_to "Export Data", "#", class: "btn btn-secondary", onclick: "alert('Export feature coming soon!')" %>