/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as o } from "../../chunks/runtime.js";
import { html as n } from "lit";
import { usePropertyChange as r } from "@arcgis/lumina/controllers";
import { u as l } from "../../chunks/useT9n.js";
import { LitElement as h, createEvent as c, nothing as p } from "@arcgis/lumina";
import { u as m } from "../../chunks/useView.js";
import { log as d } from "@arcgis/toolkit/log";
import { when as g } from "@arcgis/core/core/reactiveUtils.js";
const a = (t) => t === "hidden" ? "hide-link-chart-nonspatial-data" : "show-link-chart-nonspatial-data";
class y extends h {
  constructor() {
    super(...arguments), this.messages = l(), this._state = "disabled", this.view = s.useView(this), this.autoDestroyDisabled = !1, this.icon = a(this.view?.map?.linkChartProperties?.nonspatialDataDisplay?.mode ?? "visible"), this.visualScale = "m", this.arcgisPropertyChange = r()("state"), this.arcgisReady = c();
  }
  static {
    this.properties = { _state: 16, view: 0, autoDestroyDisabled: 5, icon: 1, label: 1, messageOverrides: 0, referenceElement: 1, state: 32, visualScale: 1 };
  }
  get state() {
    return this._state;
  }
  async destroy() {
    await this.manager.destroy();
  }
  async switchNonspatialVisibility(i) {
    this.view && (s.changeNonspatialDataDisplay(this.view, i), this.icon = a(i));
  }
  loaded() {
    this.manager.onLifecycle(() => [
      g(() => this.view?.ready ? "ready" : "disabled", (i) => {
        this._state = i, this.icon = a(this.view?.map?.linkChartProperties?.nonspatialDataDisplay?.mode ?? "visible");
      }, { sync: !0, initial: !0 })
    ]);
  }
  _handleToggle() {
    const e = (this.view?.map?.linkChartProperties?.nonspatialDataDisplay?.mode ?? "visible") === "hidden" ? "visible" : "hidden";
    this.switchNonspatialVisibility(e);
  }
  render() {
    const { messages: i } = this;
    return this.state === "ready" && this.view?.map && this.view?.map.mapType !== "webLinkChart" && d("error", this, "The <arcgis-link-chart-nonspatial-visibility-toggle> component must be used with an <arcgis-link-chart> component to provide the view"), n`<calcite-action class="root" .scale=${this.visualScale} .icon=${this.icon} @click=${this._handleToggle} @keyup=${(e) => {
      e.key === "Enter" && this._handleToggle();
    }} .disabled=${this.view?.map?.mapType !== "webLinkChart"} .text=${i.toggleLabel} title=${i.toggleLabel ?? p} data-testid=link-chart-nonspatial-visibility-toggle-action></calcite-action>`;
  }
}
const s = {
  changeNonspatialDataDisplay: (t, i) => {
    t.map?.changeNonspatialDataDisplay(i);
  },
  useView: (t) => m(t)
};
o("arcgis-link-chart-nonspatial-visibility-toggle", y);
export {
  y as ArcgisLinkChartNonspatialVisibilityToggle,
  s as exportsForTests
};
