import{toFeature as e}from"../../data/Feature.js";import{cancelifyWithAbortSignal as t}from"../../support/Cancellable.js";import*as r from"../../utilities/asyncIterable.js";import{isSubtypeSublayerExtension as i}from"../../utilities/extensions.js";import{isBuildingComponentSublayer as s}from"../../utilities/layers.js";import{IdentifyProviderBase as a}from"./IdentifyProviderBase.js";export class ClientSideIdentifyProvider extends a{_identify(t,i,s,a){const n=this;return async function*(){const o=await n._getClientSideLayerGraphics(t,i,s,a);o?.length?yield*o.map((r=>e(r,{source:t}))):yield*r.empty()}()}async _count(e,t,r,i){const s=await this._getClientSideLayerGraphics(e,t,r,i);return{source:e,count:s?s.length:0}}_createQuery(e,t,r,a){const n=i(e)?e.layerExtension:e,{_layerView:o,featureSettings:l}=n,u=s(n.sublayer)?e.layerExtension?.mapExtension:e.mapExtension,c=o.createQuery();return c.geometry=t,c.outFields=r.outFields||l.outFields,c.returnGeometry=r.returnGeometry,c.outSpatialReference=r.outSpatialReference,c.maxAllowableOffset=r.maxAllowableOffset,c.num=r.maxResults,c.returnZ="scene"===u?.viewMode,c.aggregateIds=a,c}async _getClientSideLayerGraphics(e,r,s,a){const n=i(e)?e.layerExtension:e,{_layerView:o}=n;if(!o)return;const l=await t((async t=>o.queryFeatures(this._createQuery(e,r,s),{signal:t})),s.cancelToken);return l?.features}}