<commit_before><% allow_return_item_changes = !@return_authorization.customer_returned_items? %>

<div data-hook="admin_return_authorization_form_fields">
  <table class="index return-items-table">
    <thead>
      <tr data-hook="rma_header">
        <th>
          <% if allow_return_item_changes %>
            <%= check_box_tag 'select-all' %>
          <% end %>
        </th>
        <th><%= Spree.t(:product) %></th>
        <th><%= Spree.t(:state) %></th>
        <th><%= Spree.t(:charged) %></th>
        <th><%= Spree.t(:pre_tax_refund_amount) %></th>
        <th><%= Spree.t(:reimbursement_type) %></th>
        <th><%= Spree.t(:exchange_for) %></th>
      </tr>
    </thead>
    <tbody>
      <%= f.fields_for :return_items, @form_return_items do |item_fields| %>
        <% return_item = item_fields.object %>
        <% inventory_unit = return_item.inventory_unit %>
        <tr>
          <td class="align-center" class="inventory-unit-checkbox">
            <% if inventory_unit.shipped? && allow_return_item_changes %>
              <%= item_fields.hidden_field :inventory_unit_id %>
              <%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.pre_tax_amount}, '0', '1' %>
            <% end %>
          </td>
          <td>
            <div class="variant-name"><%= inventory_unit.variant.name %></div>
            <div class="variant-options"><%= inventory_unit.variant.options_text %></div>
          </td>
          <td class="align-center"><%= inventory_unit.state.humanize %></td>
          <td class="align-center">
            <%= return_item.display_pre_tax_amount %>
          </td>
          <td class="align-center">
            <% if inventory_unit.shipped? && allow_return_item_changes %>
              <%= item_fields.text_field :pre_tax_amount, { class: 'refund-amount-input' } %>
            <% else %>
              <%= return_item.display_pre_tax_amount %>
            <% end %>
          </td>
          <td>
            <% if inventory_unit.shipped? && allow_return_item_changes %>
              <%= item_fields.select :preferred_reimbursement_type_id, @reimbursement_types.collect{|r|[r.name.humanize, r.id]}, {include_blank: true}, {class: 'select2 fullwidth'} %>
            <% end %>
          </td>
          <td class="align-center">
            <% if inventory_unit.shipped? && allow_return_item_changes %>
              <% if return_item.exchange_processed? %>
                <%= return_item.exchange_variant.options_text %>
              <% else %>
                <%= item_fields.collection_select :exchange_variant_id, return_item.eligible_exchange_variants, :id, :options_text, { include_blank: true }, { class: "select2 fullwidth return-item-exchange-selection" } %>
              <% end %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>

  <%= f.field_container :amount do %>
    <%= Spree.t(:total_pre_tax_refund) %>: <span id="total_pre_tax_refund">0.00</span>
  <% end %>

  <%= f.field_container :stock_location do %>
    <%= f.label :stock_location, Spree.t(:stock_location) %>
    <%= f.select :stock_location_id, Spree::StockLocation.order_default.active.to_a.collect{|l|[l.name, l.id]}, {include_blank: true}, {class: 'select2 fullwidth', "data-placeholder" => Spree.t(:select_a_stock_location)} %>
    <%= f.error_message_on :stock_location_id %>
  <% end %>

  <%= f.field_container :reason do %>
    <%= f.label :reason, Spree.t(:reason) %>
    <%= f.select :return_authorization_reason_id, @reasons.collect{|r|[r.name, r.id]}, {include_blank: true}, {class: 'select2 fullwidth', "data-placeholder" => Spree.t(:select_a_return_authorization_reason)} %>
    <%= f.error_message_on :reason %>
  <% end %>

  <%= f.field_container :memo do %>
    <%= f.label :memo, Spree.t(:memo) %>
    <%= f.text_area :memo, {:style => 'height:100px;', :class => 'fullwidth'} %>
    <%= f.error_message_on :memo %>
  <% end %><commit_msg>Prevent admins from editing return items that have a processed exchange<commit_after><% allow_return_item_changes = !@return_authorization.customer_returned_items? %>

