var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Dashboards;
(function (Dashboards) {
    var Models;
    (function (Models) {
        var PowerFactorImpactTrendGadget = (function (_super) {
            __extends(PowerFactorImpactTrendGadget, _super);
            function PowerFactorImpactTrendGadget(gadgetOptions) {
                gadgetOptions.renderer = new Dashboards.Views.PowerFactorImpactTrendRender();
                _super.call(this, gadgetOptions);
                this.noDataMessage = i18n.loc.unencoded('PowerQualityGadgets', 'PowerQualityPowerFactor_NoData');
            }
            PowerFactorImpactTrendGadget.CreateInstance = function (gadgetOptions) {
                var instance = new PowerFactorImpactTrendGadget(gadgetOptions);
                return instance;
            };
            PowerFactorImpactTrendGadget.prototype.canExportData = function () {
                // Even though the base class can, this gadget really needs to tweak the data to be usable first.
                return false;
            };
            PowerFactorImpactTrendGadget.prototype.isConfigured = function () {
                return _super.prototype.isConfigured.call(this) && !StringUtil.isNullOrEmpty(this.getHandler().byName(Settings.Gadget.SourceId));
            };
            PowerFactorImpactTrendGadget.prototype.hasData = function () {
                var hasData = _super.prototype.hasData.call(this);
                if (hasData) {
                    hasData = false;
                    // We look for PowerFactor data here.  It's not used in the chart (only cost), but this determines if we have data.
                    var pfData = this.dataSet.ChartingData.DataPoints.PowerFactor;
                    if (pfData) {
                        hasData = _.any(pfData, function (dataPoint) {
                            return dataPoint[Models.ChartingDataGadget.ValueIdx] != 0;
                        });
                    }
                }
                return hasData;
            };
            PowerFactorImpactTrendGadget.TypeId = "12cdb077-e184-4192-b701-a90ad57eeaeb";
            return PowerFactorImpactTrendGadget;
        }(Models.ChartingDataGadget));
        Models.PowerFactorImpactTrendGadget = PowerFactorImpactTrendGadget;
    })(Models = Dashboards.Models || (Dashboards.Models = {}));
})(Dashboards || (Dashboards = {}));
var Dashboards;
(function (Dashboards) {
    var Views;
    (function (Views) {
        var PowerFactorImpactTrendRender = (function (_super) {
            __extends(PowerFactorImpactTrendRender, _super);
            function PowerFactorImpactTrendRender() {
                _super.call(this);
            }
            /* Render Overrides
            ******************************************************************************/
            PowerFactorImpactTrendRender.prototype.destroy = function () {
                _super.prototype.destroy.call(this);
                this.gadget = null;
            };
            PowerFactorImpactTrendRender.prototype.updateGadget = function (handler) {
                var chartOptions = Views.ChartHelper.GetDefaultChartOptions(this);
                chartOptions.legend.visible = false;
                chartOptions.axes = [Views.ChartHelper.GetStandardBottomXAxis(this)];
                // Bind the left axis
                var leftAxis = Views.ChartHelper.GetStandardLeftYAxis(this);
                leftAxis.title = StringUtil.format("{0} ({1})", i18n.loc.unencoded('PowerQualityGadgets', 'Cost'), i18n.currencyFormat.currencySymbol);
                Views.ChartHelper.BindChartLeftAxisLimits(leftAxis, handler);
                chartOptions.axes.push(leftAxis);
                // Bind Series
                var chartSeries = [];
                var dataPoints = $.extend(true, {}, this.gadget.dataSet.ChartingData.DataPoints); // Deep copy of data
                var costSeries = {
                    title: i18n.loc.unencoded('PowerQualityGadgets', 'PowerFactorImpactTrend_Label'),
                    type: 'column',
                    strokeStyle: '#b10043',
                    fillStyle: '#b10043',
                    data: dataPoints['Cost'],
                    axisY: 'y1',
                    markers: null
                };
                chartOptions.series = chartSeries;
                chartOptions.series.push(costSeries);
                var existingSeries = this.$getChart().jqChart('option', 'series');
                Views.ChartHelper.UpdateSeriesVisibility(chartSeries, existingSeries);
                // Create the chart
                this.destroyChart(); // Destroy any previous chart instance
                Views.ChartHelper.BindChartAxisLabelFormat(this, ['left']);
                this.$getChart().jqChart(chartOptions);
                Views.ChartHelper.BindTimeValueTooltipFormat(this, this.gadget, handler, i18n.formatCurrency);
                Views.ChartHelper.ShowMarkerForNoDataPlotted(this);
            };
            return PowerFactorImpactTrendRender;
        }(Views.ViewPeriodChartRender));
        Views.PowerFactorImpactTrendRender = PowerFactorImpactTrendRender;
    })(Views = Dashboards.Views || (Dashboards.Views = {}));
})(Dashboards || (Dashboards = {}));
// Register the gadget type
Dashboards.Controllers.GadgetType.RegisterDefinition({
    typeId: Dashboards.Models.PowerFactorImpactTrendGadget.TypeId,
    create: Dashboards.Models.PowerFactorImpactTrendGadget.CreateInstance,
    resourceSet: 'PowerQualityGadgets'
});
//# sourceMappingURL=PowerFactorImpactTrendGadget.js.map