<?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); ?>" enctype="multipart/form-data">
            <?php if($coupon ?? ''  && $coupon->id): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>
            <?php echo csrf_field(); ?>

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

            <div class="form-group col-lg-6">
                <label><?php echo e(__('coupons.discount_status')); ?> </label>
                <select id="discount_status" class="form-control <?php echo e($errors->has('discount_status') ? 'is-invalid' : ''); ?>" name="discount_status">
                    <?php $__currentLoopData = $discount_statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option <?php echo e(isset($coupon) ? ($coupon->discount_status == $row ? 'selected' : '') : ''); ?> value="<?php echo e($row); ?>"><?php echo e(__('coupons.discount_statuses.'.$row)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

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

            <div class="form-group col-lg-6">
                <label><?php echo e(__('coupons.status')); ?> </label>
                <select id="status" onchange="statusSelect()" class="form-control <?php echo e($errors->has('status') ? 'is-invalid' : ''); ?>" name="status">
                    <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option <?php echo e(isset($coupon) ? ($coupon->status == $row ? 'selected' : '') : ''); ?> value="<?php echo e($row); ?>"><?php echo e(__('coupons.statuses.'.$row)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-6 mb-4" id="product_status">
                <label for="validationServer"><?php echo e(__('coupons.product')); ?></label>
                <input type="text" name="search_product" value="" placeholder="<?php echo e(__('coupons.product')); ?>" id="input-product" class="form-control usersBox" />
                <div id="branche-product" class="well well-sm usersBox form-control" style="height: 150px; overflow: auto;">
                    <?php if($coupon ?? '' && $coupon->id): ?>
                        <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div id="branche-product<?php echo e($row->product_id); ?>" class="branches"><i class="fa fa-minus-circle"></i> <?php echo e($row->product->currentDescription->title); ?><input type="hidden" name="product_ids[]" value="<?php echo e($row->product_id); ?>"></div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </div>
            </div>

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

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

            <div class="form-group col-lg-6" >
                <label><?php echo e(__('coupons.start_date')); ?> </label>
                <input type="date" class="form-control <?php echo e($errors->has('start_date') ? 'is-invalid' : ''); ?>" name="start_date" placeholder="<?php echo e(__('coupons.start_date')); ?>" value='<?php echo e(old("start_date", $coupon->start_date ?? "")); ?>' />
            </div>

            <div class="form-group col-lg-6" >
                <label><?php echo e(__('coupons.end_date')); ?> </label>
                <input type="date" class="form-control <?php echo e($errors->has('end_date') ? 'is-invalid' : ''); ?>" name="end_date" placeholder="<?php echo e(__('coupons.end_date')); ?>" value='<?php echo e(old("end_date", $coupon->end_date ?? "")); ?>' />
            </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 orders -->
    <script src="<?php echo e(asset('/assets/admin/js/lib/tinymce.min.js')); ?>"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script>

        $('input[name=\'search_product\']').autocomplete({

            'source': function (request, response) {
                let target = request['term'];
                $.ajax({
                    url: url_search_product,
                    data: 'title='+target,
                    dataType: 'json',
                    type: 'get',

                    success: function (json) {
                        response($.map(json, function (item) {
                            return {
                                label:`${item['title']}` ,
                                value: item['title'],
                                id: item['id']
                            };
                        }));
                    }
                });
            }, 'select': function (e, selected) {
                var item = selected['item'];
                $('#branche-product' + item['id']).remove();
                $('#input-product').removeAttr('value');
                $('#branche-product').append('<div id="branche-product' + item['id'] + '" class="branches"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="product_ids[]" value="' + item['id'] + '" /></div>');
            }
        });
        $('#branche-product').delegate('.fa-minus-circle', 'click', function () {
            $(this).parent().remove();
        });

        function statusSelect()
        {
            let data = $('#status').val()
            if(data == '0')
            {
                $('#product_status').show();
            }
            else
            {
                $('#product_status').hide();
            }
        }
        $('#status').trigger('change');
    </script>
    <script>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            url_search_product = "<?php echo e(route('admin.search_products')); ?>",
            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/modern/resources/views/admin/coupons/form.blade.php ENDPATH**/ ?>