<style>
    .form-inputs textarea.form-control {
    border-radius: 20px !important;
    height: 36px;
}
    .green-button.add button {
    width: 145px;
    margin-top: 4px !important;
    padding: 7px;
}
</style>


<?php $__env->startSection('content'); ?>
<div class="pageloader" style="display:none;" >
</div>
<div class="common-content">
          <div class="page-content">
                <div class="page-heading">
                    <div class="headings">
                        <h6><?php echo e($title); ?></h6>
                    </div>
                </div>
                <input name="_token" type="hidden" id="token_vendor" value="<?php echo e(csrf_token()); ?>">
              <div class="boxings wraper">
			  <form method="POST" id="reg_sold" action="<?php echo e(url('vendors/category_request')); ?>" >
					<?php echo csrf_field(); ?>
					 <div id="amitems"> 
					  <div class="row">
							<div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
							<div class="form-inputs">
								 <div class="form-group">
									<label>Category Name<sup>*</sup></label>
								  <input  type="text" class="form-control validatname" id="category_name[]" name="category_name[]" value="" >
								  </div>
							</div>
						  </div>
						  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
							<div class="form-inputs">
								 <div class="form-group">
									<label>Category Description<sup>*</sup></label>
									<!--<input  type="text" class="form-control" id="category_description[]" name="category_description[]" value="" >-->
									<textarea class="form-control" id="category_description[]" name="category_description[]" value=""></textarea>
								  </div>
							</div>
						  </div>
						  <div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
							<div class="form-inputs">
								 <div class="green-button add">
									 <button class=""onclick="addcategory()">ADD<i class="fa fa-plus ml-2" aria-hidden="true"></i></button>
								  </div>
							</div>
						  </div>
					   </div>
					</div>
				 <div class="row">
                     <div class="col-12">
                        <div class="green-button  green-button2">
                            <button id="sold">Request Category</button>
                         </div>
                     </div>
                  </div>					
			</form>     
                <div class="page-heading">
                    <div class="headings">
                       <!-- <h6>Requested Categories</h6>-->
                    </div>
                </div>
                    
                    
               <div class="tableBox hideshadow" style="border-top: 1px solid #ddd;padding-top: 15px;"> 
              <?php if(count($category) > 0){ ?>

                <table id="example" class="table table-striped table-bordered" style="width:100%">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Category</th>
                            <th>Description</th>
                            <th>Status</th>
                            <th>Reason</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $category; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php //print_r($vendors);die; ?>
                        <tr>
                            <td><?php echo e($key+1); ?></td>
                            <td><?php echo e(ucfirst($cat->category)); ?></td>
                            <td><?php echo e(substr_replace($cat->description, "", 30)); ?></td>
                            <td><?php if($cat->request_status == '1'): ?> <span class="tabBt btn-outline-success">Approved</span> <?php elseif($cat->request_status == '0'): ?> <span class="tabBt btn-outline-warning">Pending</span> <?php elseif($cat->request_status == '2'): ?> <span class="tabBt btn-outline-danger">Rejected</span> <?php endif; ?></td>
                             <td><?php if(!empty($cat->reject_reason)): ?><?php echo e($cat->reject_reason); ?><?php else: ?> - <?php endif; ?></td>
                        </tr>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>



                    </tbody>
                </table>
            </div>       
                <?php }else{ ?>
                    <!--<div class="wraper">
                            <div class="product-display">
                                <ul>
                                    <li>
                                        <div class="details">
                                            <div>
                                                <h6>
                                                No Data available
                                                </h6>
                                            </div>


                                        </div>
                                    </li>


                                </ul>
                            </div>
                    </div>-->
                    
    <?php } ?>
              



  </div> <!-- boxings end -->

</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.js"></script>

<script type="text/javascript">
$(function(){
    $('#reg_sold').on('submit', function(event){
        event.preventDefault();
        
    });
});

var exits=0;

