"use strict";

var $ = require('jquery'),
    Marionette = require('../../../../shim/backbone.marionette'),
    chart = require('../../../core/chart.js'),
    barChartTmpl = require('../../../core/templates/barChart.html');

var ResultView = Marionette.ItemView.extend({
    template: barChartTmpl,

    className: 'chart-container runoff-chart-container',

    modelEvents: {
        'change': 'addChart'
    },

    initialize: function(options) {
        this.compareMode = options.compareMode;
        this.scenario = options.scenario;
    },

    onAttach: function() {
        this.addChart();
    },

    addChart: function() {
        function getBarData(displayName, name) {
            return {
                type: displayName,
                inf: result[name]['inf'],
                runoff: result[name]['runoff'],
                et: result[name]['et']
            };
        }

        var chartEl = this.$el.find('.bar-chart').get(0),
            result = this.model.get('result');
        $(chartEl).empty();
        if (result) {
            var indVar = 'type',
                depVars = ['inf', 'runoff', 'et'],
                data,
                options = {
                    barColors: ['#329b9c', '#4aeab3', '#4ebaea'],
                    depAxisLabel: 'Level',
                    depDisplayNames: ['Infiltration', 'Runoff', 'Evaporation']
                };

            if (this.scenario.get('is_current_conditions') || this.compareMode) {
                // Use the modified results since they are the same as the unmodified results
                // in Current Conditions, and they are the results we want to show
                // in compareMode for other scenarios.
                data = [
                    getBarData('', 'modified'),
                ];

                this.$el.addClass('current-conditions');
            } else {
                data = [
                    getBarData('Original', 'unmodified'),
                    getBarData('Modified', 'modified')
                ];
            }
            chart.makeBarChart(chartEl, data, indVar, depVars, options);
        }
    }
});

module.exports = {
    ResultView: ResultView
};

@@ -1215,36 +1215,36 @@
  %5B'#
-329b9c', '#4aeab3', '#4ebaea
+F8AA00', '#CF4300', '#C2D33C
 '%5D,%0A
@@ -1356,16 +1356,23 @@
 , 'Evapo
+transpi
 ration'%5D

Fix Runoff colors, labels