/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

define(["angular","lodash","app/core/utils/kbn"],function(a,b,c){"use strict";a.module("grafana.services").service("linkSrv",["templateSrv","timeSrv",function(a,d){this.getLinkUrl=function(b){var c=a.replace(b.url||""),e={};if(b.keepTime){var f=d.timeRangeForUrl();e.from=f.from,e.to=f.to}return b.includeVars&&a.fillVariableValuesForUrl(e),this.addParamsToUrl(c,e)},this.addParamsToUrl=function(a,c){var d=[];return b.each(c,function(a,c){null!==a&&(a===!0?d.push(c):b.isArray(a)?b.each(a,function(a){d.push(c+"="+encodeURIComponent(a))}):d.push(c+"="+encodeURIComponent(a)))}),0===d.length?a:this.appendToQueryString(a,d.join("&"))},this.appendToQueryString=function(a,c){if(!b.isUndefined(c)&&null!==c&&""!==c){var d=a.indexOf("?");d!==-1?a.length-d>1&&(a+="&"):a+="?",a+=c}return a},this.getAnchorInfo=function(b){var c={};return c.href=this.getLinkUrl(b),c.title=a.replace(b.title||""),c},this.getPanelLinkAnchorInfo=function(b,e){var f={};if("absolute"===b.type)f.target=b.targetBlank?"_blank":"_self",f.href=a.replace(b.url||"",e),f.title=a.replace(b.title||"",e);else if(b.dashUri)f.href="dashboard/"+b.dashUri+"?",f.title=a.replace(b.title||"",e),f.target=b.targetBlank?"_blank":"";else{f.title=a.replace(b.title||"",e);var g=c.slugifyForUrl(b.dashboard||"");f.href="dashboard/db/"+g+"?"}var h={};if(b.keepTime){var i=d.timeRangeForUrl();h.from=i.from,h.to=i.to}return b.includeVars&&a.fillVariableValuesForUrl(h,e),f.href=this.addParamsToUrl(f.href,h),b.params&&(f.href=this.appendToQueryString(f.href,a.replace(b.params,e))),f}}])});