@php $currentDate=date('Y-m-d'); @endphp
@if($formattedDate >= $currentDate)
    @foreach($query as $key => $appointment)
        @php $holiDays = \App\Models\HolidaySetting::select('id')->where(['from_date'=>$formattedDate,
        'account_id'=>$appointment->doctor_id,
        'shift_id'=>$appointment->shift_id ])->first();
        @endphp

        @if(empty($holiDays))
            <div class="row mt-2" style="margin-bottom:10px;">
                <div class="col-md-12 col-sm-12">
                    <p class="btn-sm btn-default" style="font-size:15px;padding:10px 12px;color:{!! $appointment->color??'#fff' !!};background-color:{!! $appointment->bg_color??'#32A544' !!}"><b>( {{ $appointment->name }} )</b> {!! $dayOfWeekName??'' !!}, {!! $selectedMonth??'' !!} {!! $selectedDate??'' !!} </p>
                    @php
                        $gaps = $appointment->gap_between_two_patient??20;
                        $startTime = \Carbon\Carbon::parse($appointment->time_from ?? '');
                        $endTime = \Carbon\Carbon::parse($appointment->time_to ?? '');
                        $i=1;
                    @endphp
                    @while($startTime < $endTime)
                        @php
                            $current_time = \Carbon\Carbon::parse(date('H:i:s'));
                        @endphp

                        @if ($formattedDate == $currentDate && $startTime < $current_time)

                        @else
                        @php $time=$startTime->format('h:i A');
                            $checkAvaibleofNot = \App\Models\BookingCalendar::select('id')->where([
                            'shift_id' => $appointment->shift_id,
                            'appointment_date' => $formattedDate,
                            'appointment_time' => $time,
                            'appointment_serial_no' => $i,
                            'doctor_ac_id' => $doctor->account_id,
                            ])->first();
                        @endphp

                        @if(empty($checkAvaibleofNot))
                            @if($appointment->patient_quantity>=$i)
                            <span style="text-align:center;cursor: pointer;" class="booking_slot" 
                                            data-time="{{$time}}" 
                                            data-date="{!! $dayOfWeekName??'' !!}, {!! $selectedMonth??'' !!} {!! $selectedDate??'' !!}" data-shift_name="{{ $appointment->name??'' }}" data-slot="{{$i}}" 
                                            data-url='{{route("opd-bookings.reschedule-confirm",['doctor_id'=>$appointment->doctor_id,
                                            'shift_id'=>$appointment->shift_id,
                                            'time'=>$time,
                                            'date'=>$formattedDate,
                                            'block_no'=>$i,
                                            'booking_id'=>$opdData->id])}}' title="{{$i}}">{{$i}}<br>
                                <span style="font-size:10px;">{{ $time }}</span>
                            </span>
                            @endif
                        @endif
                          
                        @endif

                        @php
                            $startTime->addMinutes($gaps);
                            $i++;
                        @endphp
                    @endwhile
                </div>
            </div>
        @endif
    @endforeach
@else
<div class="row mt-2" style="margin-bottom:10px;">
    <div class="col-md-12 col-sm-12 text-center" style="height: 200px;">
        <h3 class="text-danger" style="text-align: center;vertical-align: middle;line-height: 90px; ">Booking Slot Not Available!</h3>
    </div>
</div>
@endif