<%= render :partial => 'spree/admin/shared/product_sub_menu' %>

<%= render :partial => 'spree/admin/shared/product_tabs', :locals => {:current => 'Images'} %>

<table class="index sortable" data-hook="images_table" data-sortable-link="<%= update_positions_admin_product_images_url(@product) %>">
  <tr data-hook="images_header">
    <th><%= t(:thumbnail) %></th>
    <% if @product.has_variants? %>
      <th><%= Spree::Variant.model_name.human %></th>
    <% end %>
    <th><%= t(:alt_text) %></th>
    <th><%= t(:action) %></th>
  </tr>

  <% @product.images.each do |image| %>
    <tr id="spree_image_<%= image.id %>" data-hook="images_row">
      <td>
        <span class="handle"></span>
        <%= link_to image_tag(image.attachment.url(:mini)), image.attachment.url(:product) %>
      </td>
      <% if @product.has_variants? %>
        <td><%= t(:all) %></td>
      <% end %>
      <td><%= image.alt %></td>
      <td class="actions">
        <%= link_to_with_icon 'edit', t(:edit), edit_admin_product_image_url(@product, image), :class => 'edit' %>
        &nbsp;
        <%= link_to_delete image, {:url => admin_product_image_url(@product, image) }%>
      </td>
    </tr>
  <% end %>

  <% @product.variants.each do |variant| %>
    <% variant.images.each do |image| %>
      <tr id="spree_image_<%= image.id %>" data-hook="images_row">
        <td><span class="handle"></span><%= link_to image_tag(image.attachment.url(:mini)), image.attachment.url(:product) %></td>
        <% if @product.has_variants? %>
          <td><%= variant.options_text %></td>
        <% end %>
        <td><%= image.alt %></td>
        <td class="actions">
          <%= link_to_with_icon 'edit', t(:edit), edit_admin_product_image_url(@product, image) %>
          &nbsp;
          <%= link_to_delete image, {:url => admin_product_image_url(@product, image) }%>
        </td>
      </tr>
    <% end %>
  <% end %>
</table>

<div id="images" data-hook></div>
<br />
<p data-hook="links">
    <%= link_to icon('add') + ' ' + t(:new_image), new_admin_product_image_url(@product), :id => 'new_image_link' %>
</p>
