<% if card.image.attached? %>
  <%= button_to card_image_path(card), method: :delete, class: "btn" do %>
    <%= icon_tag "picture-remove" %>
    <span class="for-screen-reader">Clear background image</span>
  <% end %>
<% elsif !card.closed? %>
  <%= form_with model: card, url: collection_card_path(card.collection, card), data: { controller: "form" } do |form| %>
    <label class="btn">
      <%= icon_tag "picture-add" %>
      <span class="for-screen-reader">Add background image</span>
      <%= form.file_field :image, class: "input",
            accept: "image/png, image/jpeg, image/jpg, image/webp",
            data: { action: "upload-preview#previewImage form#submit", upload_preview_target: "input" },
            hidden: true %>
    </label>
  <% end %>
<% end %>
