<tr data-part_id="<?= $partRow['part_id'] ?>">
   <td class="text-center">
    <div class="d-flex justify-content-center">
      <span class="part-serial mx-1"> <?= $partNum /* 계산된 일련번호 */ ?> </span>
      <button type="button" style="padding:2;" class="btn btn-primary btn-sm search-bending-btn" onclick="openBendingSearchModal(this)">
        <i class="bi bi-search"></i>
      </button>
    </div>
  </td>  
  <td class="text-center bg-light">    
	<!-- 중분류 -->
	<?php
	// 예: getCategoryByName($parentName) 함수가 존재하며,
	// '절곡물'이라는 2단계 카테고리의 자식(3단계) 카테고리 이름 배열을 리턴한다.
	$l3_list = getCategoryByName('스크린','절곡물');
	$currentPartName = isset($partRow['part_name']) ? $partRow['part_name'] : '';
	?>
	<select name="part_name[]" class="form-select mx-1 d-block w-auto" style="font-size: 0.8rem; height: 32px;">
		<option value="">(중분류)</option>
		<?php foreach($l3_list as $itemVal): ?>
			<option 
				value="<?= htmlspecialchars($itemVal, ENT_QUOTES, 'UTF-8') ?>"
				<?= ($currentPartName === $itemVal) ? 'selected' : '' ?>>
				<?= htmlspecialchars($itemVal, ENT_QUOTES, 'UTF-8') ?>
			</option>
		<?php endforeach; ?>
	</select>							  					    
  </td>
  <td class="text-center bg-light">
    <input type="text" name="spec[]" class="form-control" value="<?= htmlspecialchars($partRow['spec'], ENT_QUOTES, 'UTF-8') ?>">
  </td>
  <td class="text-center bg-light">
    <input type="text" name="unit[]" class="form-control" value="<?= htmlspecialchars($partRow['unit'], ENT_QUOTES, 'UTF-8') ?>">
  </td>
  <td class="text-center bg-light">
    <input type="number" name="quantity[]" class="form-control" value="<?= htmlspecialchars($partRow['quantity'], ENT_QUOTES, 'UTF-8') ?>">
  </td>
  <td class="text-center bg-light">
    <input type="text" name="unitprice[]" class="form-control text-end" value="<?= htmlspecialchars($partRow['unitprice'], ENT_QUOTES, 'UTF-8') ?>">
  </td>
  <td class="text-center bg-light">
    <input type="text" name="memo[]" class="form-control" value="<?= htmlspecialchars($partRow['memo'], ENT_QUOTES, 'UTF-8') ?>">
  </td>
  <td class="text-center bg-light w160px">
    <button type="button" class="btn btn-outline-dark btn-sm add-part-row" style="padding:5px;">+</button>
    <button type="button" class="btn btn-outline-danger btn-sm remove-part-row"  style="padding:5px;">-</button>
    <button type="button" class="btn btn-outline-secondary btn-sm toggle-subparts"> <i class="bi bi-caret-down"></i>하위 부품</button>
    <input type="hidden" name="part_id[]" value="<?= $partRow['part_id'] ?>">
  </td>
</tr>
<!-- 3단계 하위 부품 관리용 행 -->
<tr class="subparts-row" data-part_id="<?= $partRow['part_id'] ?>" data-part-name="<?= htmlspecialchars($currentPartName, ENT_QUOTES, 'UTF-8') ?>">
  <td colspan="8">    	  
    <div class="subparts-container d-flex justify-content-center">	
      <table class="table table-sm table-bordered subpartsTable w-95">
        <thead class="table-success">
		<tr>
		  <th class="text-center w150px">부품명</th>
		  <th class="text-center">재질</th>
		  <th class="text-center">연신율 합</th>
		  <th class="text-center">전개도 합</th>
		  <th class="text-center w110px">연신율 + 전개도</th>
		  <th class="text-center w100px">면적당 단가</th>
		  <th class="text-center w110px">단가</th>
		  <th class="text-center w60px">수량</th>
		  <th class="text-center w110px">단가합계</th>		  
		</tr>
        </thead>
        <tbody class="subpartsTable" >
          <?php
          // 해당 부품에 등록된 3단계 데이터 불러오기
          $sql_sub = "SELECT * FROM " . $DB . ".parts_sub WHERE part_id = ? AND is_deleted = 0 ORDER BY subpart_id ASC";
          $stmt_sub = $pdo->prepare($sql_sub);
          $stmt_sub->execute([$partRow['part_id']]);
          $subNum = 1;
          while ($subRow = $stmt_sub->fetch(PDO::FETCH_ASSOC)) {
              include '_part_sub_row.php';
              $subNum++;
          }
          ?>
        </tbody>
      </table>
    </div>    
  </td>
</tr>
