/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as b } from "../../chunks/runtime.js";
import { css as N, html as h } from "lit";
import { repeat as g } from "lit/directives/repeat.js";
import { u as S } from "../../chunks/useT9n.js";
import { LitElement as f, createEvent as p, safeClassMap as A } from "@arcgis/lumina";
import { e as F, A as y, G as I, T as C, J as E } from "../../chunks/interfaces.js";
import { useContextConsumer as _ } from "@arcgis/lumina/context";
const O = N`.width-full{width:100%}calcite-panel{--calcite-panel-background-color: var(--calcite-color-foreground-1);--calcite-panel-footer-space: var(--calcite-spacing-sm)}.border-color{--calcite-block-border-color: transparent}calcite-block{margin:0;--calcite-block-content-space: 0}.tree-padding{padding:0 .2rem}.display-none{display:none}`, T = {
  PUBLICSAFETY: ["EMERGENCYMANAGEMENT", "FIRESERVICE", "LAWENFORCEMENT"],
  STATEANDLOCALGOVERNMENT: [
    "AGRICULTURE",
    "AIRPORT",
    "ASSESSMENTANDTAXATION",
    "ELECTIONS",
    "EMERGENCYMANAGEMENT",
    "FIRESERVICE",
    "FISHANDWILDLIFE",
    "HEALTHANDHUMANSERVICES",
    "LAWENFORCEMENT",
    "NATURALRESOURCES",
    "PARKS",
    "PLANNINGANDDEVELOPMENT",
    "PUBLICWORKS",
    "TRANSPORTATION"
  ],
  UTILITIES: ["DISTRICTENERGY", "ELECTRIC", "GAS", "SEWER", "STORMWATER", "WATER"]
}, R = Object.keys(F).reduce(
  (u, t) => {
    const e = t;
    return u[e] = T[e] ?? [], u;
  },
  {}
);
class v extends f {
  constructor() {
    super(), this.hideIndustryFilter = !1, this.isAIDialogOpen = !1, this.showReset = !1, this._activeFilterSettings = {
      categories: []
    }, this._isMobile = !1, this._translations = S({ name: "solutions-filter-panel", blocking: !0 }), this._userFirstName = "", this._configContextConsumer = _({
      context: y,
      subscribe: !0,
      callback: (t) => {
        t?.userSession && !this._userFirstName && this._loadUserFirstName();
      }
    }), this._isMobileContextConsumer = _({
      context: I,
      subscribe: !0,
      callback: (t) => this._isMobile = t
    }), this.applyFilter = p(), this.toggleFilter = p(), this.updateUrlParams = p(), this._handleFilterRemoved = (t) => {
      const e = t.detail;
      Array.isArray(e) && (this._activeFilterSettings = {
        ...this._activeFilterSettings,
        categories: [...e]
      });
    }, this._industryMatchName = (t) => {
      const e = Object.keys(this._translations.industries).find((o) => o.toUpperCase() === t.replaceAll(" ", "").toUpperCase());
      return e && e in this._translations.industries ? this._translations.industries[e] : t;
    }, this.listenOn(window, "filterRemoved", this._handleFilterRemoved), this.listenOn(window, "closeAssistant", () => {
      this.isAIDialogOpen = !1;
    }), this.listenOn(window, "openAssistant", () => {
      this.isAIDialogOpen = !0;
    }), this.listenOn(window, "tabChanged", (t) => {
      t.detail === "all-solutions" ? this.updateUrlParams.emit(this._activeFilterSettings) : this.updateUrlParams.emit(null);
    });
  }
  static {
    this.properties = { hideIndustryFilter: 5, isAIDialogOpen: 5, showReset: 5, _activeFilterSettings: 16, _isMobile: 16, _translations: 16, _userFirstName: 16 };
  }
  static {
    this.styles = O;
  }
  get _telemetry() {
    return this._configContextConsumer.value?.telemetrySession;
  }
  changeIndustryFilter(t, e, o, d) {
    if (t !== "" || e !== "") {
      let n = [];
      if (e !== "") {
        const i = F[t];
        n = [{
          displayValue: this._industryMatchName(i),
          type: "industry",
          value: t,
          industry: t,
          domain: ""
        }, {
          displayValue: o,
          type: "domain",
          value: e,
          industry: t,
          domain: e
        }];
      } else
        n = [{
          displayValue: o,
          type: e !== "" ? "domain" : "industry",
          value: e !== "" ? e : t,
          industry: t,
          domain: e
        }];
      this._activeFilterSettings = {
        ...this._activeFilterSettings,
        categories: [...n]
      }, d && this.applyFilter.emit(n);
    } else {
      const n = {
        displayValue: o,
        type: "industry",
        value: t,
        industry: t,
        domain: e
      };
      this._activeFilterSettings = {
        ...this._activeFilterSettings,
        categories: [n]
      }, d && this.applyFilter.emit(n);
    }
  }
  clearFilters() {
    this.changeIndustryFilter("", "", ""), this.applyFilter.emit(null);
  }
  async load() {
    await this._loadUserFirstName(), this._isMobileContextConsumer.value && (this._isMobile = this._isMobileContextConsumer.value);
  }
  render() {
    return h`<calcite-panel description heading>${this.showReset && h`<calcite-action appearance=solid icon=reset @click=${() => {
      this.clearFilters();
    }} slot=header-actions-end .text=${this._translations.resetFilters} text-enabled></calcite-action>` || ""}<calcite-block-group .label=${this._translations.filters} scale=l>${!this.hideIndustryFilter && this.renderIndustryBlock() || ""}</calcite-block-group><calcite-button id=solutions-assistant-button icon-start=speech-bubbles label="Solutions Assistant" @click=${() => {
      this._telemetry?.logEvent({
        category: C.ASSISTANT,
        action: "Open"
      }), this.isAIDialogOpen = !0;
    }} round scale=l slot=footer-start></calcite-button><calcite-tooltip reference-element=solutions-assistant-button placement=right slot=footer-start offset-distance=10 open><span>${this._translations.assistant.welcomeTip}</span></calcite-tooltip><arcgis-solutions-assistant .open=${this.isAIDialogOpen} .userFirstName=${this._userFirstName}></arcgis-solutions-assistant></calcite-panel>`;
  }
  renderIndustryBlock() {
    const t = (i, a) => !this._activeFilterSettings || !this._activeFilterSettings.categories ? !1 : this._activeFilterSettings.categories.some((s) => s.industry === i && (s.domain ?? "") === a), e = (i) => !this._activeFilterSettings || !this._activeFilterSettings.categories ? !1 : this._activeFilterSettings.categories.some((a) => a.industry === i && (a.domain ?? "") === ""), o = (i, a) => a.length > 0 && (e(i) || this._activeFilterSettings.categories?.some((s) => s.industry === i && !!s.domain && a.includes(s.domain)) === !0), d = (i, a) => g(a, (s) => s, (s) => {
      const r = Object.keys(this._translations.industriesDomain).find((l) => l.toUpperCase() === s.toUpperCase()), c = r && r in this._translations.industriesDomain ? this._translations.industriesDomain[r] : s, m = t(i, s);
      return h`<calcite-tree-item .label=${c} @click=${(l) => {
        l.detail !== 0 && this.changeIndustryFilter(i, s, c, !0);
      }} @keydown=${(l) => {
        E(l, () => {
          this.changeIndustryFilter(i, s, c, !0);
        });
      }} .selected=${m || void 0}>${c}</calcite-tree-item>`;
    }), n = g(Object.entries(R), ([i, a]) => i, ([i, a]) => {
      const s = this._industryMatchName(i), r = a, c = e(i), m = o(i, r);
      return h`<calcite-tree-item .label=${s} @click=${(l) => {
        l.detail !== 0 && this.changeIndustryFilter(i, "", s, !0);
      }} @keydown=${(l) => {
        E(l, () => {
          this.changeIndustryFilter(i, "", s, !0);
        });
      }} .selected=${c || void 0} .expanded=${m ? !0 : void 0}>${s}${r.length > 0 && h`<calcite-tree slot=children selection-mode=multiple>${d(i, r)}</calcite-tree>` || ""}</calcite-tree-item>`;
    });
    return h`<calcite-block description expanded class="border-color" .heading=${this._translations.industriesHeader} .label=${this._translations.industriesHeader}><calcite-action class=${A(this._isMobile ? "" : "display-none")} icon=x @click=${this._toggleFilter} slot=content-end text></calcite-action><calcite-tree selection-mode=single-persist class="tree-padding">${n}</calcite-tree></calcite-block>`;
  }
  _toggleFilter() {
    this.toggleFilter.emit();
  }
  async _loadUserFirstName() {
    try {
      const t = await this._configContextConsumer.value?.userSession?.getUser();
      if (t?.fullName) {
        const e = t.fullName.split(" ")[0];
        this._userFirstName = e;
      }
    } catch {
    }
  }
}
b("solutions-filter-panel", v);
export {
  v as SolutionsFilterPanel
};
