// Copyright (c) 2013 SAP SE, All Rights Reserved
sap.ui.define(['jquery.sap.global','sap/ui/base/EventProvider','./Target'],function($,E,T){"use strict";return E.extend("sap.ui.core.routing.Targets",{constructor:function(o){var t,s;E.apply(this);this._mTargets={};this._oConfig=o.config;this._oViews=o.views;for(t in o.targets){if(o.targets.hasOwnProperty(t)){this._createTarget(t,o.targets[t]);}}for(s in this._mTargets){if(this._mTargets.hasOwnProperty(s)){this._addParentTo(this._mTargets[s]);}}},destroy:function(){var t;E.prototype.destroy.apply(this);for(t in this._mTargets){if(this._mTargets.hasOwnProperty(t)){this._mTargets[t].destroy();}}this._mTargets=null;this._oViews=null;this._oConfig=null;this.bIsDestroyed=true;return this;},display:function(t,d){this._display(t,d);},getViews:function(){return this._oViews;},getTarget:function(n){var t=this,r=[];if($.isArray(n)){$.each(n,function(i,N){var o=t._mTargets[N];if(o){r.push(o);}else{$.sap.log.error("The target you tried to get \""+N+"\" does not exist!",t);}});return r;}return this._mTargets[n];},attachDisplay:function(d,f,l){return this.attachEvent(this.M_EVENTS.DISPLAY,d,f,l);},detachDisplay:function(f,l){return this.detachEvent(this.M_EVENTS.DISPLAY,f,l);},fireDisplay:function(a){return this.fireEvent(this.M_EVENTS.DISPLAY,a);},M_EVENTS:{DISPLAY:"display"},_createTarget:function(n,t){var o,O;O=$.extend(true,{name:n},this._oConfig,t);o=this._constructTarget(O);o.attachDisplay(function(e){var p=e.getParameters();this.fireDisplay({name:n,view:p.view,control:p.control,config:p.config,data:p.data});},this);this._mTargets[n]=o;},_addParentTo:function(t){var p,P=t._oOptions.parent;if(!P){return;}p=this._mTargets[P];if(!p){$.sap.log.error("The target '"+t._oOptions.name+" has a parent '"+P+"' defined, but it was not found in the other targets",this);return;}t._oParent=p;},_constructTarget:function(o,p){return new T(o,this._oViews,p);},_display:function(t,d){var a=this;if($.isArray(t)){$.each(t,function(i,s){a._displaySingleTarget(s,d);});}else{this._displaySingleTarget(t,d);}return this;},_displaySingleTarget:function(n,d){var t=this.getTarget(n);if(t!==undefined){t.display(d);}else{$.sap.log.error("The target with the name \""+n+"\" does not exist!",this);}},_setRootViewId:function(i){var t,o;for(t in this._mTargets){if(this._mTargets.hasOwnProperty(t)){o=this._mTargets[t]._oOptions;if(o.rootView===undefined){o.rootView=i;}}}}});},true);
