// 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/array dojo/_base/lang dojo/Deferred jimu/BaseFeatureAction jimu/Role jimu/WidgetManager dojo/query jimu/PopupManager dojo/aspect".split(" "),function(h,f,e,k,l,m,n,g,p,q){return h(l,{_viewedFeatureIdArr:[],_widgetInstance:null,_config:null,_layerFoundDetail:{},_isInfoWindowBackBtnClickHandle:!1,_viewedFeatureDetailedArr:[],_viewedFeatureArr:[],map:null,iconClass:"icon-edit",_isRelatedRecordDisplayed:function(){var b=g(".related-records-popup-projector",this.map.infoWindow.domNode);
return b&&0<b.length&&0<b[0].childNodes.length&&"none"!==b[0].childNodes[0].style.display?!0:!1},_isLayerConfigured:function(b){var a=!1;if(!b)return!1;this._viewedFeatureDetailedArr=[];f.forEach(this._viewedFeatureIdArr,e.hitch(this,function(c,d){this._layerFoundDetail[c]?0<d?(a=this._layerFoundDetail[this._viewedFeatureIdArr[d-1]]&&this._layerFoundDetail[this._viewedFeatureIdArr[d-1]].relationshipInfos?this._showWidgetFeatureAction(this._layerFoundDetail[this._viewedFeatureIdArr[d-1]].relationshipInfos,
c):!1,this._viewedFeatureDetailedArr.push(a),a&&(this._layerFoundDetail[c]=a),this._viewedFeatureIdArr[d-1]===c&&(a=this._viewedFeatureDetailedArr[d-1]?!0:!1)):0===d&&(a=this._showWidgetFeatureAction(this._config.editor.layerInfos,c),this._viewedFeatureDetailedArr.push(a),a&&(this._layerFoundDetail[c]=a)):(a=0<d?this._layerFoundDetail[this._viewedFeatureIdArr[d-1]]&&this._layerFoundDetail[this._viewedFeatureIdArr[d-1]].relationshipInfos?this._showWidgetFeatureAction(this._layerFoundDetail[this._viewedFeatureIdArr[d-
1]].relationshipInfos,c):!1:this._showWidgetFeatureAction(this._config.editor.layerInfos,c),this._viewedFeatureDetailedArr.push(a),a&&(this._layerFoundDetail[c]=a))}));return a?!0:!1},_isInfoWindowShowing:function(){if(this.map.infoWindow.isShowing){var b=g(".statusSection",this.map.infoWindow.domNode);if(b&&0<b.length)return this._isRelatedRecordDisplayed()?!0:!1;this._isRelatedRecordDisplayed();return!0}return!1},_getWidgetConfig:function(){this._widgetInstance||(this._widgetInstance=this.appConfig.getConfigElementById(this.widgetId));
!this._config&&this._widgetInstance&&(this._config=this._widgetInstance.config);return this._config?!0:!1},_detectInfoWindowBackBtnClick:function(){var b;this._isInfoWindowBackBtnClickHandle&&(this._isInfoWindowBackBtnClickHandle.remove(),this._isInfoWindowBackBtnClickHandle=null);if(b=p.getInstance(this))if(b=b._relatedRecordsPopupProjector)this._isInfoWindowBackBtnClickHandle=q.before(b,"_onPreviouBtnClick",e.hitch(this,function(){this._isInfoWindowBackBtnClicked=!0}))},isFeatureSupported:function(b,
a){this._detectInfoWindowBackBtnClick();a=a&&a.id?a.id:a;if(!this._getWidgetConfig())return!1;this._isInfoWindowShowing()||(this._viewedFeatureIdArr=[],this._layerFoundDetail={},this._viewedFeatureDetailedArr=[],this._viewedFeatureArr=[]);this._isInfoWindowBackBtnClicked?(this._isInfoWindowBackBtnClicked=!1,this._viewedFeatureIdArr.pop(),this._viewedFeatureArr.pop()):(this._viewedFeatureIdArr.push(a),this._viewedFeatureArr.push(b.features));return this._isLayerConfigured(a)?!0:!1},onExecute:function(b,
a){var c=a||e.getObject("_wabProperties.popupInfo.layerForActionWithEmptyFeatures",!1,this.map.infoWindow);a=new k;n.getInstance().triggerWidgetOpen(this.widgetId).then(e.hitch(this,function(d){d.beginEditingByFeatures(b.features,c,this._viewedFeatureIdArr,this._viewedFeatureArr)}));return a.promise},_checkEditPrivilege:function(b){var a=!0;b&&(a=new m({id:b.roleId?b.roleId:b.role,role:b.role}),b.privileges&&a.setPrivileges(b.privileges),a=a.canEditFeatures());return a},_hasAnyEditableLayerInRelation:function(b){var a=
!1;f.forEach(b,e.hitch(this,function(c){!0===c._editFlag?a=!0:c.relationshipInfos&&0<c.relationshipInfos.length&&(a=this._hasAnyEditableLayerInRelation(c.relationshipInfos));if(a)return!0}));return a},_showWidgetFeatureAction:function(b,a){var c=!1;if(!b)return c;f.some(b,e.hitch(this,function(d){if(d.featureLayer.id===a)return c=d,!0}));c&&c.hasOwnProperty("_editFlag")&&(b=c._editFlag,!c._editFlag&&c.relationshipInfos&&0<c.relationshipInfos.length&&(b=this._hasAnyEditableLayerInRelation(c.relationshipInfos)),
b||(c=!1));return c}})});