$(document).on("focusout",".validatname",function(){
   
    var data1 = {
					_token: $('#token_vendor').val(),
					category:$(this).val(),
	
				}
				$.ajax({
					url: baseurl + 'vendors/category_exist',
					type: "POST",
					data: data1,
					success: function(res) {
						
                        if(res!=0){
                            exits=1;
                           
                            swal("", "Category Name already exists in our database", "warning");
                        }
                        
					}
				});



});


    jQuery.validator.addMethod("checkForDuplicate", function (value, element) {
		
		var textValues = [];
		var valid = true;
		var lastProduct = element; // The current element being validated (this is the last product in the list when validation is called)
	
		// Loop through each product select box
		$("input.validatname").each(function () {
			var selectedValue = $(this).val();
			
			// Skip empty selections
			if (selectedValue !== "") {
				// Check if the product ID already exists in the textValues array
				if ($.inArray(selectedValue, textValues) !== -1) {
					// If a duplicate is found, set valid to false but only on the last element
					if (this === lastProduct) {
						valid = false;
						return false; // Stop the loop immediately once we find the duplicate in the last item
					}
				} else {
					textValues.push(selectedValue); // Add the value to the array if it's not a duplicate
				}
			}
		});
	
		// Return whether the last product is valid or not
		return valid;
	}, 'Category name exists');


//ADD REGISTER SOLD VALIDATION
$("#sold").click(function(){

   
	$("#reg_sold").validate({
		ignore: [],
        rules: {
            
			"category_name[]": {
                required: true,
                checkForDuplicate: true,
               
            },
			"category_description[]": {
                required: true
               
            }
			
			
        },
        submitHandler: function(form, e) {
            $(".pageloader").show();
            form.submit();
           
		  
        }
    });
});

$(".js-example-basic-multiple").select2({
  placeholder: "Select a Manufacturer"
});
var counter=1;
$(document).on("click", ".remove", function () {
	
	$(this).closest('.amcs').remove();
	counter--;
})
function addcategory(e){	
	var addoption='';
	addoption+='<div class="row amcs">';	
	addoption+='<div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">';
	addoption+='<div class="form-inputs">';
	addoption+='<div class="form-group">';
	addoption+=' <label>Category Name<sup>*</sup></label>';
	addoption+=' <input  type="text" class="form-control validatname" id="category_name'+counter+'" name="category_name[]" value="" >';
	addoption+='</div>';
	addoption+='</div>';
	addoption+='</div>';
	
	addoption+='<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">';
	addoption+='<div class="form-inputs">';
	addoption+='<div class="form-group">';
	addoption+=' <label>Category Description<sup>*</sup></label>';
	//addoption+=' <input  type="text" class="form-control" id="category_description'+counter+'" name="category_description[]" value="" >';
	addoption+=' <textarea class="form-control" id="category_description'+counter+'" name="category_description[]" value=""></textarea>';
	addoption+='</div>';
	addoption+='</div>';
	addoption+='</div>';



	
	addoption+='<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">';
    addoption+='<div class="form-inputs">';
    addoption+='<div class="green-button add">';
    addoption+='<button class="product-submit remove">Remove  <i class="fa fa-minus" aria-hidden="true"></i></button>';
    addoption+='</div>';
    addoption+='</div>';
    addoption+='</div>';
	
	addoption+='</div>';
	
	if(counter <5){
		$("#amitems").append(addoption);
		counter++;
	}

}
<?php if(Session::has('message')): ?>
      swal({
        title: "",
        text: "<?php echo e(Session::get('message')); ?>",
        type: "success",
        showCancelButton: false,
        dangerMode: false,
        confirmButtonText: 'OK',

    });
<?php endif; ?>
<?php if(Session::has('errormessage')): ?>
      swal({
        title: "",
        text: "<?php echo e(Session::get('errormessage')); ?>",
        type: "error",
        showCancelButton: false,
        dangerMode: true,
        confirmButtonText: 'OK',

    });
<?php endif; ?>

$(document).ready(function() {
    $('#example').DataTable();
} );

</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/meddbot/public_html/resources/views/vendors/requestcategory.blade.php ENDPATH**/ ?>