<table class="table table-striped">
  <tr>
    <th><%= t("views.right_panel.detail.product") %></th>
    <th><%= t("views.right_panel.detail.instance_name") %></th>
    <th><%= t("views.right_panel.detail.atrribute_name") %></th>
    <th><%= t("views.right_panel.detail.status") %></th>
    <th><%= t("views.right_panel.detail.action") %></th>
  </tr>

  <% cate_arr = Array.new %>
  <%
    count = 0
    @menu_items.each do |item|
    count += 1
  %>

    <tr>
      <td><%= item.name rescue '-' %></td>
      <% if !item.item_instance_name.blank? %>
        <td><%= item.item_instance_name rescue '-' %></td>
      <% else %>
        <td><p style="font-size: 20px;">-</p></td>
      <% end  %>
      <td><%= JSON.parse(MenuItemAttribute.where(id: item.item_attributes).pluck(:name).to_s).join(', ') %></td>
      <td>
        <% if item.is_out_of_stock %>
          <div class="badge badge-success">Active</div>
        <% else %>
          <div class="badge badge-danger">Inactive</div>
        <% end %>
      </td>
      <td>
        <button type="button" class="delete btn btn-danger btn-sm waves-effect" data-ref="<%= settings_out_of_stock_path(item) %>" data-method="delete">
          <%= t("views.btn.reset") %>
        </button>
        <span class="hidden" id="delete_text">
            <h6>Are you sure you want to delete this row ?</h6>
            <h6>This action can't be undo. </h6>
        </span>
      </td>
    </tr>
    <% end %>
</table>

<script>

  $('.show_track').on('click', function () {
    var ID = $(this).attr("data-value");
    window.location.href = '/inventory/'+ID+'/show';
  });

  $(document).on('click', '.update', function(event){

    var item_code = $("#instance_code").val();
    var min_qty = $("#min_qty").val();
    var max_qty = $("#max_qty").val();
    var item_name = $("#item_name").val();

    console.log(item_code);
    console.log(min_qty);
    console.log(max_qty);
    var params = {'item_code': item_code,
                    'min_order_level': min_qty,
                    'max_stock_level': max_qty};
    var ajax_url = 'settings_update_menu_items_path';
     $.ajax({
      type: "PATCH",
      url: ajax_url,
      data: params,
      dataType: "json",
       success:function(result){
         if (result.status) {
          swal("Success",result.message,"success");
         }else{
          swal("Opps",result.message,"warning");
         }
       }
    });
  });

</script>
