%# A squawk's files: photos show as thumbnails that open the in-app viewer
(which has Download); other files open in a new tab and have a download link. %>
<% files = squawk.attachments.to_a %>
<% if files.any? %>
<% photos, others = files.partition { _1.image? && _1.variable? } %>
<% photos.each do |file| %>
<%= link_to rails_blob_path(file, disposition: :inline),
class: "block overflow-hidden rounded-md ring-1 ring-slate-300 hover:ring-2 hover:ring-sky-500 focus-visible:ring-2 focus-visible:ring-sky-500",
title: t(".preview", filename: file.filename),
data: { gallery_target: "item", action: "gallery#open", gallery_name: file.filename.to_s,
gallery_download: rails_blob_path(file, disposition: :attachment) } do %>
<%= image_tag file.variant(resize_to_fill: [ 160, 160 ]), alt: file.filename.to_s, loading: "lazy", width: 64, height: 64,
class: "block h-16 w-16 bg-slate-100 object-cover" %>
<% end %>
<% end %>
<% others.each do |file| %>
<%= link_to "📎 #{file.filename.to_s.truncate(28, omission: "…")}", rails_blob_path(file, disposition: :inline),
class: "px-2 py-1 text-sky-700 hover:bg-slate-100", target: "_blank", rel: "noopener", title: t(".open", filename: file.filename) %>
<%= link_to "⬇", rails_blob_path(file, disposition: :attachment), download: file.filename.to_s,
class: "border-l border-slate-300 px-1.5 py-1 text-slate-500 hover:bg-slate-100 hover:text-sky-700",
title: t(".download", filename: file.filename), aria: { label: t(".download", filename: file.filename) } %>
<% end %>
<% if photos.any? %>
"
class="m-0 h-dvh max-h-none w-screen max-w-none bg-transparent p-0 text-white backdrop:bg-black/90"
data-action="click->gallery#backdrop keydown->gallery#keydown touchstart->gallery#touchstart touchend->gallery#touchend">
<%= t(".open_2_html") %>
<%= t(".download_2_html") %>
" autofocus>✕
"
class="absolute left-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 px-3 py-2 text-2xl hover:bg-black/70">‹
"
class="absolute right-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 px-3 py-2 text-2xl hover:bg-black/70">›
<% end %>
<% end %>