<?php include "../config/config.php"; ?>   
<style>
.modal-open .modal {
    overflow-x: hidden;
    overflow-y: hidden;
}
</style>
<div class="modal-dialog modal-lg" role="document" id="add_modal" style="overflow-x: hidden; overflow-y: hidden;">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title mt-0" id="myLargeModalLabel"><b>Products Details</b></h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-top: -25px;"><i class="fa fa-times"></i></button>
            </div>
            
            <form id="form_details" method="post">
            <div id="content-div">
            
            
            <div class="modal-body" style="padding: 20px 40px 20px 40px;">
                
                
                <div class="row">
                    
                    
                    <div class="col-md-8">
                        <div class="form-group">
                            <label class="required" for="name">Name</label>
                            <input type="text" name="name" id="name" class="form-control" value="" required>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="required" for="product_hsn_code">HSN Code</label>
                            <input type="text" name="product_hsn_code" id="product_hsn_code" class="form-control" value="" required>
                        </div>
                    </div>
                    
                    
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="required" for="quantity">Quantity</label>
                            <input type="text" name="quantity" id="quantity" class="form-control" value="" required>
                        </div>
                    </div>
                    
                    
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="required" for="product_type">Product Type</label>
                            <select class="form-control" name="product_type" id="product_type" required>
                                <option value="1">Product Type</option>
                                <option value="2">Ornament Type</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="required" for="product_details">Product Details</label>
                            <select class="form-control" name="product_details" id="product_details" required>
                                <option value="">Select Product</option>
                                <?php $statement = $pdo->prepare("SELECT * FROM `tbl_ids_products` WHERE status=1");
                                    $statement->execute();
                                    $resultss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                    foreach ($resultss as $ress) { ?>
                                        <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        <div class="form-group">
                            <span class="btn btn-primary btn-xs" id="add_new_btn" style="margin-top: 25px;"><i class="fa fa-plus"></i> Add Size</span>
                        </div>
                    </div>
                    
                    
                </div>
               
                
                    
            
                    
                    <div class="form-group">
                        
                        <div class="row">
                            <div id="append_section" style="padding-top: 10px;">
                                
                                
                                <div class="col-md-3 row_size">
                                    <div class="form-group">
                                        <label>Size <span class="btn btn-danger btn-xs remove_size"><i class="fa fa-times"></i></span></label>
                                        <input type="text" name="size[]" id="" class="form-control" value="" >
                                    </div>
                                </div>
                                
                                
                            </div>
                        </div>
                    </div>
                    
                    
                    
                    
                    
                    <div class="form-group" hidden>
                        <label>Status</label>
                        <select class="form-control" name="status" id="status" required>
                            <option value="1">Active</option>
                            <option value="0">In-Active</option>
                        </select>
                    </div>
                    

            </div>
            
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Create</button>
            </div>
            
            
            </div>
            </form>
            
            
            
            <div id="loading-div" style="display: none; padding-bottom: 80px;">
                    <center><img src="img/loading.gif" style="width: 250px;"><br><b class="blinking">Processing Please Wait...</b></center>
            </div>
            
            
            
        </div>
    </div>
<script>
    $('#form_details').on('submit', function(e){
        console.log("Click And Form Working");
                e.preventDefault();
                $('#loading-div').show();
                $('#content-div').hide();
                var formData = new FormData(this);
                formData.append('type', 'create_products_name');
                            $.ajax({
                            url: 'apis/products.php',
                            type: 'post',
                            dataType: 'json',
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            enctype: 'multipart/form-data',
                            success: function (response) {
                                if(response['status']==200){
                                     /*alert(response['message']);*/
                                     $("#add_modal .close").click();
                                     $('#add_form').trigger("reset");
                                     emp_datas();
                                     $('#loading-div').hide();
                                     $('#content-div').show();
                                }else{
                                    alert(response['message']);
                                    $('#loading-div').hide();
                                    $('#content-div').show();
                                }
                                
                               
                            }
                        });
                
    });
</script>
<script>
$(document).ready(function() {
    
var count = 1;
$("#add_new_btn").click(function(){
    
    var row=`<div class="col-md-3 row_size">
                <div class="form-group">
                    <label>Size <span class="btn btn-danger btn-xs remove_size"><i class="fa fa-times"></i></span></label>
                    <input type="text" name="size[]" id="" class="form-control" value="" >
                </div>
            </div>`;
        
        $("#append_section").append(row);
        count++;
});
});

$(document).on('click', '.remove_size', function() {
        $(this).closest('.row_size').remove();
    });
</script>