
$(document).ready(function () {
    
    var campus = $("#autoSizingSelect option:selected").val();

    var userID = $('#user_id_teacher').val();
  
    $.ajax({
        type: "POST",
        url: "../../controller/scripts/teacher/assignment/ekene_select_totalassignment.php",
        data: {

            campus: campus,
            userID: userID

        },

        success: function (output) {

            var jsonDatacate = JSON.parse(output);

            //  var spotName = item.spot_name;
            var Notsubmittednew = jsonDatacate.Notsubmitted;
            var Submittednew = jsonDatacate.Submitted;
            var Assignmentsetnew = jsonDatacate.Assignmentset;

            ekene_first_chart(Notsubmittednew, Submittednew, Assignmentsetnew);
        }
    });
    
   
    //firstclass select
    $.ajax({
        type: "POST",
        url: "../../controller/scripts/teacher/assignment/ekene_select_class.php",
        data: {

            campus: campus,
            userID: userID

        },

        success: function (output) {

            $("#changelanguageclass").html(output);

        }
    });

});



$('body').on('change', '#changelanguageclass', function () {

    var userID = $('#user_id_teacher').val();
    var campus = $("#autoSizingSelect option:selected").val();

    $.ajax({
        type: "POST",
        url: "../../controller/scripts/teacher/assignment/ekene_select_subject.php",
        data: {
            userID: userID,
            campus: campus

        },
        success: function (output) {

            $("#changelanguagesubject").html(output);

        }
    });

});





$('body').on('click', '#select_assignment_display', function () {

    var campus = $("#autoSizingSelect option:selected").val();
    var subjectid = $("#changelanguagesubject option:selected").val();
    var classid = $("#changelanguageclass option:selected").val();

    $.ajax({
        type: "POST",
        url: "../../controller/scripts/teacher/assignment/ekene_select_selectedassignment.php",
        data: {

            campus: campus,
            subjectid: subjectid,
            classid: classid

        },

        success: function (output) {

            var jsonDatacate = JSON.parse(output);

            //  var spotName = item.spot_name;
            var Notsubmittednew = jsonDatacate.Notsubmitted;
            var Submittednew = jsonDatacate.Submitted;
            var Assignmentsetnew = jsonDatacate.Assignmentset;
            
            ekene_first_chart(Notsubmittednew, Submittednew, Assignmentsetnew);

        }
    });


});



function ekene_first_chart(Notsubmittednew, Submittednew, Assignmentsetnew) {

    if (assignmentChart) {
        assignmentChart.destroy();
    }

    var assignmentOptions = {
        series: [Assignmentsetnew, Submittednew, Notsubmittednew],
        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'
                }
            }
        }]
    };

    assignmentChart = new ApexCharts(document.querySelector("#assignment-chart"), assignmentOptions);
    assignmentChart.render();
}

// function first_chart(Notsubmittednew, Submittednew, Assignmentsetnew) {

//     var assignmentOptions = {
//         series: [Assignmentsetnew, Submittednew, Notsubmittednew],
//         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'
//                 }
//             }
//         }]
//     };

//     assignmentChart = new ApexCharts(document.querySelector("#assignment-chart"), assignmentOptions);
//     assignmentChart.render();
// }