/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as m } from "../../chunks/runtime.js";
import { css as y, html as r } from "lit";
import { ignoreAbortErrors as w } from "@arcgis/core/core/promiseUtils.js";
import { watch as b } from "@arcgis/core/core/reactiveUtils.js";
import { LitElement as _, createEvent as L, safeClassMap as k, nothing as z } from "@arcgis/lumina";
import { usePropertyChange as $ } from "@arcgis/lumina/controllers";
import { u as M } from "../../chunks/useT9n.js";
import { m as S } from "../../chunks/useViewModel.js";
import { H as E } from "../../chunks/heading.js";
import { g as h } from "../../chunks/globalCss.js";
import V from "@arcgis/core/analysis/SliceAnalysis.js";
import { property as d, subclass as C } from "@arcgis/core/core/accessorSupport/decorators.js";
import { A as G } from "../../chunks/AnalysisViewModel.js";
const A = y`:host{--arcgis-internal-color-black-30: color-mix(in srgb, #000000 30.2%, transparent);--arcgis-internal-box-shadow: var(--calcite-spacing-none) var(--calcite-spacing-px) var(--calcite-spacing-base) var(--arcgis-internal-color-black-30);--arcgis-internal-top-max-width: calc(min(100cqw, 100vw) - var(--calcite-spacing-xxxl));--arcgis-internal-panel-width: 300px;--arcgis-internal-panel-height: 100%;--arcgis-internal-panel-height-sm: 240px;--arcgis-internal-panel-height-md: 420px;--arcgis-internal-panel-height-lg: 540px;--arcgis-internal-panel-height-xl: 680px;--arcgis-internal-panel-gap: var(--calcite-spacing-lg);--arcgis-internal-panel-actions-gap: var(--calcite-spacing-sm);--arcgis-internal-basemap-gallery-width-lg: 450px;--arcgis-internal-collapse-icon-flip: scaleX(1);--arcgis-internal-row-direction: row;--arcgis-internal-legend-width: 300px;--arcgis-internal-layout-overlay-space-top: var(--arcgis-layout-overlay-space-top, 0px);--arcgis-internal-layout-overlay-space-bottom: var(--arcgis-layout-overlay-space-bottom, 0px);--arcgis-internal-layout-overlay-space-left: var(--arcgis-layout-overlay-space-left, 0px);--arcgis-internal-layout-overlay-space-right: var(--arcgis-layout-overlay-space-right, 0px);--arcgis-internal-view-color-focus: var(--arcgis-view-color-focus, var(--calcite-color-brand));--arcgis-internal-attribution-space-bottom: var(--arcgis-internal-layout-overlay-space-bottom);--arcgis-internal-attribution-space-left: var(--arcgis-internal-layout-overlay-space-left);--arcgis-internal-attribution-space-right: var(--arcgis-internal-layout-overlay-space-right);--arcgis-internal-attribution-font-size: var(--calcite-font-size-sm);--arcgis-internal-attribution-font-size-sm: var(--calcite-font-size-xs);--arcgis-internal-sketch-justify-content: flex-start}.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__heading{word-break:break-word}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.esri-widget--panel{min-width:300px;min-height:32px;padding:var(--arcgis-internal-padding);transition:max-height .25s ease-in-out;overflow-y:auto}.container{display:flex;overflow-y:auto;--layer-item-background: var(--calcite-color-foreground-2);flex-direction:column;flex-shrink:0;flex-basis:auto;justify-content:space-between;gap:var(--arcgis-internal-panel-gap)}.error{color:var(--calcite-color-status-danger)}.container,.hint{display:flex;flex-direction:column;gap:var(--arcgis-internal-panel-gap)}.error,.hint{overflow:hidden;animation:arcgis-slice-fade-in .25s ease-in-out}.error p,.hint p{margin:0;padding:0}.hint:not(:has(*)){display:none}.layer-item{--calcite-color-foreground-2: var(--layer-item-background);--calcite-color-foreground-1: var(--layer-item-background)}.actions{display:flex;flex-flow:column;gap:var(--arcgis-internal-panel-actions-gap);justify-content:center}.actions:not(:has(*)){display:none}@keyframes arcgis-slice-fade-in{0%{opacity:0}25%{opacity:0}to{opacity:1}}`;
var j = Object.defineProperty, T = Object.getOwnPropertyDescriptor, l = (e, i, t, s) => {
  for (var a = s > 1 ? void 0 : s ? T(i, t) : i, n = e.length - 1, c; n >= 0; n--)
    (c = e[n]) && (a = (s ? c(i, t, a) : c(a)) || a);
  return s && a && j(i, t, a), a;
};
const u = /* @__PURE__ */ new Set();
let o = class extends G {
  constructor() {
    super(...arguments), this.supportedViewType = "3d", this.unsupportedErrorMessage = "SliceViewModel is only supported in 3D views.";
  }
  async pickLayerToExclude() {
    const e = this.analysisView;
    if (e) {
      const i = super.start({
        operation: (t) => e.pickLayerToExclude(t),
        clear: !1
      });
      this._excludingLayers = i, i.finally(() => {
        this._excludingLayers === i && (this._excludingLayers = void 0);
      }), await i.catch();
    }
  }
  async place(e) {
    await this.analysisView?.place(e);
  }
  clearAnalysis() {
    this.analysis.shape = null;
  }
  initialize() {
    u.add(this);
  }
  destroy() {
    u.delete(this);
  }
  get state() {
    return this.disabled || !this.ready ? "disabled" : this._excludingLayers ? "excludingLayer" : this.operationState === "active" ? "slicing" : this.analysis.valid ? "sliced" : "ready";
  }
  get shape() {
    return this.analysis.shape;
  }
  set shape(e) {
    this.analysis.shape = e;
  }
  get tiltEnabled() {
    return this.analysis.tiltEnabled;
  }
  set tiltEnabled(e) {
    this.analysis.tiltEnabled = e;
  }
  get excludedLayers() {
    return this.analysis.excludedLayers;
  }
  set excludedLayers(e) {
    this.analysis.excludedLayers = e;
  }
  get excludeGroundSurface() {
    return this.analysis.excludeGroundSurface;
  }
  set excludeGroundSurface(e) {
    this.analysis.excludeGroundSurface = e;
  }
  async start() {
    u.forEach((e) => {
      e.view === this.view && e !== this && e.clear();
    }), await super.start();
  }
  onConnectToAnalysisView(e) {
    e.active = !0;
  }
  constructAnalysis() {
    return new V();
  }
};
l([
  d()
], o.prototype, "_excludingLayers", 2);
l([
  d({ readOnly: !0 })
], o.prototype, "state", 1);
l([
  d()
], o.prototype, "shape", 1);
l([
  d()
], o.prototype, "tiltEnabled", 1);
l([
  d()
], o.prototype, "excludedLayers", 1);
l([
  d()
], o.prototype, "excludeGroundSurface", 1);
o = l([
  C("esri.components.Slice.SliceViewModel")
], o);
const D = S(o);
class O extends _ {
  constructor() {
    super(...arguments), this.viewModel = D(this), this._messages = M(), this.view = this.viewModel.view, this.analysis = this.viewModel.analysis, this.autoDestroyDisabled = !1, this.excludeGroundSurface = this.viewModel.excludeGroundSurface, this.excludedLayers = this.viewModel.excludedLayers, this.headingLevel = 3, this.hideStartButton = !1, this.hideVisualization = this.viewModel.hideVisualization, this.icon = "slice", this.shape = this.viewModel.shape, this.state = this.viewModel.state, this.tiltEnabled = this.viewModel.tiltEnabled, this.arcgisPropertyChange = $()("analysis", "state"), this.arcgisReady = L();
  }
  static {
    this.properties = { _hasVoxelLayers: 16, view: 0, analysis: 0, autoDestroyDisabled: 5, excludeGroundSurface: 5, excludedLayers: 0, headingLevel: 9, hideStartButton: 5, hideVisualization: 5, icon: 3, label: 1, messageOverrides: 0, referenceElement: 1, shape: 0, state: 32, tiltEnabled: 5 };
  }
  static {
    this.styles = A;
  }
  get _hasVoxelLayers() {
    const i = this.viewModel?.view;
    return i != null ? i.allLayerViews.some((t) => (
      //@ts-expect-error type is missing on the base layerview interface
      t.type === "voxel-3d"
    )) : !1;
  }
  async clear() {
    this.viewModel.clear();
  }
  async destroy() {
    await this.manager.destroy();
  }
  async start() {
    w(this.viewModel.start());
  }
  load() {
    this.manager.onLifecycle(() => [
      b(() => this._renderContainerNode(), () => this.requestUpdate())
    ]);
  }
  render() {
    return r`<div class=${k({
      [h.widget]: !0,
      [h.panel]: !0
    })} role=presentation>${this._renderContainerNode()}</div>`;
  }
  _renderContainerNode() {
    const i = this._messages, { state: t, hideVisualization: s, supported: a } = this.viewModel, n = t === "slicing" || t === "excludingLayer";
    if (s || !a)
      return null;
    a || r`<div class="container"><div class="error"><p>${this._messages.unsupported}</p></div></div>`;
    const { excludedLayers: c } = this.viewModel, p = this.excludeGroundSurface, v = c.length > 0 || p, g = t === "disabled";
    return r`<div class="container"><div class="hint">${t === "excludingLayer" ? r`<p class="hint-text">${i.excludeHint}</p>` : null}${t === "slicing" ? r`<p class="hint-text">${this._hasVoxelLayers ? i.voxelHint : i.hint}</p><p class="hint-text">${i.verticalHint}</p>` : null}</div>${!n && v ? r`<div class="layer-list">${E({ class: "layer-list-title", level: this.headingLevel, children: i.excludedLayers })}${P({ layers: c.toArray(), excludeGroundSurface: p, onLayerClick: (x) => {
      this.excludedLayers.remove(x);
    }, onGroundClick: () => {
      this.excludeGroundSurface = !1;
    }, listLabel: i.excludedLayers, layerActionLabel: i.includeLayer, groundItemTitle: i.ground })}</div>` : null}<div class="actions">${!n && !this.hideStartButton ? r`<calcite-button class="new-slice-button" .disabled=${g} @click=${this.start}>${i.newSlice}</calcite-button>` : null}${t === "sliced" ? r`<calcite-button appearance=outline-fill class="exclude-button" .disabled=${g} @click=${() => this.viewModel.pickLayerToExclude()}>${i.excludeLayer}</calcite-button>` : null}${t === "excludingLayer" ? r`<calcite-button appearance=outline-fill class="cancel-button" .disabled=${g} @click=${() => this.viewModel.stop()}>${i.cancel}</calcite-button>` : null}</div></div>`;
  }
}
function f(e) {
  return r`<calcite-list-item class="layer-item" data-testid=${`list-item-${e.uid}`} .label=${e.title ?? ""}><calcite-action icon=x @click=${e.onClick} slot=actions-end .text=${e.actionLabel} title=${e.actionLabel ?? z}></calcite-action></calcite-list-item>`;
}
function P(e) {
  const i = e.layers.map((t) => f({ uid: t.uid, title: t.title ?? "", onClick: () => e.onLayerClick(t), actionLabel: e.layerActionLabel }));
  return e.excludeGroundSurface && i.push(f({ uid: "ground", title: e.groundItemTitle, onClick: e.onGroundClick, actionLabel: e.layerActionLabel })), r`<calcite-list .label=${e.listLabel} selection-mode=none>${i}</calcite-list>`;
}
m("arcgis-slice", O);
export {
  O as ArcgisSlice
};
