/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as h } from "../../chunks/runtime.js";
import { css as p, html as d } from "lit";
import { createRef as u, ref as m } from "lit-html/directives/ref.js";
import { LitElement as f } from "@arcgis/lumina";
import y from "@arcgis/core/layers/FeatureLayer.js";
const S = p`:host{display:block}.search-widget{width:100%!important;border:1px solid var(--calcite-color-border-input)}`;
class E extends f {
  constructor() {
    super(...arguments), this.popupEnabled = !1, this.resultGraphicEnabled = !1, this.searchTerm = "", this.searchComponent = u();
  }
  static {
    this.properties = { mapView: 0, popupEnabled: 5, resultGraphicEnabled: 5, searchConfiguration: 0, searchTerm: 1, searchComponent: 0 };
  }
  static {
    this.styles = S;
  }
  render() {
    const r = this.searchConfiguration && this.mapView ? this._getSearchConfig(this.searchConfiguration, this.mapView) : void 0;
    return this.mapView && d`<arcgis-search auto-destroy-disabled class="search-widget" .view=${this.mapView} .popupDisabled=${!this.popupEnabled} .resultGraphicDisabled=${!this.resultGraphicEnabled} .sources=${r?.sources} .searchTerm=${this.searchTerm} ${m(this.searchComponent)}></arcgis-search>` || "";
  }
  _getSearchConfig(r, c) {
    const l = "includeDefaultSources", t = r.sources;
    return t && t?.length > 0 ? (r[l] = !1, t.forEach((s) => {
      if (s.hasOwnProperty("layer")) {
        const e = s, a = e.layer?.id, o = a ? c.map?.findLayerById(a) : null, i = e?.layer?.url;
        o ? e.layer = o : i && (e.layer = new y(i));
      }
    }), t?.forEach((s) => {
      if (s.hasOwnProperty("locator")) {
        const e = s;
        if (e?.name === "ArcGIS World Geocoding Service") {
          const a = e.outFields || ["Addr_type", "Match_addr", "StAddr", "City"];
          e.outFields = a, e.singleLineFieldName = "SingleLine";
        }
        e.url = e.url, delete e.url;
      }
    })) : r = {
      ...r,
      includeDefaultSources: !0
    }, r;
  }
}
h("map-search", E);
export {
  E as MapSearch
};
