

<?php $__env->startSection('content'); ?>
<div class="side-title">
    <h3><?php echo e($head ?? ''); ?></h3>
</div>

<div class="border-item">
    <form class="form-row add_product_form" method="post" action="<?php echo e($action); ?>" enctype="multipart/form-data">
        <?php if($product ?? ''  && $product->id): ?>
            <?php echo method_field('PUT'); ?>
        <?php endif; ?>
        <?php echo csrf_field(); ?>


            <div class="form-group col-lg-4">
                <label><?php echo e(meta('is_special', $lang) ?? __('products.is_special')); ?></label>
                <select name="is_special" class="form-control">
                    <option <?php echo e((old('is_special') ?? $product->is_special ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('products.yes')); ?></option>
                    <option <?php echo e((old('is_special') ?? $product->is_special ?? null) == 0 ? 'selected' : ''); ?> value="0"><?php echo e(__('products.no')); ?></option>
                </select>
            </div>

            <div class="form-group col-lg-4">
                <label><?php echo e(meta('show_advantages', $lang) ?? __('products.show_advantages')); ?></label>
                <select name="show_advantages" class="form-control">
                    <option <?php echo e((old('show_advantages') ?? $product->show_advantages ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('products.yes')); ?></option>
                    <option <?php echo e((old('show_advantages') ?? $product->show_advantages ?? null) == 0 ? 'selected' : ''); ?> value="0"><?php echo e(__('products.no')); ?></option>
                </select>
            </div>

            <div class="form-group col-lg-4">
                <label><?php echo e(meta('show_table', $lang) ?? __('products.show_table')); ?></label>
                <select name="show_table" class="form-control">
                    <option <?php echo e((old('show_table') ?? $product->show_table ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('products.yes')); ?></option>
                    <option <?php echo e((old('show_table') ?? $product->show_table ?? null) == 0 ? 'selected' : ''); ?> value="0"><?php echo e(__('products.no')); ?></option>
                </select>
            </div>

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

        <div class="form-group col-lg-6">
            <label><?php echo e(meta('minimum_title', $language->local) ?? __('products.minimum_title')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
            <input type="text" class="form-control <?php echo e($errors->has('minimum_title_'.$language->local) ? 'is-invalid' : ''); ?>" name="minimum_title_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('minimum_title', $language->local) ?? __('products.minimum_title')); ?>" value='<?php echo e(old("minimum_title_{$language->local}", $product[$language->local]->minimum_title ?? "")); ?>'/>
        </div>
        <div class="form-group col-lg-6">
            <label><?php echo e(meta('maximum_title', $language->local) ?? __('products.maximum_title')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
            <input type="text" class="form-control <?php echo e($errors->has('maximum_title_'.$language->local) ? 'is-invalid' : ''); ?>" name="maximum_title_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('maximum_title', $language->local) ?? __('products.maximum_title')); ?>" value='<?php echo e(old("maximum_title_{$language->local}", $product[$language->local]->maximum_title ?? "")); ?>'/>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <div class="card col-md-12 mb-5">
                <div class="card-header">
                    <h5 class="card-title"><?php echo e(__('products.points')); ?></h5>
                </div>
                <div class="card-body product_points_appended_container">
                    <?php if(count($points)): ?>
                        <?php $__currentLoopData = $points['minimum']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key =>  $minimum): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="point_item row justify-content-between align-items-center mb-4 p-2 shadow position-relative">
                                <div class="form-group col-lg-6">
                                    <label><?php echo e(__('products.minimum')); ?></label>
                                    <input type="text" class="form-control" name="minimum[]" placeholder="<?php echo e(__('products.minimum')); ?>" value='<?php echo e($minimum); ?>'/>
                                </div>
                                <div class="form-group col-lg-6">
                                    <label><?php echo e(__('products.maximum')); ?></label>
                                    <input type="text" class="form-control" name="maximum[]" placeholder="<?php echo e(__('products.maximum')); ?>" value='<?php echo e($points['minimum'][$key]); ?>'/>
                                </div>

                                <?php if($loop->iteration > 1): ?>
                                    <div class="form-group position-absolute" style="top: 1%; right: 1%">
                                        <a class="delete_point" href="#"><i class="fa fa-times fa-2x text-danger"></i></a>
                                    </div>
                                <?php endif; ?>

                                <div class="form-group col-lg-6">
                                    <label><?php echo e(__('products.points')); ?> <?php echo e(__('products.arabic')); ?> </label>
                                    <input type="text" class="form-control" name="points[ar][]" placeholder="<?php echo e(__('products.points') .__('products.arabic')); ?>" value='<?php echo e($points['ar'][$key]); ?>'/>
                                </div>
                                <div class="form-group col-lg-6">
                                    <label><?php echo e(__('products.points')); ?> <?php echo e(__('products.english')); ?> </label>
                                    <input type="text" class="form-control" name="points[en][]" placeholder="<?php echo e(__('products.points') . __('products.english')); ?>" value='<?php echo e($points['en'][$key]); ?>'/>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php else: ?>
                        <div class="point_item row justify-content-between align-items-center mb-4 p-2 shadow position-relative">
                            <div class="form-group col-lg-6">
                                <label><?php echo e(__('products.minimum')); ?></label>
                                <input type="text" class="form-control" name="minimum[]" placeholder="<?php echo e(__('products.minimum')); ?>" value=''/>
                            </div>
                            <div class="form-group col-lg-6">
                                <label><?php echo e(__('products.maximum')); ?></label>
                                <input type="text" class="form-control" name="maximum[]" placeholder="<?php echo e(__('products.maximum')); ?>" value=''/>
                            </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(__('products.points')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                                    <input type="text" class="form-control"name="points[<?php echo e($language->local); ?>][]" placeholder="<?php echo e(__('products.points')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?>" value=''/>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="card-footer">
                    <a class="btn btn-primary btn-block add_point" href="#"><i class="fa fa-plus"></i></a>
                </div>
            </div>
            <div class="point_container d-none">
                <?php echo $__env->make('admin.products.point', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            </div>

            
            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    <?php if($product ?? false): ?>
                        <?php $__currentLoopData = $product['images']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-md-4">
                                <div class="items">
                                    <div class="img">
                                        <a href="<?php echo e(asset($image ?? '')); ?>" data-fancybox="gallery"><img src="<?php echo e(asset($image ?? '')); ?>" alt=""></a>
                                    </div>
                                    <input type="hidden" name="images[]" value="<?php echo e($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">
                            <?php echo e(__('dashboard.add_new_item')); ?>

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

        <div class="text-center mt-5 col-12">
            <button class="butn add_product_button"><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>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            currentLanguage = "<?php echo e($lang); ?>",
            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>

    <script>

        $('.add_product_button').click(async function (e) {
            e.preventDefault();
            $(this).prop('disabled', true);
            let form = $('.add_product_form'),
                data = new FormData(form[0]),
                url = form.attr('action'),
                method = form.attr('method');

            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method
            });

            if (response.url){
                window.location.href = response.url;
            }

            if (response.errors){
                $(this).prop('disabled', false);
                toasterError(response.errors);
            }

        });


        $('.add_point').click(function (e) {
            e.preventDefault();
            let pointContainer = $('.point_container').html();
            $('.product_points_appended_container').append(pointContainer);
            $('.product_points_appended_container .appended_item input').each(function () {
                $(this).attr('name', $(this).data('name'));
                $(this).removeAttr('data-name')
            });

        });
        $(document).on('click', '.delete_point', function (e) {
            e.preventDefault();
            $(this).parents('.point_item').remove();
        })
    </script>

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




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