<div data-hook="admin_return_authorization_form_fields">
  <table class="index return-items-table">
    <thead>
      <tr data-hook="rma_header">
        <th>
          <% if allow_return_item_changes %>
            <%= check_box_tag 'select-all' %>
          <% end %>
        </th>
        <th><%= Spree.t(:product) %></th>
        <th><%= Spree.t(:state) %></th>
        <th><%= Spree.t(:charged) %></th>
        <th><%= Spree.t(:pre_tax_refund_amount) %></th>
        <th><%= Spree.t(:reimbursement_type) %></th>
        <th><%= Spree.t(:exchange_for) %></th>
      </tr>
    </thead>
    <tbody>
      <%= f.fields_for :return_items, @form_return_items do |item_fields| %>
        <% return_item = item_fields.object %>
        <% inventory_unit = return_item.inventory_unit %>
        <% editable = inventory_unit.shipped? && allow_return_item_changes && return_item.reimbursement.nil? %>
        <tr>
          <td class="align-center" class="inventory-unit-checkbox">
            <% if editable %>
              <%= item_fields.hidden_field :inventory_unit_id %>
              <%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.pre_tax_amount}, '0', '1' %>
            <% end %>
          </td>
          <td>
            <div class="variant-name"><%= inventory_unit.variant.name %></div>
            <div class="variant-options"><%= inventory_unit.variant.options_text %></div>
          </td>
          <td class="align-center"><%= inventory_unit.state.humanize %></td>
          <td class="align-center">
            <%= return_item.display_pre_tax_amount %>
          </td>
          <td class="align-center">
            <% if editable %>
              <%= item_fields.text_field :pre_tax_amount, { class: 'refund-amount-input' } %>
            <% else %>
              <%= return_item.display_pre_tax_amount %>
            <% end %>
          </td>
          <td>
            <% if editable %>
              <%= item_fields.select :preferred_reimbursement_type_id, @reimbursement_types.collect{|r|[r.name.humanize, r.id]}, {include_blank: true}, {class: 'select2 fullwidth'} %>
            <% else %>
              <%= return_item.preferred_reimbursement_type.try(:name) %>
            <% end %>
          </td>
          <td class="align-center">
            <% if editable %>
              <%= item_fields.collection_select :exchange_variant_id, return_item.eligible_exchange_variants, :id, :options_text, { include_blank: true }, { class: "select2 fullwidth return-item-exchange-selection" } %>
            <% elsif return_item.exchange_processed? %>
              <%= return_item.exchange_variant.options_text %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>

  <%= f.field_container :amount do %>
    <%= Spree.t(:total_pre_tax_refund) %>: <span id="total_pre_tax_refund">0.00</span>
  <% end %>

  <%= f.field_container :stock_location do %>
    <%= f.label :stock_location, Spree.t(:stock_location) %>
    <%= f.select :stock_location_id, Spree::StockLocation.order_default.active.to_a.collect{|l|[l.name, l.id]}, {include_blank: true}, {class: 'select2 fullwidth', "data-placeholder" => Spree.t(:select_a_stock_location)} %>
    <%= f.error_message_on :stock_location_id %>
  <% end %>

  <%= f.field_container :reason do %>
    <%= f.label :reason, Spree.t(:reason) %>
    <%= f.select :return_authorization_reason_id, @reasons.collect{|r|[r.name, r.id]}, {include_blank: true}, {class: 'select2 fullwidth', "data-placeholder" => Spree.t(:select_a_return_authorization_reason)} %>
    <%= f.error_message_on :reason %>
  <% end %>

  <%= f.field_container :memo do %>
    <%= f.label :memo, Spree.t(:memo) %>
    <%= f.text_area :memo, {:style => 'height:100px;', :class => 'fullwidth'} %>
    <%= f.error_message_on :memo %>
  <% end %>
{'fraction_non_alphanumeric': 0.17503729487817007, 'fraction_numerical': 0.0029835902536051715, 'mean_word_length': 2.7228135122628414, 'pattern_counts': {'":': 0, '<': 204, '<?xml version=': 0, '>': 214, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '257956', 'n_tokens_mistral': 2883, 'n_tokens_neox': 2628, 'n_words': 418}