<?php $__env->startSection('css'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('assets/web/css/lib/toastr.css')); ?>" />
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="side-title">
        <h3><?php echo e($head ?? ''); ?></h3>
    </div>

    <div class="border-item">
        <form class="form-row add_coupon_form" method="post" 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-3">
                    <label><?php echo e(meta('status', $local) ?? __('coupons.status')); ?></label>
                    <select name="status" class="form-control <?php echo e($errors->has('status') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($coupon->status ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('coupons.active')); ?></option>
                        <option <?php echo e(($coupon->status ?? null) == 0 ? 'selected' : ''); ?> value="0"><?php echo e(__('coupons.not_active')); ?></option>
                    </select>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('service_type', $local) ?? __('coupons.service_type')); ?></label>
                    <select name="service_type" class="form-control <?php echo e($errors->has('service_type') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($coupon->service_type ?? null) == 'all' ? 'selected' : ''); ?> value="all"><?php echo e(__('coupons.all')); ?></option>
                        <option <?php echo e(($coupon->service_type ?? null) == 'consulting' ? 'selected' : ''); ?> value="consulting"><?php echo e(__('coupons.consulting')); ?></option>
                        <option <?php echo e(($coupon->service_type ?? null) == 'documentation' ? 'selected' : ''); ?> value="documentation"><?php echo e(__('coupons.documentation')); ?></option>
                    </select>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('discount_type', $local) ?? __('coupons.discount_type')); ?></label>
                    <select name="discount_type" class="form-control <?php echo e($errors->has('discount_type') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($coupon->discount_type ?? null) == 'value' ? 'selected' : ''); ?> value="value"><?php echo e(__('coupons.value')); ?></option>
                        <option <?php echo e(($coupon->discount_type ?? null) == 'percentage' ? 'selected' : ''); ?> value="percentage"><?php echo e(__('coupons.percentage')); ?></option>
                    </select>
                </div>
            <div class="form-group col-lg-3">
                <label class="discount_amount_label"><?php echo e(meta('discount_amount', $local) ?? __('coupons.discount_amount')); ?></label>
                <input type="number" min="1" max="100" class="form-control" name="discount_amount" placeholder="<?php echo e(meta('discount_amount', $local) ?? __('coupons.discount_amount')); ?>" value='<?php echo e($coupon->discount_amount  ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('start_date', $local) ?? __('coupons.start_date')); ?></label>
                <input type="date" class="form-control" name="start_date" placeholder="<?php echo e(meta('start_date', $local) ?? __('coupons.start_date')); ?>" value='<?php echo e($coupon->start_date ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('end_date', $local) ?? __('coupons.end_date')); ?></label>
                <input type="date" class="form-control" name="end_date" placeholder="<?php echo e(meta('end_date', $local) ?? __('coupons.end_date')); ?>" value='<?php echo e($coupon->end_date ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('available_users', $local) ?? __('coupons.available_users')); ?></label>
                <input type="number" min="1" class="form-control" name="available_users" placeholder="<?php echo e(meta('available_users', $local) ?? __('coupons.available_users')); ?>" value='<?php echo e($coupon->available_users ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('code', $local) ?? __('coupons.code')); ?></label>
                <input type="text" class="form-control" name="code" placeholder="<?php echo e(meta('code', $local) ?? __('coupons.code')); ?>" value='<?php echo e($coupon->code ?? ""); ?>'/>
            </div>

            <?php if($coupon ?? ''  && $coupon->id): ?>
                <div class="form-group col-lg-6">
                    <label><?php echo e(__('coupons.used_count')); ?></label>
                    <input readonly class="form-control bg-white" value='<?php echo e($coupon->used_count ?? 0); ?>'/>
                </div>
                <div class="form-group col-lg-6">
                    <label><?php echo e(__('coupons.remaining_coupon_used')); ?></label>
                    <input readonly class="form-control bg-white" value='<?php echo e($coupon->available_users - $coupon->used_count); ?>'/>
                </div>
            <?php endif; ?>


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

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

<?php $__env->startSection('inner_js'); ?>

    <script src="<?php echo e(asset('assets/web/js/lib/toastr.min.js')); ?>"></script>


    <script>
        let discountTypeSelectedOption = $('select[name="discount_type"] option:selected').val(),
            discountAmountPercentage = "<?php echo e(__('coupons.discount_percentage')); ?>";

        $('.add_coupon_button').click(async function (e) {
            e.preventDefault();

            let form = $('.add_coupon_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){
                toasterError(response.errors);
            }


        });

        let discountAmountLabel = $('.discount_amount_label'),
            discountAmountLabelHtml = discountAmountLabel.html(),
            discountAmount = $('input[name="discount_amount"]');
        $('select[name="discount_type"]').change(function () {
            let discountType = $(this).val();
            if(discountType === 'value'){
                discountAmountLabel.html(discountAmountLabelHtml);
                discountAmount.attr('placeholder', discountAmountLabelHtml);
            }
            if(discountType === 'percentage'){
                discountAmountLabel.html(discountAmountPercentage);
                discountAmount.attr('placeholder', discountAmountPercentage);
            }
        });

        if(discountTypeSelectedOption === 'value'){
            discountAmountLabel.html(discountAmountLabelHtml);
            discountAmount.attr('placeholder', discountAmountLabelHtml);
        }
        if(discountTypeSelectedOption === 'percentage'){
            discountAmountLabel.html(discountAmountPercentage);
            discountAmount.attr('placeholder', discountAmountPercentage);
        }

    </script>

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




<?php echo $__env->make('admin.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\wamp64\www\legal\resources\views/admin/coupons/form.blade.php ENDPATH**/ ?>