$(function () {
    BWA.ChartOptions = BWA.ChartOptions || {};
    var C = BWA.ChartOptions.UsageByEnergy = BWA.ChartOptions.UsageByEnergy || {};

    var valueAxises = [
        {
            title: {
                text: $G('electricityUsageWithUnit')
            }
        },
        {
            title: {
                text: $G('gasUsageWithUnit')
            }
        },
        {
            title: {
                text: $G('waterUsageWithUnit')
            }
        },
        {
            title: {
                text: $G('co2WithUnit')
            }
        },
        [
            {
                title: {
                    text: $G('electricityUsageWithUnit')
                }
            },
            {
                position: 'right',
                title: {
                    text: $G('gasUsageWithUnit')
                }
            },
        ]
    ];
    var seriesSSS = [
        [{
            type: 'StackedBar',
            valueField: '심야',
            name: '심야전력 사용량',
            label: {
                visible: false,
                customizeText: function () {
                    return this.valueText + 'kWh';
                }
            }
        },
        {
            type: 'StackedBar',
            valueField: '일반',
            name: '일반전력 사용량',
            label: {
                visible: false,
                customizeText: function () {
                    return this.valueText + 'kWh';
                }
            }
        },
        ],
        [
            {
                type: 'StackedBar',
                valueField: 'Value',
                name: '가스 사용량',
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'm3';
                    }
                }
            }
        ],
        [
            {
                type: 'StackedBar',
                valueField: 'Value',
                name: '수도 사용량',
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'm3';
                    }
                }
            },
        ],
        [
            {
                type: 'StackedBar',
                valueField: 'ECo2',
                name: $G('electricityCo2'),
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'tCO2';
                    }
                }
            }, {
                type: 'StackedBar',
                valueField: 'GCo2',
                name: $G('gasCo2'),
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'tCO2';
                    }
                }
            }
        ],
        [
            {
                type: 'bar',
                valueField: 'UnionE',
                name: '전력 사용량',
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'kWh';
                    }
                }
            },
            {
                type: 'bar',
                valueField: 'UnionG',
                visible: true,
                name: '가스 사용량',
                label: {
                    visible: false,
                    customizeText: function () {
                        return this.valueText + 'm3';
                    }
                }
            }
        ]
    ];
    C.getChartOptions = function (codeTimeType, goalUpperBound) {
        return {
            legend: {
                visible: true,
                verticalAlignment: 'top',
                horizontalAlignment: 'center'
            },

            tooltip: {
                enabled: true,
                format: 'fixedPoint',
                precision: 2,
                argumentFormat: 'shortDate',
                customizeText: function () {
                    return this.argumentText + "<br/>" + "<br/>" + this.valueText;
                }
            },
            argumentAxis: BWA.Chart.getTimeLineArgumentAxis(moment(), codeTimeType),
            commonSeriesSettings: {
                argumentField: "DateTime",
                selectionStyle: {
                    hatching: {
                        direction: "left"
                    }
                }
            },
            crosshair: {
                enabled: true,
                width: 2,
                horizontalLine: {
                    dashStyle: 'dash',
                    visible: false
                },
                verticalLine: {
                    dashStyle: 'dash'
                },
                label: {
                    visible: true,
                    backgroundColor: "#949494",
                    font: {
                        color: "#fff",
                        size: 12,
                    }
                }
            }
        };
    };

    C.getSeriesOptions = function (fuelTypeId, timeTypeId, MS, ME) {
        return {
            palette: 'Bright',
            series: seriesSSS[fuelTypeId - 1],
            valueAxis: valueAxises[fuelTypeId - 1],
        };
    }
});