// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../../chunks/tslib.es6 ../../../Graphic ../../../core/Accessor ../../../core/arrayUtils ../../../core/Clonable ../../../core/Collection ../../../core/Identifiable ../../../core/promiseUtils ../../../core/reactiveUtils ../../../core/accessorSupport/decorators/property ../../../core/has ../../../core/Logger ../../../core/accessorSupport/decorators/subclass ../../../rest/support/RelationshipQuery ../support/featureUtils ../../FeatureForm/featureFormUtils".split(" "),function(d,A,c,B,C,x,D, p,q,e,N,O,E,y,z,F){c=class extends C.ClonableMixin(D.IdentifiableMixin(c)){constructor(b){super(b);this._loaded=!1;this._queryFeatureCountAbortController=this._queryPageAbortController=this._queryAbortController=null;this.featuresPerPage=10;this.orderByFields=this.map=this.layer=this.graphic=this.description=null;this.featureCount=0;this.relationshipId=null;this.showAllEnabled=!1;this.title=null;this._cancelQuery=()=>{const {_queryAbortController:a}=this;a&&a.abort();this._queryAbortController=null}; this._cancelQueryFeatureCount=()=>{const {_queryFeatureCountAbortController:a}=this;a&&a.abort();this._queryFeatureCountAbortController=null};this._cancelQueryPage=()=>{const {_queryPageAbortController:a}=this;a&&a.abort();this._queryPageAbortController=null};this._queryController=async()=>{this._cancelQuery();const a=new AbortController;this._queryAbortController=a;await p.ignoreAbortErrors(this._query());this._queryAbortController===a&&(this._queryAbortController=null)};this._queryFeatureCountController= async()=>{this._loaded=!1;this._cancelQueryFeatureCount();const a=new AbortController;this._queryFeatureCountAbortController=a;await p.ignoreAbortErrors(this._queryFeatureCount());this._queryFeatureCountAbortController===a&&(this._queryFeatureCountAbortController=null);this._loaded=!0};this._queryPageController=async()=>{const a=new AbortController;this._queryPageAbortController=a;await p.ignoreAbortErrors(this._queryPage());this._queryPageAbortController===a&&(this._queryPageAbortController=null)}; this._queryDebounced=p.debounce(this._queryController,100);this._queryFeatureCountDebounced=p.debounce(this._queryFeatureCountController,100);this._queryPageDebounced=p.debounce(this._queryPageController,100);this._query=async()=>{const {_queryAbortController:a,relatedFeatures:f}=this;this.featureCount&&(this._destroyRelatedFeatureViewModels(),this.featurePage=1,f.destroyAll(),this.destroyed||f.addMany(this._sliceFeatures(await this._queryRelatedFeatures({signal:a?.signal}))))};this.addHandles([q.watch(()=> [this.displayCount,this.graphic,this.layer,this.layer?.loaded,this.map,this.orderByFields,this.relationshipId,this.featuresPerPage,this.showAllEnabled,this.canQuery,this.featureCount],()=>this._queryDebounced(),q.initial),q.watch(()=>[this.featurePage,this.showAllEnabled],()=>this._queryPageDebounced()),q.watch(()=>[this.layer,this.relationshipId,this.objectId,this.canQuery],()=>this._queryFeatureCountDebounced())])}destroy(){this._destroyRelatedFeatureViewModels();this.relatedFeatures.destroyAll(); this._cancelQuery();this._cancelQueryFeatureCount();this._cancelQueryPage()}set featurePage(b){const {featuresPerPage:a,featureCount:f}=this;this._set("featurePage",Math.min(Math.max(b,1),Math.ceil(f/a)||1))}get featurePage(){return this._get("featurePage")}get orderByFieldsFixedCasing(){const {orderByFields:b,relatedLayer:a}=this;return b&&a?.loaded?b.map(f=>{const g=f.clone();g.field=z.getFixedFieldName(f.field,a);return g}):b??[]}get supportsCacheHint(){return!!this.layer?.capabilities?.queryRelated?.supportsCacheHint}get canLoad(){return!!this.map&& null!=this.relationshipId&&"number"===typeof this.objectId}get canQuery(){const b=this.layer?.capabilities?.queryRelated;return!!this.relatedLayer&&!!this.relationship&&null!=this.relationshipId&&null!=this.objectId&&!!b?.supportsCount&&!!b?.supportsPagination}get itemDescriptionFieldName(){return this.orderByFieldsFixedCasing[0]?.field||null}set displayCount(b){this._set("displayCount",Math.min(Math.max(b,0),10))}get displayCount(){return this._get("displayCount")}get objectId(){return(this.objectIdField&& this.graphic?.attributes?.[this.objectIdField])??null}get objectIdField(){return this.layer?.objectIdField||null}get relatedFeatures(){return this._get("relatedFeatures")||new x}get relatedLayer(){const {layer:b,map:a,relationship:f}=this;return b?.loaded&&a&&f?z.findRelatedLayer(a,b,f)??null:null}get relationship(){const {relationshipId:b,layer:a}=this;return null!=b?a?.relationships?.find(({id:f})=>f===b)??null:null}get relatedFeatureViewModels(){return this._get("relatedFeatureViewModels")||new x}get state(){const {_queryAbortController:b, _queryFeatureCountAbortController:a,_queryPageAbortController:f,canQuery:g,_loaded:k,canLoad:l}=this;return a||l&&!k?"loading":b||f?"querying":g?"ready":"disabled"}getRelatedFeatureByObjectId(b){return this.relatedFeatures.find(a=>a.getObjectId()===b)}refresh(){this._queryFeatureCountDebounced()}_destroyRelatedFeatureViewModels(){this.relatedFeatureViewModels?.destroyAll()}async _queryFeatureCount(){const {layer:b,relatedLayer:a,relationshipId:f,objectId:g,_queryFeatureCountAbortController:k,canQuery:l, supportsCacheHint:t}=this;await b?.load();await a?.load();if(l&&b&&a&&null!=g){var m=a.createQuery(),{historicMoment:r,gdbVersion:h}=b;m=new y({cacheHint:t,gdbVersion:h,historicMoment:r,relationshipId:f,returnGeometry:!1,objectIds:[g],where:m.where??void 0});m=await b.queryRelatedFeaturesCount(m,{signal:k?.signal});this._set("featureCount",m[g]||0)}else this._set("featureCount",0)}_sliceFeatures(b){const {showAllEnabled:a,displayCount:f}=this;return a?b:f?b.slice(0,f):[]}async _queryPage(){const {relatedFeatures:b, featurePage:a,showAllEnabled:f,_queryPageAbortController:g,featureCount:k}=this;!f||2>a||!k||b.addMany(await this._queryRelatedFeatures({signal:g?.signal}))}async _queryRelatedFeatures(b){const {orderByFieldsFixedCasing:a,showAllEnabled:f,featuresPerPage:g,displayCount:k,layer:l,relationshipId:t,featurePage:m,featureCount:r,relatedLayer:h,supportsCacheHint:G}=this,{canQuery:H,objectId:u}=this;if(!H||!l||!h||null==u)return[];var v=f?((m-1)*g+r)%r:0;const I=f?g:k;var w=h.objectIdField;w=[...a.map(n=> n.field),...F.getFieldsInTitleAndDesc(h),w].filter(B.isSome);const J=a.map(n=>`${n.field} ${n.order}`),K=h.createQuery(),{historicMoment:L,gdbVersion:M}=l;v=new y({orderByFields:J,start:v,num:I,outFields:w,cacheHint:G,historicMoment:L,gdbVersion:M,relationshipId:t,returnGeometry:!1,objectIds:[u],where:K.where??void 0});b=(await l.queryRelatedFeatures(v,{signal:b?.signal}))[u]?.features||[];b.forEach(n=>{n.sourceLayer=h;n.layer=h});return b}};d.__decorate([e.property()],c.prototype,"_loaded",void 0); d.__decorate([e.property()],c.prototype,"_queryAbortController",void 0);d.__decorate([e.property()],c.prototype,"_queryPageAbortController",void 0);d.__decorate([e.property()],c.prototype,"_queryFeatureCountAbortController",void 0);d.__decorate([e.property({value:1})],c.prototype,"featurePage",null);d.__decorate([e.property()],c.prototype,"featuresPerPage",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"orderByFieldsFixedCasing",null);d.__decorate([e.property({readOnly:!0})],c.prototype, "supportsCacheHint",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"canLoad",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"canQuery",null);d.__decorate([e.property()],c.prototype,"description",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"itemDescriptionFieldName",null);d.__decorate([e.property({value:3})],c.prototype,"displayCount",null);d.__decorate([e.property({type:A})],c.prototype,"graphic",void 0);d.__decorate([e.property()],c.prototype,"layer",void 0); d.__decorate([e.property()],c.prototype,"map",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"objectId",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"objectIdField",null);d.__decorate([e.property()],c.prototype,"orderByFields",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"relatedFeatures",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"relatedLayer",null);d.__decorate([e.property({readOnly:!0})],c.prototype,"relationship",null);d.__decorate([e.property()], c.prototype,"featureCount",void 0);d.__decorate([e.property({readOnly:!0})],c.prototype,"relatedFeatureViewModels",null);d.__decorate([e.property()],c.prototype,"relationshipId",void 0);d.__decorate([e.property()],c.prototype,"showAllEnabled",void 0);d.__decorate([e.property()],c.prototype,"state",null);d.__decorate([e.property()],c.prototype,"title",void 0);return c=d.__decorate([E.subclass("esri.widgets.Feature.FeatureRelationship.FeatureRelationshipViewModel")],c)});