<?php $__env->startPush('css'); ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-12">
        <div class="page-title-box">
            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">SIS</a></li>
                    <li class="breadcrumb-item"><a href="javascript: void(0);">CRM</a></li>
                    <li class="breadcrumb-item active">Product Update</li>
                </ol>
            </div>
            <h4 class="page-title">Product Update</h4>
        </div>
    </div>
</div>   
<!-- end page title --> 

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <form method="POST" action="<?php echo e(route('admin.products.update',[$item->id])); ?>" id="ajax_form">
                    <?php echo csrf_field(); ?>
                     <?php echo e(method_field('PATCH')); ?>

                    <div class="row">
                        
                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Product Name</label>
                            <input type="text" name="name" class="form-control" placeholder="Product Name" value="<?php echo e($item->name); ?>">
                        </div>
                      
                      	<div class="col-lg-4 mb-3">
                            <label  class="form-label">Product Sku</label>
                            <input type="text" name="sku" class="form-control" placeholder="Product Sku" value="<?php echo e($item->sku); ?>">
                        </div>

                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Product Brand</label>
                            <select class="form-select" name="type_id">
                                <option value="">Select One</option>
                                <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($type->id); ?>" <?php echo e($type->id == $item->type_id ?'selected':''); ?>> <?php echo e($type->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>

                        <div class="col-lg-4 mb-3">
                            <div>
                                <img src="<?php echo e(getImage('products',$item->image)); ?>" width="50" class="mb-2">
                            </div>
                            <label for="example-email" class="form-label">Image</label>
                            <input type="file" name="image" class="form-control">
                        </div>
                        <style>
                            .img-box{
                                position: relative;
                                padding: 5px;
                            }
                            .img-box a{
                                    position: absolute;
                                    top: 2px;
                                    right: 12px;
                                    font-size: 22px;
                                    font-weight: bold;
                                    color: red;
                            }
                        </style>
                        <div class="col-lg-4 mb-3">
                            <div class="d-flex">
                                <?php $__currentLoopData = $item->images; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                                <div class="img-box">
                                    <a href="<?php echo e(route('admin.deleteImage',[$image->id])); ?>" class="" onclick="return confirm(' you want to delete?');">&times;</a> 
                                    <img src="<?php echo e(getImage('products',$image->image)); ?>" width="50">
                                </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>
                            <label for="example-email" class="form-label">Multi Image</label>
                            <input type="file" name="images[]" class="form-control" multiple>
                        </div>

                        <div class="col-lg-4 mb-3">
                            <label for="example-email" class="form-label">Video Embedded Code</label>
                            <textarea name="video_link" class="form-control"><?php echo e($item->video_link); ?></textarea>
                        </div>

                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Product Category</label>
                            <select class="form-select" name="category_id">
                                <option value="">Select One</option>
                                <?php $__currentLoopData = $cats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($cat->id); ?>" <?php echo e($cat->id == $item->category_id ?'selected':''); ?>> <?php echo e($cat->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    
                            </select>
                        </div>


                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Sub Category</label>
                            <select class="form-select" name="sub_category_id">
                                <option value="">Select One</option>
                                <?php $__currentLoopData = $subs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sub): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($sub->id); ?>" <?php echo e($sub->id == $item->sub_category_id ?'selected':''); ?>> <?php echo e($sub->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                
                            </select>
                        </div>

                        <!--<div class="col-lg-4 mb-3">-->
                        <!--    <label  class="form-label">Purchase Price</label>-->
                        <!--    <input type="text" name="purchase_price" class="form-control" value="<?php echo e($item->purchase_price); ?>">-->
                        <!--</div>-->

                        <!--<div class="col-lg-4 mb-3">-->
                        <!--    <label  class="form-label">Sell Price</label>-->
                        <!--    <input type="text" name="sell_price" class="form-control" value="<?php echo e($item->sell_price); ?>">-->
                        <!--</div>-->
                        
                        <!--<div class="col-lg-4 mb-3 d-none">-->
                        <!--    <label  class="form-label">Regular Price</label>-->
                        <!--    <input type="text" name="regular_price" class="form-control" value="<?php echo e($item->regular_price); ?>">-->
                        <!--</div>-->

                        <div class="col-lg-3 mb-3 d-none">
                            <label  class="form-label">Manage Stock</label>
                            <select name="is_stock" class="form-control">
                                <!--<option value="1" <?php echo e($item->is_stock == '1' ? 'selected' : ''); ?> >Yes</option>-->
                                <option value="0" selected>No</option>
                            </select>
                        </div>
                        
                        <?php if($item->discount_type == null): ?>
                        <?php else: ?>
                        <div id="dis_type" class="col-lg-3 mb-3 dis_type">
                            <label  class="form-label">Discount Type</label>
                             <select class="form-control dicount_type" name="discount_type">
                                <option value="">Select Discount Type</option>
                                <option value="fixed" <?php echo e($item->discount_type == 'fixed' ? 'selected' : ''); ?> >Fixed</option>
                                <option value="percentage" <?php echo e($item->discount_type == 'percentage' ? 'selected' : ''); ?> >Percentage</option>
                        </select>
                        </div>
                        
                        <div id="dis_amount" class="col-lg-3 mb-3 dis_amount">
                            <label  class="form-label">Discount Amount</label>
                            <input type="number" step="any" name="dicount_amount" class="form-control dicount_amount" value="<?php echo e($item->dicount_amount); ?>">
                        </div>
                        <?php endif; ?>
                        
                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Purchase Price</label>
                            <input type="text" name="purchase_prices" class="form-control" value="<?php echo e($item->purchase_prices); ?>">
                        </div>
                        
                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Sell Price</label>
                            <input type="text" id="sell_price" name="sell_price" class="form-control" placeholder="Product Sku" value="<?php echo e($item->sell_price); ?>">
                        </div>
                        
                            <div class="col-lg-4 mb-3">
                                <label  class="form-label">After Discount Price</label>
                                <input type="text" id="after_discount" name="after_discount" class="form-control" placeholder="Product Sku" value="<?php echo e($item->after_discount); ?>">
                            </div>
                        <div class="col-lg-4 mb-3">
                            <label  class="form-label">Stock Quantity</label>
                            <input type="text" name="pro_quantity" class="form-control" placeholder="Product Sku" value="<?php echo e($item->stock_quantity); ?>">
                        </div>
                        
                    
                        
                    </div>
                    <hr>
                    
                    
                    
                    <div class="row">
                    <?php if($item->type == 'variable'): ?>
                       <div class="col-md-12">
                            <div class="table-responsive">
                                <table class="table table-centered table-nowrap table-bordered text-center">
                                    <thead>
                                        <tr>
                                           <th>Size</th>
                                            <th>Color</th>
                                            <th style="width: 20%;">Purchase Price</th>
                                            <th style="width: 20%;">Price</th>
                                            <th style="width: 20%;">Discount Price</th>
                                            <th style="width: 20%;">Stock Quantity</th>
                                            <th width="5">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $item->variations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td>
                                                <input type="hidden" name="variation_id[]" value="<?php echo e($v->id); ?>">
                                                <input type="hidden" name="product_id[]" value="<?php echo e($item->id); ?>">
                                                <select name="size_id[]" class="form-control">
                                                    <?php $__currentLoopData = $sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option <?php echo e($size->id==$v->size_id ?'selected':''); ?> value="<?php echo e($size->id); ?>"><?php echo e($size->title); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </td>
                                            <td>
                                            <select name="color_id[]" class="form-control">
                                                    <?php $__currentLoopData = $colors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $color): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option <?php echo e($color->id==$v->color_id ?'selected':''); ?> value="<?php echo e($color->id); ?>"><?php echo e($color->name); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                            </td>
                                            <td style="width: 16%;">
                                                <input class="variable_purchase_price form-control" type="number" value="<?php echo e($v->purchase_price); ?>" name="purchase_price[]" placeholder="Price">
                                            </td>
                                            <td style="width: 16%;">
                                                <input class="variable_sell_price form-control" type="number" value="<?php echo e($v->price); ?>" name="price[]" placeholder="Price">
                                            </td>
                                            <td>
                                                <input class="variable_dis_price form-control" value="<?php echo e($v->after_discount_price); ?>" type="number" name="after_discount_price[]" placeholder="Discount Price">
                                            </td>
                                            <td>
                                                <input class="quantity form-control" type="number" value="<?php echo e($v->stock_quantity); ?>" name="quantity[]" placeholder="Price">
                                            </td>
                                            <td>
                                                <a class="action-icon btn-primary add_moore"><i class="mdi mdi-plus"></i> </a>
                                                <a class="action-icon btn-danger remove"><i class="mdi mdi-delete"></i> </a>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <?php else: ?>
                    <?php endif; ?>
                        <!--<div class="col-lg-12">-->
                        <!--    <label  class="form-label">Feature</label>-->
                        <!--    <textarea class="form-control" name="feature" id="feature" rows="5"><?php echo $item->feature; ?></textarea>-->
                        <!--</div>-->

                        <div class="col-lg-12">
                            <div class="mb-3">
                                <label  class="form-label">Product Body</label>
                                <textarea class="form-control" name="body" id="body" rows="5"><?php echo $item->body; ?></textarea>
                            </div>
                        </div>

                        <div class="col-lg-12">
                            <div class="mb-3">
                                <button type="submit" class="btn btn-primary">Update</button>
                            </div>
                        </div>
                        
                    </div>
                    
                </form>
       
            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div> <!-- end col -->
