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

(deletion in progress...)

<% end %>
<% if plaid_item.syncing? %>
<%= lucide_icon "loader", class: "w-4 h-4 animate-pulse" %> <%= tag.span t(".syncing") %>
<% elsif plaid_item.requires_update? %>
<%= lucide_icon "alert-triangle", class: "w-4 h-4" %> <%= tag.span t(".requires_update") %>
<% elsif plaid_item.sync_error.present? %>
<%= lucide_icon "alert-circle", class: "w-4 h-4 text-red-500" %> <%= tag.span t(".error"), class: "text-red-500" %>
<% else %>

<%= plaid_item.last_synced_at ? t(".status", timestamp: time_ago_in_words(plaid_item.last_synced_at)) : t(".status_never") %>

<% end %>
<% if plaid_item.requires_update? %> <% begin %> <% link_token = plaid_item.get_update_link_token(webhooks_url: plaid_webhooks_url(plaid_item.plaid_region), redirect_url: accounts_url) %> <% rescue PlaidItem::PlaidConnectionLostError %>
<%= lucide_icon "alert-triangle", class: "w-4 h-4" %> <%= tag.span t(".connection_lost") %>

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

<%= button_to plaid_item_path(plaid_item), method: :delete, class: "btn btn--danger flex items-center gap-2", data: { turbo_confirm: { title: t(".confirm_title"), body: t(".confirm_body"), accept: t(".confirm_accept") } } do %> <%= lucide_icon "trash-2", class: "w-4 h-4" %> <%= tag.span t(".delete") %> <% end %> <%= link_to new_account_path, class: "btn btn--secondary flex items-center gap-2" do %> <%= lucide_icon "plus", class: "w-4 h-4" %> <%= tag.span t(".add_new") %> <% end %>
<% end %> <% else %> <%= button_to sync_plaid_item_path(plaid_item), disabled: plaid_item.syncing? || plaid_item.scheduled_for_deletion?, class: "disabled:text-subdued text-primary flex hover:text-gray-800 items-center text-sm font-medium hover:underline" do %> <%= lucide_icon "refresh-cw", class: "w-4 h-4" %> <% end %> <% end %> <%= contextual_menu do %>
<%= button_to plaid_item_path(plaid_item), method: :delete, class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg", disabled: plaid_item.syncing? || plaid_item.scheduled_for_deletion?, data: { turbo_confirm: { title: t(".confirm_title"), body: t(".confirm_body"), accept: t(".confirm_accept") } } do %> <%= lucide_icon "trash-2", class: "w-5 h-5" %> <%= t(".delete") %> <% end %>
<% end %>
<% unless plaid_item.scheduled_for_deletion? %>
<% if plaid_item.accounts.any? %> <%= render "accounts/index/account_groups", accounts: plaid_item.accounts %> <% else %>

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

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

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