import{toFeature as e}from"../../data/Feature.js";import{cancelifyWithAbortSignal as t}from"../../support/Cancellable.js";import{executeQuery as r,executeCount as a}from"../../support/_query.js";import{isGeoJSONLayerExtension as i}from"../../utilities/extensions.js";import{removeZValues as o}from"../../utilities/geometry.js";import{IdentifyProviderBase as n}from"./IdentifyProviderBase.js";import{hitTestForClusterFeatures as s}from"./_utilities.js";async function u(e,r,a,i){const o=await s(e,r);if(0===o.length)return[];i.aggregateIds=o.map((e=>e.getObjectId()));const n=await t((t=>e._layerView.queryFeatures(i,{signal:t})),a.cancelToken);return n?.features}export class GeoJSONLayerClientSideQueryIdentifyProvider extends n{isSupported(e,t,r){return i(e)&&!!e.layer}_identify(t,a,i,n){return async function*(){const s=t,l=s.layer.createQuery();if(l.outFields=i.outFields??t.featureSettings.outFields,l.returnGeometry=i.returnGeometry,l.outSpatialReference=i.outSpatialReference,l.maxAllowableOffset=i.maxAllowableOffset,l.num=i.maxResults,l.returnZ=s.layer.hasZ,"cluster"===s?.layer?.featureReduction?.type&&"point"===n){const r=await u(s,a,i,l);if(r?.length>0)return void(yield*r.map((r=>e(r,{source:t}))))}let c=a;c&&!s.layer.capabilities?.data?.supportsZ&&(c=o(c.clone())),l.geometry=c,yield*r(l,s,s.layer,i.cancelToken)}()}async _count(e,t,r,i){const n=e,s=n.layer.createQuery();if(s.num=r.maxResults,s.returnGeometry=r.returnGeometry,s.outFields=r.outFields??e.featureSettings.outFields,"cluster"===n?.layer?.featureReduction?.type&&"point"===i){const e=await u(n,t,r,s);if(e?.length>0)return{source:n,count:e.length}}if(!s.aggregateIds){let e=t;e&&!n.layer.capabilities?.data?.supportsZ&&(e=o(e.clone())),s.geometry=e}return a(s,n,n.layer,r.cancelToken)}}