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

    var seriesBudgetCode;

    BWA.ChartOptions.LCCView = {

        MakeSeries: function (CodeType) {
            seriesBudgetCode = new Array();
            for (var s = 0; s < CodeType.length; s++) {
                var ss = {
                    type: 'stackedBar',
                    //valueField: CodeType[s].Name() + "누적",
                    valueField: CodeType[s].Name(),
                    name: CodeType[s].Name(),
                    label: {
                        visible: false,
                        customizeText: function () {
                            return this.valueText + '원';
                        }
                    }
                };
                seriesBudgetCode.push(ss);
            }
        },


        getPieChartDayOptions: function () {

            return _.extend({
                //palette: "Pastel",
            }, BWA.ChartOptions.LCCView.getPieChartOptions());
        },

        getPieChartMonthOptions: function () {

            return _.extend({
                //palette: "Pastel",
            }, BWA.ChartOptions.LCCView.getPieChartOptions());
        },

        getBarChartDayOptions: function (handlePointClick) {
            return _.extend({
                //palette: "Pastel",
            }, BWA.ChartOptions.LCCView.getBarChartOptions($Code.TimeType.MONTH, handlePointClick));
        },

        getBarChartMonthOptions: function (handlePointClick) {

            return _.extend({
                //palette: "Pastel",
            }, BWA.ChartOptions.LCCView.getBarChartOptions2($Code.TimeType.MONTH, handlePointClick));
        },

        getPieChartOptions: function () {
            return {

                legend: {
                    horizontalAlignment: "right",
                    verticalAlignment: "top",
                    margin: 10,
                    border: {
                        visible: true
                    }
                },

                tooltip: {
                    enabled: true,
                    format: 'fixedPoint',
                    precision: 0,
                    customizeTooltip: function (point) {
                        return {
                            text: [this.argumentText, ': ', this.valueText].join('')
                        };
                    }
                },

                series: [
                    {
                        type: "doughnut",  // if not, pie.
                        argumentField: "FuelTypeName",
                        argumentType: "string",
                        valueField: "Value",
                        hoverStyle: {
                            color: "#ffd700"
                        },
                        label: {
                            visible: false,
                            connector: {
                                visible: true
                            },
                            customizeText: function (pointInfo) {
                                return pointInfo.argumentText;
                            }
                        }
                    }
                ]
            };
        },

        getBarChartOptions: function (codeTimeType, handlePointClick) {

            switch (codeTimeType) {
                case $Code.TimeType.DAY:
                    argumentAxis = {
                        label: {
                            customizeText: function () {
                                return this.value + '일';
                            }
                        },
                        tickInterval: 5,
                    };
                    break;
                case $Code.TimeType.MONTH:
                    argumentAxis = {
                        label: {
                            customizeText: function () {
                                return this.value + '월';
                            }
                        },
                    };
                    break;
            }
            argumentAxis.argumentType = 'string';

            return {
                pointClick: handlePointClick,
                legend: {
                    visible: false,
                    verticalAlignment: 'center',
                    horizontalAlignment: 'right',
                    border: {
                        visible: true
                    }
                },

                argumentAxis: argumentAxis,
                commonSeriesSettings: {
                    //type: 'stackedBar',
                    argumentField: 'DateTime',
                    selectionStyle: {
                        hatching: {
                            direction: "left"
                        }
                    }
                },

                valueAxis: [{
                    label: {
                        //format: 'thousands'
                        //precision: 2
                    },
                    title: {
                        text: '원'
                    }
                }],

                series: seriesBudgetCode,

                tooltip: {
                    enabled: true,
                    format: 'fixedPoint',
                    precision: 0,
                    customizeTooltip: function(point) {
                        return {
                            text: [this.seriesName, ': ', this.valueText].join('')
                        };
                    }
                },
            };

        },
        getBarChartOptions2: function (codeTimeType, handlePointClick) {
            var argumentAxis;
            switch (codeTimeType) {
                case $Code.TimeType.DAY:
                    argumentAxis = {
                        label: {
                            customizeText: function () {
                                return this.value + '일';
                            }
                        },
                        tickInterval: 5,
                    };
                    break;
                case $Code.TimeType.MONTH:
                    argumentAxis = {
                        label: {
                            customizeText: function () {
                                return this.value + '월';
                            }
                        },
                    };
                    break;
            }
            argumentAxis.argumentType = 'string';

            return {
                //pointClick: handlePointClick,
                legend: {
                    visible: false,
                    verticalAlignment: 'center',
                    horizontalAlignment: 'right',
                    border: {
                        visible: true
                    }
                },

                argumentAxis: argumentAxis,
                commonSeriesSettings: {
                    type: 'stackedBar',
                    argumentField: 'DateTime',
                    selectionStyle: {
                        hatching: {
                            direction: "left"
                        }
                    }
                },

                valueAxis: [{
                    label: {
                        //format: 'thousands'
                        //precision: 2
                    },
                    title: {
                        text: '원'
                    }
                }],

                series:   
                [ {
                    type: 'stackedBar',
                    valueField: "InvestTotal",
                    name: "고정비",
                    label: {
                        visible: false,
                        customizeText: function () {
                            return this.valueText + '원';
                        }
                    }
                },
                    {
                    type: 'stackedBar',
                    valueField: "운영비합산",
                    name: "운영비",
                    label: {
                        visible: false,
                        customizeText: function () {
                            return this.valueText + '원';
                        }
                    }
                },
                ],

                tooltip: {
                    enabled: true,
                    format: 'fixedPoint',
                    precision: 0,
                    customizeTooltip: function (point) {
                        return {
                            text: [this.seriesName, ': ', this.valueText].join('')
                        };
                    }
                },
            };

        },

    };
});