</div> <!-- end row -->
<?php $__env->stopSection(); ?> 

<?php $__env->startPush('js'); ?>
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote-lite.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<!--<script src="https://cdn.ckeditor.com/4.12.1/standard/ckeditor.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote-lite.min.js"></script>
<script>
$(document).ready(function() {
    // ===== Feature Editor =====
    $('#feature').summernote({
        height: 200,
        toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'italic', 'underline', 'clear']],
            ['fontname', ['fontname']],
            ['fontsize', ['fontsize']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['insert', ['link', 'picture', 'video', 'hr']],
            ['view', ['fullscreen', 'codeview', 'help']]
        ],
        callbacks: {
            onImageUpload: function(files) {
                let editor = $(this); // Current editor
                let data = new FormData();
                data.append('upload', files[0]);
                data.append('_token', '<?php echo e(csrf_token()); ?>');

                $.ajax({
                    url: "<?php echo e(route('admin.ckeditor.upload')); ?>",
                    type: "POST",
                    data: data,
                    processData: false,
                    contentType: false,
                    success: function(resp) {
                        if (resp.url) {
                            editor.summernote('insertImage', resp.url); // Insert into #feature
                        } else {
                            alert('Image upload failed.');
                        }
                    },
                    error: function(xhr) {
                        console.log(xhr.responseText);
                        alert('Upload error.');
                    }
                });
            }
        }
    });

    // ===== Body Editor =====
    $('#body').summernote({
        height: 300,
        toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'italic', 'underline', 'clear']],
            ['fontname', ['fontname']],
            ['fontsize', ['fontsize']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['insert', ['link', 'picture', 'video', 'hr']],
            ['view', ['fullscreen', 'codeview', 'help']]
        ],
        callbacks: {
            onImageUpload: function(files) {
                let editor = $(this); // Current editor
                let data = new FormData();
                data.append('upload', files[0]);
                data.append('_token', '<?php echo e(csrf_token()); ?>');

                $.ajax({
                    url: "<?php echo e(route('admin.ckeditor.upload')); ?>",
                    type: "POST",
                    data: data,
                    processData: false,
                    contentType: false,
                    success: function(resp) {
                        if (resp.url) {
                            editor.summernote('insertImage', resp.url); // Insert into #body
                        } else {
                            alert('Image upload failed.');
                        }
                    },
                    error: function(xhr) {
                        console.log(xhr.responseText);
                        alert('Upload error.');
                    }
                });
            }
        }
    });
});
</script>
<script type="text/javascript">
    // CKEDITOR.replace('body', {
    //     filebrowserUploadUrl: "<?php echo e(route('admin.ckeditor.upload', ['_token' => csrf_token() ])); ?>",
    //     filebrowserUploadMethod: 'form'
    // });
    // CKEDITOR.replace('feature');

    $(document).ready(function() {
        $('.js-example-basic-multiple').select2();
    });

    $("document").ready(function () {
        $('select[name="category_id"]').on('change', function () {
            var cat_id = $(this).val();
            if (cat_id) {
                $.ajax({
                    url: '<?php echo e(route("admin.getSubcategory")); ?>',
                    type: "GET",
                    dataType: "json",
                    data:{cat_id},
                    success: function (data) {
                        $('select[name="sub_category_id"]').empty();
                        $.each(data, function (key, value) {
                            $('select[name="sub_category_id"]').append('<option value=" ' + key + '">' + value + '</option>');
                        })
                    }

                })
            } else {
                $('select[name="sub_category_id"]').empty();
            }
        });

        // add moore
        
        // $(document).on('blur', '#sell_price', function() {
        //     var sell_price = $(this).val(); 
            
        //     var discount_type=$("select[name='discount_type']").val();
        //     var discount_amount = $("input[name='dicount_amount']").val();
        //     if (discount_type=='percentage') {
        //         new_price= (sell_price / 100) * discount_amount;
        //         new_price=sell_price - new_price;
        //     }else{
        //         new_price= sell_price - discount_amount;
        //     }
        //     $('#after_discount').val(new_price);
            
        // });
        
        $(document).on('blur', '.dicount_amount', function(){
            
            let discount_amount=$(this).val();
            let new_price=0;
            var price=$("input[name='sell_price']").val();
            var discount_type=$("select[name='discount_type']").val();
            if (discount_type=='percentage') {
                new_price= (price / 100) * discount_amount;
                new_price=price - new_price;
            }else{
                new_price= price - discount_amount;
            }
            $("input[name='after_discount']").val(new_price.toFixed(2));
            $(".variable_dis_price").val(new_price.toFixed(2));
            $(".variable_dis_price_extra").val(12);
            // $(".variable_dis_price_extra").val(new_price.toFixed(2));
        });
        
        $(document).on('blur', '.variable_sell_price', function() {
            let tblrow = $(this).closest("tr");
            
            var discount_type=$("select[name='discount_type']").val();
            
            let variable_sell_price = tblrow.find('td input.variable_sell_price').val();
            var discount_amount = $("input[name='dicount_amount']").val();
            
            if (discount_type=='percentage') {
                new_price= (variable_sell_price / 100) * discount_amount;
                new_price=variable_sell_price - new_price;
            }else{
                new_price= variable_sell_price - discount_amount;
            }
            tblrow.find('td input.variable_dis_price').val(new_price);
        });

        $(document).on('click','a.add_moore', function(){
            
            let tblrow = $(this).closest("tr");
            let variable_purchase_price = tblrow.find('td input.variable_purchase_price').val();
            let variable_sell_price = tblrow.find('td input.variable_sell_price').val();
            let variable_dis_price = tblrow.find('td input.variable_dis_price').val();
            let quantity = tblrow.find('td input.quantity').val();
            
            let type='<?php echo e($item->type); ?>';

            if (type=='single') {
                toastr.error('For Single Product You Can\'t Add Moore');
                return;
            }
            let row=`<tr>
                        <td>
                            <select name="size_id[]" class="form-control">
                                <?php $__currentLoopData = $sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($size->id); ?>"><?php echo e($size->title); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </td>
                        
                        <td>
                            <select name="color_id[]" class="form-control">
                                <?php $__currentLoopData = $colors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $color): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option  value="<?php echo e($color->id); ?>"><?php echo e($color->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </td>
                        <td>
                        <input class="variable_purchase_price form-control" type="number" value="${variable_purchase_price}" name="variable_purchase_price[]" placeholder="Purchase Price">
                        </td>
                        <td>
                        <input class="variable_sell_price form-control" type="number" value="${variable_sell_price}" name="price[]" placeholder="Price">
                        </td>
                        <td>
                        <input class="variable_dis_price form-control" type="number" value="${variable_dis_price}" name="after_discount_price[]" placeholder="Discount Price">
                        </td>
                        <td>
                        <input class="form-control quantity" type="number" value="${quantity}" name="quantity[]" placeholder="Stock Quantity">
                        </td>
                        <td>
                            <a class="action-icon btn-primary add_moore"><i class="mdi mdi-plus"></i> </a>
                            <a class="action-icon btn-danger remove"><i class="mdi mdi-delete"></i> </a>
                        </td>
                    </tr>`;
            $(document).find('.table tbody').append(row);

        });

        $(document).on('click', "a.remove",function(e) {
            var whichtr = $(this).closest("tr");
            whichtr.remove();      
        });


    });

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('backend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/softitglobal/demo1.softitglobal.xyz/resources/views/backend/products/edit.blade.php ENDPATH**/ ?>