

$(document).ready(function() {
  
      var campus = $(".abba_display_campus option:selected").val();
      var userID = $('#user_id_teacher').val();
      var usertype = $('#user_type_holder').val();
      var institution = $('#institutionid_header').val();
      
      prosloadclassforassignmentdash(campus,userID,usertype,institution);
       prosloadstudentinclassdash(campus,userID,usertype,institution);
        
});

    
    
  $('body').on('change','.abba_display_campus', function() {
      
       var campus = $(this).val();
       var userID = $('#user_id_teacher').val();
       var usertype = $('#user_type_holder').val();
       var institution = $('#institutionid_header').val();
      
      prosloadclassforassignmentdash(campus,userID,usertype,institution);
      prosloadstudentinclassdash(campus,userID,usertype,institution);
      
  });




 function prosloadclassforassignmentdash(campus,userID,usertype,institution)
 {
     
         $('.prosloadassignmentdropdown').html(`<option value="NULL">load..</option>`);
         $('.prosselectclassforgressreport').html(`<option value="NULL">load..</option>`);
    
    
        $.ajax({
            type: "POST",
            url: "../../controller/scripts/teacher/dashboard/prosloadtecherdash.php",
            data: {
              
                  campus: campus,
                  userID: userID,
                  usertype:usertype,
                  institution:institution
               },
        
            success: function (output) { 
                $('.prosloadassignmentdropdown').html(output);
                $('.prosselectclassforgressreport').html(output);
                
                
                 var classID = $('.prosloadassignmentdropdown').val();
                  var progressclassID = $('.prosselectclassforgressreport').val();
                
                    prosloadsubjectforassignmentdashboard(campus,userID,usertype,institution,classID);
                    prosloadprogressreportdashboard(campus,userID,usertype,institution,progressclassID);
                
            }
        });
            
    }
    
    // PROS ONCHANGE CLASS TO LOAD SUBJECT HERE
    
    $('body').on('change','.prosloadassignmentdropdown', function() {
      
       var campus = $('.abba_display_campus option:selected').val();
       var userID = $('#user_id_teacher').val();
       var usertype = $('#user_type_holder').val();
       var institution = $('#institutionid_header').val();
        var classID = $(this).val();
      
        prosloadsubjectforassignmentdashboard(campus,userID,usertype,institution,classID);
      
  });
  
  
    function prosloadsubjectforassignmentdashboard(campus,userID,usertype,institution,classID)
    {
     
         $('.prosloadsubjectforassignmentdash').html(`<option value="NULL">load..</option>`);
    
    
        $.ajax({
            type: "POST",
            url: "../../controller/scripts/teacher/dashboard/prosloadtecherdashsubject.php",
            data: {
              
                  campus:campus,
                  userID:userID,
                  usertype:usertype,
                  institution:institution,
                  classID:classID
                  
               },
        
            success: function (output) { 
                $('.prosloadsubjectforassignmentdash').html(output);
                
                 prosloadassignemnetfordashboard();
            }
        });
            
    }
    
    
      $('body').on('change','.prosloadsubjectforassignmentdash', function() {
          
           prosloadassignemnetfordashboard();
      });
    
    
   
    
    
    
    function prosloadassignemnetfordashboard()
    {
        
        
                 $('#assignment-chart').html('<div class="text-center p-5 prosremovepreloaderforassignment"> <span class="spinner-border spinner-border-lg" role="status" aria-hidden="true" style="color:#007ffb;"></span></div>');
                
               var campus = $('.abba_display_campus option:selected').val();
               var userID = $('#user_id_teacher').val();
               var usertype = $('#user_type_holder').val();
               var institution = $('#institutionid_header').val();
               var classID = $('.prosloadassignmentdropdown').val();
               var subject = $('.prosloadsubjectforassignmentdash').val();
                
            
              $.ajax({
                type: "POST",
                url: "../../controller/scripts/teacher/dashboard/prosloadtecherdashsubjectassignment.php",
                data: {
                       campus:campus,
                      userID:userID,
                      usertype:usertype,
                      institution:institution,
                      classID:classID,
                      subject:subject
                     },
            
                success: function (output) { 
                    
                    
                    
                    $('.prosremovepreloaderforassignment').fadeOut();
                    
                    
                   var prosloadout = JSON.parse(output.trim());

                    var submitted = prosloadout.submitted_assign;
                    var notSubmitted = prosloadout.notsubmitted_assign;
                    var total = prosloadout.total_assign;
            
                    console.log("Submitted assignments:", submitted);
                    console.log("Not submitted assignments:", notSubmitted);
                    console.log("Total assignments:", total);
                   
                    
                    
                    //     var jsonDatacate = JSON.parse(output);
                    //     var itemnew = jsonDatacate[0];
               
               
                    // var submitted = itemnew.submitted_assign;
                    // var notsubmitted = itemnew.notsubmitted_assign;
                    // var totalassign = itemnew.total_assign;
          
                          
                    //   console.log('totlal submitted '+output);
                         
                    
                    
                   
                    
                            	/// Simple Dounut for Assignment
            			var assignmentOptions = {
            				series: [total, submitted, notSubmitted],
            				labels: ['Assignment', 'Submitted', 'Not Submitted',],
            				chart: {
            				width: 400,
            				type: 'donut',
            			},
            				plotOptions: {
            				pie: {
            					startAngle: -90,
            					endAngle: 270
            				}
            			},
            			dataLabels: {
            			enabled: false
            			},
            
            			fill: {
            				type: 'gradient',
            			},
            			legend: {
            				formatter: function(val, opts) {
            					return val + " - " + opts.w.globals.series[opts.seriesIndex]
            				}
            			},
            				responsive: [{
            					breakpoint: 480,
            					options: {
            						chart: {
            						width: 200
            						},
            						legend: {
            						position: 'bottom'
            						}
            					}
            				}]
            			};
            
            		var assignmentChart = new ApexCharts(document.querySelector("#assignment-chart"), assignmentOptions);
            		assignmentChart.render();
                                
                                
                    
                    // $('.prosloadsubjectforassignmentdash').html(output);
                    
                     
                }
            });
                
        
        
    }
    
    
    
    
    // prosload progress report here
    
            function  prosloadprogressreportdashboard(campus,userID,usertype,institution,progressclassID)
            {
                
                
              
               $('.prosloadprogressreportcontent').html('<div class="text-center p-5 "> <span class="spinner-border spinner-border-lg" role="status" aria-hidden="true" style="color:#007ffb;"></span></div>');
               
                
                 $.ajax({
                        type: "POST",
                        url: "../../controller/scripts/teacher/dashboard/prosloadprogressreportdash.php",
                        data: {
                               campus:campus,
                              userID:userID,
                              usertype:usertype,
                              institution:institution,
                              progressclassID:progressclassID,
                           },
                    
                        success: function (output) {
                            
                                $('.prosloadprogressreportcontent').html(output);
                            
                        }
                            
                });
                
                
                
                
            }
            
            
            $('body').on('change','.prosselectclassforgressreport', function() {
      
               var campus =  $(".abba_display_campus option:selected").val();
               var userID = $('#user_id_teacher').val();
               var usertype = $('#user_type_holder').val();
               var institution = $('#institutionid_header').val();
               var progressclassID = $(this).val();
              
             
               prosloadprogressreportdashboard(campus,userID,usertype,institution,progressclassID);
              
          });
    
     // prosload progress report here
    
    // prosloadstudentimageinclasscontenthere
    
    function prosloadstudentinclassdash(campus,userID,usertype,institution)
    {
        
        
                $('.prosloadstudentimageinclasscontenthere').html(`<div class="spinner-grow spinner-grow-sm text-light" role="status">
                  <span class="visually-hidden">Loading...</span>
                </div>`);
                
        
                 $.ajax({
                        type: "POST",
                        url: "../../controller/scripts/teacher/dashboard/prosloaddashstudentimagecontent.php",
                        data: {
                               campus:campus,
                              userID:userID,
                              usertype:usertype,
                              institution:institution
                         },
                    
                        success: function (output) {
                            
                             $('.prosloadstudentimageinclasscontenthere').html(output);
                            
                               
                            
                        }
                            
                });
        
    }
    
    
    
    
    
    
    
    
    