<%# locals: (lunchflow_item:) %> <%= tag.div id: dom_id(lunchflow_item) do %>
<%= icon "chevron-right", class: "group-open:transform group-open:rotate-90" %>
<% if lunchflow_item.logo.attached? %> <%= image_tag lunchflow_item.logo, class: "rounded-full h-full w-full", loading: "lazy" %> <% else %>
<%= tag.p lunchflow_item.name.first.upcase, class: "text-orange-600 text-xs font-medium" %>
<% end %>
<%= tag.p lunchflow_item.name, class: "font-medium text-primary" %> <% if lunchflow_item.scheduled_for_deletion? %>

<%= t(".deletion_in_progress") %>

<% end %>
<% if lunchflow_item.accounts.any? %>

<%= lunchflow_item.institution_summary %>

<% end %> <% if lunchflow_item.syncing? %>
<%= icon "loader", size: "sm", class: "animate-spin" %> <%= tag.span t(".syncing") %>
<% elsif lunchflow_item.sync_error.present? %>
<%= render DS::Tooltip.new(text: lunchflow_item.sync_error, icon: "alert-circle", size: "sm", color: "destructive") %> <%= tag.span t(".error"), class: "text-destructive" %>
<% else %>

<% if lunchflow_item.last_synced_at %> <% if lunchflow_item.sync_status_summary %> <%= t(".status_with_summary", timestamp: time_ago_in_words(lunchflow_item.last_synced_at), summary: lunchflow_item.sync_status_summary) %> <% else %> <%= t(".status", timestamp: time_ago_in_words(lunchflow_item.last_synced_at)) %> <% end %> <% else %> <%= t(".status_never") %> <% end %>

<% end %>
<% if Rails.env.development? %> <%= icon( "refresh-cw", as_button: true, href: sync_lunchflow_item_path(lunchflow_item) ) %> <% end %> <%= render DS::Menu.new do |menu| %> <% menu.with_item( variant: "button", text: t(".delete"), icon: "trash-2", href: lunchflow_item_path(lunchflow_item), method: :delete, confirm: CustomConfirm.for_resource_deletion(lunchflow_item.name, high_severity: true) ) %> <% end %>
<% unless lunchflow_item.scheduled_for_deletion? %>
<% if lunchflow_item.accounts.any? %> <%= render "accounts/index/account_groups", accounts: lunchflow_item.accounts %> <% end %> <%# Sync summary (collapsible) - using shared ProviderSyncSummary component %> <% stats = if defined?(@lunchflow_sync_stats_map) && @lunchflow_sync_stats_map @lunchflow_sync_stats_map[lunchflow_item.id] || {} else lunchflow_item.syncs.ordered.first&.sync_stats || {} end %> <%= render ProviderSyncSummary.new( stats: stats, provider_item: lunchflow_item, institutions_count: lunchflow_item.connected_institutions.size ) %> <%# Use model methods for consistent counts %> <% unlinked_count = lunchflow_item.unlinked_accounts_count %> <% linked_count = lunchflow_item.linked_accounts_count %> <% total_count = lunchflow_item.total_accounts_count %> <% if unlinked_count > 0 %>

<%= t(".setup_needed") %>

<%= t(".setup_description", linked: linked_count, total: total_count) %>

<%= render DS::Link.new( text: t(".setup_action"), icon: "settings", variant: "primary", href: setup_accounts_lunchflow_item_path(lunchflow_item), frame: :modal ) %>
<% elsif lunchflow_item.accounts.empty? && total_count == 0 %>

<%= t(".no_accounts_title") %>

<%= t(".no_accounts_description") %>

<%= render DS::Link.new( text: t(".setup_action"), icon: "settings", variant: "primary", href: setup_accounts_lunchflow_item_path(lunchflow_item), frame: :modal ) %>
<% end %>
<% end %>
<% end %>