/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","angular","moment","app/core/utils/rangeutil","./input_date"],function(a,b){"use strict";function c(){return{restrict:"E",templateUrl:"public/app/features/dashboard/timepicker/settings.html",controller:i,bindToController:!0,controllerAs:"ctrl",scope:{dashboard:"="}}}function d(){return{restrict:"E",templateUrl:"public/app/features/dashboard/timepicker/timepicker.html",controller:i,bindToController:!0,controllerAs:"ctrl",scope:{dashboard:"="}}}b&&b.id;a("settingsDirective",c),a("timePickerDirective",d);var e,f,g,h,i,j;return{setters:[function(a){e=a},function(a){f=a},function(a){g=a},function(a){h=a},function(a){j=a}],execute:function(){i=function(){function a(b,c,d){var f=this;this.$scope=b,this.$rootScope=c,this.timeSrv=d,b.ctrl=this,c.onAppEvent("shift-time-forward",function(){return f.move(1)},b),c.onAppEvent("shift-time-backward",function(){return f.move(-1)},b),c.onAppEvent("refresh",this.onRefresh.bind(this),b),this.panel=this.dashboard.timepicker,e.default.defaults(this.panel,a.defaults),this.firstDayOfWeek=g.default.localeData().firstDayOfWeek(),this.onRefresh()}return a.$inject=["$scope","$rootScope","timeSrv"],a.prototype.onRefresh=function(){var a=f.default.copy(this.timeSrv.timeRange()),b=f.default.copy(a.raw);this.dashboard.isTimezoneUtc()?this.isUtc=!0:(a.from.local(),a.to.local(),g.default.isMoment(b.from)&&b.from.local(),g.default.isMoment(b.to)&&b.to.local(),this.isUtc=!1),this.rangeString=h.describeTimeRange(b),this.absolute={fromJs:a.from.toDate(),toJs:a.to.toDate()},this.tooltip=this.dashboard.formatDate(a.from)+" <br>to<br>",this.tooltip+=this.dashboard.formatDate(a.to),this.timeRaw=b},a.prototype.zoom=function(a){this.$rootScope.appEvent("zoom-out",2)},a.prototype.move=function(a){var b,c,d=this.timeSrv.timeRange(),e=(d.to.valueOf()-d.from.valueOf())/2;a===-1?(b=d.to.valueOf()-e,c=d.from.valueOf()-e):1===a?(b=d.to.valueOf()+e,c=d.from.valueOf()+e,b>Date.now()&&d.to<Date.now()&&(b=Date.now(),c=d.from.valueOf())):(b=d.to.valueOf(),c=d.from.valueOf()),this.timeSrv.setTime({from:g.default.utc(c),to:g.default.utc(b)})},a.prototype.openDropdown=function(){this.onRefresh(),this.editTimeRaw=this.timeRaw,this.timeOptions=h.getRelativeTimesList(this.panel,this.rangeString),this.refresh={value:this.dashboard.refresh,options:e.default.map(this.panel.refresh_intervals,function(a){return{text:a,value:a}})},this.refresh.options.unshift({text:"off"}),this.$rootScope.appEvent("show-dash-editor",{editview:"timepicker",scope:this.$scope,cssClass:"gf-timepicker-dropdown"})},a.prototype.applyCustom=function(){this.refresh.value!==this.dashboard.refresh&&this.timeSrv.setAutoRefresh(this.refresh.value),this.timeSrv.setTime(this.editTimeRaw),this.$rootScope.appEvent("hide-dash-editor")},a.prototype.absoluteFromChanged=function(){this.editTimeRaw.from=this.getAbsoluteMomentForTimezone(this.absolute.fromJs)},a.prototype.absoluteToChanged=function(){this.editTimeRaw.to=this.getAbsoluteMomentForTimezone(this.absolute.toJs)},a.prototype.getAbsoluteMomentForTimezone=function(a){return this.dashboard.isTimezoneUtc()?g.default(a).utc():g.default(a)},a.prototype.setRelativeFilter=function(a){var b={from:a.from,to:a.to};this.panel.nowDelay&&"now"===b.to&&(b.to="now-"+this.panel.nowDelay),this.timeSrv.setTime(b),this.$rootScope.appEvent("hide-dash-editor")},a.tooltipFormat="MMM D, YYYY HH:mm:ss",a.defaults={time_options:["5m","15m","1h","6h","12h","24h","2d","7d","30d"],refresh_intervals:["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"]},a}(),a("TimePickerCtrl",i),f.default.module("grafana.directives").directive("gfTimePickerSettings",c),f.default.module("grafana.directives").directive("gfTimePicker",d),f.default.module("grafana.directives").directive("inputDatetime",j.inputDateDirective)}}});