<div class="card-body">
    <div class="table-responsive">
        <form action="{!! route('appointment-doctor-shifts.store', $id) !!}" method="post" enctype='multipart/form-data'>
            @csrf
            @method('patch')
            <table class="table table-bordered align-middle" style="width:100%">
                <thead class="table-light">
                    <tr>
                        <th class="thbutton">Sl No</th>
                        <th>Shifts</th>
                        <th>Appointment Settings</th>
                        {{--<th class="thbutton">Booking Limit</th>
                        <th class="thbutton">Serial Start</th>--}}
                        <th class="text-center">Days</th>
                        <th class="text-center">Fees</th>
                        {{--<th>Consultation Fees</th>--}}
                        <th class="thbutton">Web Booking</th>
                        <th class="thbutton">App Booking</th>

                        <th class="thbutton">Active</th>
                        <th class="thbutton">Edit</th>
                    </tr>
                </thead>
                <tbody>

                    @php
                    $doctor_shift_ids = explode(',', $doctor_shifts->shifts);
                    $doctor_id=request()->segment(2);
                    $doctor = \App\Models\Doctor::find($doctor_id);
                    @endphp
                    @if(count($appointment_shifts) > 0)
                    @foreach ($appointment_shifts as $key => $shift)
                    @php $doctor_days = \App\Models\AppointmentDoctorShiftDay::select('*',
                    \DB::raw("(GROUP_CONCAT(day_id SEPARATOR ',')) as `days`"),
                    )
                    ->where('doctor_id', $doctor_id)
                    ->where('shift_id', $shift->id)
                    ->where('chamber_id',$doctor->doctors_chamber_id)
                    ->first();

                    $doctor_day = explode(',', $doctor_days->days) ?? [];

                   
                    $dataFees = \App\Models\AppointmentDoctorFees::select([
                    'id',
                    'doctor_id',
                    'shift_id',
                    'product_id',
                    'status'
                    ])
                    ->where('doctor_id', $doctor_id)
                    ->where('shift_id', $shift->id)
                    ->where('chamber_id',$doctor->doctors_chamber_id)
                    ->with('getProduct')
                    ->get();
                    
                    $doctor_shiftss = \App\Models\AppointmentDoctorShift::select('*')
                    ->where('doctor_id', $id)
                    ->where('shift_id', $shift->id)
                    ->where('chamber_id',$doctor->doctors_chamber_id)
                    ->first();
                    @endphp
                    <tr>
                        <td class="text-center">{{$key+1}}</td>
                        <td>{{ ucfirst($shift->name) }}</td>
                        <td>
                        Days:
                            @foreach (daysOfWeek() as $keys => $day)
                            @if(in_array($keys, $doctor_day))
                            <span class="badge bg-info">{{ $day }}</span>
                            &nbsp;
                            @endif
                            @endforeach
                            <br>
                            Patient Limit: {!! $doctor_shiftss->patient_quantity??'' !!}, &nbsp;  Serial Start: {!! isset($doctor_shiftss->serial_start_from) && $doctor_shiftss->serial_start_from?$doctor_shiftss->serial_start_from:'' !!}, Start Time: {!! isset($doctor_shiftss->time_from) && $doctor_shiftss->time_from?formatedTime($doctor_shiftss->time_from):'' !!}, End Time: {!! isset($doctor_shiftss->time_to) && $doctor_shiftss->time_to?formatedTime($doctor_shiftss->time_to):'' !!}<br>
                            Fees: 
                            @if(count($dataFees)>0)
                            @foreach($dataFees as $keysfee => $fees)
                            <a href="{{route('products.edit',$fees->id)}}" title="{{ $fees->getProduct?$fees->getProduct->name:'' }}">{{ $fees->getProduct?Str::limit($fees->getProduct->name, 50, ' ..'):'' }}</a> - ({{$fees->getProductPrice?$fees->getProductPrice->mrp:''}})
                            ,
                            @if($keysfee % 1 === 0)
                            <br>
                            @endif
                            @endforeach
                            @endif
                        </td>


                        {{--<td>{!! $doctor_shiftss->patient_quantity??'' !!}</td>
                        <td>{!! $doctor_shiftss->serial_start??'' !!}</td>--}}
                        <td class="text-center" style="width:100px;">
                            <div class="btn-group shift" style="width: 70%" id="shift">
                                <button type="button" onclick="document.location.href='{{ route('appointment-doctor-shift-days.index', ['doctor_id' => $id,'shift_id' => $shift->id]) }}'" class="btn btn-success shift" {!! in_array($shift->id, $doctor_shift_ids) ? '123' : 'disabled' !!} style="color: white"> Setting</button>
                            </div>
                        </td>
                        <td class="text-center" style="width:100px;">
                            <div class="btn-group fees" style="width: 70%" id="fees">
                                <button type="button" onclick="document.location.href='{{ route('appointment-doctor-fees.index', ['doctor_id' => $id,'shift_id' => $shift->id]) }}'" class="btn btn-success fees" {!! in_array($shift->id, $doctor_shift_ids) ? '' : 'disabled' !!} data-doctor_id="{{ $id }}" data-shift_id="{{ $shift->id }}"> Setting</button>
                            </div>
                        </td>


                        {{--<td>
                            @if(count($dataFees)>0)
                            @foreach($dataFees as $keysfee => $fees)
                            <a href="{{route('products.edit',$fees->id)}}" title="{{ $fees->getProduct?$fees->getProduct->name:'' }}">{{ $fees->getProduct?Str::limit($fees->getProduct->name, 20, ' ..'):'' }}</a> - ({{$fees->getProductPrice?$fees->getProductPrice->mrp:''}})
                            ,
                            @if($keysfee % 1 === 0)
                            <br>
                            @endif
                            @endforeach
                            @endif
                        </td>--}}



                        <td class="text-center">
                            <input class="body-checkbox web_booking_click" data-shift_id="{{$shift->id}}" type="checkbox" {!! $doctor_shiftss?($doctor_shiftss->web_booking=='1' ? 'checked' : ''):'' !!} name="shift_id[{{ $shift->id }}]">
                        </td>
                        <td class="text-center">
                            <input class="body-checkbox app_booking_click" data-shift_id="{{$shift->id}}" type="checkbox" {!! $doctor_shiftss?($doctor_shiftss->app_booking_click=='1' ? 'checked' : ''):'' !!} name="shift_id[{{ $shift->id }}]">
                        </td>

                        <td class="text-center shiftcheck">
                            <input class="body-checkbox shifts_click" data-shift_id="{{$shift->id}}" type="checkbox" {!! in_array($shift->id, $doctor_shift_ids) ? 'checked' : '' !!} name="shift_id[{{ $shift->id }}]">
                        </td>
                        <td class="text-center">
                            @if(isset($doctor_shiftss->id))

                            <a data-id="{!! $doctor_shiftss->id !!}" data-url="{!! route('appointment-doctor-shifts.edit',['id'=>$doctor_shiftss->id]) !!}" id="edit" data-bs-toggle="modal" data-bs-target="#commonModal" class="btn btn-outline-secondary edits" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Edit">
                             <i class="bi bi-pencil-square"></i>
                            </a>

                            @endif
                        </td>
                    </tr>
                    @endforeach
                    @else
                    <tr>
                        <td colspan="5">No Data Found</td>
                    </tr>
                    @endif
                </tbody>
            </table>
        </form>
    </div>
</div>
