<div class="modal fade" id="edit">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
          	<div class="modal-header">
            	<h4 class="modal-title"><b>Update Complaint</b></h4>
            	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
              		<span aria-hidden="true">&times;</span>
                </button>
          	</div>

          	<div class="modal-body">
          	    <form class="forms-sample" method="POST" action="editComplaint.php">
                    <input type="hidden" name="id" id="ucid" value="">
                    <input type="hidden" name="ptype" id="ptype" value="">

                    <div class="form-group">
                        <label for="remarks">Official Remarks</label>
                        <textarea class="form-control" name="remarks" required id="remarks" rows="4"></textarea>
                    </div>

                    <div class="form-group">
                        <label>Status</label>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="1">
                                Assigned
                            </label>
                        </div>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="2">
                                Completed
                            </label>
                        </div>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="5">
                                Complaint Transfer to Other Contractor
                            </label>
                        </div>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="6">
                                Material Not Available
                            </label>
                        </div>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="7">
                                Qtr Found Locked
                            </label>
                        </div>

                        <div class="form-check form-check-primary">
                            <label class="form-check-label">
                                <input type="radio" name="c_status" class="c_status form-check-input" value="3">
                                Cancelled
                            </label>
                        </div>
                    </div>

                    <div id="materialBox" style="display:none;">
                        <hr>
                        <h5>Material Used</h5>

                        <div id="materialRows">
                            <div class="row material-row mb-2">
                                <div class="col-md-7">
                                    <label>Material Name</label>
                                    <select name="material_id[]" class="form-control material-select">
                                        <option value="">Select Material</option>
                                        <?php
                                        if($materials && $materials->num_rows > 0) {
                                            while($mat = $materials->fetch_assoc()) {
                                        ?>
                                            <option 
                                                value="<?= $mat['m_id']; ?>" 
                                                data-unit="<?= htmlspecialchars($mat['m_unit']); ?>"
                                            >
                                                <?= htmlspecialchars($mat['material_name']); ?>
                                                <?php if(!empty($mat['serial_number'])) { ?>
                                                    - <?= htmlspecialchars($mat['serial_number']); ?>
                                                <?php } ?>
                                            </option>
                                        <?php } } ?>
                                    </select>
                                </div>

                                <div class="col-md-3">
                                    <label>Qty</label>
                                    <input type="number" step="0.01" min="0" name="qty[]" class="form-control" placeholder="Qty">
                                </div>

                                <div class="col-md-2">
                                    <label>Unit</label>
                                    <input type="text" name="unit[]" class="form-control unit-field" readonly>
                                </div>
                            </div>
                        </div>

                        <button type="button" class="btn btn-success btn-sm mt-2" id="addMaterial">
                            + Add More
                        </button>
                    </div>

                    <br>
                    <button type="submit" name="submit" class="btn btn-primary me-2">Submit</button>
                </form>
            </div>
        </div>
    </div>
</div>