/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as m } from "../../chunks/runtime.js";
import { css as h, html as n } from "lit";
import p from "@arcgis/core/core/Collection.js";
import { substitute as u } from "@arcgis/core/intl.js";
import { LitElement as g } from "@arcgis/lumina";
import { log as s, composeEmptyPropertyMessage as b } from "@arcgis/toolkit/log";
import { u as f } from "../../chunks/useT9n.js";
const v = h`:host{margin-block-start:0;padding:0 var(--calcite-spacing-sm) var(--calcite-spacing-sm) var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}calcite-list{border:solid 1px var(--calcite-color-border-3);border-radius:var(--calcite-corner-radius-sm);overflow:hidden}calcite-list-item[selected] [slot=content-bottom]{display:block}.warning{color:var(--calcite-color-status-danger)}.terminals{padding:var(--calcite-spacing-sm) var(--calcite-spacing-md);display:flex;flex-direction:column}.filter-barrier-container{display:flex;width:100%;calcite-label{width:100%}}.filter-barrier{display:flex;justify-content:space-between;align-items:center;width:100%}`;
class w extends g {
  constructor() {
    super(...arguments), this._messages = f({ blocking: !0 }), this.traceLocations = new p(), this.traceLocationType = "starting-point";
  }
  static {
    this.properties = { traceLocations: 0, traceLocationType: 1, view: 0 };
  }
  static {
    this.styles = v;
  }
  loaded() {
    this.traceLocations.length || s("warn", this, b("traceLocations"));
  }
  _handleTraceLocationItemRemoved(e) {
    const { traceLocations: i, view: t } = this;
    e.spatialProperties.flagGraphic && t && t.graphics.remove(e.spatialProperties.flagGraphic), i?.remove(e);
  }
  _renderTerminal(e, i) {
    const { flagProperties: t } = e, { selectedTerminals: r } = t;
    if (!e)
      return s("warn", this, "One or more elements in `traceLocations` are missing the required property `flag`."), null;
    const { name: c, id: a } = i, o = r?.has(a) ?? !1;
    return n`<calcite-label layout=inline><calcite-checkbox .value=${a} .checked=${o} @calciteCheckboxChange=${(l) => {
      l.target.checked ? r?.add(a) : r?.delete(a), this.requestUpdate();
    }}></calcite-checkbox>${c}</calcite-label>`;
  }
  _renderTerminalError() {
    const { _messages: e } = this;
    return n`<calcite-notice kind=danger open scale=s width=auto><div slot=message>${e.errors.noTerminalSelected}</div></calcite-notice>`;
  }
  _renderFilterBarrier(e) {
    const { _messages: i } = this, { traceLocation: t } = e;
    return n`<div class="filter-barrier-container"><calcite-label layout=inline><div class="filter-barrier">${i.labels.filterBarrier}<calcite-switch .checked=${t.isFilterBarrier} @calciteSwitchChange=${(r) => {
      t.isFilterBarrier = r.target.checked;
    }}></calcite-switch></div></calcite-label></div>`;
  }
  _renderContents(e) {
    const { flagProperties: i } = e, { terminalConfiguration: t, selectedTerminals: r } = i, c = e.traceLocation.type === "barrier", a = t && t.terminals.length > 0 && r?.size === 0;
    return n`<calcite-action .icon=${i.expanded ? "chevron-up" : "chevron-down"} slot=actions-end scale=s text @click=${() => {
      i.expanded = !i.expanded, this.requestUpdate();
    }}></calcite-action>${a && n`<calcite-icon class="warning" icon=exclamation-mark-triangle scale=s slot=content-start></calcite-icon>` || ""}${i.expanded && n`<div class="terminals" slot=content-bottom>${c && this._renderFilterBarrier(e) || ""}${t && this._renderTerminals(e) || ""}${a && this._renderTerminalError() || ""}</div>` || ""}`;
  }
  _renderTerminals(e) {
    const { flagProperties: i } = e, { terminalConfiguration: t } = i;
    if (!t)
      return s("warn", this, "One or more locations are missing the required flag property `terminalConfiguration`."), [];
    const r = t.terminals;
    return !r || r.length === 0 ? (s("warn", this, "`terminalConfiguration.terminals` is required but either missing or empty.`"), []) : r.length === 1 ? [] : r.map((a) => this._renderTerminal(e, a));
  }
  _renderListItem(e) {
    const { flagProperties: i } = e, { terminalConfiguration: t, expanded: r, title: c } = i, a = t && t.id !== 0, o = e.traceLocation.type === "barrier", l = a || o, d = t?.name ?? void 0;
    return n`<calcite-list-item .label=${c} .description=${d} .value=${c} .expanded=${r}>${l ? this._renderContents(e) : n`<div slot=content-bottom></div>`}<calcite-action icon=x slot=actions-end scale=s text @click=${() => this._handleTraceLocationItemRemoved(e)}></calcite-action></calcite-list-item>`;
  }
  render() {
    const { _messages: e, traceLocationType: i } = this, t = u(e.labels.list, { traceLocationType: i }), r = this.traceLocations?.map((c) => this._renderListItem(c)).toArray() ?? [];
    return r.length === 0 ? null : n`<div><calcite-list interaction-mode=static selection-mode=none .label=${t}>${r}</calcite-list></div>`;
  }
}
m("arcgis-utility-network-trace-location-list", w);
export {
  w as ArcgisUtilityNetworkTraceLocationList
};
