import{isGeocoder as e}from"../../ItemType.js";import{SCORE_FIELD as t,SCORE_FIELD_ORIGINAL as a}from"../../data/Feature.js";import{SearchProviderBase as r}from"./SearchProviderBase.js";const c=.001;export class GeocoderSearchProvider extends r{isSupported(t){return e(t)}async*_search(e,r,s){const[n]=e,{cancelToken:o,currentScale:i,initialSearchArea:u,outSpatialReference:l,maxResults:S}=s??{},m={cancelToken:o,searchPoint:i&&u?.extent?.center,searchArea:!i&&u,outFields:n.featureSettings.outFields,outSpatialReference:l,maxResults:S};if(!r)return;let f=0,h=c;for await(const e of n.geocode(r,m)){const r=e.attributes.get(t);r===f?(e.attributes.set(t,f-h),e.attributes.set(a,f-h),h+=c):(f=r,h=c),yield e}}async _count(e,t,a){const[r]=e,{cancelToken:c,currentScale:s,initialSearchArea:n,maxResults:o}=a??{},i={cancelToken:c,searchPoint:s&&n?.extent?.center,searchArea:!s&&n,maxResults:o};if(t)return[await r.count(t,i)]}async _suggest(e,t,a){const[r]=e,{cancelToken:s,currentScale:n,initialSearchArea:o,outSpatialReference:i,maxSuggestions:u}=a??{},l={cancelToken:s,searchPoint:n&&o?.extent?.center,searchArea:!n&&o,outFields:["*"],outSpatialReference:i,maxResults:u},S=await r.suggest(t,l);let m=100;return S.map((e=>(m-=c,{featureSource:r,suggestion:e,score:m})))}}