/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{a as v}from"./EUYSSHX7.js";import"./2GLF4DQN.js";import"./5AI6MQMZ.js";import"./ZNBKMZP7.js";import{O as h,P as g,U as p,a as u,b as l,x as m}from"./IWZQMWZ5.js";import"./ALDX5YZO.js";export default $arcgis.t(([b,{locationToAddress:f},{substitute:$},{watch:_}])=>{var R=u`.coordinates{font-size:var(--calcite-font-size-sm);color:var(--calcite-color-text-3);padding-inline-start:var(--calcite-spacing-md);padding-block-end:var(--calcite-spacing-sm)}`,C={coordinates:"coordinates"},c=class extends h{constructor(){super(...arguments),this.messages=v(),this._abortController=null,this._results=null,this.headingLevel=3,this.portal=b.getDefault(),this.arcgisReverseGeocodeResultsChange=m()}static{this.properties={_abortController:16,_results:16,headingLevel:9,portal:0,location:0,messageOverrides:0,reverseGeocodeResults:32}}static{this.styles=R}get reverseGeocodeResults(){return this._results}async destroy(){await this.manager.destroy(),this._cancelQueries()}loaded(){this.manager.onLifecycle(()=>[_(()=>[this.portal,this.location],()=>void this._update(),{initial:!0}),_(()=>this._results,()=>{this.arcgisReverseGeocodeResultsChange.emit()})])}_cancelQueries(){this._abortController?.abort(),this._abortController=null}async _update(){let{location:e,messages:t}=this;if(this._cancelQueries(),!e){this._results=null;return}let s=new AbortController,a=s.signal;this._abortController=s,await this.portal?.load({signal:a});let i=this.portal?.helperServices?.geocode?.filter(o=>o.reverseGeocode??!0);if(!i){this._results=null;return}let r=i.map(async o=>await f(o.url,{location:e},{signal:a})),n=await Promise.allSettled(r);this._abortController=null,this._results=i.map((o,d)=>({name:o.name??t?.untitledService??"",address:(n[d].status==="fulfilled"?n[d].value.address:null)??t?.noResultsFound??"",url:o.url}))}_renderMoreResults(e){let{messages:t}=this;return!this._abortController&&e?.length?l`<calcite-block collapsible .headingLevel=${this.headingLevel} .heading=${$(t?.showMoreResults??"",{count:e.length})}><calcite-list display-mode=flat interaction-mode=static selection-mode=none .label=${t?.moreResults??""}>${e?.map(s=>l`<calcite-list-item .label=${s.name} .description=${s.address}></calcite-list-item>`)}</calcite-list></calcite-block>`:null}render(){let{_abortController:e,location:t,_results:s,messages:a}=this;if(!t)return null;let i=s?.slice(),r=i?.shift(),n=l`<div class=${g(C.coordinates)} slot=content-bottom>${`${t.latitude?.toFixed(6)}, ${t.longitude?.toFixed(6)}`}</div>`;return l`<calcite-list .loading=${!!e} display-mode=flat interaction-mode=static selection-mode=none .label=${a.label??""}>${r?l`<calcite-list-item .label=${r.name} .description=${r.address}>${n}</calcite-list-item>`:e?null:l`<calcite-list-item .label=${a.noResultsFound??""}>${n}</calcite-list-item>`}</calcite-list>${this._renderMoreResults(i)}`}};p("arcgis-reverse-geocode-list",c);return c},"portal/Portal","rest/locator","intl","core/reactiveUtils")