  <section class="content mt-4">
    <div class="container-fluid">
      <div class="card" style="border-radius: 10px; background-color: #1d2532;">
      <nav>
          <div class="nav nav-tabs transaction nav-fill" id="myTab" role="tablist">
              <a class="nav-item nav-link active" href="#pending" data-toggle="tab" role="tab" aria-controls="nav-home" aria-selected="true">
            Available
              </a>
              <a class="nav-item nav-link" href="#mobilestockist" data-toggle="tab" role="tab" aria-controls="nav-profile" aria-selected="false">
            Out of Stock
              </a>
            
          </div>
      </nav>

      <div class="tab-content">
        <div role="tablist" class="active tab-pane" id="pending">
          <div class="card-body pt-4">
            <div align="right" class="mb-3">
              <a data-toggle="modal" data-target="#addProduct" class="btn btn-success btn-sm text-white">Add Product</a>
            </div>
               <div class="modal" id="addProduct">
                <div class="modal-dialog">
                  <div class="modal-content" style="background-color: #151e27!important;">
                    <div class="modal-header pb-0" style="border: 0px;">
                      <h5 class="modal-title text-white" style="font-weight: bold;">Add Product</h5>
                    </div>
                    <form style="margin: 0px;" method="POST" id="myform">
                      <div class="modal-body pt-2 pb-0">
                        <div class="form-group">
                          <label class="mb-1">
                            <small>Select Product</small>
                          </label>
                          <select class="select2" multiple="multiple" name="product[]" placeholder="Select a product" required>
                            <?php 
                              $sqlProductSelect = "SELECT * FROM tbl_product";
                              $resultProductSelect = $conn->query($sqlProductSelect);
                                while($rowProductSelect = mysqli_fetch_array($resultProductSelect)) {
                                  $product_id = $rowProductSelect['product_id'];

                                  $sqlYourProduct = "SELECT * FROM tbl_stockist_inventory WHERE stockist_id = '$stockist_id' AND product_id = '$product_id'";
                                  $resultYourProduct = $conn->query($sqlYourProduct);
                                  if ($resultYourProduct->num_rows < 1) {
                            ?>
                              <option value="<?php echo $rowProductSelect['product_id'] ?>"><?php echo $rowProductSelect['product_name'] ?></option>
                            <?php } } ?>
                          </select>
                        </div>
                        <div class="form-group">
                          <label class="mb-1">
                            <small>Quantity</small>
                          </label>
                          <input type="number" name="number_of_stock" class="form-control" placeholder="Enter a Value" required>
                        </div>
                      </div>
                      <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                        <div class="row">
                          <div class="col-6">
                            <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                          </div>
                          <div class="col-6">
                            <button type="submit" name="addProduct" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                          </div>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
              </div>

            <table id="unassign_table" class="table table-striped text-white">
              <thead>
              <tr>
                <th width="15%">Product ID</th>
                <th>Product</th>
                <th>Stock(s)</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php 
                $sqlProductInventory = "SELECT * FROM tbl_stockist_inventory WHERE stockist_id = '$stockist_id' AND number_stocks != 0";
                $resultProductInventory = $conn->query($sqlProductInventory);
                  while($rowProductInventory = mysqli_fetch_array($resultProductInventory)) {
                    $productID = $rowProductInventory['product_id'];

                    $sqlProductDetails = "SELECT * FROM tbl_product WHERE product_id = '$productID'";
                    $resultProductDetails = $conn->query($sqlProductDetails);
                    $rowProductDetails = mysqli_fetch_assoc($resultProductDetails);
              ?>
                <tr>
                  <td><?php echo $rowProductInventory['product_id']; ?></td>
                  <td><?php echo $rowProductDetails['product_name']; ?></td>
                  <td><span class="badge badge-success"><?php echo $rowProductInventory['number_stocks']; ?></span></td>
                  <td>
                    <a data-toggle="modal" data-target="#removeProduct" data-product-id="<?php echo $rowProductInventory['id']; ?>" class="btn btn-sm btn-danger text-white removeBtn">Remove</a>
                  </td>
                </tr>
              <?php } ?>
              </tbody>
          </table>
       </div> 

       <div class="modal" id="removeProduct">
        <div class="modal-dialog">
          <div class="modal-content" style="background-color: #151e27!important;">
            <div class="modal-header pb-0" style="border: 0px;">
              <h5 class="modal-title text-white" style="font-weight: bold;">Remove</h5>
            </div>
            <form style="margin: 0px;" method="POST" id="myform">
              <input type="hidden" name="id" id="productID">
              <div class="modal-body pt-0 pb-0">
                <p class="text-muted">Are you sure you want to remove?</p>
              </div>
              <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                <div class="row">
                  <div class="col-6">
                    <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                  </div>
                  <div class="col-6">
                    <button type="submit" name="remove" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>

     </div>
 
    <div role="tablist" class="tab-pane" id="mobilestockist">
        <div class="card-body pt-4">
            <table id="example2" class="table table-striped text-white">
              <thead>
                <tr>
                  <th width="15%">Product ID</th>
                  <th>Product</th>
                  <th>Sold(s)</th>
                  <th width="20%">Action</th>
                </tr>
              </thead>
              <tbody>
              <?php 
                $sqlProductInventory = "SELECT * FROM tbl_stockist_inventory WHERE stockist_id = '$stockist_id' AND number_stocks = 0";
                $resultProductInventory = $conn->query($sqlProductInventory);
                  while($rowProductInventory = mysqli_fetch_array($resultProductInventory)) {
                    $productID = $rowProductInventory['product_id'];

                    $sqlProductDetails = "SELECT * FROM tbl_product WHERE product_id = '$productID'";
                    $resultProductDetails = $conn->query($sqlProductDetails);
                    $rowProductDetails = mysqli_fetch_assoc($resultProductDetails);

                    $sqlNumberSold = "SELECT sum(tbl_user_checkout_details.quantity) as total_sold FROM tbl_user_checkout_details LEFT JOIN tbl_user_checkout ON tbl_user_checkout_details.order_number = tbl_user_checkout.order_number WHERE tbl_user_checkout_details.product_id = '$productID' AND tbl_user_checkout.assigned_stockist = '$stockist_id' AND tbl_user_checkout.order_status = '4'";
                    $resultNumberSold = $conn->query($sqlNumberSold);
                    $rowNumberSold = mysqli_fetch_assoc($resultNumberSold);
              ?>
                    <tr>
                      <td><?php echo $rowProductInventory['product_id']; ?></td>
                      <td><?php echo $rowProductDetails['product_name']; ?></td>
                      <td><span class="badge badge-success"><?php echo $rowNumberSold['total_sold']; ?></span></td>
                      <td>
                        <a data-toggle="modal" data-target="#restock<?php echo $rowProductInventory['id']; ?>" class="btn btn-sm btn-success text-white">Restock</a>
                      </td>
                    </tr>

                    <div class="modal" id="restock<?php echo $rowProductInventory['id']; ?>">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Restock</h5>
                          </div>
                          <form style="margin: 0px;" method="POST" id="myform">
                          <input type="hidden" name="id" value="<?php echo $rowProductInventory['id']; ?>">
                          <div class="modal-body pt-2 pb-0">
                            <div class="form-group">
                              <input type="number" name="quantity" class="form-control" placeholder="Enter a value" required>
                            </div>
                          </div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                              </div>
                              <div class="col-6">
                                <button type="submit" name="save" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                              </div>
                            </div>
                          </div>
                          </form>
                        </div>
                      </div>
                    </div>
              <?php } ?>
              </tbody>
            </table>
            </div>
          </div>
   </div>
 
   </div> 



      </div>
    </div>
  </section>