<?php 
include('include/session.php');
// session_start();
include('include/navigation.php');
include('connection.php');
$dbConnection = new DbConnection();
$connection = $dbConnection->connection;
?>
<html lang="en">
<head>
    <link rel="stylesheet" href="assets/css/style.css">
<?php
include('include/header_links.php');

?>
</head>
<style>
    .variation_form{
        width:100%;
        display:flex;
        justify-content:center;
        align-items:center;
    }
    .form-group{
        width:100%;
    }
    
    .variation_button{
        display:flex;
        justify-content:center;
    }
    #clientUid{
        width:80%;
    }
</style>
<body>
    <div class="container_main">
        <h1>Add Stock</h1>
              <div id="warantee_button">
                    <div class="item-left"><button class="reset-button"><a href="_stock_list.php"><i class="fa-solid fa-backward"></i></a></button></div>
                     <div class="reset-button item-right"><a href="_order_list.php">Order Summary</a></div>
                </div>
       
         <!--<h3>Client UID: -->
         <!--       <select data-live-search="true" name="cuid" id="clientUid" required >-->
         <!--       <option value="">Select Client UID</option>-->
                
                       <?php
                    //     $option = mysqli_query($connection, "SELECT * FROM clients");-->
                    //     while ($row = mysqli_fetch_array($option)) {-->
                    //       echo '<option value="' . $row['u_id'] . '">' . $row['u_id'] . ' - ' . $row['firm_name'] . ' - ' . $row['address'] . '</option>';-->
                    //   }
                      ?>
            
         <!--       </select></h3><br><br>-->
            <form action="add_category.php"method="POST">
            <div class="form-group">
            <h3>Add Category</h3><br>
                    <div class="input-group mb-3">
                         
                        <input type="text" class="form-control" placeholder="Add Category" aria-label="Recipient's username" aria-describedby="basic-addon2" name="category" required>
                        <button class="btn btn-outline-secondary" type="submit" name="submit">Add category</button>
               
                    </div>
            </div>
            </form>

  <form action="add_product.php" method="POST">
    <div class="form-group">  
        <h3>Add Product</h3><br>
        <div class="input-group">
        
            <select class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" name="category" required>
                <option value=""> Select Category </option>
            <?php
                        $sql = "SELECT * FROM category";
                        $result = $connection->query($sql);

                        // Check if there are rows in the result
                        if ($result->num_rows > 0) {
                            while ($row = $result->fetch_assoc()) {
                                echo '<option value="' . $row["category"] . '">' . $row["category"] . '</option>';
                            }
                        }
                    ?>
            </select>
            <input type="text" class="form-control" placeholder="Add Product" aria-label="Text input with segmented dropdown button" name="product" required>
            <button type="submit" class="btn btn-outline-secondary" name="submit">Add Product</button>
        </div>
    </div>
</form>

<form action="add_product_variation.php" method="POST" class="variation_form">
    <div class="form-group">  
        
    <h3>Add Product Variation</h3><br>
     <div class="form-group row">
          <label for="inputPassword" class="col-sm-2 col-form-label"><h5>Select Product:</h5></label>
         <div class="col-sm-10">
                <select data-live-search="true" class="form-control" name="product" id="">
                <option value="">Select Product</option>
                
                     <?php
            $sql = "SELECT * FROM product ORDER BY category"; // Assuming 'products' is the table name
            $result = $connection->query($sql);
            if ($result->num_rows > 0) {
                $current_category = "";
                while ($row = $result->fetch_assoc()) {
                    if ($current_category != $row['category']) {
                        if ($current_category != "") {
                            echo '</optgroup>'; // Close the previous category
                        }
                        echo '<optgroup label="' . $row["category"] . '">'; // Start a new category
                        $current_category = $row['category'];
                    }
                    echo '<option value="' . $row["product"] . '">' . $row["product"] . '</option>';
                }
                echo '</optgroup>'; // Close the last category
            }
        ?>
                </select></h5>
        </div></div>
                
      <div class="form-group row">
    <label for="inputPassword" class="col-sm-2 col-form-label"><h5>Product Variation:</h5></label>
    <div class="col-sm-10">
         <input type="text" class="form-control" placeholder="Enter Product variation" aria-label="Text input with segmented dropdown button" name="variation"required>
    </div>
  </div>
  
     <div class="form-group row">
    <label for="inputPassword" class="col-sm-2 col-form-label"><h5>Product Id:</h5></label>
    <div class="col-sm-10">
         <input type="text" class="form-control" placeholder="Enter Product Id" aria-label="Text input with segmented dropdown button" name="product_id"required>
    </div>
  </div>
 
    <div class="form-group row">
    <label for="inputPassword" class="col-sm-2 col-form-label"><h5>Price:</h5></label>
    <div class="col-sm-10" style="display:flex;">
    <input type="text" class="form-control" value="Rs. " aria-label="Text input with segmented dropdown button" name="" style="width:10%;">
        <input type="text" class="form-control" placeholder="Enter Price" aria-label="Text input with segmented dropdown button" name="price"required>

    </div>
  </div>

       <div class="form-group row" width>
    <label for="inputPassword" class="col-sm-2 col-form-label"><h5>Quantity:</h5></label>
    <div class="col-sm-10">
         <input type="text" class="form-control" placeholder="Enter Quantity" aria-label="Text input with segmented dropdown button" name="quantity" required>

    </div>
  </div>
  <div class="variation_button">
   <button type="submit" class="btn btn-outline-secondary" name="submit">Add variation</button>
</div>
    </div>
</form>
</div>


 <section class="footer">
    <?php
    include_once("include/footer_two.php");
  ?>
     </section>
  </body>
 
  <?php 
 include("include/footer_link.php");
  ?>

 
<script src="assets/script/script.js"></script>
</html>

<?php
//ob_end_flush(); // Send the buffered output
?>
</html>