
<?php $__env->startSection('title', $page_title); ?>
<?php $__env->startPush('styles'); ?>
    <link href="<?php echo e(asset('css/tagify.css')); ?>" rel="stylesheet" type="text/css" />
    <link href="<?php echo e(asset('css/bootstrap-datetimepicker.min.css')); ?>" rel="stylesheet" type="text/css" />
    <style>
        .tagsinput{
            height: calc(1.5em + 1.3rem + 2px) !important;
        }
    </style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div class="d-flex flex-column-fluid">
        <div class="container-fluid">
            <div class="card card-custom gutter-b">
                <div class="card-header flex-wrap py-5">
                    <div class="card-title"><h3 class="card-label"><i class="<?php echo e($page_icon); ?> text-primary"></i> <?php echo e($sub_title); ?></h3></div>
                    <div class="card-toolbar">
                        <a href="<?php echo e(route('category')); ?>" class="btn btn-warning btn-sm font-weight-bolder"><i class="fas fa-arrow-left"></i> Back</a>
                    </div>
                </div>
            </div>
            <form  method="post" id="store_or_update_form" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="update_id" id="update_id" value="<?php echo e($data->id); ?>">
                <div class="card card-custom">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-3 form-group required code">
                                <label for="code">Code</label>
                                <div class="input-group" id="code_section">
                                    <input type="text" class="form-control" name="cat_code" id="cat_code" required="required" value="<?php echo e($data->cat_code); ?>" readonly>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="row">
                                    <input type="hidden" name="product_id" id="product_id">
                                    <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.form.textbox','data' => ['labelName' => 'Category Name','name' => 'name','required' => 'required','col' => 'col-md-12','value' => ''.e($data->name).'']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => 'Category Name','name' => 'name','required' => 'required','col' => 'col-md-12','value' => ''.e($data->name).'']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
                                </div>
                            </div>
                            <div class="col-md-3 form-group required code">
                                <label for="code">Parent Category</label>
                                <div class="input-group" id="code_section">
                                    <select class=" form-control selectpicker" name="parent_id" data-toggle="select2" data-placeholder="Choose ..." data-live-search="true">
                                        <option value="">Select a Category</option>
                                        <?php $__currentLoopData = $categories->where('parent_id', 0); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                       
                                            <?php echo $__env->make('category.edit_option', ['category' => $category, 'level' => 0,'data_value' => $data ], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="row">
                                    <div class="form-group col-md-12 mb-0 text-center">
                                        <label for="image" class="form-control-label">Category Image</label>
                                        <div class="col=md-12 px-0  text-center">
                                            <div id="image"></div>
                                            <div class="text-center"><span class="text-muted">Maximum  File Size 2MB <span style="color: red">( 611 X 350 )</span> and Format (png,jpg,jpeg,svg,webp)</span></div>
                                        </div>
                                        <input type="hidden" name="old_image" id="old_image" value="<?php echo e($data->image); ?>">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="row" >
                                    <div class="form-group col-md-12 mb-0 text-center">
                                        <input type="checkbox" id="type" name="type" value="1" <?php echo e(($data->type == 1 ? ' checked' : '')); ?> style="height: 23px; width: 39px;">
                                        <label for="vehicle1">Show Home Section </label><br>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card card-custom">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12 text-center">
                                <a type="button" class="btn btn-danger btn-sm mr-3" href="<?php echo e(route('category')); ?>"><i class="fas fa-sync-alt"></i> Reset</a>
                                <button type="button" class="btn btn-primary btn-sm mr-3" onclick="storeData(1)" id="update-btn"><i class="far fa-save"></i> Save</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('js/jQuery.tagify.min.js')); ?>"></script>
    <script src="<?php echo e(asset('js/spartan-multi-image-picker.min.js')); ?>"></script>
    <script src="<?php echo e(asset('js/moment.js')); ?>"></script>
    <script src="<?php echo e(asset('js/bootstrap-datetimepicker.min.js')); ?>"></script>
    <script>
        $(document).ready(function(){
            /** Start :: Product Image **/
            $("#image").spartanMultiImagePicker({
                fieldName:        'image',
                maxCount: 1,
                rowHeight:        '150px',
                groupClassName:   'col-md-12 col-sm-12 col-xs-12',
                maxFileSize:      '',
                dropFileLabel : "Drop Here",
                allowedExt: '',
            });
            $("input[name='image']").prop('required',true);
            $('.remove-files').on('click', function(){
                $(this).parents(".col-md-12").remove();
            });
            <?php if(!empty($data->image)): ?>
            $('#image img').css('display','none');
            $('#image .spartan_remove_row').css('display','block');
            $('#image .img_').css('display','block');
            $('#image .img_').attr('src',"<?php echo e(asset('storage/'.PRODUCT_IMAGE_PATH.$data->image)); ?>");
            <?php else: ?>
            $('#image img').css('display','block');
            $('#image .spartan_remove_row').css('display','none');
            $('#image .img_').css('display','none');
            $('#image .img_').attr('src','');
            <?php endif; ?>
            /** End :: Product Image **/
        //Generate Code
            $(document).on('click','#generate-code',function(){
                $.ajax({
                    url: "<?php echo e(route('category.generate.code')); ?>",
                    type: "GET",
                    dataType: "JSON",
                    beforeSend: function(){
                        $('#generate-code').addClass('spinner spinner-white spinner-right');
                    },
                    complete: function(){
                        $('#generate-code').removeClass('spinner spinner-white spinner-right');
                    },
                    success: function (data) {
                        data ? $('#store_or_update_form #cat_code').val(data) : $('#store_or_update_form #cat_code').val('');
                    },
                    error: function (xhr, ajaxOption, thrownError) { console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText); }
                });
            });

            /****************************/
            $(document).on('click','#update-btn',function(){
                let form = document.getElementById('store_or_update_form');
                let formData = new FormData(form);
                $.ajax({
                    url: "<?php echo e(route('category.update')); ?>",
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    contentType: false,
                    processData: false,
                    cache: false,
                    beforeSend: function(){
                        $('#update-btn').addClass('spinner spinner-white spinner-right');
                    },
                    complete: function(){
                        $('#update-btn').removeClass('spinner spinner-white spinner-right');
                    },
                    success: function (data) {
                        $('#store_or_update_form').find('.is-invalid').removeClass('is-invalid');
                        $('#store_or_update_form').find('.error').remove();
                        if (data.status == false) {
                            $.each(data.errors, function (key, value){
                                var key = key.split('.').join('_');
                                $('#store_or_update_form input#' + key).addClass('is-invalid');
                                $('#store_or_update_form textarea#' + key).addClass('is-invalid');
                                $('#store_or_update_form select#' + key).parent().addClass('is-invalid');
                                if(key == 'code' || key == 'start_date' || key == 'end_date'){
                                    $('#store_or_update_form #' + key).parents('.form-group').append('<small class="error text-danger">' + value + '</small>');
                                }else{
                                    $('#store_or_update_form #' + key).parent().append('<small class="error text-danger">' + value + '</small>');
                                }
                            });
                        } else {
                            notification(data.status, data.message);
                            if (data.status == 'success') { window.location.replace("<?php echo e(route('category')); ?>"); }

                        }
                    },
                    error: function (xhr, ajaxOption, thrownError) { console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText); }
                });
            });
        });
    </script>
<?php $__env->stopPush(); ?>

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