<% page_title "Batch Upload" %>
<%= render "uploads/secondary_links" %>

<div id="c-uploads">
  <div id="a-batch">
    <h1>Batch Upload</h1>

    <%= simple_form_for(:batch, url: batch_uploads_path, method: :get, defaults: { required: false }, html: { class: "one-line-form" }) do |f| %>
      <%= f.input :url, label: "URL", input_html: { size: 70, value: @url, placeholder: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746" } %>
      <%= f.submit "Fetch" %>
    <% end %>

    <% if @source.present? %>
      <section>
        <% @source.image_urls.zip(@source.preview_urls).each.with_index do |(url, preview_url), i| %>
          <div class="upload-preview">
            <p class="caption-top">
              <%= link_to "Image ##{i}", new_upload_path(url: url, ref: @url), target: "_blank" %>
            </p>

            <%= link_to new_upload_path(url: url, ref: @url), target: "_blank" do %>
              <% if ImageProxy.needs_proxy?(url) %>
                <%= image_tag(image_proxy_uploads_path(url: preview_url)) %>
              <% elsif url.is_a?(String) %>
                <%= image_tag preview_url %>
              <% else %>
                Direct Link
              <% end %>
            <% end %>
          </div>
        <% end %>

        <p><%= link_to "Open all links in new tabs", "#", :id => "link" %></p>
      </section>
    <% end %>
  </div>
</div>
