/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as o } from "../../chunks/runtime.js";
import { css as s, html as a } from "lit";
import { createRef as h, ref as n } from "lit-html/directives/ref.js";
import { LitElement as d, createEvent as l } from "@arcgis/lumina";
import f from "@arcgis/core/widgets/FloorFilter";
import * as r from "@arcgis/core/core/reactiveUtils";
const m = s`:host{display:block}`;
class c extends d {
  constructor() {
    super(...arguments), this.enabled = !1, this._floorFilterElement = h(), this.facilityChanged = l(), this.levelChanged = l(), this.siteChanged = l();
  }
  static {
    this.properties = { enabled: 5, floorFilterWidget: 0, mapView: 0 };
  }
  static {
    this.styles = m;
  }
  willUpdate(t) {
    t.has("mapView") && this.mapViewWatchHandler(), t.has("enabled") && this.enabledWatchHandler();
  }
  async mapViewWatchHandler() {
    this.mapView && await this._initFloorFilter(this.mapView);
  }
  async enabledWatchHandler() {
    this.enabled ? this.mapView && await this._initFloorFilter(this.mapView) : this.enabled || this._destroyWidget();
  }
  render() {
    return a`<div ${n(this._floorFilterElement)}></div>`;
  }
  async loaded() {
    this.mapView && !this.floorFilterWidget && await this._initFloorFilter(this.mapView);
  }
  _destroyWidget() {
    this.floorFilterWidget && (this.floorFilterWidget.destroy(), this.floorFilterWidget = void 0), this._floorFilterElement.value && this._floorFilterElement.value.remove();
  }
  _initContainer() {
    this._destroyWidget(), this._floorFilterElement && (this._floorFilterElement.value = document.createElement("div"));
  }
  async _initFloorFilter(t) {
    const i = t?.map;
    i && await i.when(() => {
      t && this.enabled && i?.floorInfo && (this._initContainer(), this.floorFilterWidget = new f({
        container: this._floorFilterElement.value,
        view: t
      }), this._facilityHandle?.remove(), this._facilityHandle = r?.watch(() => this.floorFilterWidget?.facility, (e) => {
        e && this.facilityChanged.emit(e);
      }), this._levelHandle?.remove(), this._levelHandle = r.watch(() => this.floorFilterWidget?.level, (e) => {
        e && this.levelChanged.emit(e);
      }), this._siteHandle?.remove(), this._siteHandle = r.watch(() => this.floorFilterWidget?.site, (e) => {
        e && this.siteChanged.emit(e);
      }));
    });
  }
}
o("map-floor-filter", c);
export {
  c as MapFloorFilter
};
