<%# Month-over-Month Trends %>

<%= t("reports.trends.monthly_breakdown") %>

<% if trends_data.any? %>
<%= t("reports.trends.month") %>
<%= t("reports.trends.income") %>
<%= t("reports.trends.expenses") %>
<%= t("reports.trends.net") %>
<%= t("reports.trends.savings_rate") %>
<% trends_data.each_with_index do |trend, idx| %>
"> <%= trend[:month] %> <% if trend[:is_current_month] %> (<%= t("reports.trends.current") %>) <% end %>
<%= Money.new(trend[:income], Current.family.currency).format %>
<%= Money.new(trend[:expenses], Current.family.currency).format %>
"> <%= Money.new(trend[:net], Current.family.currency).format %>
"> <% savings_rate = trend[:income] > 0 ? ((trend[:net].to_f / trend[:income].to_f) * 100).round(1) : 0 %> <%= savings_rate %>%
<% if idx < trends_data.size - 1 %> <%= render "shared/ruler", classes: "mx-3 lg:mx-4" %> <% end %> <% end %>
<%# Trend Insights %>
<% avg_income = trends_data.sum { |t| t[:income] } / trends_data.length %> <% avg_expenses = trends_data.sum { |t| t[:expenses] } / trends_data.length %> <% avg_net = trends_data.sum { |t| t[:net] } / trends_data.length %>

<%= t("reports.trends.avg_monthly_income") %>

<%= Money.new(avg_income, Current.family.currency).format %>

<%= t("reports.trends.avg_monthly_expenses") %>

<%= Money.new(avg_expenses, Current.family.currency).format %>

<%= t("reports.trends.avg_monthly_savings") %>

"> <%= Money.new(avg_net, Current.family.currency).format %>

<% else %>
<%= t("reports.trends.no_data") %>
<% end %>