/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as t } from "../../chunks/runtime.js";
import { css as i, html as s } from "lit";
import { createRef as n, ref as a } from "lit-html/directives/ref.js";
import { LitElement as r } from "@arcgis/lumina";
import d from "@arcgis/core/widgets/Legend";
const m = i`:host{display:block}`;
class l extends r {
  constructor() {
    super(...arguments), this._legendElement = n();
  }
  static {
    this.properties = { mapView: 0, legendWidget: 0 };
  }
  static {
    this.styles = m;
  }
  willUpdate(e) {
    e.has("mapView") && this.mapViewWatchHandler();
  }
  async mapViewWatchHandler() {
    await this.mapView?.when(() => {
      this.mapView && this._initLegend(this.mapView);
    });
  }
  render() {
    return s`<div ${a(this._legendElement)}></div>`;
  }
  async loaded() {
    this.mapView && await this.mapViewWatchHandler();
  }
  _initLegend(e) {
    e && (this.legendWidget ? this.legendWidget.view = e : this.legendWidget = new d({
      container: this._legendElement.value,
      respectLayerDefinitionExpression: !0,
      view: e
    }));
  }
}
t("map-legend", l);
export {
  l as MapLegend
};
