//inject angular file upload directives and services.
var app = angular.module('app', ['highcharts-ng']);

app.directive('countdown', [
        'Util',
        '$interval',
        function (Util, $interval) {
            return {
                restrict: 'A',
                scope: { date: '@' },
                link: function (scope, element) {
                    var future;
                    future = new Date(scope.date);
                    $interval(function () {
                        var diff;
                        diff = Math.floor((future.getTime() - new Date().getTime()) / 1000);
                        return element.text(Util.dhms(diff));
                    }, 1000);
                }
            };
        }
    ])
app.factory('Util', [function () {
            return {
                dhms: function (t) {
                    var days, hours, minutes, seconds;
                    days = Math.floor(t / 86400);
                    t -= days * 86400;
                    hours = Math.floor(t / 3600) % 24;
                    t -= hours * 3600;
                    minutes = Math.floor(t / 60) % 60;
                    t -= minutes * 60;
                    seconds = t % 60;
                    return [
                        days + 'd',
                        hours + 'h',
                        minutes + 'm',
                        seconds + 's'
                    ].join(' ');
                }
            };
        }]);

app.controller('SrecaStatistika', function ($scope, $http, $timeout) {
    //console.log("imaaaa");
    // sacuvaj
    //console.log("imaaaaaaaa");
	    $scope.podatak = "85";
    $scope.sacuvajA = function(data) {        
        $http.post('api/sreca-dodaj/', data).success(function(data) {             
        });
		
		$http.get('api/uzmi-sreca-2016/', data).success(function(data) {            
			$scope.sreca2016 = data[0].opcija * 10;           
            $scope.sreca12016 = data[0].opcija1 * 10;           
            $scope.sreca22016 = data[0].opcija2 * 10;           
            $scope.sreca32016 = data[0].opcija3 * 10;             
        });

        $scope.hvala = true;
        $http.get('api/uzmi-sreca/').success(function(data) {    
			$scope.nesto = data[0].opcija2;      

            $scope.sreca2015 = data[0].opcija * 10;           
            $scope.sreca12015 = data[0].opcija1 * 10;           
            $scope.sreca22015 = data[0].opcija2 * 10;           
            $scope.sreca32015 = data[0].opcija3 * 10;    

            $scope.srecau2015 = data[0].opcija;           
            $scope.srecau12015 = data[0].opcija1;           
            $scope.srecau22015 = data[0].opcija2;           
            $scope.srecau32015 = data[0].opcija3;          
        });  
    }
	$scope.RezultateOtkrij = false;
    
    
        $http.get('api/uzmi-sreca-2016/').success(function(data) {    
            
            $scope.broju = data[0].broj;
            $scope.sreca = data[0].opcija * 10;           
            $scope.sreca1 = data[0].opcija1 * 10;           
            $scope.sreca2 = data[0].opcija2 * 10;           
            $scope.sreca3 = data[0].opcija3 * 10;    

            $scope.srecau = data[0].opcija;           
            $scope.srecau1 = data[0].opcija1;           
            $scope.srecau2 = data[0].opcija2;           
            $scope.srecau3 = data[0].opcija3;          

            console.log($scope.sreca);
        });  

        $http.get('api/uzmi-sreca-p/').success(function(data) {    
            
            $scope.polovi = data;
        });  

       


        

        $scope.dataSource = [];

        $http.get('api/uzmi-sreca-p1/').success(function(data) {    
            $scope.dataSource = data;
            console.log(data[1]);

            $scope.chart = {
                options: {
                    chart: {
                        height: 300,
                        type: 'spline'
                    },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                  spline: {
                        lineWidth: 4,
                        states: {
                            hover: {
                                lineWidth: 7
                            }
                        }
                    }
                }
                },
                series: [{
                    name: 'Muški pol (36)',
                    data: $scope.dataSource[0],
					marker: {
						symbol: 'url(images/m.png)'
					}
                }, {
                    name: 'Ženski pol (122)',
                    data: $scope.dataSource[1],
					marker: {
						symbol: 'url(images/z.png)'
					}
                }],
                title: {
                    text: ''
                },
                xAxis: {                    
                    categories: ['Koliko ste zadovoljni životom?', 'Koliko ste bili srećni juče?', 'Koliko ste bili nervozni juče?', 'Koliko ste srećni ove godine?', 'U kojoj mjeri je ono što radite u životu vrijedno?']
                },
                yAxis: {
                    title: {
                        text: 'Zadovoljstvo skala od 1 do 10'
                    },
                    min: 1, max: 10,
                    minorGridLineWidth: 0,
                    gridLineWidth: 0,
                    alternateGridColor: null,
                    plotBands: [{ // Light air
                        from: 1,
                        to: 2,
                        color: 'rgba(68, 170, 213, 0.1)',
                        label: {
                            text: 'Najniža vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }, 
                    { // High wind
                        from: 9,
                        to: 10,
                        color: 'rgba(246, 255, 0, 0.2)',
                        label: {
                            text: 'Najviša vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }]
                },
                credits: {
                   enabled: false
                },        
                loading: false,
                size: {},
                useHighStocks: false
            }

        }); 
		
		
		$http.get('api/uzmi-sreca-zaposlenost/').success(function(data) {    
            $scope.dataSource = data;
            console.log(data[1]);

            $scope.chartZaposlenost = {
                options: {
                    chart: {
                        height: 300,
                        type: 'column'
                    },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                  spline: {
                        lineWidth: 4,
                        states: {
                            hover: {
                                lineWidth: 7
                            }
                        }
                    }
                }
                },
                series: [{
                    name: 'Muški pol (31)',
                    data: $scope.dataSource[0],
					marker: {
						symbol: 'url(images/m.png)'
					}
                }, {
                    name: 'Ženski pol (86)',
                    data: $scope.dataSource[1],
					marker: {
						symbol: 'url(images/z.png)'
					}
                }],
                title: {
                    text: ''
                },
                xAxis: {                    
                    categories: ['Koliko ste zadovoljni životom?', 'Koliko ste bili srećni juče?', 'Koliko ste bili nervozni juče?', 'Koliko ste srećni ove godine?', 'U kojoj mjeri je ono što radite u životu vrijedno?']
                },
                yAxis: {
                    title: {
                        text: 'Zadovoljstvo skala od 1 do 10'
                    },
                    min: 1, max: 10,
                    minorGridLineWidth: 0,
                    gridLineWidth: 0,
                    alternateGridColor: null,
                    plotBands: [{ // Light air
                        from: 1,
                        to: 2,
                        color: 'rgba(68, 170, 213, 0.1)',
                        label: {
                            text: 'Najniža vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }, 
                    { // High wind
                        from: 9,
                        to: 10,
                        color: 'rgba(246, 255, 0, 0.2)',
                        label: {
                            text: 'Najviša vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }]
                },
                credits: {
                   enabled: false
                },        
                loading: false,
                size: {},
                useHighStocks: false
            }

        }); 
		
		$http.get('api/uzmi-sreca-ne-zaposlenost/').success(function(data) {    
            $scope.dataSource = data;
            console.log(data[1]);

            $scope.chartNeZaposlenost = {
                options: {
                    chart: {
                        height: 300,
                        type: 'column'
                    },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                  spline: {
                        lineWidth: 4,
                        states: {
                            hover: {
                                lineWidth: 7
                            }
                        }
                    }
                }
                },
                series: [{
                    name: 'Muški pol (5)',
                    data: $scope.dataSource[0],
					marker: {
						symbol: 'url(images/m.png)'
					}
                }, {
                    name: 'Ženski pol (36)',
                    data: $scope.dataSource[1],
					marker: {
						symbol: 'url(images/z.png)'
					}
                }],
                title: {
                    text: ''
                },
                xAxis: {                    
                    categories: ['Koliko ste zadovoljni životom?', 'Koliko ste bili srećni juče?', 'Koliko ste bili nervozni juče?', 'Koliko ste srećni ove godine?', 'U kojoj mjeri je ono što radite u životu vrijedno?']
                },
                yAxis: {
                    title: {
                        text: 'Zadovoljstvo skala od 1 do 10'
                    },
                    min: 1, max: 10,
                    minorGridLineWidth: 0,
                    gridLineWidth: 0,
                    alternateGridColor: null,
                    plotBands: [{ // Light air
                        from: 1,
                        to: 2,
                        color: 'rgba(68, 170, 213, 0.1)',
                        label: {
                            text: 'Najniža vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }, 
                    { // High wind
                        from: 9,
                        to: 10,
                        color: 'rgba(246, 255, 0, 0.2)',
                        label: {
                            text: 'Najviša vrijednost',
                            style: {
                                color: '#606060'
                            }
                        }
                    }]
                },
                credits: {
                   enabled: false
                },        
                loading: false,
                size: {},
                useHighStocks: false
            }

        }); 


   





    

    

});

/**
 * Dark theme for Highcharts JS
 * @author Torstein Honsi
 */

// Load the fonts
Highcharts.createElement('link', {
    href: '//fonts.googleapis.com/css?family=Lobster',
    rel: 'stylesheet',
    type: 'text/css'
}, null, document.getElementsByTagName('head')[0]);

Highcharts.theme = {
    colors: ["#9954bb", "#57FF20", "#f45b5b", "#ff7518", "#ff0039", "#ff0066", "#eeaaee",
        "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
    chart: {
        backgroundColor: 'transparent',
        style: {
            fontFamily: "'Lobster', cursive"
        },
        plotBorderColor: '#606063'
    },
    title: {
        style: {
            color: '#E0E0E3',
            textTransform: 'uppercase',
            fontSize: '20px'
        }
    },
    subtitle: {
        style: {
            color: '#E0E0E3',
            textTransform: 'uppercase'
        }
    },
    xAxis: {
        gridLineColor: '#707073',
        labels: {
            style: {
                color: '#E0E0E3'
            }
        },
        lineColor: '#707073',
        minorGridLineColor: '#505053',
        tickColor: '#707073',
        title: {
            style: {
                color: '#A0A0A3'

            }
        }
    },
    yAxis: {
        gridLineColor: '#707073',
        labels: {
            style: {
                color: '#E0E0E3'
            }
        },
        lineColor: '#707073',
        minorGridLineColor: '#505053',
        tickColor: '#707073',
        tickWidth: 1,
        title: {
            style: {
                color: '#000'
            }
        }
    },
    tooltip: {
        backgroundColor: 'rgba(0, 0, 0, 0.85)',
        style: {
            color: '#F0F0F0'
        }
    },
    plotOptions: {
        series: {
            dataLabels: {
                color: '#B0B0B3'
            },
            marker: {
                lineColor: '#333'
            }
        },
        boxplot: {
            fillColor: '#505053'
        },
        candlestick: {
            lineColor: '#000'
        },
        errorbar: {
            color: '#000'
        }
    },
    legend: {
        itemStyle: {
            color: '#E0E0E3'
        },
        itemHoverStyle: {
            color: '#FFF'
        },
        itemHiddenStyle: {
            color: '#606063'
        }
    },
    credits: {
        style: {
            color: '#666'
        }
    },
    labels: {
        style: {
            color: '#707073'
        }
    },

    drilldown: {
        activeAxisLabelStyle: {
            color: '#F0F0F3'
        },
        activeDataLabelStyle: {
            color: '#F0F0F3'
        }
    },

    navigation: {
        buttonOptions: {
            symbolStroke: '#000',
            theme: {
                fill: '#505053'
            }
        }
    },

    // scroll charts
    rangeSelector: {
        buttonTheme: {
            fill: '#505053',
            stroke: '#000000',
            style: {
                color: '#CCC'
            },
            states: {
                hover: {
                    fill: '#707073',
                    stroke: '#000000',
                    style: {
                        color: 'white'
                    }
                },
                select: {
                    fill: '#000003',
                    stroke: '#000000',
                    style: {
                        color: 'white'
                    }
                }
            }
        },
        inputBoxBorderColor: '#505053',
        inputStyle: {
            backgroundColor: '#333',
            color: 'silver'
        },
        labelStyle: {
            color: 'silver'
        }
    },

    navigator: {
        handles: {
            backgroundColor: '#666',
            borderColor: '#AAA'
        },
        outlineColor: '#CCC',
        maskFill: 'rgba(255,255,255,0.1)',
        series: {
            color: '#7798BF',
            lineColor: '#A6C7ED'
        },
        xAxis: {
            gridLineColor: '#505053'
        }
    },

    scrollbar: {
        barBackgroundColor: '#808083',
        barBorderColor: '#808083',
        buttonArrowColor: '#CCC',
        buttonBackgroundColor: '#606063',
        buttonBorderColor: '#606063',
        rifleColor: '#FFF',
        trackBackgroundColor: '#404043',
        trackBorderColor: '#404043'
    },

    // special colors for some of the
    legendBackgroundColor: 'rgba(0, 0, 0, 0.5)',
    background2: '#505053',
    dataLabelsColor: '#B0B0B3',
    textColor: '#C0C0C0',
    contrastTextColor: '#F0F0F3',
    maskColor: 'rgba(255,255,255,0.3)'
};

// Apply the theme
Highcharts.setOptions(Highcharts.theme);

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})