<%# nasty hack, otherwise postgres uses a bad query plan %>
<% fav_posts = user.faved_posts.with_user_post_fav.includes(:creator).limit(5) %>
<section class="animated-shadow-sky sky-section">
  <h2 class="section-header">
    <span class="font-medium text-slate-900">Favorited Posts</span>
    <span class="float-right">
      <%= link_to "#{user.user_post_favs.size} total", domain_user_favorites_path(user), class: "blue-link" %>
    </span>
  </h2>
  <% if fav_posts.any? %>
    <% fav_posts.each do |post| %>
      <div class="flex flex-col px-4 py-2">
        <span class="flex gap-2">
          <%= render "domain/has_description_html/inline_link_domain_post", post: post, visual_style: "sky-link" %>
          <span class="whitespace-nowrap flex-grow text-right text-slate-500">
            <% if (faved_at = post.user_post_fav&.faved_at) && (time = faved_at.time) %>
              <%= time_ago_in_words(faved_at.time) %> ago
            <% else %>
              unknown
            <% end %>
          </span>
        </span>
        <% if creator = post.primary_creator_for_view %>
          <span class="text-sm flex gap-1 items-center">
            <span class="text-slate-500 italic">by</span>
            <%= render "domain/has_description_html/inline_link_domain_user", user: creator, visual_style: "sky-link" %>
          </span>
        <% end %>
      </div>
    <% end %>
  <% else %>
    <div class="px-4 py-3 text-slate-500">No posts</div>
  <% end %>
</section>
