<%# locals: (entry:, selectable: true, show_balance: false, origin: nil) %>
<% transaction, account = entry.account_transaction, entry.account %>

<div class="grid grid-cols-12 items-center <%= entry.excluded ? "text-gray-400 bg-gray-25" : "text-gray-900" %> text-sm font-medium p-4">
  <div class="pr-10 flex items-center gap-4 col-span-6">
    <% if selectable %>
      <%= check_box_tag dom_id(entry, "selection"),
                        class: "maybe-checkbox maybe-checkbox--light",
                        data: { id: entry.id, "bulk-select-target": "row", action: "bulk-select#toggleRowSelection" } %>
    <% end %>

    <div class="max-w-full">
      <%= content_tag :div, class: ["flex items-center gap-2"] do %>
        <div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-gray-600/5 text-gray-600">
          <%= transaction.name.first.upcase %>
        </div>

        <div class="truncate">
          <% if entry.new_record? %>
            <%= content_tag :p, transaction.name %>
          <% else %>
            <%= link_to transaction.name,
                        entry.transfer.present? ? account_transfer_path(entry.transfer, origin:) : account_entry_path(account, entry, origin:),
                        data: { turbo_frame: "drawer", turbo_prefetch: false },
                        class: "hover:underline hover:text-gray-800" %>
          <% end %>
        </div>
      <% end %>
    </div>

    <% if unconfirmed_transfer?(entry) %>
      <%= render "account/transfers/transfer_toggle", entry: entry %>
    <% end %>
  </div>

  <% if entry.transfer.present? %>
    <% unless show_balance %>
      <div class="col-span-2"></div>
    <% end %>

    <div class="col-span-2">
      <%= render "account/transfers/account_logos", transfer: entry.transfer, outflow: entry.outflow? %>
    </div>
  <% else %>
    <div class="flex items-center gap-1 col-span-2">
      <%= render "categories/menu", transaction: transaction, origin: origin %>
    </div>

    <% unless show_balance %>
      <%= tag.div class: "col-span-2 overflow-hidden truncate" do %>
        <% if entry.new_record? %>
          <%= tag.p account.name %>
        <% else %>
          <%= link_to account.name,
                      account_path(account, tab: "transactions"),
                      data: { turbo_frame: "_top" },
                      class: "hover:underline" %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>

  <div class="col-span-2 ml-auto">
    <%= content_tag :p,
                    format_money(-entry.amount_money),
                    class: ["text-green-600": entry.inflow?] %>
  </div>

  <% if show_balance %>
    <div class="col-span-2 justify-self-end">
      <% if entry.account.investment? %>
        <%= tag.p "--", class: "font-medium text-sm text-gray-400" %>
      <% else %>
        <%= tag.p format_money(entry.trend.current), class: "font-medium text-sm text-gray-900" %>
      <% end %>
    </div>
  <% end %>
</div>
