@extends('admin.sub_contents.base')  
@section('main') 
<div class="table-responsive mt-2">
    @if(count($institution)>0)
    <table class="table table-bordered list_table" style="margin-bottom:10px;">
        <thead>
            <tr>
                <th style="width: 30%;">Institution</th>
                <th style="width: 20%;">Academic level</th>
                <th style="width: 30%;">Subject</th>
                <th>Result</th>
                <th style="width: 10%;">Passing Year</th>
                {{-- @if(profile_permission($institution[0]->student_id)) --}}
                <th style="width: 10%;">Action</th>
                {{-- @endif --}}
            </tr>
        </thead>
        <tbody>
            @foreach($institution as $row)  
                <tr>
                    <td style="font-size: 11px;">{{$row->institution}}</td>
                    <td style="font-size: 11px;">
                        <span class="label_badge_radius" style="background-image: linear-gradient(90deg,rgba(46,17,83,.19),#f5f4fd) !important;">{{$row->academic_level_info->name}}</span>
                    </td>
                    <td style="font-size: 11px;">{{$row->subject}}</td> 
                    <td style="font-size: 11px;">{{$row->result}}</td>
                    <td style="font-size: 11px;">
                        <span style="font-weight: 400; font-size: 12px;">{{$row->passing_year}}</span>
                    </td>
                    <!-- <td style="font-size: 11px;">{{date("d M, Y", strtotime($row->start_date)).' - '.date("d M, Y", strtotime($row->end_date))}}</td> -->
                     
                    <td class="text-center" style="width: 75px;"> 
                            <div class="icon_bar" style="border: none;">  
                                <span class="edit_education_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_education_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>  
                      
                </tr>

                <?php 
                    $edit_cls_name = "edit_cls_".$row->id;
                ?>
                <tr class="edit_edu_data {{$edit_cls_name}} d-none">
                    <td colspan="6">
                        <div class="edit_education_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 Education History available.</span>
    </div> 
    @endif
</div>
 
@endsection


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

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

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

    $('.delete_education_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_education_info']) }}",form_data
                ).done(function(res){ 
                    pop_up_msg(res.msg); 
                    fetch_sub_content(
                        '#education_history_load',
                        "{{ route('sub-content', ['name'=>'education_history_load']) }}"
                    );

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