<% readonly = @issue.status.is_closed? %>

<% @issue.line_items.build if @issue.line_items.empty? && !readonly %>

<div class="box tabular"
     data-nested-form
     data-wrapper-selector=".line-item">

  <strong><%= t :label_line_items %></strong>

  <table class="list line-items-table">
    <thead>
      <tr>
        <th style="width:60%;"><%= t :label_description %></th>
        <th style="width:10%;"><%= t :label_qty %></th>
        <th style="width:10%;"><%= t :label_price %></th>
        <th style="width:10%;"><%= t :label_total %></th>
        <% unless readonly %>
          <th style="width:80px;"></th>
        <% end %>
      </tr>
    </thead>

    <tbody data-nested-form-container>
      <%= f.fields_for :line_items do |item_form| %>
        <%= render "line_items/line_item_fields",
              f: item_form,
              readonly: readonly %>
      <% end %>
    </tbody>
  </table>

  <p class="line-items-grand-total">
    <strong><%= t :label_total %>:</strong>
    <span id="line-items-grand-total">0.00</span>
  </p>

  <% unless readonly %>
    <template data-nested-form-template>
      <%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
        <%= render "line_items/line_item_fields",
              f: item_form,
              readonly: false %>
      <% end %>
    </template>

    <p>
      <button type="button"
              class="icon icon-add"
              data-nested-form-add>
        <%= l(:button_add) %>
      </button>
    </p>
  <% end %>

</div>