<div class="row" style="">
    <div class="col-xl-3 col-md-3">
        <div class="card style_table">
            <div class="card-body pt-2 ps-3" style="border-radius:0px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="txt" style="height:51px">
                            <div class="col-md-12">
                                <span class="mt-1 mb-0 h6"> Dr. {!! $doctor->getAccount?$doctor->getAccount->name:'' !!}</span>
                            </div>

                            <h6 class="border-top mb-0"></h6>
                            <p class="mb-2 mb-xl-1 mb-lg-1 mt-0">{!! $doctor->getAccount->account_contact?Str::limit($doctor->getAccount->account_contact->qualifications,60):'' !!}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-md-3">
        <div class="card radius-5">
            <div class="card-body pt-2 ps-3" style="border-radius:0px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="d-flex align-items-center">
                            <div class="">
                                <p class="mb-1">No of Appointment</p>
                                <h4 class="mb-0 text-primary"><span class="doneReports">{!! $totalDoneAppointment??0 !!}</span>/<span class="total_reports">{!! $totalAppointment??0 !!}</span></h4>
                            </div>
                            <div class="ms-auto fs-2 text-primary">
                                <i class="bi bi-kanban-fill"></i>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-md-3">
        <div class="card radius-5">
            <div class="card-body pt-2 ps-3" style="border-radius:0px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="d-flex align-items-center">
                            <div class="">
                                <p class="mb-1">No of CheckIn</p>
                                <h4 class="mb-0 text-primary"><span class="doneReports">{!! $totalCheckInDone??0 !!}</span>/<span class="total_reports">{!! $totalCheckIn??0 !!}</span></h4>
                            </div>
                            <div class="ms-auto fs-2 text-primary">
                                <i class="bi bi-door-open"></i>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="col-xl-3 col-md-3">
        <div class="card radius-5">
            <div class="card-body pt-2 ps-3" style="border-radius:0px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="d-flex align-items-center">
                            <div class="">
                                <p class="mb-1">No of Visit</p>
                                <h4 class="mb-0 text-primary"><span class="doneReports">{!! $totalVisitDone??0 !!}</span>/<span class="total_reports">{!! $totalVisit??0 !!}</span></h4>
                            </div>
                            <div class="ms-auto fs-2 text-primary">
                                <i class="bi bi-kanban-fill"></i>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
@php 
$shiftIds=[];
@endphp
@foreach($shiftAvailable as $Keys => $result)
@php $shiftIds[$Keys] = $Keys;@endphp
@endforeach

