/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as h } from "../../chunks/runtime.js";
import { css as m, html as o } from "lit";
import { u } from "../../chunks/useT9n.js";
import { LitElement as f, createEvent as g, nothing as s, safeClassMap as c } from "@arcgis/lumina";
import { useContextConsumer as y } from "@arcgis/lumina/context";
import { c as v } from "../../chunks/deployAppContexts.js";
import { T as _ } from "../../chunks/interfaces.js";
import { d as b } from "../../chunks/cardsHelpers.js";
import { l as x } from "../../chunks/helpers.js";
import * as $ from "@esri/solution-common";
const C = m`calcite-card{height:100%;padding-bottom:2px;border:2px solid transparent;transition:border-color .1s ease;box-sizing:border-box}@media(max-width:400px){calcite-card{width:100%}}calcite-card:hover img{-webkit-filter:brightness(30%);filter:brightness(30%);-webkit-transition:all .1s ease;-moz-transition:all .1s ease;-o-transition:all .1s ease;-ms-transition:all .1s ease;transition:all .1s ease}calcite-card:hover .hover-text{opacity:1;color:#fff}calcite-card:hover{border-color:var(--calcite-color-brand);cursor:pointer}.chip-status{--calcite-chip-icon-color: var(--calcite-color-brand);cursor:pointer}.chip-deployed{--calcite-chip-icon-color: var(--calcite-color-status-success)}.chip-deployed-warn{--calcite-chip-icon-color: var(--calcite-color-status-warning)}.hover-text{transition:.1s ease;opacity:0;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);text-align:center;display:flex;flex-direction:row;align-items:center;height:100%;font-size:1.2rem}.font-color-text-2{--calcite-label-text-color: var(--calcite-color-text-2)}.font-line-height{line-height:1.4}.font-size-size--1{font-size:var(--calcite-font-size--1)}.header-line-height{--calcite-label-margin-bottom: 0;margin-top:.5rem;margin-bottom:.7rem}.info-icon{--calcite-icon-color: var(--calcite-color-text-inverse);padding-inline-end:.3rem}.card-image-wrap{flex:0 0 auto}.card-image-wrap{width:100%;position:relative;margin-bottom:0;-webkit-box-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto}.card-image{width:100%;display:block}video,img{max-width:100%;height:auto}img{overflow-clip-margin:content-box;overflow:clip}a{text-decoration:none;color:inherit;outline:0;padding:0;margin:0;display:inherit;height:100%}`;
class T extends f {
  constructor() {
    super(...arguments), this.referrerSolutionId = "", this.referrerSolutionTitle = "", this.referrerSolutionVersion = "", this.source = "all-solutions", this._deployedTooltipContent = "", this._isTooltipOpen = !1, this._translations = u({ name: "solution-details-card", blocking: !0 }), this._configContextConsumer = y({
      context: v,
      subscribe: !0
    }), this.detailsCardSelected = g();
  }
  static {
    this.properties = { card: 0, referrerSolutionId: 1, referrerSolutionTitle: 1, referrerSolutionVersion: 1, source: 1, _deployedTooltipContent: 16, _isTooltipOpen: 16, _translations: 16 };
  }
  static {
    this.styles = C;
  }
  get _telemetry() {
    return this._configContextConsumer.value?.telemetrySession;
  }
  render() {
    const e = b(this.card.title);
    return o`<a aria-disabled=${this._isTooltipOpen ? "true" : "false"} href=${(this._isTooltipOpen ? void 0 : e) ?? s} @click=${this._anchorClick} tabindex=-1 title=${(this._isTooltipOpen ? void 0 : `${this._translations.arcgisSolutions} | ${this.card.title}`) ?? s}>${this._renderCard()}</a>`;
  }
  _anchorClick(e) {
    e.preventDefault();
  }
  _cardSelected() {
    if (this.source === "you-may-also-like") {
      const i = [
        this.referrerSolutionTitle,
        this.referrerSolutionId,
        this.referrerSolutionVersion,
        this.card?.title || "",
        this.card?.deployCommonId || "",
        this.card?.deployVersion || ""
      ];
      this._telemetry?.logEvent({
        category: _.SOLUTION_DETAILS,
        action: "Related Solution",
        dimensions: i
      });
    }
    this.detailsCardSelected.emit(this.card);
  }
  _renderChips(e) {
    const i = e.filter((t) => t === "deployed" || t === "deployedOlderVersion"), d = e.filter((t) => t !== "deployed" && t !== "deployedOlderVersion"), r = [];
    return d.forEach((t) => {
      const l = "chip-status", n = `solution-details-card-chip-${t}`, p = t === "new" ? "star" : "mega-phone", a = t === "new" ? this._translations.newSolution : this._translations.updated;
      r.push(o`<calcite-chip class=${c(l)} .icon=${p} id=${n ?? s} .label=${a} .value=${a} scale=s></calcite-chip><calcite-tooltip .referenceElement=${n}><span>${a}</span></calcite-tooltip>`);
    }), i.length > 0 && r.push(o`<calcite-chip class=${c(i[0] === "deployedOlderVersion" ? "chip-deployed-warn" : "chip-deployed")} .icon=${i[0] === "deployedOlderVersion" ? "recent" : "check-circle"} id=solution-details-card-chip-deployed .label=${this._translations.deployed} .value=${this._translations.deployed} scale=s></calcite-chip><calcite-tooltip placement=top reference-element=solution-details-card-chip-deployed @calciteTooltipBeforeOpen=${async () => {
      this._isTooltipOpen = !0;
      const t = {
        q: `${this.card?.deployCommonId} and owner:${this._configContextConsumer.value?.userSession?.username}`,
        authentication: this._configContextConsumer.value?.userSession,
        pagingParam: { start: 1, num: 100 }
      }, l = await $.searchItems(t);
      this._deployedTooltipContent = o`<solutions-deployed-list .results=${l} has-links .listTitle=${i[0] === "deployedOlderVersion" ? this._translations.deployedPreviousTitle : this._translations.deployedTitle}></solutions-deployed-list>`;
    }} @calciteTooltipBeforeClose=${() => {
      this._isTooltipOpen = !1;
    }}>${this._deployedTooltipContent}</calcite-tooltip>`), r;
  }
  _renderCard() {
    const e = this.card;
    return o`<calcite-card .label=${e.snippet} @click=${this._isTooltipOpen ? void 0 : this._cardSelected} @keydown=${(i) => x(i, () => this._isTooltipOpen ? void 0 : this._cardSelected())}><div class="card-image-wrap" slot=thumbnail><img alt=${e.title ?? s} aria-hidden=true class="thumbnail card-image" src=${e.thumbnailUrl ?? s}><div class="hover-text">${this._translations.viewDetails}</div></div><calcite-label slot=heading class="header-line-height" scale=l>${e.title}</calcite-label><p slot=description class="font-color-text-2 font-line-height font-size-size--1">${e.snippet}</p>${e.chips && e.chips.length > 0 ? o`<div slot=footer-end style="display: flex; gap: 0.5rem; justify-content: flex-end;">${this._renderChips(e.chips)}</div>` : void 0}<div slot=footer-start></div></calcite-card>`;
  }
}
h("solution-details-card", T);
export {
  T as SolutionDetailsCard
};
