import { c as o } from "../../chunks/runtime.js";
import { repeat as a } from "lit/directives/repeat.js";
import { css as r, html as i } from "lit";
import { LitElement as n, createEvent as c } from "@arcgis/lumina";
import { a as m } from "../../chunks/sql-expr-defaults.js";
import { u as d } from "../../chunks/useT9n.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
v5.0.0-next.14 */
const h = r`:host{calcite-flow{height:100%}calcite-list-item-group{background-color:var(--calcite-color-foreground-2)}}`;
class g extends n {
  constructor() {
    super(...arguments), this.messages = d(), this._filterValue = "", this._flowItemRenderers = [], this._mutationCounter = 1, this.loading = !1, this.arcgisClose = c({ bubbles: !1 }), this.arcgisFieldSelected = c({ bubbles: !1 });
  }
  static {
    this.properties = { _filterValue: 16, _flowItemRenderers: 16, _mutationCounter: 16, loading: 5, modelId: 1 };
  }
  static {
    this.styles = h;
  }
  willUpdate(t) {
    t.has("modelId") && (this._flowItemRenderers = []);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._flowObserver?.disconnect();
  }
  _handleSelectField(t) {
    if (t.target instanceof HTMLElement)
      switch (t.target.tagName.toLowerCase()) {
        case "calcite-list-item": {
          const s = t.target.value;
          this.arcgisFieldSelected.emit(s ?? "");
          break;
        }
        case "calcite-action":
          t.stopPropagation();
          break;
      }
  }
  _handleSelectDomain(t) {
    const e = t.target.value;
    this.arcgisFieldSelected.emit(e ? `'${e}'` : "");
  }
  _emitClose() {
    this.arcgisClose.emit();
  }
  render() {
    const t = m.getFeatureLayerForModel(this.modelId ?? "");
    return this.loading || !this.modelId || !t ? i`<calcite-block .heading=${this.messages.availablefields ?? ""}></calcite-block>` : i`<calcite-flow><calcite-flow-item heading-level=2 .heading=${this.messages.availablefields ?? ""} closable @calciteFlowItemClose=${this._emitClose}><calcite-list label=fields filter-enabled>${a(t.fields, (e) => e.name, (e) => i`<calcite-list-item @click=${this._handleSelectField} .label=${e.name} .description=${e.alias ?? ""} .value=${e.name}>${e.domain && i`<calcite-action slot=actions-end text=open icon=chevron-right @click=${() => {
      const s = e.domain;
      s?.type === "coded-value" && (this._flowItemRenderers = [
        ...this._flowItemRenderers,
        () => i`<calcite-flow-item closable heading-level=2 .heading=${this.messages.domainvalues ?? ""} .description=${e.name} @calciteFlowItemClose=${this._emitClose}><calcite-list label=domains>${a(s.codedValues, (l) => l.code, (l) => i`<calcite-list-item @click=${this._handleSelectDomain} .label=${l.name} .description=${String(l.code)} .value=${String(l.code)}></calcite-list-item>`)}</calcite-list></calcite-flow-item>`
      ]);
    }}></calcite-action>` || ""}</calcite-list-item>`)}</calcite-list></calcite-flow-item>${this._flowItemRenderers.map((e) => e())}</calcite-flow>`;
  }
}
o("arcgis-sql-expression-fields", g);
export {
  g as SqlExpressionFields
};
