<% content_for :page_header do %>

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

<%= t("reports.index.subtitle") %>

<%# Flash messages %> <% if flash[:alert].present? %>
<%= flash[:alert] %>
<% end %> <%# Print Report Button %> <%= link_to print_reports_path(period_type: @period_type, start_date: @start_date, end_date: @end_date), target: "_blank", rel: "noopener", aria: { label: t("reports.index.print_report") }, class: "font-medium whitespace-nowrap inline-flex items-center gap-1 rounded-lg px-3 py-2 text-sm text-primary border border-secondary bg-transparent hover:bg-surface-hover" do %> <%= icon("printer", size: "sm") %> <% end %>
<%# Period Navigation Tabs %>
<%= render DS::Link.new( text: t("reports.index.periods.monthly"), variant: @period_type == :monthly ? "secondary" : "ghost", href: reports_path(period_type: :monthly), size: :sm ) %> <%= render DS::Link.new( text: t("reports.index.periods.quarterly"), variant: @period_type == :quarterly ? "secondary" : "ghost", href: reports_path(period_type: :quarterly), size: :sm ) %> <%= render DS::Link.new( text: t("reports.index.periods.ytd"), variant: @period_type == :ytd ? "secondary" : "ghost", href: reports_path(period_type: :ytd), size: :sm ) %> <%= render DS::Link.new( text: t("reports.index.periods.last_6_months"), variant: @period_type == :last_6_months ? "secondary" : "ghost", href: reports_path(period_type: :last_6_months), size: :sm ) %> <%= render DS::Link.new( text: t("reports.index.periods.custom"), variant: @period_type == :custom ? "secondary" : "ghost", href: reports_path(period_type: :custom), size: :sm ) %>
<%# Custom Date Range Picker (only shown when custom is selected) %> <% if @period_type == :custom %> <%= form_with url: reports_path, method: :get, data: { controller: "auto-submit-form" }, class: "flex items-center gap-3 bg-surface-inset p-3 rounded-lg" do |f| %> <%= f.hidden_field :period_type, value: :custom %>
<%= f.date_field :start_date, value: @start_date.strftime("%Y-%m-%d"), data: { auto_submit_form_target: "auto" }, autocomplete: "off", class: "px-3 py-1.5 border border-primary rounded-lg text-sm bg-container-inset text-primary" %>
<%= f.date_field :end_date, value: @end_date.strftime("%Y-%m-%d"), data: { auto_submit_form_target: "auto" }, autocomplete: "off", class: "px-3 py-1.5 border border-primary rounded-lg text-sm bg-container-inset text-primary" %>
<% end %> <% end %> <%# Period Display %> <% if @nav %>
<%= render DS::Link.new( variant: "icon", icon: "chevron-left", href: reports_path(period_type: @period_type, start_date: @nav[:prev_start], end_date: @nav[:prev_end]), aria: { label: t("reports.index.previous_period") }, ) %> <% if @nav[:at_latest] %> <% else %> <%= render DS::Link.new( variant: "icon", icon: "chevron-right", href: reports_path(period_type: @period_type, start_date: @nav[:next_start], end_date: @nav[:next_end]), aria: { label: t("reports.index.next_period") }, ) %> <% end %>
<% if [:monthly, :quarterly, :ytd].include?(@period_type) %> <%= render DS::Popover.new(variant: "button") do |popover| %> <% popover.with_button class: "flex items-center gap-1 hover:bg-alpha-black-25 cursor-pointer rounded-md p-2" do %> <%= @nav[:label] %> <%= icon("chevron-down") %> <% end %> <% popover.with_custom_content do %> <%= render "reports/period_picker", period_type: @period_type, start_date: @start_date %> <% end %> <% end %> <% else %> <%= @nav[:label] %> <% end %>
<%= render DS::Link.new( text: t("reports.index.today"), variant: "outline", href: reports_path(period_type: @period_type), ) %>
<% end %>
<% end %>
<% if Current.family.transactions.any? %> <%# Summary Dashboard - Always visible, not collapsible %>
<%= render partial: "reports/summary_dashboard", locals: { metrics: @summary_metrics, period_type: @period_type } %>
<%# Collapsible & Reorderable Sections %>
<% @reports_sections.each do |section| %> <% next unless section[:visible] %>

<%= t(section[:title]) %>

<%= render partial: section[:partial], locals: section[:locals] %>
<% end %>
<% else %> <%# Empty State %>
<%= render partial: "reports/empty_state" %>
<% end %>