<?php $__env->startSection('content'); ?>
    <section class="inner_header">
        <img src="<?php echo e(asset('assets/web/images/icons/inner.svg')); ?>" alt="" class="inner_shap">
        <div class="container">
            <ul class="links">
                <li>
                    <a href="<?php echo e(LaravelLocalization::getLocalizedURL($lang, route('home'), [], true)); ?>"><?php echo e(__('main.home')); ?></a>
                </li>
                <li>
                    <a href="#"> <?php echo e($title); ?> </a>
                </li>
            </ul>
            <h4><?php echo e($title); ?></h4>
        </div>
    </section>
    <section class="consultation-pg section_padding">
        <div class="container">
            <form method="post" action="<?php echo e(route('consulting.consultingRequest', $consultingType)); ?>" class="consulting_request_form">
                <div class="sec-cards mb-5">
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="form-check color2">
                                <input style="cursor:pointer;" class="form-check-input" type="radio" name="consulting_way" id="consulting_phone" value="phone">
                                <label class="form-check-label" for="consulting_phone">
                                    <div class="item">
                                        <div class="icon-outer">
                                            <i class="bi bi-telephone-fill"></i>
                                        </div>
                                        <div class="content">
                                            <h5 class="title text-white"><b><?php echo e(__('consultings.consulting_phone')); ?></b></h5>
                                        </div>
                                    </div>
                                </label>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="form-check color1">
                                <input style="cursor:pointer;" class="form-check-input" type="radio" name="consulting_way" id="consulting_zoom"value="zoom">
                                <label class="form-check-label" for="consulting_zoom">
                                    <div class="item">
                                        <div class="icon-outer">
                                            <i class="bi bi-camera-video-fill"></i>
                                        </div>
                                        <div class="content">
                                            <h5 class="title text-white"><b><?php echo e(__('consultings.visible_consulting')); ?> <br><?php echo e(__('consultings.via_zoom')); ?></b></h5>
                                        </div>
                                    </div>
                                </label>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="form-check color2">
                                <input style="cursor:pointer;" class="form-check-input" type="radio" name="consulting_way" id="consulting_office"value="office">
                                <label class="form-check-label" for="consulting_office">
                                    <div class="item">
                                        <div class="icon-outer">
                                            <i class="bi bi-building"></i>
                                        </div>
                                        <div class="content">
                                            <h5 class="title text-white"><b><?php echo e(__('consultings.visible_consulting')); ?> <br><?php echo e(__('consultings.via_office')); ?></b></h5>
                                        </div>
                                    </div>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-container">
                    <div class="row justify-content-between">
                        <h5 class="title text-dark mb-4"><b><?php echo e(__('activeConsultings.consulting_subject')); ?></b></h5>
                        <div class="col-md-5">
                            <div class="form-group">
                                <input name="consulting_subject" class="form-control" placeholder="<?php echo e(__('activeConsultings.consulting_subject')); ?>"/>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <p class="note">
                                <i class="bi bi-exclamation-circle"></i>
                                <?php echo e(__('consultings.consulting_hint_1')); ?>

                            </p>
                        </div>
                    </div>
                    <div class="date-outer mt-5">
                        <h5 class="title text-dark mb-4"><b><i class="bi bi-calendar3 me-2"></i> <?php echo e(__('consultings.consulting_date')); ?></b></h5>
                        
                        <div class="date-inner consulting_date_container"></div>
                    </div>
                    <div class="date-outer mt-5">
                        <h5 class="title text-dark mb-4"><b><i class="bi bi-clock me-2"></i><?php echo e(__('consultings.consulting_time')); ?></b></h5>
                        
                        <div class="date-inner consulting_time_container"></div>
                    </div>
                    <p class="note mt-5">
                        <i class="bi bi-exclamation-circle"></i>
                        <?php echo e(__('consultings.consulting_hint_2')); ?>

                    </p>
                    <div class="payment_methods mt-5">
                        <h5 class="title text-dark mb-4"><b><?php echo e(__('activeConsultings.pay_way')); ?></b></h5>
                        <div class="row">
                            <div class="col-md-6 mb-2">
                                <div class="form-check color3">
                                    <input class="form-check-input" type="radio" name="pay_way" id="visa_master" value="2">
                                    <label class="form-check-label" for="visa_master">
                                        <?php echo e(__('activeConsultings.visa_master')); ?>

                                        <img src="<?php echo e(asset('assets/web/images/icons/payment-3.svg')); ?>" alt="" class="icon">
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-6 mb-2">
                                <div class="form-check color1">
                                    <input class="form-check-input" type="radio" name="pay_way" id="mada" value="6">
                                    <label class="form-check-label" for="mada">
                                        <?php echo e(__('activeConsultings.mada')); ?>

                                        <img src="<?php echo e(asset('assets/web/images/icons/payment-1.svg')); ?>" alt="" class="icon">
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-check color2">
                                    <input class="form-check-input" type="radio" name="pay_way" id="stc_pay" value="14">
                                    <label class="form-check-label" for="stc_pay">
                                        <?php echo e(__('activeConsultings.stc_pay')); ?>

                                        <img src="<?php echo e(asset('assets/web/images/icons/payment-2.svg')); ?>" alt="" class="icon">
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-check color2">
                                    <input class="form-check-input" type="radio" name="pay_way" id="apple_pay" value="11">
                                    <label class="form-check-label" for="apple_pay">
                                        <?php echo e(__('activeConsultings.apple_pay')); ?>

                                        <img src="<?php echo e(asset('assets/web/images/icons/payment-2.svg')); ?>" alt="" class="icon">
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5 mb-5">
                        <div class="col-md-6">
                            <h5 class="title text-dark mb-4"><b> <?php echo e(__('activeConsultings.coupon_id')); ?> </b></h5>
                            <div class="form-group copun-group">
                                <input name="coupon_code" class="form-control" placeholder="<?php echo e(__('activeConsultings.coupon_id')); ?>"/>
                                <a href="#" class="butn sub_butn check_coupon"><span> <?php echo e(__('consultings.apply_coupon')); ?> </span></a>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <h5 class="title text-dark mb-4 discount_title"><b> <?php echo e(__('consultings.discount_percentage')); ?> </b></h5>
                            <div class="form-group">
                                <input class="form-control discount_value" placeholder="0" disabled/>
                            </div>
                        </div>
                    </div>
                    <div class="total_box text-center col-md-5 m-auto">
                        <h5 class="title main_color"><b><?php echo e(__('consultings.total')); ?></b></h5>
                        <h1 class="price text-dark mt-3"><b class="total">0</b> <small><?php echo e(__('main.sar')); ?></small></h1>
                    </div>
                    <p class="note mt-3 col-md-4 m-auto">
                        <i class="bi bi-exclamation-circle"></i>
                        <?php echo e(__('main.total_including_added_value')); ?>

                    </p>
                    <button class="submit-butn butn mt-5 m-auto d-block consulting_request_button" type="button"><span><b><?php echo e(__('consultings.complete_consultation_request')); ?></b></span></button>
                </div>
            </form>
        </div>
    </section>
