// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/topic dojo/Deferred dojo/promise/all ./featureActions/main ./utils".split(" "),function(q,e,g,h,m,k,r,p){var l=null,n=q(null,{constructor:function(){this._actions=[];window.isBuilder?(h.subscribe("app/mapLoaded",e.hitch(this,this._onMapLoaded)),h.subscribe("app/mapChanged",e.hitch(this,this._onMapChanged))):(h.subscribe("mapLoaded",e.hitch(this,this._onMapLoaded)),h.subscribe("mapChanged",e.hitch(this,this._onMapChanged)));window.isBuilder?
(h.subscribe("app/appConfigLoaded",e.hitch(this,this._onAppConfigLoaded)),h.subscribe("app/appConfigChanged",e.hitch(this,this._onAppConfigChanged))):(h.subscribe("appConfigLoaded",e.hitch(this,this._onAppConfigLoaded)),h.subscribe("appConfigChanged",e.hitch(this,this._onAppConfigChanged)));this._registerFrameworkActions()},getAllActions:function(){return this._actions},getSupportedActions:function(a){a=this._getFeatureSet(a);var b=[];g.forEach(this._actions,function(d){var c=this.testActionSupportFeature(d,
a);c.action=d;b.push(c)},this);return k(b).then(e.hitch(this,function(d){return d.map(e.hitch(this,function(c,f){return{result:c,action:this._actions[f]}})).filter(function(c){return c.result}).map(function(c){return c.action})}))},testActionSupportFeature:function(a,b){b=this._getFeatureSet(b);var d;b.features&&0<b.features.length&&(d=b.features[0].getLayer());a=a.isFeatureSupported(b,d);var c=new m;a&&"function"===typeof a.then?a.then(function(f){c.resolve(f)},function(f){console.error(f);c.resolve(!1)}):
c.resolve(a);return c},registerAction:function(a){var b=new m;require([a.uri],e.hitch(this,function(d){var c=new d({map:this.map,appConfig:this.appConfig,label:a.label,name:a.name,widgetId:a.widgetId});g.some(this._actions,function(f){return c.name===f.name&&c.widgetId===f.widgetId})?(console.warn("Feature/FeatureSet action has been registered.",c.name),b.reject("Feature/FeatureSet action has been registered.",c.name)):(this._actions.push(c),b.resolve(c))}));return b},removeActionsByWidgetId:function(a){this._actions=
g.filter(this._actions,function(b){return b.widgetId!==a},this)},getActionsByWidgetId:function(a){return g.filter(this._actions,function(b){return b.widgetId===a},this)},getActionsByActionName:function(a){return g.filter(this._actions,function(b){return b.name===a},this)},registerWidgetFeatureActions:function(a){var b=new m;if(!a.featureActions||!a.uri)return b.resolve(),b;var d=[];g.forEach(a.featureActions,function(c){var f=a.manifest["i18nLabels_featureAction_"+c.name];d.push(this.registerAction({uri:a.isRemote?
a.amdFolder+c.uri+".js":a.amdFolder+c.uri,widgetId:a.id,name:c.name,label:f[window.dojoConfig.locale]||f[window.dojoConfig.locale.split("-")[0]]||f.defaultLabel}))},this);return k(d)},registerAllWidgetFeatureActions:function(a){var b=[];a.visitElement(e.hitch(this,function(d){d.uri&&d.visible&&b.push(this.registerWidgetFeatureActions(d))}));return k(b).then(function(){h.publish("widgetsActionsRegistered")})},_reRegisterWidgetActions:function(a){var b=[];g.forEach(this.getAllActions(),function(d){var c=
a.getConfigElementById(d.widgetId);"framework"===d.widgetId||c&&c.uri&&!1!==c.visible||this.removeActionsByWidgetId(d.widgetId)},this);a.visitElement(e.hitch(this,function(d){d.uri&&d.visible&&0===this.getActionsByWidgetId(d.id).length&&b.push(this.registerWidgetFeatureActions(d))}));0<b.length&&k(b).then(function(){h.publish("widgetsActionsRegistered")})},_registerFrameworkActions:function(){g.forEach(r,function(a){this.registerAction({uri:a.uri,widgetId:"framework",label:window.jimuNls.featureActions[a.name],
name:a.name})},this)},_getFeatureSet:function(a){return"[object Object]"===Object.prototype.toString.call(a)?a.features?a:p.toFeatureSet([a]):p.toFeatureSet(a)},_onAppConfigLoaded:function(a){this.appConfig=a=e.clone(a);this._setActionsAppConfig(a);this.registerAllWidgetFeatureActions(this.appConfig)},_onAppConfigChanged:function(a){this.appConfig=a=e.clone(a);this._reRegisterWidgetActions(this.appConfig);this._setActionsAppConfig(a)},_onMapLoaded:function(a){this.map=a;this._setActionsMap(a)},_onMapChanged:function(a){this.map=
a;this._setActionsMap(a)},_setActionsMap:function(a){g.forEach(this._actions,function(b){b.setMap(a)},this)},_setActionsAppConfig:function(a){g.forEach(this._actions,function(b){b.setAppConfig(a)},this)}});n.getInstance=function(){null===l&&(l=new n,window._featureActionManager=l);return l};return n});