<table>
  <tr>
    <td>
      <p class="lede">
        <%= t('.dear_customer') %>
      </p>
      <p>
        <%= t('.instructions') %>
      </p>
      <p>
        <%= t('.order_summary') %>
      </p>
      <table>
        <% @order.line_items.each do |item| %>
          <tr>
            <td><%= item.variant.sku %></td>
            <td>
              <%= item.variant.product.name %>
              <%= item.variant.options_text -%>
            </td>
            <td>(<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %></td>
          </tr>
        <% end %>
        <tr>
          <td></td>
          <td>
            <%= t('.subtotal') %>
          </td>
          <td>
            <%= @order.display_item_total %>
          </td>
        </tr>
        <% if @order.line_item_adjustments.exists? %>
          <% if @order.all_adjustments.promotion.eligible.exists? %>
            <% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
              <tr>
                <td></td>
                <td><%= t('spree.promotion') %> <%= label %>:</td>
                <td><%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %></td>
              </tr>
            <% end %>
          <% end %>
        <% end %>
        <% @order.shipments.group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %>
          <tr>
            <td></td>
            <td><%= t('spree.shipping') %> <%= name %>:</td>
            <td><%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %></td>
          </tr>
        <% end %>
        <% if @order.all_adjustments.eligible.tax.exists? %>
          <% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %>
            <tr>
              <td></td>
              <td><%= t('spree.tax') %> <%= label %>:</td>
              <td><%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %></td>
            </tr>
          <% end %>
        <% end %>
        <% @order.adjustments.eligible.each do |adjustment| %>
          <% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
          <tr>
            <td></td>
            <td><%= adjustment.label %>:</td>
            <td><%= adjustment.display_amount %></td>
          </tr>
        <% end %>
        <tr>
          <td></td>
          <td>
            <%= t('.total') %>
          </td>
          <td>
            <%= @order.display_total %>
          </td>
        </tr>
      </table>
      <p>
        <%= t('.thanks') %>
      </p>
    </td>
    <td class="expander"></td>
  </tr>
</table>
