<%# locals: (entry:, selectable: true, balance_trend: nil) %>

<div class="grid grid-cols-12 items-center text-gray-900 text-sm font-medium p-4 <%= @focused_record == entry ? "border border-gray-900 rounded-lg" : "" %>">
  <div class="pr-10 flex items-center gap-4 <%= balance_trend ? "col-span-6" : "col-span-8" %>">
    <% if selectable %>
      <%= check_box_tag dom_id(entry, "selection"),
                        disabled: entry.entryable.transfer?,
                        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 %>
        <% if entry.entryable.merchant&.icon_url %>
          <%= image_tag entry.entryable.merchant.icon_url, class: "w-6 h-6 rounded-full", loading: "lazy" %>
        <% else %>
          <%= render "shared/circle_logo", name: entry.display_name, size: "sm" %>
        <% end %>

        <div class="truncate">
          <div class="space-y-0.5">
            <div class="flex items-center gap-1">
              <% if entry.new_record? %>
                <%= content_tag :p, entry.display_name %>
              <% else %>
                <%= link_to entry.entryable.transfer? ? entry.entryable.transfer.name : entry.display_name,
                        entry.entryable.transfer? ? transfer_path(entry.entryable.transfer) : account_entry_path(entry),
                        data: { turbo_frame: "drawer", turbo_prefetch: false },
                        class: "hover:underline hover:text-gray-800" %>
              <% end %>

              <% if entry.excluded %>
                <span title="One-time <%= entry.amount.negative? ? "income" : "expense" %> (excluded from averages)">
                  <%= lucide_icon "asterisk", class: "w-4 h-4 shrink-0 text-orange-500" %>
                </span>
              <% end %>

              <% if entry.entryable.transfer? %>
                <%= render "account/transactions/transfer_match", entry: entry %>
              <% end %>
            </div>

            <div class="text-gray-500 text-xs font-normal">
              <% if entry.entryable.transfer? %>
                <%= render "transfers/account_links", transfer: entry.entryable.transfer, is_inflow: entry.entryable.transfer_as_inflow.present? %>
              <% else %>
                <%= link_to entry.account.name, account_path(entry.account, tab: "transactions", focused_record_id: entry.id), data: { turbo_frame: "_top" }, class: "hover:underline" %>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
    </div>
  </div>

  <div class="flex items-center gap-1 col-span-2">
    <%= render "account/transactions/transaction_category", entry: entry %>
  </div>

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

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