/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as i } from "../../chunks/runtime.js";
import { css as l, html as p } from "lit";
import { createRef as o, ref as m } from "lit-html/directives/ref.js";
import { LitElement as c } from "@arcgis/lumina";
import n from "@arcgis/core/widgets/BasemapGallery/support/PortalBasemapsSource.js";
const d = l`.display-block{display:block}`;
class u extends c {
  constructor() {
    super(...arguments), this.basemapGalleryRef = o(), this._basemapGalleryReady = () => {
      this._updateBasemapSource();
    };
  }
  static {
    this.properties = { basemapGalleryRef: 0, mapView: 0, basemapConfig: 0 };
  }
  static {
    this.styles = d;
  }
  willUpdate(a) {
    a.has("basemapConfig") && this.basemapConfigWatchHandler();
  }
  async basemapConfigWatchHandler() {
    await this._updateBasemapSource();
  }
  render() {
    return this.mapView && p`<arcgis-basemap-gallery auto-destroy-disabled .view=${this.mapView} @arcgisReady=${this._basemapGalleryReady} ${m(this.basemapGalleryRef)}></arcgis-basemap-gallery>` || "";
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.basemapGalleryRef.value && this.basemapGalleryRef.value.destroy();
  }
  async _updateBasemapSource() {
    const a = this.basemapGalleryRef.value;
    if (!a)
      return;
    const t = (r) => {
      const s = r.portalItem?.id;
      return !s || !this.basemapConfig ? !0 : !this.basemapConfig.basemapIdsToFilter.includes(s);
    }, e = new n({
      query: this.basemapConfig?.basemapGroupId ? `id:${this.basemapConfig.basemapGroupId}` : null,
      filterFunction: t
    });
    await e.refresh(), a.source = e;
  }
}
i("map-basemap-gallery", u);
export {
  u as MapBasemapGallery
};
