@extends('admin.sub_contents.base')  
@section('main') 
<div class="table-responsive mt-2">
    @if(count($work_experience)>0)
        <table class="table table-bordered list_table" style="margin-bottom: 10px;">
            <thead>
                <tr>
                    <th>Company Name</th>
                    <th>Designation</th>
                    <th>Currently working</th>
                    <th>Start Date</th>
                    <th>End Date</th>
                    {{-- @if(profile_permission($work_experience[0]->student_id))  --}}
                    <th>Action</th> 
                    {{-- @endif --}}
                </tr>
            </thead>
            <tbody>
            @foreach($work_experience as $row)                                                               
                    <tr>
                        <td style="font-size: 11px;">{{$row->company_name}}</td>
                        <td style="font-size: 11px;">{{$row->designation}}</td> 
                        <td style="font-size: 11px;">{{$row->currently_working == 0 ? 'off' : 'on'}}</td> 
                        <td style="font-size: 11px;">@if(!empty($row->start_date)){{date("d M, Y", strtotime($row->start_date))}} @else @endif</td>
                        <td style="font-size: 11px;">@if(!empty($row->end_date)) {{date("d M, Y", strtotime($row->end_date))}} @else @endif</td>
                         
                        <td class="text-center" style="width: 100px;">
                            <div class="icon_bar" style="border: none;"> 
                                <span class="edit_work_experience_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_work_experience_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_data {{$edit_cls_name}} d-none">
                        <td colspan="7">
                            <div class="edit_work_experience_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 Work Experience available.</span>
        </div> 
        @endif
    </div>
 
@endsection


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

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

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

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

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