<?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($marketerCoupon ?? ''  && $marketerCoupon->id): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>
            <?php echo csrf_field(); ?>

                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('user_id', $lang) ?? __('marketerCoupons.user_id')); ?></label>
                    <select name="user_id" class="form-control">
                        <option value=""><?php echo e(__('marketerCoupons.user_id')); ?></option>
                        <?php if(count($users)): ?>
                            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option <?php echo e(($marketerCoupon->user_id ?? null) == $user->id ? 'selected' : ''); ?> value="<?php echo e($user->id); ?>"><?php echo e($user->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </select>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('status', $lang) ?? __('marketerCoupons.status')); ?></label>
                    <select name="status" class="form-control <?php echo e($errors->has('status') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($marketerCoupon->status ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('marketerCoupons.active')); ?></option>
                        <option <?php echo e(($marketerCoupon->status ?? null) == 0 ? 'selected' : ''); ?> value="0"><?php echo e(__('marketerCoupons.not_active')); ?></option>
                    </select>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('service_type', $lang) ?? __('marketerCoupons.service_type')); ?></label>
                    <select name="service_type" class="form-control <?php echo e($errors->has('service_type') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($marketerCoupon->service_type ?? null) == 'all' ? 'selected' : ''); ?> value="all"><?php echo e(__('marketerCoupons.all')); ?></option>
                        <option <?php echo e(($marketerCoupon->service_type ?? null) == 'consulting' ? 'selected' : ''); ?> value="consulting"><?php echo e(__('marketerCoupons.consulting')); ?></option>
                        <option <?php echo e(($marketerCoupon->service_type ?? null) == 'documentation' ? 'selected' : ''); ?> value="documentation"><?php echo e(__('marketerCoupons.documentation')); ?></option>
                    </select>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo e(meta('discount_type', $lang) ?? __('marketerCoupons.discount_type')); ?></label>
                    <select name="discount_type" class="form-control <?php echo e($errors->has('discount_type') ? 'is-invalid' : ''); ?>">
                        <option <?php echo e(($marketerCoupon->discount_type ?? null) == 'value' ? 'selected' : ''); ?> value="value"><?php echo e(__('marketerCoupons.value')); ?></option>
                        <option <?php echo e(($marketerCoupon->discount_type ?? null) == 'percentage' ? 'selected' : ''); ?> value="percentage"><?php echo e(__('marketerCoupons.percentage')); ?></option>
                    </select>
                </div>
            <div class="form-group col-lg-3">
                <label class="discount_amount_label"><?php echo e(meta('discount_amount', $lang) ?? __('marketerCoupons.discount_amount')); ?></label>
                <input type="number" min="1" max="100" class="form-control" name="discount_amount" placeholder="<?php echo e(meta('discount_amount', $lang) ?? __('marketerCoupons.discount_amount')); ?>" value='<?php echo e($marketerCoupon->discount_amount  ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('start_date', $lang) ?? __('marketerCoupons.start_date')); ?></label>
                <input type="date" class="form-control" name="start_date" placeholder="<?php echo e(meta('start_date', $lang) ?? __('marketerCoupons.start_date')); ?>" value='<?php echo e($marketerCoupon->start_date ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('end_date', $lang) ?? __('marketerCoupons.end_date')); ?></label>
                <input type="date" class="form-control" name="end_date" placeholder="<?php echo e(meta('end_date', $lang) ?? __('marketerCoupons.end_date')); ?>" value='<?php echo e($marketerCoupon->end_date ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('available_users', $lang) ?? __('marketerCoupons.available_users')); ?></label>
                <input type="number" min="1" class="form-control" name="available_users" placeholder="<?php echo e(meta('available_users', $lang) ?? __('marketerCoupons.available_users')); ?>" value='<?php echo e($marketerCoupon->available_users ?? ""); ?>'/>
            </div>
                <div class="form-group col">
                    <label><?php echo e(meta('code', $lang) ?? __('marketerCoupons.code')); ?></label>
                    <input type="text" class="form-control" name="code" placeholder="<?php echo e(meta('code', $lang) ?? __('marketerCoupons.code')); ?>" value='<?php echo e($marketerCoupon->code ?? ""); ?>'/>
                </div>
                <div class="form-group col">
                    <label><?php echo e(meta('marketer_percentage', $lang) ?? __('marketerCoupons.marketer_percentage')); ?></label>
                    <input type="number" min="1" class="form-control" name="marketer_percentage" placeholder="<?php echo e(meta('marketer_percentage', $lang) ?? __('marketerCoupons.marketer_percentage')); ?>" value='<?php echo e($marketerCoupon->marketer_percentage ?? ""); ?>'/>
                </div>

            <?php if($marketerCoupon ?? ''  && $marketerCoupon->id): ?>
                <div class="form-group col">
                    <label><?php echo e(__('marketerCoupons.used_count')); ?></label>
                    <input readonly class="form-control bg-white" value='<?php echo e($marketerCoupon->used_count ?? 0); ?>'/>
                </div>
                <div class="form-group col">
                    <label><?php echo e(__('marketerCoupons.remaining_coupon_used')); ?></label>
                    <input readonly class="form-control bg-white" value='<?php echo e($marketerCoupon->available_users - $marketerCoupon->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(__('marketerCoupons.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');

            data.append('marketer_coupons', true);

            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 /home/balyomhost/public_html/legal/resources/views/admin/marketer_coupons/form.blade.php ENDPATH**/ ?>