<%# locals: (transaction:, can_upload: false, can_delete: false) %>
<% if can_upload && transaction.attachments.count < Transaction::MAX_ATTACHMENTS_PER_TRANSACTION %> <%= styled_form_with url: transaction_attachments_path(transaction), method: :post, multipart: true, local: true, class: "mb-4", data: { controller: "attachment-upload", attachment_upload_max_files_value: Transaction::MAX_ATTACHMENTS_PER_TRANSACTION - transaction.attachments.count, attachment_upload_max_size_value: Transaction::MAX_ATTACHMENT_SIZE } do |form| %>
<%= icon "plus", size: "lg", class: "mb-2 text-secondary" %>

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

<%= form.file_field :attachments, multiple: true, accept: Transaction::ALLOWED_CONTENT_TYPES.join(","), class: "hidden", data: { attachment_upload_target: "fileInput", action: "change->attachment-upload#updateSubmitButton" } %>

<%= t(".select_up_to", count: Transaction::MAX_ATTACHMENTS_PER_TRANSACTION, size: Transaction::MAX_ATTACHMENT_SIZE / 1.megabyte, used: transaction.attachments.count) %>

<%= render DS::Button.new( text: t(".upload"), variant: :primary, size: :sm, data: { attachment_upload_target: "submitButton" } ) %>
<% end %> <% elsif can_upload %>
<%= icon "alert-circle", size: "sm", color: "warning", class: "mt-0.5" %>
<%= t(".max_reached", count: transaction.attachments.count, max: Transaction::MAX_ATTACHMENTS_PER_TRANSACTION) %>
<% end %> <% if transaction.attachments.any? %>

<%= t(".files", count: transaction.attachments.count) %>

<% transaction.attachments.each do |attachment| %>
<% if attachment.image? %> <%= icon "image", size: "sm", color: "secondary" %> <% else %> <%= icon "file", size: "sm", color: "secondary" %> <% end %>

<%= attachment.filename %>

<%= number_to_human_size(attachment.byte_size) %>

<%= render DS::Link.new( href: transaction_attachment_path(transaction, attachment, disposition: :inline), variant: :outline, size: :sm, icon: "eye", text: "", target: "_blank" ) %> <%= render DS::Link.new( href: transaction_attachment_path(transaction, attachment, disposition: :attachment), variant: :outline, size: :sm, icon: "download", text: "", data: { turbo: false } ) %> <% if can_delete %> <%= render DS::Button.new( href: transaction_attachment_path(transaction, attachment), method: :delete, variant: :outline_destructive, size: :sm, icon: "trash-2", confirm: CustomConfirm.for_resource_deletion("attachment") ) %> <% end %>
<% end %>
<% else %>

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

<% end %>