@extends('admin.sub_contents.base')  
@section('main') 
<div class="table-responsive mt-2">
    @if(count($score)>0)
        <table class="table table-bordered list_table" style="margin-bottom:10px;">
            <tbody>
            @foreach($score as $row)
                <tr>
                    <td>
                        <div class="institute_info">
                            <div class="left">
                                <i class="fa fa-align-center" style="padding: 7px;"></i>
                            </div>
                            <div class="right">
                                <span class="main_title" style="font-size: 11px;font-weight: 600; display: flex;"> Testing System</span>
                                <span class="label_badge_light test_score_level">{{$row->test_name}}</span>
                                <span style="font-weight: 400; font-size: 12px;">Test Date: {{date("d M, Y", strtotime($row->test_date))}}</span>
                            </div>
                        </div>
                    </td>
                    <td class="text-center">
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">{{$row->overall_score}}</strong><br>
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">Overall</strong>
                    </td>
                    <td class="text-center">
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">{{$row->listening}}</strong><br>
                        <strong style="font-size: 12px;">Listening</strong>
                    </td>
                    <td class="text-center">
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">{{$row->speaking}}</strong><br>
                        <strong style="font-size: 12px;">Speaking</strong>
                    </td>
                    <td class="text-center">
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">{{$row->writing}}</strong><br>
                        <strong style="font-size: 12px;">Writing</strong>
                    </td>
                    <td class="text-center">
                        <strong style="color: rgb(57, 59, 62); font-size: 12px;">{{$row->reading}}</strong><br>
                        <strong style="font-size: 12px;">Reading</strong>
                    </td>
                    @if(profile_permission($row->student_id))
                    <td class="text-center" style="width: 100px;">  
                        <div class="icon_bar" style="border: none;">  
                            <span class="edit_score_info" data-id="{{$row->id}}" style="cursor: pointer; @if($is_freez_profile) pointer-events:none; @endif"><i class="fa fa-edit change_pass_btn" ></i></span>
                            <span class="delete_score_info" data-id="{{$row->id}}" style="cursor: pointer; @if($is_freez_profile) pointer-events:none; @endif"><i class="fa fa-trash change_pass_btn ms-1" ></i></span>
                        </div> 
                    </td>  
                    @endif                                                     
                </tr>
                <?php 
                    $edit_cls_name = "edit_cls_".$row->id;
                ?>
                <tr class="edit_data {{$edit_cls_name}} d-none">
                    <td colspan="7">
                        <div class="edit_english_languge_proficiency_form"></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 Test Score available.</span>
            </div> 
        @endif
    </div>
@endsection


<script>
    $(function(){
        $('.edit_score_info').on('click', function(){  

        $('.edit_english_languge_proficiency_form').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_english_languge_proficiency_form = self.closest('tbody').find('.edit_english_languge_proficiency_form');

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

    $('.delete_score_info').on('click', function(){ 
        var id = $(this).attr("data-id"); 
        var form_data={
            _token: "{{ csrf_token() }}",  
            delete_id: id,
        }  
        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this data!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            cancelButtonClass: "btn-info",
            confirmButtonText: "Yes, delete!",
            cancelButtonText: "No, cancel!",

        }, function(isConfirm){

            if(isConfirm){  
                $.post("{{ route('ajax-post', ['name'=>'delete_score_info']) }}",form_data
                ).done(function(res){ 
                    pop_up_msg(res.msg); 
                    fetch_sub_content(
                        '#english_languge_proficiency_load',
                        "{{ route('sub-content', ['name'=>'english_languge_proficiency_load']) }}"
                    );

                }).fail(function(err){ 
                    pop_up_msg(err_msg(err), 'error'); 
                }); 
            } 
        }); 
            
    });
});
</script>