/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as p } from "../../chunks/runtime.js";
import { html as a } from "lit";
import l from "@arcgis/core/Camera.js";
import { watch as s } from "@arcgis/core/core/reactiveUtils.js";
import v from "@arcgis/core/geometry/Point.js";
import u from "@arcgis/core/views/SceneView.js";
import g from "@arcgis/core/WebScene.js";
import { LitElement as d, createEvent as r, safeClassMap as n } from "@arcgis/lumina";
import { reEmitEvent as t, reCreateAccessor as y, makeAccessorController as w } from "@arcgis/lumina/controllers/accessor";
import { createRef as o, ref as h } from "lit/directives/ref.js";
import { U as f, u as b, a as V } from "../../chunks/useArcgisViewReadyError.js";
import { s as C } from "../../chunks/esri-main.js";
import { s as E } from "../../chunks/slots.js";
import { C as c } from "../../chunks/resources.js";
import { b as _, c as P, p as A, i as R } from "../../chunks/component-utils.js";
const D = w(g, {}), I = w(u, {});
class M extends d {
  constructor() {
    super(), this._containerRef = o(), this._mapRef = o(), this._uiController = new f(this), this._cameraProperties = {}, this.arcgisLoadError = b(this), this.arcgisViewReadyError = V(this), this._map = D(this), this.view = I(this), this.allLayerViews = this.view.allLayerViews, this.alphaCompositingEnabled = this.view.alphaCompositingEnabled, this.analyses = this.view.analyses, this.animationsDisabled = this.view.animationsEnabled, this.attributionMode = this.view.attributionMode, this.autoDestroyDisabled = !1, this.basemap = this._map.basemap, this.basemapView = this.view.basemapView, this.canZoomIn = this.view.canZoomIn, this.canZoomOut = this.view.canZoomOut, this.clippingArea = this.view.clippingArea, this.constraints = this.view.constraints, this.displayFilterDisabled = this.view.displayFilterEnabled, this.environment = this.view.environment, this.fatalError = this.view.fatalError, this.floors = this.view.floors, this.graphics = this.view.graphics, this.ground = this._map.ground, this.groundView = this.view.groundView, this.highlights = this.view.highlights, this.layerViews = this.view.layerViews, this.magnifier = this.view.magnifier, this.map = this.view.map, this.navigation = this.view.navigation, this.padding = this.view.padding, this.popup = this.view.popup, this.popupDisabled = this.view.popupEnabled, this.popupComponentEnabled = !1, this.qualityProfile = this.view.qualityProfile, this.ready = this.view.ready, this.selectionManager = this.view.selectionManager, this.slotGroupRefs = this._uiController.slotGroupRefs, this.spatialReference = this.view.spatialReference, this.suspended = this.view.suspended, this.theme = this.view.theme, this.timeExtent = this.view.timeExtent, this.updating = this.view.updating, this.viewingMode = this.view.viewingMode, this.visibleArea = this.view.visibleArea, this.arcgisViewAnalysisViewCreate = t(() => this.view, "analysis-view-create"), this.arcgisViewAnalysisViewCreateError = t(() => this.view, "analysis-view-create-error"), this.arcgisViewAnalysisViewDestroy = t(() => this.view, "analysis-view-destroy"), this.arcgisViewChange = r(), this.arcgisViewClick = t(() => this.view, "click"), this.arcgisViewDoubleClick = t(() => this.view, "double-click"), this.arcgisViewDoubleTapDrag = t(() => this.view, "double-tap-drag"), this.arcgisViewDrag = t(() => this.view, "drag"), this.arcgisViewHold = t(() => this.view, "hold"), this.arcgisViewImmediateClick = t(() => this.view, "immediate-click"), this.arcgisViewImmediateDoubleClick = t(() => this.view, "immediate-double-click"), this.arcgisViewKeyDown = t(() => this.view, "key-down"), this.arcgisViewKeyUp = t(() => this.view, "key-up"), this.arcgisViewLayerviewCreate = t(() => this.view, "layerview-create"), this.arcgisViewLayerviewCreateError = t(() => this.view, "layerview-create-error"), this.arcgisViewLayerviewDestroy = t(() => this.view, "layerview-destroy"), this.arcgisViewMouseWheel = t(() => this.view, "mouse-wheel"), this.arcgisViewPointerDown = t(() => this.view, "pointer-down"), this.arcgisViewPointerEnter = t(() => this.view, "pointer-enter"), this.arcgisViewPointerLeave = t(() => this.view, "pointer-leave"), this.arcgisViewPointerMove = t(() => this.view, "pointer-move"), this.arcgisViewPointerUp = t(() => this.view, "pointer-up"), this.arcgisViewReadyChange = r(), this.arcgisViewVerticalTwoFingerDrag = t(() => this.view, "vertical-two-finger-drag"), this.view.ui = {
      components: []
    };
  }
  static {
    this.properties = { _map: 16, aria: 0, view: 32, allLayerViews: 32, alphaCompositingEnabled: 5, analyses: 0, animationsDisabled: 5, attributionItems: 32, attributionMode: 1, autoDestroyDisabled: 5, basemap: 1, basemapView: 0, camera: 0, cameraFov: 9, cameraHeading: 9, cameraPosition: 1, cameraTilt: 9, canZoomIn: 36, canZoomOut: 36, center: 1, clippingArea: 0, constraints: 0, displayFilterDisabled: 5, environment: 0, extent: 0, fatalError: 0, floors: 0, focusAreas: 0, gamepad: 32, graphics: 0, ground: 1, groundView: 32, hideAttribution: 5, highlights: 0, interacting: 32, itemId: 3, layerViews: 32, magnifier: 32, map: 0, navigating: 32, navigation: 0, padding: 0, performanceInfo: 32, popup: 0, popupElement: 32, popupDisabled: 5, popupComponentEnabled: 5, qualityProfile: 1, ready: 36, resolution: 32, selectionManager: 32, scale: 9, slotGroupRefs: 32, spatialReference: 0, stationary: 32, suspended: 39, theme: 0, timeExtent: 0, updating: 36, viewingMode: 1, viewpoint: 0, visibleArea: 32, zoom: 9, loadErrorSources: 0 };
  }
  static {
    this.styles = [C, E];
  }
  get aria() {
    return this.view?.aria ?? null;
  }
  set aria(i) {
    this.view && (this.view.aria = i);
  }
  get attributionItems() {
    return this.view?.attributionItems ?? [];
  }
  get camera() {
    return this.view.camera;
  }
  set camera(i) {
    _(this.camera, i) || (this.view.camera = i);
  }
  get cameraFov() {
    const { view: i } = this;
    return i.ready ? this.view.camera?.fov : this._cameraProperties.fov;
  }
  set cameraFov(i) {
    i != null && this._mutateCamera((e) => {
      e.fov = i;
    });
  }
  get cameraHeading() {
    const { view: i } = this;
    return i.ready ? i.camera?.heading : this._cameraProperties.heading;
  }
  set cameraHeading(i) {
    i != null && this._mutateCamera((e) => {
      e.heading = i;
    });
  }
  get cameraPosition() {
    const { view: i } = this;
    if (i.ready)
      return i.camera?.position;
    const { position: e } = this._cameraProperties;
    return e ? new v(e) : void 0;
  }
  set cameraPosition(i) {
    const e = P(this.view.camera?.position, i);
    e && this._mutateCamera((m) => {
      m.position = e;
    });
  }
  get cameraTilt() {
    const { view: i } = this;
    return i.ready ? i.camera?.tilt : this._cameraProperties.tilt;
  }
  set cameraTilt(i) {
    i != null && this._mutateCamera((e) => {
      e.tilt = i;
    });
  }
  get center() {
    return this.view.center;
  }
  set center(i) {
    const e = A(i, this.view);
    e && (this.view.center = e);
  }
  get extent() {
    return this.view.extent;
  }
  set extent(i) {
    i && !this.extent.equals(i) && (this.view.extent = i);
  }
  get focusAreas() {
    return this.map ? this.map?.focusAreas : {
      areas: [],
      style: "bright"
    };
  }
  set focusAreas(i) {
    this.map && (this.map.focusAreas = i);
  }
  get gamepad() {
    return this.view.input.gamepad;
  }
  get hideAttribution() {
    return !this.view.attributionVisible;
  }
  set hideAttribution(i) {
    this.view.attributionVisible = !i;
  }
  get interacting() {
    return this.view.interacting;
  }
  get itemId() {
    return this._map.portalItem?.id;
  }
  set itemId(i) {
    y(this._map, this), this._map.portalItem = { id: i }, this.view.map = this._map;
  }
  get navigating() {
    return this.view.navigating;
  }
  get performanceInfo() {
    return this.view.performanceInfo;
  }
  get popupElement() {
    return this._uiController.popupElement || null;
  }
  get resolution() {
    return this.view.resolution;
  }
  get scale() {
    return this.view.scale;
  }
  set scale(i) {
    this.view.scale = i;
  }
  get stationary() {
    return this.view.stationary;
  }
  get viewpoint() {
    return this.view.viewpoint;
  }
  set viewpoint(i) {
    R(this.viewpoint, i) && (this.view.viewpoint = i);
  }
  get zoom() {
    return this.view.zoom;
  }
  set zoom(i) {
    this.view.zoom = i;
  }
  async closePopup() {
    this._uiController.closePopup();
  }
  async fetchPopupFeatures(i, e) {
    return this.view.fetchPopupFeatures(i, e);
  }
  async destroy() {
    await this.manager.destroy();
  }
  async goTo(i, e) {
    return await this.view.goTo(i, e);
  }
  async hitTest(i, e) {
    return await this.view.hitTest(i, e);
  }
  async openPopup(i) {
    this._uiController.openPopup(i);
  }
  async takeScreenshot(i) {
    return await this.view.takeScreenshot(i);
  }
  toMap(i, e) {
    return this.view.toMap(i, e);
  }
  toScreen(i) {
    return this.view.toScreen(i);
  }
  async tryFatalErrorRecovery() {
    this.view.tryFatalErrorRecovery();
  }
  async viewOnReady(i, e) {
    return await this.componentOnReady(), await this.view.whenReady().then(() => i?.()).catch(e);
  }
  async whenAnalysisView(i) {
    return await this.view.whenAnalysisView(i);
  }
  async whenLayerView(i) {
    return await this.view.whenLayerView(i);
  }
  async zoomIn() {
    this.view.zoomIn();
  }
  async zoomOut() {
    this.view.zoomOut();
  }
  loaded() {
    const i = this;
    i.el.childElem = this._mapRef.value, this.view.container ??= i.el.childElem, this.map ||= this._map, this.manager.onLifecycle(() => [
      s(() => this.map, (e) => {
        e && (this._map = e);
      }, { initial: !0, sync: !0 }),
      s(() => this.view.stationary, () => this.arcgisViewChange.emit(), { initial: !0 }),
      s(() => this.view.ready, (e) => {
        e && (this.camera = this.view.camera.clone().set(this._cameraProperties), this._cameraProperties = {}), this.arcgisViewReadyChange.emit();
      }, { initial: this.view.ready }),
      s(() => this.view.attributionHeight, (e) => {
        this._uiController.handleAttributionHeightChange(e);
      }, { initial: !0 })
    ]);
  }
  _mutateCamera(i) {
    if (!this.view.ready) {
      i(this._cameraProperties);
      return;
    }
    const e = this.view.camera?.clone() ?? new l();
    i(e), this.camera = e;
  }
  renderMain() {
    return a`<div class=${n(c.base)} ${h(this._mapRef)}></div>`;
  }
  render() {
    return a`${this.renderMain()}<section class=${n(c.containerUI)} ${h(this._containerRef)}>${this._uiController.render()}</section>`;
  }
}
p("arcgis-scene", M);
export {
  M as ArcgisScene
};
