$(document).ready( function() {

    $('.machine-series option:eq(9)').attr('selected', true);

    ethernetStatusSettings();
    // opticalPowerTimeSeriesChart();
    // currentTimeSeries();
    // temperatureTimeSeries();
    // OpticalfrequencycombSeries_100();
    // OpticalfrequencycombSeries_1000();
    // DemuxSpectrumSeries();

    $('.machine-series').on('change', function() {
        $('.machine-series option:selected').removeAttr('selected', false);
        var selectedText = $(this).find("option:selected").text();
        var selectedValue = $(this).val();
        machineSeriesSelection(selectedValue);
    });

});


function ethernetStatusSettings() {
    var statusData = {

        "ethernetStatus" : [
            {
                "status": "active",
                "name": "Ethernet Connection"
            },
            {
                "status": "in-active",
                "name": "Remote Connection"
            },
            {
                "status": "active",
                "name": "TEC"
            },
            {
                "status": "active",
                "name": "Temperature"
            },
            {
                "status": "active",
                "name": "Power Supply"
            },
            {
                "status": "active",
                "name": "Fans"
            },
            {
                "status": "active",
                "name": "Section 1"
            },
            {
                "status": "active",
                "name": "Section 2"
            },
            {
                "status": "active",
                "name": "Section 3"
            },
            {
                "status": "active",
                "name": "Section 4"
            },
            {
                "status": "active",
                "name": "Section 5"
            },
            {
                "status": "active",
                "name": "Section N"
            }
        ]
    }

    // template = $('#homepage-etharnet-template').html();
    // html = Mustache.to_html(template, statusData);
        
    // $('#ethernetAppendDiv').append(html);

}

function opticalPowerTimeSeriesChart() {
    Highcharts.chart('opticalPowerContainer', {
        title: {
            text: null  
        },
        credits: {
            enabled: false
        },

        yAxis: {
            title: {
                text: null
            }
        },

        legend: {
            enabled: false
        },
    
        plotOptions: {
            series: {
                label: {
                    connectorAllowed: false
                },
                pointStart: 2010
            }
        },
    
        series: [{
            data: [75, 150, 100, 80, 200, 110, 225]
        }],
    
        responsive: {
            rules: [{
                condition: {
                    maxWidth: 500
                },
                chartOptions: {
                    legend: {
                        layout: 'horizontal',
                        align: 'center',
                        verticalAlign: 'bottom'
                    }
                }
            }]
        }
    
    });
}

function currentTimeSeries() {
    Highcharts.chart('currentTimeContainer', {
        chart: {
            type: 'line'
        },

        credits: {
            enabled: false
        },

        title: {
            text: null  
        },

        yAxis: {
            title: {
                text: null
            }
        },

        legend: {
            enabled: false
        },

        xAxis: {
            categories: [140, 200, 260, 320, 380, 440, 500]
        },

        plotOptions: {
            series: {
                label: {
                    connectorAllowed: false
                }
            }
        },

        series: [{
            data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
    

}

function temperatureTimeSeries() {
    Highcharts.chart('temperatureTimeContainer', {
        title: {
            text: null  
        },

        credits: {
            enabled: false
        },
        
        yAxis: {
            title: {
                text: null
            }
        },

        legend: {
            enabled: false
        },
    
        plotOptions: {
            series: {
                label: {
                    connectorAllowed: false
                },
                pointStart: 2010
            }
        },
    
        series: [{
            data: [75, 150, 100, 80, 200, 110, 225]
        }],
    
        responsive: {
            rules: [{
                condition: {
                    maxWidth: 500
                },
                chartOptions: {
                    legend: {
                        layout: 'horizontal',
                        align: 'center',
                        verticalAlign: 'bottom'
                    }
                }
            }]
        }
    
    });
}
function OpticalfrequencycombSeries_100() {

    CallCSVData(csvPath_100).then(function (response) {
        console.log(response);
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'divOpticalfrequencycomb_100',
                type: 'line',
                zoomType: 'xy'
            },
            title: {
                text: 'Optical frequency comb - 100 points'
            },
            xAxis: {
                title: {
                    text: 'Wavelength (nm)'
                }
            },
            yAxis: {
                title: {
                    text: 'Power (dBm)'
                }
            },
            series: [{
                name: 'Optical frequency comb',
                data: response,//[[1549.608888888889, -38.90705129753387]],
                dashStyle: 'dash',
            }]
        });
    });
}
function OpticalfrequencycombSeries_1000() {

    CallCSVData(csvPath_1000).then(function (response) {
        console.log(response);
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'divOpticalfrequencycomb_1000',
                type: 'line',
                zoomType: 'xy'
            },
            title: {
                text: 'Optical frequency comb - 1000 points'
            },
            xAxis: {
                title: {
                    text: 'Wavelength (nm)'
                }
            },
            yAxis: {
                title: {
                    text: 'Power (dBm)'
                }
            },
            series: [{
                name: 'Optical frequency comb',
                data: response,//[[1549.608888888889, -38.90705129753387]],
                dashStyle: 'dash',
            }]
        });
    });
}    

var chartDataDemux = [];

function DemuxSpectrumSeries() {
    CallCSVData(csvPath_demux1).then(function (response) {
        chartDataDemux.push(response.slice(0,response.length-1));
        CallCSVData(csvPath_demux2).then(function (response) {
            chartDataDemux.push(response.slice(0,response.length-1));
            CallCSVData(csvPath_demux3).then(function (response) {
                chartDataDemux.push(response.slice(0,response.length-1));
                CallCSVData(csvPath_demux4).then(function (response) {
                    chartDataDemux.push(response.slice(0,response.length-1));
                    console.log(chartDataDemux);
                    RenderDemuxChart();
                });
            });
        });
    });
}

function RenderDemuxChart(){
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'divDemuxSpectrum',
                type: 'line',
                zoomType: 'xy'
            },
            title: {
                text: 'Demux Spectrum'
            },
            xAxis: {
                title: {
                    text: 'Wavelength (nm)'
                }
            },
            yAxis: {
                title: {
                    text: 'Power (dBm)'
                }
            },
            series: [{
                name: 'Demux Spectrum 1',
                data: chartDataDemux[0],
                dashStyle: 'dash',
            },{
                name: 'Demux Spectrum 2',
                data: chartDataDemux[1],
                dashStyle: 'dash',
            },{
                name: 'Demux Spectrum 3',
                data: chartDataDemux[2],
                dashStyle: 'dash',
            },{
                name: 'Demux Spectrum 4',
                data: chartDataDemux[3],
                dashStyle: 'dash',
            }]
        });
}


