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

define(["angular","lodash","jquery","./gfunc"],function(a,b,c,d){"use strict";function e(a){return b.reduce(a,function(a,c){return b.each(c,function(b){a.push(b.name)}),a},[])}function f(a){return b.map(a,function(a,c){var d=b.map(a,function(a){return{text:a.name,click:"ctrl.addFunction('"+a.name+"')"}});return{text:c,submenu:d}})}a.module("grafana.directives").directive("graphiteAddFunc",["$compile",function(a){var g='<input type="text" class="gf-form-input" spellcheck="false" style="display:none"></input>',h='<a  class="gf-form-label query-part dropdown-toggle" tabindex="1" gf-dropdown="functionMenu" data-toggle="dropdown"><i class="fa fa-plus"></i></a>';return{link:function(i,j){var k=i.ctrl,l=k.datasource.graphiteVersion,m=d.getCategories(l),n=e(m);i.functionMenu=f(m);var o=c(g),p=c(h);o.appendTo(j),p.appendTo(j),o.attr("data-provide","typeahead"),o.typeahead({source:n,minLength:1,items:10,updater:function(a){var c=d.getFuncDef(a);if(c||(a=a.toLowerCase(),c=b.find(n,function(b){return 0===b.toLowerCase().indexOf(a)})))return i.$apply(function(){k.addFunction(c)}),o.trigger("blur"),""}}),p.click(function(){p.hide(),o.show(),o.focus()}),o.keyup(function(){j.toggleClass("open",""===o.val())}),o.blur(function(){setTimeout(function(){o.val(""),o.hide(),p.show(),j.removeClass("open")},200)}),a(j.contents())(i)}}}])});