/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as o } from "../../chunks/runtime.js";
import { css as n, html as s } from "lit";
import { u as r } from "../../chunks/useT9n.js";
import { LitElement as a, createEvent as c, nothing as l } from "@arcgis/lumina";
import { c as d } from "../../chunks/deployAppContexts.js";
import { useContextConsumer as u } from "@arcgis/lumina/context";
import { C as m } from "../../chunks/CardsFetcher.js";
import "@esri/arcgis-rest-portal";
import "@esri/solution-common";
import { s as h } from "../../chunks/helpers.js";
const p = n`.text-center{text-align:center}.no-solutions{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;min-height:calc(100vh - 190px)}.display-flex{display:flex;align-items:center}.display-none{display:none}.flex-direction-column{flex-direction:column}.flex-direction-row{flex-direction:row}.padding-10{padding:10px}.padding-y-10{padding-top:10px;padding-bottom:10px}.subnote{font-size:var(--calcite-font-size--2);font-weight:var(--calcite-font-weight-normal)}.solution-list-item-label{color:var(--calcite-color-text-1);font-size:var(--calcite-font-size--1)}.solution-list-item-label,.solution-list-item-description{font-family:var(--calcite-font-family);font-weight:var(--calcite-font-weight-normal);overflow-wrap:break-word;word-break:break-word}.solution-list-item-description{font-size:var(--calcite-font-size--2);margin-block-start:.125rem;color:var(--calcite-color-text-3)}.solution-list-item-content{display:flex;flex:1 1 auto;flex-direction:column;justify-content:center;line-height:1.375}.underline{text-decoration:underline}`;
class f extends a {
  constructor() {
    super(), this.referenceCards = [], this.results = null, this.hasLinks = !1, this.listTitle = "", this._translations = r({ name: "solutions-deployed-list", blocking: !0 }), this._cardsFetcher = null, this._configContextConsumer = u({
      context: d,
      subscribe: !0
    }), this.deployedCardSelected = c();
  }
  static {
    this.properties = { referenceCards: 0, results: 0, hasLinks: 5, listTitle: 1, _translations: 16, _cardsFetcher: 16 };
  }
  static {
    this.styles = p;
  }
  async load() {
    if (this._configContextConsumer?.value) {
      const t = this._configContextConsumer.value;
      this._cardsFetcher = new m(t.locale, t.orgUrl, t.portalURL);
    }
  }
  disconnectedCallback() {
    super.disconnectedCallback();
  }
  render() {
    if (!this.results)
      return s`<div class="no-solutions"></div>`;
    const t = this.listTitle || this._translations.dependencyList, e = "solutions-deployed-list-title";
    return s`${this.listTitle !== "" && s`<div class="solutions-deployed-list-title" id=${e}>${this.listTitle}</div>` || ""}${this.hasLinks ? s`<calcite-list aria-labelledby=${(this.listTitle !== "" ? e : void 0) ?? l} .label=${t}>${this._renderCards()}</calcite-list>` : s`<calcite-list aria-labelledby=${(this.listTitle !== "" ? e : void 0) ?? l} .label=${t} selection-mode=none interaction-mode=static>${this._renderCards()}</calcite-list>`}`;
  }
  _renderCards() {
    if (this._cardsFetcher && this.results) {
      const t = { ...this.results };
      return t.results = h(t.results), this._cardsFetcher.getCardsFromResponse(t).map((i) => s`<calcite-list-item .label=${i.title} @calciteListItemSelect=${() => {
        this.hasLinks && this._cardSelected(i);
      }} .value=${i.id}><div class="solution-list-item-content" slot=content><div class=${`solution-list-item-label ${this.hasLinks ? "underline" : ""}`}>${i.title}</div><div class="solution-list-item-description">${`${this._translations.deployedVersion} ${i.deployVersion} - ${new Date(i.created).toLocaleDateString(this._configContextConsumer.value?.locale, { year: "numeric", month: "long", day: "numeric" })}`}</div></div></calcite-list-item>`);
    }
    return [];
  }
  async _cardSelected(t) {
    const e = {
      tabType: "deployed-card",
      tabTitleOrId: t.id
    };
    window.dispatchEvent(new CustomEvent("forceSelectTab", {
      detail: e
      // Pass the payload here
    }));
  }
}
o("solutions-deployed-list", f);
export {
  f as SolutionsDeployedList
};