<?php $__env->stopSection(); ?>

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

        let getConsultingDateAndTimeRoute = "<?php echo e(route('consulting.getConsultingDateAndTime')); ?>",
            checkCouponRoute = "<?php echo e(route('checkCoupon')); ?>",
            consultingType = "<?php echo e($consultingType); ?>",
            consultingDateAlet = "<?php echo e(__('consultings.select_consulting_date_time')); ?>",
            discountTitlePercentage = "<?php echo e(__('coupons.discount_percentage')); ?>",
            discountTitleValue = "<?php echo e(__('coupons.discount_amount')); ?>",
            noData = "<?php echo e(__('consultings.no_data')); ?>";

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

            data.append('consulting_id', $('input[name="consulting_time"]:checked').data('consulting-id'));
            data.append('consulting_type', consultingType);
            data.append('coupon_code', $('input[name="coupon_code"]').val());
            data.append('service_type', 'consulting');

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

            if (response.errors) {
                $(this).attr('disabled', false);
                toasterError(response.errors);
            }
            if (response.url) {
                window.location.href = response.url;
            }
        });

        $('input[name="consulting_way"]').click(async function () {
            let data = {consulting_way: $(this).val(), type: consultingType},
                url = getConsultingDateAndTimeRoute,
                method = 'get';

            $('.consulting_time_container').html('');

            const response=await ajax({
                url,
                data,
                dataType: 'html',
                method,
                contentType: false,
                processData: false,
            });

            if (response.consulting_dates) {
                $('.consulting_date_container').html('');
                for(let consulting of response.consulting_dates){
                    $('.consulting_date_container').append(`
                    <div class="form-check">
                        <input data-consulting-date="${consulting.date}" class="form-check-input" type="radio" name="consulting_date" id="consulting_date_${consulting.id}" value="${consulting.date}">
                        <label class="form-check-label" for="consulting_date_${consulting.id}">
                            ${consulting.label}
                        </label>
                    </div>`);
                }
            } else {
                $('.consulting_date_container').html(`<div class="alert alert-secondary text-danger text-center">${noData}</div>`);
            }
        });

        let oldPrice = 0;
        $(document).on('click', 'input[name="consulting_date"]',async function () {
            let data = {
                    consulting_type: consultingType,
                    consulting_date: $(this).data('consulting-date'),
                    consulting_way: $('input[name="consulting_way"]:checked').val()
                },
                url = getConsultingDateAndTimeRoute,
                method = 'get';

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

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

            if(response.consulting_times){
                $('.consulting_time_container').html('');
                for(let consultingTimes of response.consulting_times){
                    $('.consulting_time_container').append(`
                        <div class="form-check">
                            <input data-consulting-id="${consultingTimes.id}" class="form-check-input" type="radio" name="consulting_time" id="consulting_time_${consultingTimes.id}" value="${consultingTimes.time}">
                            <label class="form-check-label" for="consulting_time_${consultingTimes.id}">
                                ${consultingTimes.label}
                            </label>
                        </div>`);
                }
            } else {
                $('.consulting_time_container').html(`<div class="alert alert-secondary text-danger text-center">${noData}</div>`);
            }
        });

        $(document).on('click', 'input[name="consulting_time"]',async function () {
            let data = {
                    consulting_id: $(this).data('consulting-id'),
                },
                url = getConsultingDateAndTimeRoute,
                method = 'get';

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

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

            if(response.price && $('input[name="coupon_code"]').val() !== ''){
                oldPrice = response.price;
                $('.check_coupon').trigger('click');
            } else {
                oldPrice = response.price;
                $('.total').html(response.price);
            }

        });

        $('input[name="coupon_code"]').focus(function () {
            $(this).css({
                borderColor: '#E1E1E1'
            })
        }).blur(function () {
            if($(this).val() === ''){
                $('.discount_value').val(0);
                $('.total').html(oldPrice);
            }
        });

        $('.check_coupon').click(async function (e) {
            e.preventDefault();
            let couponCode = $('input[name="coupon_code"]');
            if(couponCode.val() === ''){
                couponCode.css({
                    borderColor: 'red'
                });
                return false;
            }
            let data = {
                    consulting_type: consultingType,
                    coupon_code: couponCode.val(),
                    consulting_id: $('input[name="consulting_time"]:checked').data('consulting-id'),
                    service_type : 'consulting'
                },
                url = checkCouponRoute,
                method = 'get';

            if(data.consulting_id === undefined){
                alert(consultingDateAlet);
                return false;
            }

            $(this).attr('disabled', true);
            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method,
                contentType: false,
                processData: false,
            });
            if (response.errors) {
                $(this).attr('disabled', false);
                toasterError(response.errors);
            }
            if (!response.errors) {
                $(this).attr('disabled', true);
                let discountTitle = response.discount_type === 'percentage' ? discountTitlePercentage : discountTitleValue;
                $('.discount_title').html(discountTitle);
                $('.discount_value').val(response.coupon_discount);
                $('.total').html(response.total);
            }
        })
    </script>
<?php $__env->stopSection(); ?>

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