%# TODO: This is mostly just copy pasta from the field_field partial.
# Should we just try to make that partial aware of images?
# If not, should we make a new dedicated stimulus controler for this partial,
# instead of hijacking the "fields--file-field" controller?
%>
<%
form ||= current_fields_form
options ||= {}
other_options ||= {}
multiple ||= false
persisted_files = multiple ? form.object.send(method) : [form.object.send(method)]
options[:width] ||= 100
options[:height] ||= 100
# options[:resize_to_limit] ||= [options[:width], options[:height]]
%>
<%= render 'shared/fields/field', form: form, method: method, helper: :file_field, options: options, other_options: other_options do %>
<% content_for :field do %>
<%= form.file_field method, class: 'file-upload hidden', multiple: multiple, direct_upload: true, data: {'fields--file-field-target': 'fileField', action: 'change->fields--file-field#handleFileSelected'} %>
<% if form.object.send(method).attached? %>
<% persisted_files.each do |file| %>
<%= form.hidden_field "#{method}_removal".to_sym, multiple: multiple, value: nil, data: {'fields--file-item-target': 'removeFileFlag'} %>
<%= image_tag photo_url_for_active_storage_attachment(file, options), class: 'mb-1.5', data: {'fields--file-item-target': "fileName"} %>
<%= link_to url_for(file), class: 'button download-file mr-3', data: {'fields--file-item-target': 'downloadFileButton'} do %>
<%= t('fields.download_image') %>
<% end %>
<%= t('fields.remove_image') %>
<% end %>
<% end %>
<%= t('fields.upload_image') %>
<% end %>
<% end %>