<%# locals: (plaid_item:) %> <%= tag.div id: dom_id(plaid_item) do %>
<%= icon "chevron-right", class: "group-open:transform group-open:rotate-90" %>
<% 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? %>
<%= icon "loader", size: "sm", class: "animate-pulse" %> <%= tag.span t(".syncing") %>
<% elsif plaid_item.requires_update? %>
<%= icon "alert-triangle", size: "sm" %> <%= tag.span t(".requires_update") %>
<% elsif plaid_item.sync_error.present? %>
<%= icon "alert-circle", size: "sm", color: "destructive" %> <%= tag.span t(".error"), class: "text-destructive" %>
<% 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) %> <%= render ButtonComponent.new( text: t(".update"), icon: "refresh-cw", variant: "secondary", data: { controller: "plaid", action: "plaid#open", plaid_region_value: plaid_item.plaid_region, plaid_link_token_value: link_token, plaid_is_update_value: true, plaid_item_id_value: plaid_item.id } ) %> <% rescue PlaidItem::PlaidConnectionLostError %>
<%= icon "alert-triangle", size: "sm", color: "warning" %> <%= tag.span t(".connection_lost") %>

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

<%= render ButtonComponent.new( text: t(".delete"), icon: "trash-2", variant: "destructive", href: plaid_item_path(plaid_item), method: :delete, confirm: CustomConfirm.for_resource_deletion(plaid_item.name, high_severity: true) ) %> <%= render LinkComponent.new( text: t(".add_new"), icon: "plus", variant: "secondary", href: new_account_path ) %>
<% end %> <% elsif Rails.env.development? %> <%= icon( "refresh-cw", as_button: true, href: sync_plaid_item_path(plaid_item), disabled: plaid_item.syncing? || plaid_item.scheduled_for_deletion? ) %> <% end %> <%= render MenuComponent.new do |menu| %> <% menu.with_item( variant: "button", text: t(".delete"), icon: "trash-2", href: plaid_item_path(plaid_item), method: :delete, confirm: CustomConfirm.for_resource_deletion(plaid_item.name, high_severity: true) ) %> <% 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 %>