define(["events"],function(events){"use strict";var cacheParam=Date.now();function PluginManager(){this.pluginsList=[]}return PluginManager.prototype.loadPlugin=function(url){console.log("Loading plugin: "+url);var instance=this;return require([url,"globalize","appRouter"]).then(function(responses){var pluginFactory=responses[0],globalize=responses[1],appRouter=responses[2];console.log("creating plugin instance");var plugin=new pluginFactory;if(instance.pluginsList.filter(function(p){return p.id===plugin.id})[0])return Promise.resolve();var urlLower=(plugin.installUrl=url).toLowerCase();-1===urlLower.indexOf("http:")&&-1===urlLower.indexOf("https:")&&-1===urlLower.indexOf("file:")&&0!==url.indexOf(appRouter.baseUrl())&&(url=appRouter.baseUrl()+"/"+url);var separatorIndex=Math.max(url.lastIndexOf("/"),url.lastIndexOf("\\"));plugin.baseUrl=url.substring(0,separatorIndex);var paths={};return paths[plugin.id]=plugin.baseUrl,console.log("setting require config"),require.config({waitSeconds:0,paths:paths}),instance.register(plugin),plugin.getRoutes&&plugin.getRoutes().forEach(function(route){!function(pluginManager,appRouter,route,plugin){route.contentPath=pluginManager.mapPath(plugin,route.path),route.path=pluginManager.mapRoute(plugin,route),appRouter.addRoute(route)}(instance,appRouter,route,plugin)}),console.log("loading plugin strings"),function(plugin,globalize){var strings=plugin.getTranslations?plugin.getTranslations():[];return globalize.loadStrings({name:plugin.id||plugin.packageName,strings:strings})}(plugin,globalize)})},PluginManager.prototype.register=function(obj){this.pluginsList.push(obj),events.trigger(this,"registered",[obj])},PluginManager.prototype.ofType=function(type){return this.pluginsList.filter(function(o){return o.type===type})},PluginManager.prototype.plugins=function(){return this.pluginsList},PluginManager.prototype.mapRoute=function(plugin,route){return"string"==typeof plugin&&(plugin=this.pluginsList.filter(function(p){return(p.id||p.packageName)===plugin})[0]),0===(route=route.path||route).toLowerCase().indexOf("http")?route:"/plugins/"+plugin.id+"/"+route},PluginManager.prototype.mapPath=function(plugin,path,addCacheParam){"string"==typeof plugin&&(plugin=this.pluginsList.filter(function(p){return(p.id||p.packageName)===plugin})[0]);var url=plugin.baseUrl+"/"+path;return addCacheParam&&(url+=-1===url.indexOf("?")?"?":"&",url+="v="+cacheParam),url},new PluginManager});