<%# Renders a breakdown table for income or expense groups %> <%# Local variables: groups, total, type (:income or :expense), amount_sort_params, current_sort_by, current_sort_direction %> <% color_class = type == :income ? "text-success" : "text-destructive" icon_name = type == :income ? "trending-up" : "trending-down" title_key = type == :income ? "reports.transactions_breakdown.table.income" : "reports.transactions_breakdown.table.expense" %>

<%= icon(icon_name, class: "w-5 h-5") %> <%= t(title_key) %> (<%= Money.new(total, Current.family.currency).format %>)

<% groups.each do |group| %> <% percentage = total.zero? ? 0 : (group[:total].to_f / total * 100).round(1) %> <% has_subcategories = group[:subcategories].present? && group[:subcategories].any? %> <%# Render subcategories if present %> <% if has_subcategories %> <% group[:subcategories].each do |subcategory| %> <% sub_percentage = total.zero? ? 0 : (subcategory[:total].to_f / total * 100).round(1) %> <% end %> <% end %> <% end %>
<%= t("reports.transactions_breakdown.table.category") %> <%= link_to reports_path(amount_sort_params), class: "inline-flex items-center gap-1 hover:text-primary" do %> <%= t("reports.transactions_breakdown.table.amount") %> <% if current_sort_by == "amount" %> <%= icon(current_sort_direction == "desc" ? "chevron-down" : "chevron-up", class: "w-3 h-3") %> <% end %> <% end %> <%= t("reports.transactions_breakdown.table.percentage") %>
<%= group[:category_name] %> (<%= t("reports.transactions_breakdown.table.entries", count: group[:count]) %>)
<%= Money.new(group[:total], Current.family.currency).format %> <%= percentage %>%
<%= subcategory[:category_name] %> (<%= t("reports.transactions_breakdown.table.entries", count: subcategory[:count]) %>)
<%= Money.new(subcategory[:total], Current.family.currency).format %> <%= sub_percentage %>%