<%= stylesheet_link_tag 'wk-time', plugin: "redmine_wktime" %>
<%= javascript_include_tag 'index', plugin: "redmine_wktime" %>
<script type="text/javascript">
	productModifyUrl="<%= "#{url_for(controller: "wklogmaterial", action: 'modifyProductDD')}" %>";
	productItemUrl="<%= "#{url_for(controller: "wkproductitem", action: 'getItemDetails')}" %>";
</script>
<h2><b><%= l(:label_assemble_item) %></b></h2>
<%= form_tag({controller: controller_name, action: 'update'}, method: :post, id: 'query_form') do %>
  <div id="product_item_form">
		<%= hidden_field_tag('product_item_id', @productItem&.id || "") %>
		<%= hidden_field_tag('inventory_item_id', @inventoryItem&.id || "") %>
		<%= hidden_field_tag('product_type', controller.getItemType) %>
		<%= render :partial => 'wkproductitem/edit_product_item', locals: {invntItem: @inventoryItem} %>
		<div style="clear:both;"></div>
		<fieldset id="date-range" class="collapsible">
			<legend onclick="toggleFieldset(this);" class="icon icon-expanded"><%= l(:label_additional_info) %></legend>
			<div class="splitcontent">
				<%= render :partial => 'wkproductitem/edit_inventory', locals: {invntItem: @inventoryItem, isTransfer: false}%>
			</div>
		</fieldset>
	</div>
  <div style="clear:both"></div>
  <div>
    <%= render partial: "child_component", locals: { component: []} %>
  </div>
<%= submit_tag l(:button_save),  hidden: false, id: 'items_save'%>
<% end %>
<%
    locationArr = WkLocation.order(:name).pluck(:name, :id)
    productArr = getProductArray(WkProduct, '', 'I', false)
    locationId = locationArr[0][1] || nil
    productId = productArr[0][1] || nil
    itemArr = getPdtItemArr(productId, false, 'I', locationId)
    productSNs = getProductSNs(itemArr[0][1]) if itemArr.present?
%>
<div id="assembleItem">
  <div class="box tabular" style="width: 100%;">
    <%= hidden_field_tag 'product_serial_numbers', productSNs.to_json || [] %>
    <%= hidden_field_tag 'item_avail_quantity'%>
    <table style="width: 100%;">
      <tr>
        <th><%= l(:field_location) %></th>
        <td><%= select_tag('location_id', options_for_select(locationArr), style: "width:200px;", onchange: "productChanged('product', 'product_item', #{User.current.id}, true, false, null, 'location_id'); ") %></td>
      </tr>
      <tr>
        <th><%= l(:label_product) %></th>
        <td><%= select_tag('product', options_for_select(productArr), style: "width:200px;", onchange: "productChanged(this.id, 'product_item', #{User.current.id}, true, false, null, 'location_id'); ") %></td>
      </tr>
      <tr>
        <th><%= l(:label_item) %></th>
        <td><%= select_tag('product_item', options_for_select(itemArr), onchange: "itemChanged(this.value);", style: "width:200px;") %></td>
      </tr>
      <tr>
        <th><%= l(:field_quantity) %></th>
        <td><%= text_field_tag('quantity')%> <%= l(:label_available_quantity)%>: <span id="avail_quantity"></span> </td>
      </tr>
      <tr>
        <th><%= l(:label_serial_number) %></th>
        <td><%= text_area_tag('serial_no','', class: 'itemSN')%><div><%= l(:label_serial_number_note) %></div>
        <span class="icon icon-warning warning" id="warn_serial_number" style="background-color: unset; border: 0;display:none;"><%= l(:warn_sn_range) %></span></td>
        </td>
      </tr>
    </table>
  </div>
</div>