@extends('admin.sub_contents.base')
@section('main')
<div class="table-responsive">
    @if(count($register_teachers_list)  > 0)
    <table class="table table-bordered list_table" style="margin: 0px;">
        <thead>
            <tr>
                <th>Sl</th>
                <th>Name</th>
                <th>University Name</th>
                <th>Department</th>
                <th class="text-center">Status</th>
                <th class="text-center">Action</th>
            </tr>
        </thead>
        <tbody>

            @foreach($register_teachers_list as $key=>$row)
            <tr>
                <td style="font-size: 11px;">{{++$key}}</td>
                <td style="font-size: 11px;"><span style="font-weight: bold !important;">{{$row->first_name }} {{$row->last_name }}</span><br>
                    <span>{{$row->designation}}</span><br>
                    <span>{{$row->email}}</span>
                </td>
                <td style="font-size: 11px;">
                    @if($row->university_name)
                        {{$row->university_name}}
                    @else
                      {{ cn($row, 'university.name','') }}
                    @endif
                     <br>
                    <span>{{$row->uni_website}}</span>
                </td>
                <td style="font-size: 11px;">
                    @if($row->others_department)
                        {{ $row->others_department }}
                    @else
                        {{ cn($row, 'department_name.name','') }}
                    @endif
                </td>
                <td style="font-size: 11px; width: 9%;">
                    <div class="single_glance_row mt-1" style="display: flex;">
                        <div class="top_part_status" style="position: relative; width: fit-content; margin-left: 10px;">
                            <span class="top_part_status_name" style="background: #dcdcdc; color: #8c9094;">
                                @if($row->apply_status==0)
                                    Pending
                                @endif
                            </span>
                            <div class="dropdown" style="top: 0.4px; position: absolute; right: 9px;">
                                    <i class="fa fa-caret-down dropdown-toggle add_hover tooltips" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" data-original-title="Change Status" style="color: #8c9094;"></i>
                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton" x-placement="bottom-start" style="position: absolute; transform: translate3d(10px, 13px, 0px); top: 0px; left: 0px; will-change: transform; margin-left: -75px; z-index: 2; margin-top: 10px;">
                                    <a class="dropdown-item active_inactive_status_change hand" data-value="1" data-id={{$row->id}}>Active</a>
                                    <a class="dropdown-item active_inactive_status_change hand" data-value="2" data-id={{$row->id}}>In active</a>
                                    <a class="dropdown-item active_inactive_status_change hand" data-value="3" data-id={{$row->id}}>Suspend</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
                <td class="text-center">
                    <span class="edit_info" data-id="{{$row->id}}"><i class="fa fa-edit"></i></span>
                </td>
            </tr>

            <?php
                $edit_cls_name = "edit_cls_".$row->id;
            ?>
            <tr class="edit_data {{$edit_cls_name}} d-none">
                <td colspan="6">
                    <div class="edit_teacher_load"></div>
                </td>
            </tr>
            @endforeach

        </tbody>
    </table>
    @else
    <div class="alert  mt-1 mb-3" style="border-color: #e9f0f3; font-size: 12px !important; color: #dc3545; border-radius: 30px; padding: 8px 15px;">
        <span>No data available.</span>
    </div>
    @endif
</div>
@endsection

<script>
    $(function(){

        $('.edit_info').on('click', function(){

            $('.edit_teacher_load').empty();
            var self = $(this);
            var id = self.attr("data-id");
            var edit_cls = "edit_cls_"+id;
            $('.edit_data').addClass('d-none');
            $("."+edit_cls).removeClass('d-none');
            var edit_teacher_load = self.closest('tbody').find('.edit_teacher_load');

            fetch_sub_content(
                edit_teacher_load,
                "{!! route('sub-content', ['name'=>'edit_teacher_load','action'=>'edit']) !!}&edit_id="+id
            );
        });

        $('.active_inactive_status_change').on('click', function(e){
                var self =$(this);
                var id =$(this).data('id');
                var value =$(this).data('value');

                var form_data={
                _token:"{{ csrf_token() }}",
                'id':id,
                'status':value
                }
                swal({
                    title: "Are you sure?",
                    text: "Do you want to change this status?",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonClass: "btn btn-md btn-success",
                    cancelButtonClass: 'btn btn-md btn-danger',
                    confirmButtonText: "Yes"
                }, function(isConfirm){

                    if(isConfirm) {
                        $.post("{{ route('ajax-post', ['name'=>'teacher_user_status_change'])}}" ,form_data).done(function(res){

                                pop_up_msg(res.msg);
                                //window.location.reload();
                                fetch_sub_content(
                                    '#pending_teacher_load',
                                    "{{ route('sub-content', ['name'=>'register_pending_teacher_load']) }}"
                                );

                        }).fail(function(error){

                                let msg='Sorry!, form submission failed try again later.';

                                if(error.responseJSON.msg){
                                    msg=error.responseJSON.msg;
                                }

                            pop_up_msg(msg, 'error');
                        });
                    }
                });
            });


    });
</script>
