<% if @line_item.try(:errors).present? %>
  <%= render 'shared/error_messages', :target => @line_item %>
<% end %>

<%= form_for(@order, :url => admin_order_url(@order), :html => { :method => :put}) do |f| %>
  <%= f.hidden_field :number %>
  <table class="index">
    <tbody id='line-items'>
      <tr>
        <%= hook :admin_order_form_line_items_headers do %>
          <th><%= t('item_description') %></th>
          <th class="price"><%= t('price') %></th>
          <th class="qty"><%= t('qty') %></th>
          <th class="total"><span><%= t('total') %></span></th>
        <% end %>
        <th class="orders-actions"><%= hook :admin_order_form_line_items_header_actions %></th>
      </tr>
      <%= f.fields_for :line_items do |li_form| %>
        <%= render :partial => "admin/orders/line_item", :locals => { :f => li_form } %>
      <% end %>
    </tbody>
    <%= hook :admin_order_form_subtotal do %>
      <tbody id='subtotal'>
        <tr id="subtotal-row">
          <td colspan="3"><b><%= t('subtotal') %>:</b></td>
          <td class="total"><span><%= number_to_currency @order.item_total %></span></td>
          <td></td>
        </tr>
      </tbody>
    <% end %>
    <%= hook :admin_order_form_adjustments do %>
      <tbody id="order-charges">
        <% @order.adjustments.each do |adjustment| %>
          <tr>
            <td colspan="3"><strong><%= adjustment.label %></strong></td>
            <td class="total"><span><%= number_to_currency adjustment.amount %></span></td>
            <td></td>
          </tr>
        <% end %>
      </tbody>
    <% end %>
    <%= hook :admin_order_form_total do %>
      <tbody id='order-total'>
        <tr>
          <td colspan="3"><b><%= t('order_total') %>:</b></td>
          <td class="total"><span id="order_total"><%= number_to_currency @order.total %></span></td>
          <td></td>
        </tr>
      </tbody>
    <% end %>
  </table>

  <%= hook :admin_order_form_buttons do %>
    <p class="form-buttons">
      <%= button @order.complete? ? t('update') : t('continue') %>
      <%= t("or") %> <%= link_to t("actions.cancel"), admin_orders_url %>
    </p>
  <% end %>

<% end %>

<script type="text/javascript">
  <%= render 'admin/shared/update_order_state.js' %>
</script>

<%= javascript_include_tag 'admin/orders/edit_form.js' %>