<%= helpers.icon "chevron-right", class: "group-open:transform group-open:rotate-90" %> <%= t("provider_sync_summary.title") %>
<% if last_synced_at %> <%= t("provider_sync_summary.last_sync", time_ago: last_synced_ago) %> <% end %>
<%# Accounts section - always shown if we have account stats %> <% if total_accounts > 0 || stats.key?("total_accounts") %>

<%= t("provider_sync_summary.accounts.title") %>

<%= t("provider_sync_summary.accounts.total", count: total_accounts) %> <%= t("provider_sync_summary.accounts.linked", count: linked_accounts) %> <%= t("provider_sync_summary.accounts.unlinked", count: unlinked_accounts) %> <% if institutions_count.present? %> <%= t("provider_sync_summary.accounts.institutions", count: institutions_count) %> <% end %>
<% end %> <%# Transactions section - shown if provider collects transaction stats %> <% if has_transaction_stats? || activities_pending? %>

<%= t("provider_sync_summary.transactions.title") %>

<% if activities_pending? && !has_transaction_stats? %>
<%= helpers.icon "loader-circle", size: "sm", class: "animate-spin text-secondary" %> <%= t("provider_sync_summary.transactions.fetching") %>
<% else %>
<%= t("provider_sync_summary.transactions.seen", count: tx_seen) %> <%= t("provider_sync_summary.transactions.imported", count: tx_imported) %> <%= t("provider_sync_summary.transactions.updated", count: tx_updated) %> <%= t("provider_sync_summary.transactions.skipped", count: tx_skipped) %>
<% end %> <%# Protected entries detail - shown when entries were skipped due to protection %> <% if has_skipped_entries? %>
<%= helpers.icon "shield-check", size: "sm" %> <%= t("provider_sync_summary.transactions.protected", count: tx_skipped) %>
<% if skip_summary.any? %>
<% skip_summary.each do |reason, count| %> <%= t("provider_sync_summary.skip_reasons.#{reason}", default: reason.humanize) %>: <%= count %> <% end %>
<% end %> <% if skip_details.any? %>
<%= t("provider_sync_summary.transactions.view_protected") %>
<% skip_details.each do |detail| %>

<%= detail["name"] %> (<%= t("provider_sync_summary.skip_reasons.#{detail["reason"]}", default: detail["reason"].humanize) %>)

<% end %>
<% end %>
<% end %>
<% end %> <%# Holdings section - shown if provider collects holdings stats %> <% if has_holdings_stats? %>

<%= t("provider_sync_summary.holdings.title") %>

<%= t("provider_sync_summary.holdings.#{holdings_label_key}", count: holdings_count) %>
<% end %> <%# Trades section - shown if provider collects trades stats (investment activities) %> <% if has_trades_stats? || activities_pending? %>

<%= t("provider_sync_summary.trades.title") %>

<% if activities_pending? && !has_trades_stats? %>
<%= helpers.icon "loader-circle", size: "sm", class: "animate-spin text-secondary" %> <%= t("provider_sync_summary.trades.fetching") %>
<% else %>
<%= t("provider_sync_summary.trades.imported", count: trades_imported) %> <% if trades_skipped > 0 %> <%= t("provider_sync_summary.trades.skipped", count: trades_skipped) %> <% end %>
<% end %>
<% end %> <%# Health section - always shown %>

<%= t("provider_sync_summary.health.title") %>

<% if rate_limited? %> <%= t("provider_sync_summary.health.rate_limited", time_ago: rate_limited_ago || t("provider_sync_summary.health.recently")) %> <% end %> <% if has_errors? %> <%= t("provider_sync_summary.health.errors", count: total_errors) %> <% if error_details.any? %>
<%= t("provider_sync_summary.health.view_error_details") %>
<% error_details.each do |detail| %>

<% if detail["name"].present? %><%= detail["name"] %>: <% end %><%= detail["message"] %>

<% end %>
<% end %> <% elsif import_started? %> <%= t("provider_sync_summary.health.errors", count: 0) %> <% else %> <%= t("provider_sync_summary.health.errors", count: 0) %> <% end %>
<%# Pending→posted reconciliation %> <% if has_pending_reconciled? %>
<%= helpers.icon "check-circle", size: "sm", color: "success" %> <%= t("provider_sync_summary.health.pending_reconciled", count: pending_reconciled) %>
<% if pending_reconciled_details.any? %>
<%= t("provider_sync_summary.health.view_reconciled") %>
<% pending_reconciled_details.each do |detail| %>

<%= detail["account_name"] %>: <%= detail["pending_name"] %>

<% end %>
<% end %>
<% end %> <%# Duplicate suggestions needing review %> <% if has_duplicate_suggestions_created? %>
<%= helpers.icon "alert-triangle", size: "sm", color: "warning" %> <%= t("provider_sync_summary.health.duplicate_suggestions", count: duplicate_suggestions_created) %>
<% if duplicate_suggestions_details.any? %>
<%= t("provider_sync_summary.health.view_duplicate_suggestions") %>
<% duplicate_suggestions_details.each do |detail| %>

<%= detail["account_name"] %>: <%= detail["pending_name"] %> → <%= detail["posted_name"] %>

<% end %>
<% end %>
<% end %> <%# Stale pending transactions (auto-excluded) %> <% if has_stale_pending? %>
<%= helpers.icon "clock", size: "sm", color: "warning" %> <%= t("provider_sync_summary.health.stale_pending", count: stale_pending_excluded) %>
<% if stale_pending_details.any? %>
<%= t("provider_sync_summary.health.view_stale_pending") %>
<% stale_pending_details.each do |detail| %>

<%= detail["account_name"] %>: <%= t("provider_sync_summary.health.stale_pending_count", count: detail["count"]) %>

<% end %>
<% end %>
<% end %> <%# Stale unmatched pending (need manual review) %> <% if has_stale_unmatched_pending? %>
<%= helpers.icon "help-circle", size: "sm" %> <%= t("provider_sync_summary.health.stale_unmatched", count: stale_unmatched_pending) %>
<% if stale_unmatched_details.any? %>
<%= t("provider_sync_summary.health.view_stale_unmatched") %>
<% stale_unmatched_details.each do |detail| %>

<%= detail["account_name"] %>: <%= t("provider_sync_summary.health.stale_unmatched_count", count: detail["count"]) %>

<% end %>
<% end %>
<% end %> <%# Data quality warnings %> <% if has_data_quality_issues? %>
<% if data_warnings > 0 %>
<%= helpers.icon "alert-triangle", size: "sm", color: "warning" %> <%= t("provider_sync_summary.health.data_warnings", count: data_warnings) %>
<% end %> <% if notices > 0 %>
<%= helpers.icon "info", size: "sm" %> <%= t("provider_sync_summary.health.notices", count: notices) %>
<% end %>
<% if data_quality_details.any? %>
<%= t("provider_sync_summary.health.view_data_quality") %>
<% data_quality_details.each do |detail| %>

"><%= detail["message"] %>

<% end %>
<% end %> <% end %>