$(document).ready( function() {

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

    homePageCurrentSettings();
    ethernetStatusSettings();
    opticalPowerTimeSeriesChart();
    currentTimeSeries();
    temperatureTimeSeries();

    $('.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 homePageCurrentSettings() {

    //Api call
    var settings = {};
    settings.centralWaveLength = "1550.00nm";
    settings.comboFreSpacing = "10 GHz";
    settings.outputone = "Comb Tone 2 - 1549.84 nm";
    settings.outputtwo = "Comb Tone 1 - 1549.84 nm";
    settings.outputthree = "Comb Tone 0 - 1549.84 nm";
    settings.outputfour = "Comb Tone +5 - 1550.40 nm";

    template = $('#homepage-setting-template').html();
    html = Mustache.to_html(template, settings);
        
    $('#settingAppendDiv').append(html);
}

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": "Slave Laser"
            },
            {
                "status": "active",
                "name": "Variable Optical Attenuator"
            },
            {
                "status": "active",
                "name": "Master Laser"
            },
            {
                "status": "active",
                "name": "1:4 Coupler"
            },
            {
                "status": "active",
                "name": "Demux Output 1"
            },
            {
                "status": "active",
                "name": "Demux Output 2"
            },
            {
                "status": "active",
                "name": "Demux Output 3"
            },
            {
                "status": "active",
                "name": "Demux Output 4"
            },
            {
                "status": "active",
                "name": "RF Synthesizer"
            },
            {
                "status": "active",
                "name": "RF Power ON"
            }
        ]
    }

    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'
                    }
                }
            }]
        }
    
    });
}