$(function () {

    // wywołanie tooltipster
    $('.tooltipster-top').tooltipster({
        position: "top"
    });

    // Wyświetlanie więcej newsów
    $('.lastNewsButtonMore').on('click', function () {
        $('.lastNewsItemsHiden').toggle();
    });

    // Wyświetlanie więcej stron
    $('.lastPagesButtonMore').on('click', function () {
        $('.lastPagesItemsHiden').toggle();
    });

    // Wyświetlanie więcej formularzy
    $('.FormsButtonMore').on('click', function () {
        $('.formsItemHiden').toggle();
    });

    // Ukryj / rozwić wszystkie boxy
    $('.collapseAll').on('click', function () {
        $('.box').removeClass('collapsed-box');
        $('.collapseExpand').click();
    });
    $('.expandAll').on('click', function () {
        $('.collapsed-box .collapseExpand').click();
    });

    // Rozwinięcie accrodion w leadach i wiadomościach.
    $('.accordionMessages').on('click', function () {
        $('.accordionMess').foundation('toggle', $(`.accordionMessagesContent`));
        $('.iconMessagesDown').toggleClass('hide');
        $('.iconMessagesUp').toggleClass('hide');
    });
    $('.accordionLead').on('click', function () {
        $('.accordionLeads').foundation('toggle', $(`.accordionLeadContent`));
        $('.iconLeadDown').toggleClass('hide');
        $('.iconLeadUp').toggleClass('hide');
    });

    // Generowanie wykresów Google Chars - Googla Analytics
    //console.log(tableChannel);
    // Load the Visualization API and the corechart package.
    google.charts.load('current', {'packages':['corechart']});
    // Set a callback to run when the Google Visualization API is loaded.
    google.charts.setOnLoadCallback(drawChart);

    google.charts.setOnLoadCallback(drawChartLine);
    // Callback that creates and populates a data table,
    // instantiates the pie chart, passes in the data and
    // draws it.
    function drawChart() {
        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'channelGrouping');
        data.addColumn('number', 'sessions');
        data.addRows(tableChannel);

        // Set chart options
        var options = {
            height: 300,
            pieHole:0.4,
        };

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('channelGrouping-wykres'));
        chart.draw(data, options);
    }

    function drawChartLine() {
        var data = google.visualization.arrayToDataTable(tableSessions);

        var options = {
            height: 400,
            //curveType: 'function',
            legend: { position: 'top', },
            lineWidth: 4,
            pointSize: 8,
            series: {
                0: {color: '#058dc7'},
                1: {color: '#8bba13'}
            }
        };

        var chart = new google.visualization.LineChart(document.getElementById('sessions-wykres'));

        chart.draw(data, options);
    }

});

