import{isLayerExtension as e}from"../../ItemType.js";import{toFeature as t}from"../../data/Feature.js";import*as r from"../../utilities/asyncIterable.js";import{isPoint as i}from"../../utilities/esri.js";import{isBuildingComponentSublayer as s}from"../../utilities/layers.js";import{caseInsensitiveEquals as n}from"../../utilities/string.js";import{IdentifyProviderBase as o}from"./IdentifyProviderBase.js";export class HitTestIdentifyProvider extends o{queryProvider;isSupported(e,t,r){return"point"===t?.type||!this._supportsQuery(e)}_identify(i,s,o){const u=this,y={...o};return async function*(){const o=await a(i,s),l=e(i)?i.layer:i.sublayer;if(o?.length){const e="point-cloud"===l.type?void 0:l.objectIdField;if(u.queryProvider&&u._supportsQuery(i)&&e&&(p=o[0],!i.featureSettings.outFields.every((e=>p.attributes.hasOwnProperty(e))))){const t="string"===l.fields?.find((t=>n(t.name,e)))?.type,r=o.map((r=>`${e} = ${t?`'${r.getAttribute(e)}'`:r.getAttribute(e)}`)).join(" OR ");yield*u.queryProvider.query(i,r,y)}else yield*o.map((e=>t(e,{source:i})))}else yield*r.empty();var p}()}async _count(e,t,r){const i=await a(e,t);return{source:e,count:i?i.length:0}}_supportsQuery(e){return!0}async _applyTolerance(e){return e}}async function a(e,t){const r=s(e.sublayer),n=r?e.layerExtension?.mapExtension:e.mapExtension,o=r?e.sublayer:e.layer,a=e._layerView.view;if("map"===n.viewMode||!a)return;const y=await a.hitTest(a.toScreen(i(t)?t:t.extent.center));let l=y?y.results.sort(u).map((e=>e.graphic)).filter((e=>(e.sourceLayer??e.layer)===o)):void 0;const p=r?e.sublayer.objectIdField:e.layer.objectIdField;if(l&&p){const e=new Set(l.map((e=>e.getAttribute(p))));l=[...e].map((e=>l.find((t=>t.getAttribute(p)===e))))}return l}function u(e,t){return e.distance<=t.distance?-1:1}