var status = {
    settings: {
        patient_autocompleteUrl: '',
        status_report_data: '',
    },
    init: function() {
        this.bindAutoComplete();
        this.statusReportData();
    },
    bindAutoComplete: function() {
        global.autocomplete.bind(status.settings.patient_autocompleteUrl, '#form-patient-fullName', '#form-patient-id');

    },
    statusReportData: function() {

        if(jQ('#status-report-data-container').length) {

            var requestName = 'statusReportData';
            //global.ajaxCancel(requestName);

            var settings = {
                url: status.settings.url.status_report_data,
                type: 'GET',
                success: function(json) {
                    if(json.success) {

                        jQ('#status-report-data-loading').addClass('hide');
                        jQ('#status-report-data-title').removeClass('hide');
                        jQ('#status-report-data-container').removeClass('has-loading');

                        var i, labels = [], data = [], colors = [];

                        if(json.data.length) {
                            for(i=0; i<json.data.length; i++) {
                                labels.push(json.data[i].status);
                                data.push(json.data[i].ctr);
                            }
                        }

                        for(i=0; i<labels.length; i++) {
                            if(labels[i] === 'Active') {
                                colors.push('rgb(7, 199, 2)');
                            } else if(labels[i] === 'Pending') {
                                colors.push('rgb(233, 0, 38)');
                            } else if(labels[i] === 'New') {
                                colors.push('rgb(173, 173, 173)');
                            } else { // Closed
                                colors.push('rgb(100, 121, 247)');
                            }
                            labels[i] = labels[i] + ': ' + data[i];
                        }

                        var canvass = document.getElementById('status-report-data-status'),
                            ctx = canvass.getContext('2d'),
                            ctxChart = new Chart(ctx, {
                                type: 'bar',
                                data: {
                                    labels: labels,
                                    datasets: [{
                                        data: data,
                                        borderColor: colors,
                                        backgroundColor: colors
                                    }]
                                },
                                options: {
                                    responsive: true,
                                    title:{
                                        display:true,
                                        text: 'Sales Report',
                                        fontSize:25
                                    }
                                }
                            });
                    } else {
                        location.reload();
                    }
                }
            };

            global.ajax(settings, requestName);
        }
    },
};