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

define(["jquery","angular","../core_module"],function(a,b,c){"use strict";var d={settings:{src:"public/app/features/dashboard/partials/settings.html"},annotations:{src:"public/app/features/annotations/partials/editor.html"},templating:{src:"public/app/features/templating/partials/editor.html"},history:{html:'<gf-dashboard-history dashboard="dashboard"></gf-dashboard-history>'},timepicker:{src:"public/app/features/dashboard/timepicker/dropdown.html"},import:{html:"<dash-import></dash-import>"}};c.default.directive("dashEditorView",["$compile","$location","$rootScope",function(a,c,e){return{restrict:"A",link:function(f,g){function h(a){j&&j.dismiss(a)}function i(i,l){if(l.editview&&(l.src=d[l.editview].src,l.html=d[l.editview].html),k&&k===l.editview)return void h(!1);if(h(!0),k=l.editview,j=l.scope?l.scope.$new():f.$new(),j.dismiss=function(a){if(j.$destroy(),k=null,j=null,g.removeClass("dash-edit-view--open"),a||setTimeout(function(){g.empty()},250),l.editview){var b=c.search();l.editview===b.editview&&(delete b.editview,setTimeout(function(){e.$apply(function(){c.search(b)})}))}},"import"===l.editview){var m=e.$new();return m.$on("$destroy",function(){j.dismiss()}),void e.appEvent("show-modal",{templateHtml:"<dash-import></dash-import>",scope:m,backdrop:"static"})}var n;l.src?(n=b.element(document.createElement("div")),n.html('<div class="tabbed-view" ng-include="\''+l.src+"'\"></div>")):(n=b.element(document.createElement("div")),n.addClass("tabbed-view"),n.html(l.html)),a(n)(j),setTimeout(function(){g.empty(),g.append(n),setTimeout(function(){g.addClass("dash-edit-view--open")},10)},10)}var j,k;f.$watch("dashboardViewState.state.editview",function(a,b){a?i(null,{editview:a}):b&&k===b&&h()}),f.$on("$destroy",h),f.onAppEvent("hide-dash-editor",function(){h(!1)}),f.onAppEvent("show-dash-editor",i),f.onAppEvent("panel-fullscreen-enter",function(){f.appEvent("hide-dash-editor")})}}}])});