@php $shiftData = \App\Models\AppointmentShift::whereIn('id',$shiftIds)->orderBy('priority')->get(); @endphp
@foreach($shiftData as $shiftIds => $row)
<div class="row" style="">
    <div class="col-md-12">
        
        <div class="col-md-12" style="background-color: {!! $row->bg_color??'' !!}; color:{!! $row->color  !!};border-radius:5px">
            <p class="text-center" style="font-size: 18px;"><b>{!! strtoupper($row->name)??'' !!} SHIFT ({!! isset($date) && $date!='' ?formatedDate($date):'' !!})</b></p>
        </div>

        @if(count($data)>0)
        <div class="card-body mt-3" id="tables">
            <div class="table-responsive">
                <table id="example" class="table table-bordered align-middle" style="width:100%">
                    <thead class="table-light">
                        <tr class="text-uppercase">
                            <th class="thbutton">#</th>
                            <th class="thbutton">Token No</th>
                            
                            <th style="text-align: left;width: 25%;">Patient Info.</th>
                            {{--<th style="text-align: left;width: 6%;">Booking</th>--}}
                            @if(request()->segment(2)!='patient-display')
                            <th class="thbutton">Check In</th>
                            @endif
                            <th style="text-align: center;width: 10%;">Appointment</th>
                          {{--  @if($status=="Pending")
                            <th class="thbutton">Start</th>
                            @endif--}}
                            @if(request()->segment(2)!='patient-display')
                            <th class="thbutton">Service</th>
                            @endif
                            <th style="text-align: left;width: 10%;">Check @if($status=="Pending") In @else Out @endif Time</th>
                            @if(request()->segment(2)!='patient-display')
                            @if($status=="Pending")
                            <th style="text-align: left;">RESC.</th>
                            @endif
                            @endif
                            
                        </tr>
                    </thead>

                    <tbody>
                        @php $i=1;@endphp

                        @foreach($data as $key=> $list)
                        @if($list->shift_id == $row->id)
                        <tr>
                            <td class="text-center">@if($list->check_in_status==0)
                                <i class="bi bi-x-circle text-danger" style="font-size: 30px;"></i>
                                @else
                                <i class="bi bi-check-circle text-success" style="font-size: 30px;"></i>
                                @endif
                            </td>
                            <td class="text-center"><b style="font-size: 30px;">{{$list->appointment_serial_no ?? ''}}</b></td>
                            
                            <td style="text-align: left;">
                                <b>{{$list->getPatient->account_title->name ?? ''}}
                                {{strtoupper($list->getPatient->name) ?? ''}}</b><br>
                                {{$list->getPatient->account_contact->gender->name ?? ''}}{{ isset($list->getPatient->account_contact->date_of_birth) && isset($list->getPatient->account_contact->gender) ? ', ' : '' }} {{ isset($list->getPatient->account_contact->date_of_birth) ? age($list->getPatient->account_contact->date_of_birth) . ' Year`s' : '' }}
                                ,
                                {{ isset($list->getPatient->account_contact->phone_no) ?'Ph:'. $list->getPatient->account_contact->phone_no:''}}
                            </td>
                            {{--<td class="text-left">
                                @php  $booking_date_time = \Illuminate\Support\Carbon::parse($list->booking_date_time); @endphp
                                    {{$booking_date_time->format('d-m-Y') ?? ''}}
                            </td>--}}
                            @if(request()->segment(2)!='patient-display')
                            <td style="text-align:center">
                            <div class="form-check form-check-inline{{ $i }}">
                                <input class="form-check-input{{ $i }} btn-lg changeStatusCustom" type="checkbox" 
                                id="inlineCheckbox{{ $i }}" data-url="{!! route('opd-appointment.checkIn') !!}" 
                                data-id="{{ $list->id }}" 
                                data-status="{!! $list->check_in_status=='0'?1:0 !!}" {{ $list->check_in_status == '1' ? 'checked' : '' }}>
                            </div>
                            </td>
                            @endif
                            <td style="text-align: center;">
                                
                                
                                @php $appointment_date_time = \Illuminate\Support\Carbon::parse($list->appointment_date_time); @endphp
                                <span class="badge btn-secondary" style="font-size: 15px;">{{$appointment_date_time->format('h:i A') ?? '' }}</span>
                                <br>
                                <b>{{$list->booking_no}}</b>
                            </td>
                           {{-- @if($status=="Pending")
                            <td style="text-align:center">
                                <div class="form-check form-check-inline{{ $i }}">
                                    <input class="form-check-input{{ $i }} btn-lg changeStatusCustom" type="checkbox" id="inlineCheckbox{{ $i }}" data-url="{!! route('queue-manager.consultation.start',$list->id) !!}" data-id="{{ $list->id }}" data-status="{!! $list->consultation_start_date_time==''?1:0 !!}" {{ $list->consultation_start_date_time != '' ? 'checked' : '' }}>
                                </div>
                            </td>
                            @endif--}}
                            @if(request()->segment(2)!='patient-display')
                            <td>
                            @if($list->service_status!="Done")
                                @if($list->check_in_status == '1')
                                <div class="btn-group" style="width: 100%">
                                    <a data-url="{{ route('queue-manager.patient-visit.done', ['booking_id' => $list->id]) }}" 
                                       data-id="{{ $list->id }}" 
                                        href="#" 
                                        class="btn btn-success serviceDone" style="color: white;height:35px;font-size: 18px;line-height: 1.9">
                                        Done
                                    </a>
                                </div>
                                @endif
                            @else
                                @if($list->check_in_time)
                                <div class="btn-group" style="width: 100%">
                                    <a data-url="{{ route('queue-manager.patient-visit.undo', ['booking_id' => $list->id]) }}" 
                                       data-id="{{ $list->id }}" 
                                        href="#" 
                                        class="btn btn-danger changeStatusCustom" style="color: white">
                                        <i class="bi bi-arrow-counterclockwise"></i>Undo
                                    </a>
                                </div>
                                @endif
                            @endif
                            </td>
                            @endif
                            <td style="text-align: left;">

                                @if($list->check_in_time) <b>Time: 
                                    @if($status=="Pending")
                                    {!! formatedTime($list->check_in_time) !!}
                                    @else
                                     {!! formatedTime($list->checkout_date_time) !!}
                                    @endif
                                </b> @endif
                                @if($list->service_status!="Done")
                               
                                @php
                                $startTime = \Illuminate\Support\Carbon::parse(now());
                                $finishTime = \Illuminate\Support\Carbon::parse($list->check_in_time);
                                $totalDays = $finishTime->diffInDays($startTime);
                                $totalDuration = $finishTime->diffInHours($startTime) % 24;
                                $totlaMinute = $finishTime->diffInMinutes($startTime) % 60;
                                @endphp
                                @if($list->check_in_time)
                                @if($totalDuration<6 && $totalDays<1)
                                <br>
                                <span class="badge 
                                badge-pill
                                bg-@if($totalDuration>0){!! 'danger' !!}@elseif($totlaMinute>30){!! 'warning' !!}@else{!!'info'!!}@endif" style="font-size:11px"><b>Since:
                                        @if($totalDays>0) {!! $totalDays !!} Days @endif
                                        @if($totalDuration>0) {!! $totalDuration !!} hour @endif
                                        {!! $totlaMinute !!} minutes</b></span>
                                @endif
                                @else
                                Not yet arrived!
                                @endif
                                @endif
                            </td>
                            @if(request()->segment(2)!='patient-display')
                            @if($status=="Pending")
                            <td style="width: 5%;">
                            @if($list->service_status!="Done")
                                <div class="btn-group" style="width: 100%;">
                                    <a href="{{route('opd-bookings.reschedule',$list->id)}}" class="btn btn-primary text-white me-1" title="Re-Schedule"><i class="bi bi-arrow-repeat"></i> </a>
                                </div>
                            @endif
                            </td>
                            @endif
                            @endif
                            

                        </tr>
                        @endif
                        @php $i++; @endphp
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        @endif
    </div>
</div>
@endforeach