<?php $__env->startPush('css'); ?>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <section class="make-appointment pt-120 pb-60">
        <div class="container">
            <form action="<?php echo e(setRoute('frontend.parlour.booking.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="parlour" value="<?php echo e($parlour->slug); ?>">
                <input type="hidden" name="vendor_id" value="<?php echo e($parlour->vendor_id); ?>">
                <input type="hidden" name="price" id="price">
                <div class="row justify-content-center">
                    <div class="col-lg-10">
                        <div class="appointment-area">
                            <h3 class="title"><i class="fas fa-info-circle text--base mb-20"></i>
                                <?php echo e(__('Make Appointment')); ?></h3>
                            <div class="salon-thumb">
                                <img src="<?php echo e(get_image($parlour->image, 'site-section')); ?>" alt="img">
                            </div>
                            <div class="about-details">
                                <div class="salon-title">
                                    <h3 class="title"><i class="las la-user-alt"></i> <?php echo e(__('Salon Details')); ?></h3>
                                </div>
                                <div class="list-wrapper">
                                    <div class="preview-area">
                                        <div class="preview-item">
                                            <p><?php echo e(__('Salon Name')); ?> :</p>
                                        </div>
                                        <div class="preview-details">
                                            <p><?php echo e($parlour->name ?? ''); ?></p>
                                        </div>
                                    </div>
                                    <div class="preview-area">
                                        <div class="preview-item">
                                            <p><?php echo e(__('Salon Address')); ?> :</p>
                                        </div>
                                        <div class="preview-details">
                                            <p><?php echo e($parlour->address ?? ''); ?></p>
                                        </div>
                                    </div>
                                    <div class="preview-area">
                                        <div class="preview-item">
                                            <p><?php echo e(__('Experience')); ?> :</p>
                                        </div>
                                        <div class="preview-details">
                                            <p><?php echo e($parlour->experience ?? ''); ?></p>
                                        </div>
                                    </div>
                                </div>
                                <div class="salon-title pt-4">
                                    <h3 class="title"><i class="las la-street-view"></i> <?php echo e(__('Service Select')); ?></h3>
                                </div>
                                <div class="service-select">
                                    <div class="service-option pt-10">
                                        <?php $__currentLoopData = $parlour->services ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="service-item">
                                                <div class="service-inner">
                                                    <input type="checkbox" name="service[]"
                                                        value="<?php echo e($item->service_name); ?>" class="hide-input service"
                                                        id="service_<?php echo e($item->id); ?>"
                                                        data-item="<?php echo e(json_encode($item)); ?>">
                                                    <label for="service_<?php echo e($item->id); ?>" class="package--amount">
                                                        <p><?php echo e($item->service_name); ?>

                                                            <span><?php echo e(get_default_currency_symbol()); ?><?php echo e(get_amount($item->price)); ?>

                                                            </span>
                                                        </p>
                                                    </label>
                                                </div>
                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </div>
                                <div class="shedule-title pt-4">
                                    <h3 class="title"><i class="fas fa-history"> </i> <?php echo e(__('Schedule')); ?></h3>
                                </div>
                                <div class="row">
                                    <div class="col-lg-3">
                                        <div class="date-picker">
                                            <div class="row">
                                                <div class="col-xl-12 form-group">
                                                    <?php
                                                        $currentDate = \Carbon\Carbon::now();
                                                        $todaysDate = $currentDate->format('d F, Y');
                                                        $schedule_date = $parlour->number_of_dates;
                                                        $offDays = explode(',', $parlour->off_days);
                                                    ?>
                                                    <input type="hidden" class="todays-date" value="<?php echo e($todaysDate); ?>">
                                                    <label><?php echo e(__('Select Date')); ?> <span>*</span></label>
                                                    <select class="form--control nice-select date" name="date">
                                                        <?php for($i = 0; $i < $schedule_date; $i++): ?>
                                                            <?php
                                                                $currentDayName = $currentDate->format('l');
                                                            ?>
                                                            <?php if(!in_array($currentDayName, $offDays)): ?>

                                                                <option value="<?php echo e($currentDate->format('d F, Y')); ?>">
                                                                    <?php echo e($currentDate->format('d F, Y')); ?>


                                                                </option>
                                                            <?php endif; ?>
                                                            <?php
                                                                $currentDate->addDay();
                                                            ?>
                                                        <?php endfor; ?>
                                                    </select>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                    <?php
                                        $current_time = now()
                                            ->setTimeZone($basic_settings->timezone)
                                            ->format('H:i');
                                    ?>
                                    <input type="hidden" class="current_time" value="<?php echo e($current_time); ?>">
                                    <div class="col-lg-9">
                                        <div class="shedule-area">
                                            <label><?php echo e(__('Select Time')); ?> <span>*</span></label>
                                            <div class="shedule-option" data-item="<?php echo e(json_encode($parlour->schedules)); ?>">

                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="appointment-footer pt-5">
                                    <div class="col-xl-12 col-lg-12 form-group">
                                        <?php echo $__env->make('admin.components.form.textarea', [
                                            'label' =>
                                                __('Message') .
                                                '<span class="text--warning">' .
                                                '(' .
                                                __('Optional') .
                                                ')' .
                                                '</span>',
                                            'name' => 'message',
                                            'placeholder' => __('Write Here') . '...',
                                            'value' => old('message'),
                                        ], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                    </div>
                                    <div class="col-lg-12 form-group pt-3">
                                        <button type="submit" class="btn--base small w-100"><?php echo e(__('Checkout')); ?> ( <span
                                                class="price"><?php echo e(get_default_currency_symbol()); ?> </span> )<i
                                                class="fas fa-chevron-circle-right ms-1"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
    <script>
        $('.service').on('change', function() {
            var servicePrice = [];
            $('.service:checked').each(function() {
                var checkedPrice = $(this).data('item');
                var price = parseFloat(checkedPrice.price)
                servicePrice.push(price);
            });
            var totalPrice = servicePrice.reduce(function(a, b) {
                return a + b;
            }, 0);
            $('.price').text('<?php echo e(get_default_currency_symbol()); ?>' + totalPrice.toFixed(2))
            $('#price').val(totalPrice.toFixed(2));
        });
        $(document).ready(function() {
            var selectedDate = $('.date').val();
            var todaysDate = $('.todays-date').val();
            var currentTime = $('.current_time').val();
            var data = JSON.parse($('.shedule-option').attr("data-item"));
            run(selectedDate, todaysDate, currentTime, data);

        });
        $('.date').on('change', function() {
            var selectedDate = $(this).val();
            var todaysDate = $('.todays-date').val();
            var currentTime = $('.current_time').val();

            var data = JSON.parse($('.shedule-option').attr("data-item"));
            $('.shedule-option').html('');
            $('.shedule-option').html('');

            run(selectedDate, todaysDate, currentTime, data);

        });

        function run(selectedDate, todaysDate, currentTime, data) {
            var getScheduleURL = "<?php echo e(route('frontend.parlour.booking.get.schedule')); ?>";
            $.post(getScheduleURL, {
                selectedDate: selectedDate,
                _token: "<?php echo e(csrf_token()); ?>"
            }, function(response) {
                $('.shedule-option').empty();
                $.each(data, function(index, item) {
                    let fromTime = item.from_time;
                    let disabled = (todaysDate === selectedDate && currentTime > fromTime) ? 'disabled' :
                        '';

                    let disableClassName = disabled ? 'danger' : '';
                    let textClass = disabled ? 'text--disable' : '';
                    let itemData = '';

                    if (response.data.data.length === 0) {
                        itemData = `
                        <div class="shedule-item ${disableClassName}">
                            <div class="shedule-inner ">
                                <input type="radio" name="schedule" class="hide-input" value="${item.id}" id="shedule_${item.id}" ${disabled}>
                                <label for="shedule_${item.id}" class="package--amount ${disableClassName}">
                                    <strong class="${textClass}">${item.from_time} - </strong>
                                    <strong class="${textClass}">${item.to_time}</strong>
                                </label>
                            </div>
                        </div>
                    `;
                        $('.shedule-option').append(itemData);
                    } else {
                        let isDisabledForBooking = false;

                        $.each(response.data.data, function(dataIndex, booked) {
                            if (item.id === booked.schedule_id && item.max_client == booked.total) {
                                isDisabledForBooking = true;
                            }
                        });
                        itemData = `
                        <div class="shedule-item">
                            <div class="shedule-inner ${disableClassName} ${isDisabledForBooking ? 'danger' : ''}">
                                <input type="radio" name="schedule" class="hide-input" value="${item.id}" id="shedule_${item.id}" ${isDisabledForBooking ? 'disabled' : disabled}>
                                <label for="shedule_${item.id}" class="package--amount">
                                    <strong class="${textClass}">${item.from_time} - </strong>
                                    <strong class="${textClass}">${item.to_time}</strong>
                                </label>
                            </div>
                        </div>
                    `;
                        $('.shedule-option').append(itemData);
                    }
                });
            });
        }
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('frontend.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\cc_projects_files\salonhub_project\salonhub\resources\views/frontend/pages/parlour-booking/index.blade.php ENDPATH**/ ?>