

<?php $__env->startSection('content'); ?>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>

    <script src="https://cdn.ckeditor.com/4.14.0/standard/ckeditor.js"></script>


    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/css/bootstrap-select.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js"></script>


    <main id="main" class="main">
        <?php if( Session::get('permissions.user_type') == 'A' ): ?>
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                        	<?php $__currentLoopData = ['danger', 'warning', 'success', 'info']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $msg): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
			                    <?php if(Session::has('alert-' . $msg)): ?>
			                        <h4 class="font-weight-light alert alert-<?php echo e($msg); ?>"><?php echo e(Session::get('alert-' . $msg)); ?></h4>
			                    <?php endif; ?>
			                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <form action="<?php echo e(url('admin/product-edit/')); ?>/<?php echo e(encrypt($productdetails->id)); ?>" method="POST" class="form-horizontal" id="formadd" enctype="multipart/form-data">
                                <?php echo csrf_field(); ?>
                                <div class="card-body">
                                    <h4 class="card-title" style="display: inline-block;padding: 0 10px 0 0;">Edit Product</h4>

                                    <input type="hidden" name="formid" value="<?php echo $productdetails->id; ?>">

                                    <div class="form-group m-t-20">
                                        <label>Category<span style="color:red;">*</span></label>
                                        <select class="form-control selectpicker2" name="categories_id[]" multiple="multiple" data-live-search="true" data-live-search-placeholder="Search" data-actions-box="true" id="cat_id" required>
                                        </select>
                                    </div>


                                    
                                    <div class="form-group m-t-20">
                                        <label>Product Title</label><span>*</span>
                                        <input type="text" class="form-control" id="product_title" name="product_title" placeholder="Enter Product Title" value="<?php echo e($productdetails->product_name); ?>" required>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Product Description</label><span>*</span>
                                        <textarea class="form-control" rows="5" id="product_description" name="product_description"  placeholder="Enter Product Description" required><?php echo e($productdetails->description); ?></textarea>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Content</label>
                                        <textarea class="form-control" rows="5" id="content" name="content" placeholder="Enter Content"><?php echo e($productdetails->content); ?></textarea>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Shipping</label>
                                        <textarea class="form-control" rows="5" id="shipping" name="shipping" placeholder="Enter Shipping"><?php echo e($productdetails->delivery_info); ?></textarea>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Has Attribute?</label><br>
                                        <span><input type="radio" name="has_attribute" class="pattribute" value="Y" <?php if($productdetails->has_attribute=="Y"): ?> checked <?php endif; ?>>Yes</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span><input type="radio" name="has_attribute" class="pattribute" value="N" <?php if($productdetails->has_attribute=="N"): ?> checked <?php endif; ?>>No</span>
                                    </div>
                                    
                                    <input type="hidden" name="attribute_title" id="attribute_title" value="<?php echo e($productdetails->has_attribute); ?>">

                                    <div class="form-group m-t-20 has_attribute_show" id="formfield" style="display:none">
                                        <label>Create Attribute</label><span>*</span>
                                            <?php 
                                                $index = 0; 
                                            ?>
                                            <?php if(count($attributedetails)>0): ?>
                                                <?php $__currentLoopData = $attributedetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $attributedetails): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <div>
                                                        <input type="text" name="attr_title[<?php echo e($index); ?>]" id="attr_title<?php echo e($index); ?>" placeholder="Enter Attribute Title" value="<?php echo e($attributedetails->title); ?>">&nbsp;&nbsp;&nbsp;
                                                        <input type="number" min=0 name="attr_price[<?php echo e($index); ?>]" id="attr_price<?php echo e($index); ?>" placeholder="Enter Price" value="<?php echo e($attributedetails->price); ?>">
                                                        <input type="number" min=0 name="attr_actual_price[<?php echo e($index); ?>]" id="attr_actual_price<?php echo e($index); ?>" placeholder="Enter MRP" value="<?php echo e($attributedetails->actual_price); ?>">
                                                        <span class="col-sm-2"><a class="deleteRow" data-aid="<?php echo e($attributedetails->id); ?>" href="javascript: void(0);"><i class="fas fa-trash-alt ibtnDel"></i></a></span>
                                                        <?php
                                                            $index++;
                                                        ?>
                                                    </div><br>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php else: ?>
                                                <div>
                                                    <input type="text" name="attr_title[<?php echo e($index); ?>]" id="attr_title<?php echo e($index); ?>" placeholder="Enter Attribute Title">&nbsp;&nbsp;&nbsp;
                                                    <input type="number" min=0 name="attr_price[<?php echo e($index); ?>]" id="attr_price<?php echo e($index); ?>" placeholder="Enter Price">
                                                    <input type="number" min=0 name="attr_actual_price[<?php echo e($index); ?>]" id="attr_actual_price<?php echo e($index); ?>" placeholder="Enter MRP">
                                                    <?php
                                                        $index++;
                                                    ?>
                                                </div><br>
                                            <?php endif; ?>
                                            <div class="addField"></div><br>
                                            <input type="button" class="btn btn-info" id="addrow" value="Add More Attribute" />
                                    </div>
                                    
                                    <div class="form-group m-t-20 no_attribute_show" >
                                        <label>Product Price</label><span>*</span>
                                        <input type="text" class="form-control" id="product_price" name="product_price" placeholder="Enter Product Price" value="<?php echo e($productdetails->price); ?>">
                                    </div>
                                    <div class="form-group m-t-20 actual_price">
                                        <label>MRP</label>
                                        <input type="number" class="form-control" id="product_actual_price" name="product_actual_price" min=0 <?php if(!$productdetails->actual_price): ?> value="0" <?php else: ?> value="<?php echo e($productdetails->actual_price); ?>" <?php endif; ?>>
                                        <span>Note: You can leave it blank if product price and actual price is same</span>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Delivery Delay Days</label><span>*</span>
                                        <input type="text" class="form-control" id="delivery_delay_days" name="delivery_delay_days" placeholder="0" value="<?php echo e($productdetails->delivery_delay_days); ?>" required>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Alt Keyword</label><span>*</span>
                                        <input type="text" class="form-control" id="alt_keyword" name="alt_keyword" placeholder="Enter Alt Keyword" value="<?php echo e($productdetails->alt_key); ?>" required>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Meta Title</label><span>*</span>
                                        <input type="text" class="form-control" id="meta_title" name="meta_title" placeholder="Enter Meta Title" value="<?php echo e($productdetails->meta_title); ?>" required>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Meta Description</label><span>*</span>
                                        <textarea class="form-control" rows="5" id="meta_description" name="meta_description" placeholder="Enter Meta Description" required><?php echo e($productdetails->meta_description); ?></textarea>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Search Tag</label>
                                        <input type="text" class="form-control" id="search_tag" name="search_tag" placeholder="Enter Search Tag" <?php if($productdetails->search_tag): ?> value="<?php echo e($productdetails->search_tag); ?>"<?php endif; ?>>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>FNID</label><span>*</span>
                                        <input type="text" class="form-control" id="fnid" name="fnid" placeholder="Enter FIND" value="<?php echo e($productdetails->fnid); ?>" required>
                                    </div>
                                    <div class="form-group m-t-20">
                                        <label>Extra Field</label><span>*</span>
                                        <input type="text" class="form-control" id="extra_field" name="extra_field" placeholder="Enter Extra Value" value="<?php echo e($productdetails->extra_field); ?>" required>
                                    </div>
                                </div>
                                <div class="border-top">
                                    <div class="card-body">
                                        <input class="btn btn-primary" type="submit" value="Update">
                                    </div>
                                </div>
                                
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>        
    </main><!-- End #main -->

    <script type="text/javascript">
        $(document).ready(function(){
            $('.selectpicker2').selectpicker();

            $.validator.setDefaults({
                    submitHandler: function(form) {
                        form.submit();
                    }
            });
            $(function() {
                // validate the comment form when it is submitted
                $("#formadd").validate({
                    ignore: [],
                    errorPlacement: function(label, element) {
                        label.addClass('mt-2 text-danger');
                        label.insertAfter(element);
                    },
                    highlight: function(element, errorClass) {
                        $(element).parents('.form-group').addClass('has-danger')
                        $(element).addClass('form-control-danger')
                    }
                  });
            });

            CKEDITOR.replace("product_description");
            CKEDITOR.replace("content");
            CKEDITOR.replace("shipping");


            $('#title').on('blur', function(){
                var title = $.trim($(this).val());
                if(title != ''){
                    //if($.trim($('#slug').val()) == ''){
                        $('#slug').val(title.replace(/ /g,"-").toLowerCase());
                        $('#slug-error').hide();
                    //}
                }
            });
               
            $('.pattribute').click(function(){
                if(this.value == 'Y'){
                    $('.has_attribute_show').slideDown();
                    $('.no_attribute_show').slideUp();
                    $('.actual_price').slideUp();
                    $('.product_actual_price').hide();
                    $("input[id*=attr_price]").attr("required",true);
                    $("input[id*=attr_title]").attr("required",true);
                    $("input[id*=product_price]").attr("required",false);
                }else{
                    $("input[id*=product_price]").attr("required",true);
                    $("input[id*=attr_price]").attr("required",false);
                    $("input[id*=attr_title]").attr("required",false);
                    $('.has_attribute_show').slideUp();
                    $('.no_attribute_show').slideDown();
                    $('.product_actual_price').show();
                    $('.actual_price').slideDown();

                }
            });
            
            if($('#attribute_title').val()=="Y"){
                    $('.has_attribute_show').slideDown();
                    $('.no_attribute_show').slideUp();
                    $('.actual_price').slideUp();
                    $("input[id*=attr_price]").attr("required",true);
                    $("input[id*=attr_title]").attr("required",true);
                    $("input[id*=product_price]").attr("required",false);
                }else{
                    $("input[id*=product_price]").attr("required",true);
                    $("input[id*=attr_price]").attr("required",false);
                    $("input[id*=attr_title]").attr("required",false);
                    $('.has_attribute_show').slideUp();
                    $('.no_attribute_show').slideDown();
                    $('.actual_price').slideDown();

                }

          
            $(function(){
                $('select').selectpicker();
            })
        });

        $(document).ready(function(){
            var counter = <?php echo e($index-1); ?>;
            $("#addrow").on("click", function () {

                if(counter < 9){
                    counter++;
                    var cols = '';
                    var newRow = $('<div class="row" style="margin-top: 5px;">');

                    cols += '<div class="col-sm-4"><input required class="form-control" placeholder="Enter Attribute Title" id="attr_title'+counter+'" name="attr_title['+counter+']" type="text"></div>';
                    cols += '<div class="col-sm-3"><input required class="form-control" placeholder="Enter Price" id="attr_price'+counter+'" name="attr_price['+counter+']" type="number" min=0></div>';
                    cols += '<div class="col-sm-3"><input required class="form-control" placeholder="Enter MRP" id="attr_actual_price'+counter+'" name="attr_actual_price['+counter+']" type="number" min=0></div>';
                    cols += '<div class="col-sm-2"><a class="deleteRow" href="javascript: void(0);"><i class="fas fa-trash-alt ibtnDel"></i></a></div>';

                    newRow.append(cols);
                    $(".addField").append(newRow);
                }else{
                    alert("You can't add more than 8 attributes.");
                }

            });

            $(".row").on("click", ".ibtnDel", function (event) {
                $(this).closest(".row").remove();
                counter--;
            });
            
        });

        
         
        $(document).ready(function(){
            <?php 
                $category_selected = implode(',',$category_selected);
            ?>

            $.ajaxSetup({
                  headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                  }
              });
            $.ajax({
              type : "POST",
              url : "<?php echo e(route('admin.getcategory')); ?>",
              data : { id : 99 },
              success : function(response){
                console.log(response)
                response = JSON.parse(response);
                if(response.status == "success"){
                  $('#cat_id').html(response.data);
                  $('#cat_id').selectpicker('val', [<?php echo $category_selected; ?>]);

                  
                  $('.selectpicker2').selectpicker('refresh');
                }
              },
              error : function(){

              }
            });
        });

</script> 

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/adminrighflorist/public_html/resources/views/admin/product/edit.blade.php ENDPATH**/ ?>