<%= t("reports.budget_performance.title") %>

<%= start_date.strftime("%B %Y") %>

<% if budget_data.any? %>
<% budget_data.each do |budget_item| %>
<%# Category Header %>

<%= budget_item[:category_name] %>

<% case budget_item[:status] %> <% when :over %> <%= icon("alert-circle", class: "w-3 h-3") %> <%= t("reports.budget_performance.status.over") %> <% when :warning %> <%= icon("alert-triangle", class: "w-3 h-3") %> <%= t("reports.budget_performance.status.warning") %> <% when :good %> <%= icon("check-circle", class: "w-3 h-3") %> <%= t("reports.budget_performance.status.good") %> <% end %> <%= budget_item[:percent_used].round(0) %>%
<%# Progress Bar %>
<% bar_width = [budget_item[:percent_used], 100].min %> <% bar_color = case budget_item[:status] when :over then "bg-destructive" when :warning then "bg-warning" else "bg-success" end %>
<%# Budget Details %>
<%= t("reports.budget_performance.spent") %>: <%= Money.new(budget_item[:actual], Current.family.currency).format %>
<%= t("reports.budget_performance.budgeted") %>: <%= Money.new(budget_item[:budgeted], Current.family.currency).format %>
<% if budget_item[:remaining] >= 0 %> <%= t("reports.budget_performance.remaining") %>: <%= Money.new(budget_item[:remaining], Current.family.currency).format %> <% else %> <%= t("reports.budget_performance.over_by") %>: <%= Money.new(budget_item[:remaining].abs, Current.family.currency).format %> <% end %>
<%# Suggested Daily Limit (if remaining days in month) %> <% if budget_item[:remaining] > 0 && start_date.month == Date.current.month && start_date.year == Date.current.year %> <% days_remaining = (start_date.end_of_month - Date.current).to_i + 1 %> <% if days_remaining > 0 %>

<%= t("reports.budget_performance.suggested_daily", amount: Money.new((budget_item[:remaining] / days_remaining), Current.family.currency).format, days: days_remaining) %>

<% end %> <% end %>
<% end %>
<% else %>
<%= icon("gauge", class: "w-12 h-12 text-tertiary mx-auto mb-4") %>

<%= t("reports.budget_performance.no_budgets") %>

<% end %>