<?php $__env->startSection('content'); ?>
<div class="side-title">
    <h3><?php echo e($head ?? ''); ?></h3>
</div>
<div class="border-item">
    <form class="form-row" method="post"  onsubmit="saveForm(this)" action="<?php echo e($action); ?>">
        <?php if($product ?? ''  && $product->id): ?>
            <?php echo method_field('PUT'); ?>
        <?php endif; ?>
        <?php echo csrf_field(); ?>

        <div class="form-group col-lg-6">
            <label><?php echo e(meta('code', getCurrentLocale()) ?? __('products.code')); ?> </label>
            <input type="text" class="form-control <?php echo e($errors->has('code') ? 'is-invalid' : ''); ?>" name="code" placeholder="<?php echo e(meta('code', getCurrentLocale()) ?? __('products.code')); ?>" value='<?php echo e(old("code", $product->code ?? "")); ?>'/>
        </div>

        <div class="form-group col-lg-6">
            <label><?php echo e(meta('category_id', getCurrentLocale()) ?? __('products.category_id')); ?> </label>
            <select onchange="selectCategory(this)" class="form-control <?php echo e($errors->has('category_id') ? 'is-invalid' : ''); ?>" name="category_id" >
                <option value=""><?php echo e(__('dashboard.select')); ?></option>
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option <?php if((isset($product) ? $product->category_id : "") == $row->id ): ?> selected <?php endif; ?> value="<?php echo e($row->id); ?>"><?php echo e($row->name); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>

        <div class="form-group col-lg-12 row" id="attributes">
            <?php if($product ?? ''  && $product->id): ?>
                <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                    <?php if(count($models)): ?>
                        <div class="form-group col-lg-6">
                            <label><?php echo e(meta('model_id', getCurrentLocale()) ?? __('products.model_id')); ?> </label>
                            <select class="form-control <?php echo e($errors->has('model_id') ? 'is-invalid' : ''); ?>" name="model_id" >
                                <option value=""><?php echo e(__('dashboard.select')); ?></option>
                                <?php $__currentLoopData = $models; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option <?php echo e($product->model_id == $row->id ? 'selected' : ''); ?> value="<?php echo e($row->id); ?>"><?php echo e($row->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    <?php endif; ?>

                    <?php if($category->brand_status == 'true'): ?>
                        <div class="form-group col-lg-6">
                            <label><?php echo e(meta('brand_id', getCurrentLocale()) ?? __('products.brand_id')); ?> </label>
                            <select  class="form-control <?php echo e($errors->has('brand_id') ? 'is-invalid' : ''); ?>" name="brand_id" >
                                <option value=""><?php echo e(__('dashboard.select')); ?></option>
                                <?php $__currentLoopData = $brands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option <?php echo e($product->brand_id == $row->id ? 'selected' : ''); ?> value="<?php echo e($row->id); ?>"><?php echo e($row->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    <?php endif; ?>
                    <?php $__currentLoopData = $ones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $attribute): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color:white;height:auto">
                            <div class="col-lg-12">
                                <h3><?php echo e($attribute->name); ?></h3>
                            </div>
                            <div class="form-group col-lg-6">
                                <label><?php echo e(__('products.choice')); ?> </label>
                                <select class="form-control" name="one[<?php echo e($attribute->id); ?>][choice_id]" >
                                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                                    <?php $__currentLoopData = $attribute->choices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $choice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option <?php echo e($product->attributeChoice($attribute->id,$choice->choice_id) ? 'selected' : ''); ?> value="<?php echo e($choice->choice_id); ?>"><?php echo e($choice->choice->currentLangauge->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    <?php if($main): ?>
                    <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color:white;height:auto">
                        <div class="col-lg-12">
                            <h3><?php echo e($main->details->name); ?></h3>
                        </div>

                        <?php $__currentLoopData = $main->choices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $main_choice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-lg-12 row">
                                <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                                    <div class="form-group col-lg-12">
                                        <h3><?php echo e($main_choice->choice->details->name); ?></h3>
                                    </div>
                                        <div class="form-group col-lg-6">

                                            <h4><?php echo e($sub->details->name); ?></h4>
                                        </div>

                                        <?php $__currentLoopData = $sub->choices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $choice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                                                <div class="form-group col-lg-12">
                                                    <h5><?php echo e($choice->choice->details->name); ?></h5>
                                                </div>
                                                <div class="form-group col-lg-6">
                                                    <label><?php echo e(__('products.count')); ?> </label>
                                                    <input type="number" name="multi[<?php echo e($main->id); ?>][<?php echo e($main_choice->choice_id); ?>][<?php echo e($sub->id); ?>][<?php echo e($choice->choice_id); ?>][count]" value="<?php echo e($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['count']); ?>" class="form-control" placeholder="<?php echo e(__('products.count')); ?>">
                                                </div>
                                                <div class="form-group col-lg-6 image_container">
                                                    <label><?php echo e(__('pages.image')); ?> </label>
                                                    <input id="image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_thumbnail" class="image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_thumbnail" type="hidden" name="multi[<?php echo e($main->id); ?>][<?php echo e($main_choice->choice_id); ?>][<?php echo e($sub->id); ?>][<?php echo e($choice->choice_id); ?>][image]" value="<?php echo e($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']); ?>"  />

                                                    <div class="photos main_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_photo <?php if($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']): ?> wow fadeInUp <?php else: ?> hide <?php endif; ?>">
                                                        <div class="col-md-4">
                                                            <div class="items">
                                                                <div class="img">
                                                                    <a href="#" id="lfm" data-input=".image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_thumbnail" data-preview=".image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_holder" class="lfm" data-hide=".pick_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_button">
                                                                        <img   id="image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_holder" class="image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_holder"/>
                                                                    </a>
                                                                </div>
                                                                <a href="#" class="showHide resetImage close" data-empty=".image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_thumbnail" data-hide=".main_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_photo" data-show=".pick_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_button"><i class="fas fa-times"></i></a>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div class="clearfix"></div>
                                                    <span class="input-group-btn pick_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_button  <?php if($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']): ?> hide <?php endif; ?> ">
                                                        <a id="lfm"  data-input=".image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_thumbnail" data-preview=".image_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_holder" data-show=".main_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_photo" data-hide=".pick_<?php echo e($main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id); ?>_button" class="lfm btn btn-primary text-light">
                                                            <i class="fas fa-camera-retro"></i> Choose
                                                        </a>
                                                     </span>
                                                </div>
                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                <?php endif; ?>
                </div>
            <?php endif; ?>
        </div>


        <?php $__currentLoopData = $cost_status; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="form-group col-lg-6">
                <label><?php echo e(__('products.cost'). ' (' . __('products.'.$status) .')'); ?> </label>
                <input type="number" class="form-control" name="costs[<?php echo e($status); ?>][cost]" placeholder="<?php echo e(meta('cost', getCurrentLocale()) ?? __('products.cost')); ?>" value='<?php echo e(old("cost",  isset($product) ? $product->costs($status,'cost') : "")); ?>'/>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('products.cost_discount'). ' (' . __('products.'.$status) .')'); ?> </label>
                <input type="number" class="form-control" name="costs[<?php echo e($status); ?>][cost_discount]" placeholder="<?php echo e(meta('cost_discount', getCurrentLocale()) ?? __('products.cost_discount')); ?>" value='<?php echo e(old("cost_discount", isset($product) ? $product->costs($status,'cost_discount') : "")); ?>'/>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <div class="form-group col-lg-6">
            <label><?php echo e(meta('count', getCurrentLocale()) ?? __('products.count')); ?> </label>
            <input type="number" class="form-control <?php echo e($errors->has('count') ? 'is-invalid' : ''); ?>" name="count" placeholder="<?php echo e(meta('count', getCurrentLocale()) ?? __('products.count')); ?>" value='<?php echo e(old("count", $product->count ?? "")); ?>'/>
        </div>

        <div class="form-group col-lg-6">
            <label><?php echo e(meta('most_sale', getCurrentLocale()) ?? __('products.most_sale')); ?> </label>
            <select  class="form-control <?php echo e($errors->has('most_sale') ? 'is-invalid' : ''); ?>" name="most_sale" >
                <option <?php if((isset($product) ? $product->most_sale : "") == 'false' ): ?> selected <?php endif; ?> value="false"><?php echo e(__('products.false')); ?></option>
                <option <?php if((isset($product) ? $product->most_sale : "") == 'true' ): ?> selected <?php endif; ?> value="true"><?php echo e(__('products.true')); ?></option>
            </select>
        </div>

        <?php $__currentLoopData = $languages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $language): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="form-group col-lg-6">
                <label><?php echo e(meta('name', $language->local) ?? __('products.name')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                <input type="text" class="form-control <?php echo e($errors->has('name_'.$language->local) ? 'is-invalid' : ''); ?>" name="name_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('name', $language->local) ?? __('products.name')); ?>" value='<?php echo e(old("name_{$language->local}", $product[$language->local]->name ?? "")); ?>'/>
            </div>
            <div class="form-group col-lg-12">
                <label><?php echo e(meta('description', $language->local) ?? __('products.description')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                <textarea type="text" class="form-control my-editor <?php echo e($errors->has('description_'.$language->local) ? 'is-invalid' : ''); ?>" name="description_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('name', $language->local) ?? __('products.description')); ?>"><?php echo e(old("name_{$language->local}", $product[$language->local]->description ?? "")); ?></textarea>
            </div>

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


            <div class="form-group col-lg-12 image_container" >
                <label><?php echo e(meta('image', getCurrentLocale()) ?? __('products.image')); ?> </label>
                <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="image" value="<?php echo e(old("image", $product->image ?? "")); ?>"/>

                <div class="photos main_photo <?php echo e(old('image', $product->image ?? '') ? ' wow fadeInUp' : 'hide'); ?>">
                    <div class="col-md-4">
                        <div class="items">
                            <div class="img">
                                <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                    <img src="<?php echo e(asset(old('image', $product->image ?? ''))); ?> "  id="image_holder" class="image_holder"/>
                                </a>
                            </div>
                            <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_photo" data-show=".pick_button"><i class="fas fa-times"></i></a>
                        </div>
                    </div>
                </div>

                <div class="clearfix"></div>
                <span class="input-group-btn pick_button <?php echo e(old('image', $product->image ?? '') ? 'hide' : ''); ?> ">
                <a id="lfm"  data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_photo" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                    <i class="fas fa-camera-retro"></i> <?php echo e(__('dashboard.choose')); ?>

                </a>
             </span>
            </div>

            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    <?php if($product ?? false): ?>
                        <?php $__currentLoopData = $product['photos']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $photo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-md-4">
                                <div class="items">
                                    <div class="img">
                                        <a href="<?php echo e(asset($photo->image ?? '')); ?>" data-fancybox="gallery"><img src="<?php echo e(asset($photo->image ?? '')); ?>" alt=""></a>
                                    </div>
                                    <input type="hidden" name="images[]" value="<?php echo e($photo->image ?? ""); ?>">
                                    <a href="#" class="close"><i class="fas fa-times"></i></a>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </div>
                <div class="text-center">
                    <input id="other_image_thumbnail" class="other_image_thumbnail" type="hidden"/>
                    <div class="clearfix"></div>
                    <span id="add">
                    <a id="lfm" data-width="" data-cache="article_gallery" data-input=".other_image_thumbnail" data-preview="" data-show="" data-hide="" class="lfm add">
                        Add New Item
                    </a>
                </span>
                </div>
            </div>


        <div class="text-center mt-5 col-12">
            <button class="butn"><span><?php echo e(__('dashboard.save')); ?></span></button>
        </div>
    </form>
</div>

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

<?php $__env->startSection('inner_js'); ?>
    <!-- Editor JS files -->
        <script src="<?php echo e(asset('/assets/admin/js/lib/tinymce.min.js')); ?>"></script>

    <script>
        function saveForm(elem)
        {
            event.preventDefault();
            var action = $(elem).attr('action');
            let dataform = new FormData( $(elem)[0]);
            $.ajax
            ({
                url : action,
                type: 'POST',
                data: dataform,
                dataType : 'json',
                contentType: false,
                processData: false,
                success:function(data)
                {
                    $('#errors').html('');
                    $('#errors').css("display", "none");
                    if(data.hasOwnProperty('errors'))
                    {
                         $('#errors').css("display", "block");
                        let html = '<div class="alert alert-danger">';
                        $.each(data.errors, function(key,value)
                        {
                            html += '<li>'+value+'</li>';
                        });
                        html += "</div>";
                        $('#errors').html(html);
                    }
                    else
                    {
                        setTimeout(
                            function()
                            {
                                window.location.assign(<?php echo json_encode(url('/admin/products')); ?>);
                            }, 1000);
                    }
                }
                ,error:function(data)
                {
                    $('#errors').css("display", "block");
                    let html = '<div class="alert alert-danger">';
                    $.each(data.responseJSON.errors, function(key,value)
                    {
                        html += '<li>'+value+'</li>';
                    });
                    html += "</div>";
                    $('#errors').html(html);
                }
            })
        }
        function selectCategory(elem)
        {
        var data = $(elem).val();
        if(data == '')
        {
            $('#attributes').html('');
        }
        else
        {
            $.ajax({
                url : url_attribute,
                type : 'GET',
                data : 'id='+data,
                success:function(data)
                {
                    $('#attributes').html(data);
                }
            })
        }
    }
    </script>
    <script>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            url_attribute = "<?php echo e(url('/')); ?>/admin/attribute",
            currentLanguage = "<?php echo e(getCurrentLocale()); ?>",
            imagePath = "<?php echo e(asset('')); ?>";
    </script>
    <script src="<?php echo e(asset('assets/admin/js/editor.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/admin/js/lfm.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/admin/js/articles.js')); ?>"></script>
<?php $__env->stopSection(); ?>




<?php echo $__env->make('admin.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/MAMP/htdocs/city/resources/views/admin/products/form.blade.php ENDPATH**/ ?>