@if(count($students) >0)
    <div class="col-md-12 bg-white" style="padding:10px; height:500px;">
        <!-- <h4 class="text-info"></h4> -->
        <div class="table-responsive">
            <table class="table table-bordered list_table">
                <thead>
                    <tr>
                        <th>Sl</th>
                        <th>Student Information</th>
                        <th>Education</th>
                        <th class="text-center">English Test</th>
                        <th class="text-center">Others</th>
                        <th>Proposal Summary</th>
                        <th class="text-center">Status</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($students as $key=>$row)
                    <tr>
                        <td style="font-size: 11px;">{{$key+1}}</td>
                        <td style="width: 20%;">
                            <div style="display:flex;">
                                @if($row->student_details->nationality)
                                    <img class="img-responsive listFlag mt-2" style="border-radius: 2px; padding: 0px;height: 35px; width: 35px;" src="{{ asset('/assets/img/flags/4x3').'/'.strtolower(cn($row,'student_details.country_name.iso_3166_2','')).'.svg' }}" alt="Flag" data-toggle="tooltip" title="" data-placement="top">
                                @endif
                                <div class="alert" style="background-color:white; padding: 3px 7px; margin-bottom: 0px;">
                                    <div style="font-size: 12px; font-weight: 600; color: black; text-transform: capitalize;">
                                        <span>{{cn($row,'student_details.first_name','')}} {{cn($row,'student_details.last_name','')}}</span>
                                    </div>
                                    <div style="font-size: 11.5px;">
                                        <a href="" class="" style="color: #868e96;"><span>Ref : {{$row->student_apply_ref ?? "N/A"}} </span></a>
                                    </div>
                                    <div style="font-size: 11.5px;">
                                        <span style="color: #868e96;">Applied : {{utc_to_ltz($row->submitted_date, 'd M Y g:i A', local_tz($user))}}</span>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td style="font-size: 11.5px; width: 17%;">
                            <div style="display:flex;"> 
                                <div class="alert" style="background-color:white; padding: 3px 7px; margin-bottom: 0px;">
                                    <div style="font-size: 11.5px; font-weight: 600; display:block;">
                                        <span style="color: black;">{{cn($row,'institutes.institution','')}}</span>
                                    </div>
                                    <div style="font-size: 11.5px;">
                                        <span style="color: black;">Passing Year :  {{cn($row,'institutes.passing_year','N/A')}} </span>
                                    </div>
                                    <div class="mt-1" style="font-size: 11.5px;">
                                        <span class="label_badge_gpa">{{cn($row,'institutes.result','')}} (GPA)</span>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td class="mb-1" style="font-size: 11.5px; text-align:center; color: black;"><span class="label_badge_gpa" style="background-color: #eee; color: black;">{{cn($row,'scores.test_name','N/A')}} • {{cn($row,'scores.overall_score','')}}</span>
                            <div style="font-size: 11.5px;">
                                <span style="color: black;">
                                @php
                                        $work_history_first =$row->work_experience_date()->whereNotNull('start_date')->oldest()->first();

                                        $work_history_last =$row->work_experience_date()->latest()->first();
                                        if($work_history_first && $work_history_last && $work_history_last->end_date){

                                        $diff_in_days =diff_in_days($work_history_first->start_date,$work_history_last->end_date);

                                        }elseif($work_history_first){
                                        $diff_in_days =diff_in_days($work_history_first->start_date, now());
                                        }else{
                                        $diff_in_days =0;
                                        }

                                        $years = ($diff_in_days / 365) ;
                                        $years = floor($years);
                                        $month = ($diff_in_days % 365) / 30.5;
                                        $month = floor($month);
                                        $days = ($diff_in_days % 365) % 30.5;
                                        @endphp

                                        <div class="mt-1" style="font-size: 11px; display:block;">
                                            <span class="label_badge_work"><i class="fa fa-briefcase" style="color: rgb(152, 152, 152); margin-right: 5px;"></i>{{$years}} years</span>
                                        </div>
                                </span>
                            </div>
                        </td>
                        <td style="font-size: 11px; text-align:center;">
                            <div style="font-size: 11px; display:block;">
                                <div style="font-size: 11px; color: black;"> Pub :
                                    @if($row->student_details->is_publication==1)
                                        <span class="label_badge_work"> yes</span>
                                    @else
                                        <span class="label_badge_no"> No</span>
                                    @endif
                                </div>
                                <div class="mt-1" style="font-size: 11px; color: black;"> Con :
                                    @if($row->student_details->is_attended_conference==1)
                                        <span class="label_badge_work"> yes</span>
                                    @else
                                        <span class="label_badge_no"> No</span>
                                    @endif
                                </div>
                            </div>
                        </td>
                        <td style="font-size: 11px; width: 30%;">
                            @php
                                $hashids = new \Hashids\Hashids('application', 25);
                            @endphp
                            <div class="inner_right">
                                <a href="{{ url('supervisor/application/'.$hashids->encode($row->id)) }}"><strong style="font-size:11px; color:black;">{{cn($row,'proposal.title','')}}</strong></a></br>
                                <span style="color:black;">{{cn($row,'proposal.methology','')}}</span>
                                @php
                                    $proposal =\DB::table('proposal')->where(
                                        'student_id',$row->student_id
                                        )->first();

                                    if(isset($proposal)){
                                        $department =\DB::table('departments')->where(
                                            'id',$proposal->department
                                        )->first();
                                    }
                                @endphp
                                @if(isset($department))
                                <span>.</span>
                                <span style="color:black;">
                                    {{ $department->name }}
                                </span>
                                @endif
                                <span>.</span>
                                <span style="color:black;">{{cn($row,'proposal.status','')}}</span>
                            </div>
                        </td>
                        <td style="font-size: 11px; text-align:center;">

                            <div class="top_part_status">
                                @if($row->accepted_status==1 && $row->proposal_status ==1)
                                        <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Reviewing</button>
                                @elseif($row->accepted_status==1 && $row->proposal_status ==2)
                                    <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Reviewing</button>
                                @elseif($row->accepted_status==1 && $row->proposal_status ==3)
                                    <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Push</button>
                                @elseif($row->accepted_status==1 && $row->proposal_status ==4)
                                    <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Hold</button>
                                @elseif($row->accepted_status==1 && $row->proposal_status ==5)
                                    <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Interested</button>
                                @elseif($row->accepted_status==1 && $row->proposal_status ==6)
                                    <button class="btn btn2" style="padding: 1px 10px !important; font-size: 11px;">Rejected</button>
                                @else
                                    <button class="btn btn2 accept_status_update" data-id="{{$row->id}}" style="padding: 1px 10px !important; font-size: 11px;">Accept</button>
                                @endif

                                @if($row->proposal_status_date)
                                    <br>
                                    <span style="font-size:11px; font-weight: bold;">
                                    {{utc_to_ltz($row->proposal_status_date, 'd M Y g:i A', local_tz($user))}}
                                </span>

                                @endif
                            </div>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div><!--end col-->
    @else
    <div class="col-md-12 bg-white" style="padding:10px;">
        <div class="alert  mt-1 mb-3" style="border-color: #e9f0f3; font-size: 12px !important; color: #dc3545; border-radius: 30px; padding: 8px 15px; text-align: center;">
            <span>No data available.</span>
        </div>
    </div>
@endif



@push('js') 
<script>
    $(function(){
        $('.accept_status_update').on('click', function(){
           
            var self =$(this);
            var id =self.data('id');

            var form_data={
                _token :"{{csrf_token()}}",
                'id':id,
            }

            swal({
                title: "Are you sure you want to change status?",
                text: "Please check before submitting!",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                cancelButtonClass: "btn-info",
                confirmButtonText: "Yes",
                cancelButtonText: "No",
                closeOnConfirm: true,
                closeOnCancel: true
            }, function(isConfirm){

                if(isConfirm){
                    $.post("{{ route('ajax-post', ['name'=>'accept_status_update']) }}", form_data, function(res){
                        pop_up_msg(res.msg);
                        window.location.reload();

                    }).fail(function(err){

                        pop_up_msg(err_msg(err), 'error');

                    });
                }
            });
        });

    });
</script>


@endpush