/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as S } from "../../chunks/runtime.js";
import { u as I } from "../../chunks/useT9n.js";
import { createRef as h, ref as p } from "lit-html/directives/ref.js";
import { LitElement as C, createEvent as f, safeClassMap as u, nothing as y, safeStyleMap as D } from "@arcgis/lumina";
import { useContextConsumer as w } from "@arcgis/lumina/context";
import { E as m, V as L, g as x, A as E, G as R, T as g, W as b, X as T, K as $, J as P, Y as A, Z as O, D as U } from "../../chunks/interfaces.js";
import { css as N, html as l } from "lit";
import { request as F, getWorkflowBaseURL as H, getWorkflowManagerAuthorized as V, sanitizeHTML as _, getItemDataAsJson as z, getItem as B, getPropWithDefault as M, getProp as v, setCreateProp as Y } from "@esri/solution-common";
import { _findExistingItem as G } from "@esri/solution-deployer";
import "../../chunks/solution-deploy-dialog.js";
import "../solution-snapshot-gallery/customElement.js";
import "../solution-deploying-dialog/customElement.js";
const W = N`.display-flex{display:flex}.flex-direction-row{flex-direction:row}.flex-direction-column{flex-direction:column}.flex-1{flex:1}.cursor-default{cursor:default}solution-details-card[id*=you-may-also-like]{width:240px}.border-bottom{border-bottom-color:var(--calcite-color-border-1);border-bottom-width:var(--calcite-spacing-px);border-bottom-style:solid}ul{list-style-type:disc;margin-block-start:var(--calcite-spacing-none);margin-block-end:var(--calcite-spacing-none)}ul ul{list-style-type:circle}li{margin:var(--calcite-spacing-sm) var(--calcite-spacing-none)}calcite-label{--calcite-label-margin-bottom: var(--calcite-spacing-none)}.padding-1{padding:var(--calcite-spacing-lg)}.padding-1-5{padding:var(--calcite-spacing-xl)}.padding-2px{padding:var(--calcite-spacing-base)}.padding-bottom-xxl{padding-bottom:var(--calcite-spacing-xxl)}.padding-bottom-1{padding-bottom:var(--calcite-spacing-lg)}.padding-bottom-sm{padding-bottom:var(--calcite-spacing-sm)}.padding-top-md{padding-top:var(--calcite-spacing-md)}.padding-top-sm{padding-top:var(--calcite-spacing-sm)}.padding-top-xs{padding-top:.25rem}.padding-bottom-1-5{padding-bottom:var(--calcite-spacing-xxl)}.padding-top-1{padding-top:var(--calcite-spacing-lg)}.padding-top-1-5{padding-top:var(--calcite-spacing-xxl)}.padding-top-1-2{padding-top:var(--calcite-spacing-sm)}.padding-end-1{padding-inline-end:var(--calcite-spacing-lg)}.padding-end-1-75{padding-inline-end:1.75rem}.padding-end-2{padding-inline-end:var(--calcite-spacing-xxxl)}.padding-start-1{padding-inline-start:var(--calcite-spacing-lg)}.margin-bottom-1{margin-bottom:var(--calcite-spacing-lg)}.margin-bottom-1-5{margin-bottom:var(--calcite-spacing-xxl)}.margin-end-1{margin-inline-end:var(--calcite-spacing-lg)}.margin-top-0{margin-top:var(--calcite-spacing-none)}.margin-top-1{margin-top:var(--calcite-spacing-lg)}.margin-top-875{margin-top:.875rem}.margin-top-1-5{margin-top:var(--calcite-spacing-xxl)}.margin-sides-0-5{margin-left:var(--calcite-spacing-sm);margin-right:var(--calcite-spacing-sm)}.margin-sides-1{margin-left:var(--calcite-spacing-lg);margin-right:var(--calcite-spacing-lg)}.margin-block-start-end-0{margin-block-start:var(--calcite-spacing-none);margin-block-end:var(--calcite-spacing-none)}.align-self-center{align-self:center;padding:5px;--calcite-fab-shadow: #FFFFFF00}.align-items-center{align-items:center}.align-items-baseline{align-items:baseline}.button-width{width:260px;flex-grow:0;flex-shrink:0}@media(max-width:1280px){.button-width{width:auto}}.image-width{width:300px;flex-grow:0;flex-shrink:0}@media(max-width:1280px){.image-width{flex-grow:0;flex-shrink:1}}.width-full{width:100%}@media(max-width:768px){.width-full{flex-direction:column}.width-full>.display-flex{flex-direction:column}.image-width{width:100%;padding-inline-end:0;margin-bottom:var(--calcite-spacing-lg)}.button-width{width:100%;margin-top:var(--calcite-spacing-lg)}}.card-group{overflow:hidden;padding:.25rem var(--calcite-spacing-sm) var(--calcite-spacing-md)}#screenshots-subsection calcite-card{width:calc(33.333% - .5rem)}calcite-card{width:450px;--calcite-card-border-color: transparent}@media(max-width:1496px){calcite-card{width:calc(100% / 3 - .5rem)}#screenshots-subsection calcite-card{width:calc(33.333% - .5rem)}}@media(max-width:1100px){calcite-card{width:calc(50% - .5rem)}#screenshots-subsection calcite-card{width:calc(50% - .5rem)}}@media(max-width:550px){calcite-card{width:100%}#screenshots-subsection calcite-card{width:100%}}.max-height-300{max-height:300px}.display-none{display:none}.cursor-pointer{cursor:pointer}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:var(--calcite-spacing-base) solid var(--calcite-color-brand);box-sizing:border-box;cursor:pointer;padding:var(--calcite-spacing-base)}calcite-card.is-mobile:hover img{cursor:default;-webkit-filter:brightness(100%);filter:brightness(100%);transition:all .1s ease}calcite-card{border:var(--calcite-spacing-base) solid transparent;box-sizing:border-box;padding:var(--calcite-spacing-base)}.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:var(--calcite-spacing-xl)}.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}#screenshots-subsection .card-image{background-color:var(--calcite-color-surface-2)}.card-image{width:100%;display:block}video,img{max-width:100%;height:auto}img{overflow-clip-margin:content-box;overflow:clip;display:block}.margin-inline-unset{margin-inline:unset}.collapsible-div{overflow:hidden;transition:max-height .3s ease-in-out}.collapsible-div.expanded{max-height:100%}.back-color-override{--calcite-panel-background-color: var(--calcite-color-foreground-2)}.back-color-override-1{background-color:var(--calcite-color-foreground-1)}.title-font{font-size:1.8rem;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-color-text-1)}.heading-font{font-size:var(--calcite-font-size-0);font-weight:var(--calcite-font-weight-medium)}.line-height-xxl{line-height:var(--calcite-spacing-xxl)}.line-height-1{line-height:1.1}.font-1{font-size:var(--calcite-spacing-lg)}.font-color-1{color:var(--calcite-color-text-1)}.font-color-2{color:var(--calcite-color-text-2)}h1{font-weight:unset;margin:var(--calcite-spacing-none);padding:var(--calcite-spacing-none)}.item-padding{--calcite-internal-accordion-item-padding: var(--calcite-spacing-xl)}.accordion-bg{--calcite-accordion-background-color: var(--calcite-color-foreground-1)}.table-cell{font-size:var(--calcite-spacing-lg);color:var(--calcite-color-text-2);margin:0}.table-cell p{margin:0}calcite-table-header{font-weight:var(--calcite-font-weight-medium);--calcite-internal-table-cell-font-size: var(--calcite-font-size-md)}.position-relative{position:relative}.background-color-2{background-color:var(--calcite-color-foreground-2)}.panel-background-2{--calcite-panel-background-color: var(--calcite-color-foreground-2);background-color:var(--calcite-color-foreground-2)}.border-none{border:none}.padding-end-xxl{padding-inline-end:var(--calcite-spacing-xxl)}calcite-shell{block-size:unset}.solution-detail-action{--calcite-color-focus: initial}a{color:var(--calcite-link-text-color, var(--calcite-color-text-link));cursor:pointer;text-decoration:none;line-height:inherit;background-image:linear-gradient(currentColor,currentColor),linear-gradient(var(--calcite-color-brand-underline),var(--calcite-color-brand-underline));background-position-x:0%,100%;background-position-y:min(1.5em,100%);background-repeat:no-repeat,no-repeat;background-size:0% 1px,100% 1px;transition-property:background-size,color;transition-duration:var(--calcite-animation-timing, .15s);transition-timing-function:ease-in-out;outline-color:transparent;position:relative}a:hover{background-size:100% 1px,100% 1px}a:focus{outline:2px solid var(--calcite-color-brand);outline-offset:2px;outline-color:var(--calcite-color-brand)}a:active{color:var(--calcite-color-brand-press)}*[tabindex]:focus-visible{outline:2px solid var(--calcite-color-brand);outline-offset:2px}`;
async function K(n, e, t) {
  let i = t;
  return n && (n?.IsEnterprisePortal && await X(
    "",
    // the portal url
    e
  ) && i.push(m.NOTEBOOK), await L(e) ? t.push(m.VELOCITY) : n?.PortalUserPrivileges && [
    x.VELOCITYFEEDS,
    x.VELOCITYBIGDATA,
    x.VELOCITYREALTIME
  ].forEach((o) => {
    const c = t.indexOf(o) || -1;
    c !== -1 && t.splice(c, 1);
  }), i = i.concat(
    q(
      Z(n),
      Q(n)
    )
  ), i = i.concat(j(n)), i = i.concat(await J(n))), Promise.resolve(i);
}
function q(n, e) {
  let t = [];
  return n && e ? t = [
    m.TRACKINGADMINANDTRACKING,
    m.TRACKINGADMIN,
    m.TRACKING
  ] : n && !e ? t = [m.TRACKINGADMIN] : !n && e && (t = [m.TRACKING]), t;
}
function j(n) {
  return ee(
    n
  ) ? [m.HUBPREMIUM] : [];
}
async function J(n) {
  const e = n?.RestUserSession;
  if (!e?.username)
    return [];
  const t = await H(e);
  return await V(t, e) ? [m.WORKFLOW] : [];
}
async function X(n, e) {
  const t = n + "/sharing/rest", i = {
    authentication: e,
    portal: t,
    params: {
      f: "json"
    }
  };
  return F(`${t}/portals/self/servers`, i).then((s) => s?.servers?.find((a) => a.serverFunction.indexOf("NotebookServer") > -1), (s) => (console.error(s), !1));
}
function Z(n) {
  const e = n?.PortalUserSubset?.privileges, t = [
    "portal:admin:create",
    "portal:admin:delete",
    "portal:admin:update",
    "portal:admin:reassign"
  ];
  return e ? t.every(
    (i) => e.some((s) => s.startsWith(i))
  ) : !1;
}
function Q(n) {
  return n?.PortalSubset?.locationTrackingEnabled || !1;
}
function ee(n) {
  return n?.PortalSubset?.hubPremiumEnabled || !1;
}
class te extends C {
  constructor() {
    super(), this._isDeployDisabled = !1, this._isLoaded = !1, this._showScreenshotsShowMore = !1, this._showYouMayAlsoLikeShowMore = !1, this.isMobile = !1, this._isScreenshotsRowExpanded = !1, this._isYouMayAlsoLikeRowExpanded = !1, this._screenshotsRowBaseHeight = 340, this._showLoader = !1, this._templates = [], this._translations = I({ name: "solution-details-panel", blocking: !0 }), this._youMayAlsoLikeBaseHeight = 340, this._allCards = [], this._configContextConsumer = w({
      context: E,
      subscribe: !0
    }), this._configureLearnMore = "", this._customDeploymentMappings = {}, this._deployDialogRef = h(), this._deployingDialogRef = h(), this._isMobileContextConsumer = w({
      context: R,
      subscribe: !0,
      callback: (e) => this.isMobile = e
    }), this._overviewAccordionItemElement = h(), this._privilegePopoverRef = h(), this._privileges = [], this._regexFsUrl = "https?:\\/\\/.+FeatureServer\\b", this._regexID = "\\b[0-9A-F]{32}\\b", this._releaseNotesAccordionItemElement = h(), this._relatedResourcesAccordionItemElement = h(), this._screenshotsAccordionItemElement = h(), this._screenshotsDialogRef = h(), this._screenshotsElement = h(), this._termsOfUseAccordionItemElement = h(), this._userOptions = [], this._youMayAlsoLikeAccordionItemElement = h(), this._youMayAlsoLikeElement = h(), this._signInParamValue = null, this._deploymentStartTime = null, this._cancellationStartTime = null, this._deployToCancelDuration = 0, this.templatesFetched = f(), this.itemPropertiesFetched = f(), this.sortTypeChanged = f(), this.tokenRefreshed = f(), this._handleDeployCancelled = () => {
      this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Deploy Dialog Canceled",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || ""
        ]
      });
    }, this._handleDeploySuccess = () => {
      const e = b(this._deploymentStartTime);
      this._deploymentStartTime = null, this._deployingDialogRef.value && (this._deployingDialogRef.value.isWaitingForCard = !0), this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Deploy Success",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || ""
        ],
        metrics: [e]
      });
    }, this._handleDeployedCardReady = async (e) => {
      this._closeDialogs(), await new Promise((t) => requestAnimationFrame(() => requestAnimationFrame(t))), window.dispatchEvent(new CustomEvent("displayDeployedCard", {
        detail: e.detail
      }));
    }, this._handleDeploymentFallback = () => {
      console.warn("Deployment completed but unable to navigate to deployed card - closing dialogs"), this._closeDialogs(), window.dispatchEvent(new CustomEvent("navTabSelected", {
        detail: "deployments"
      }));
    }, this._handleDeploymentProcessCancelled = () => {
      this._cancellationStartTime = Date.now(), this._deployToCancelDuration = b(this._deploymentStartTime), this._deploymentStartTime = null;
    }, this._handleDeployFailed = (e) => {
      if (this._cancellationStartTime !== null) {
        this._closeDialogs();
        return;
      }
      const t = b(this._deploymentStartTime);
      this._deploymentStartTime = null;
      const i = T(e.detail?.error), s = i.length > 200 ? i.slice(-200) : i;
      console.error("Deployment failed:", e.detail?.error), this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Deploy Failure",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || "",
          s
        ],
        metrics: [t]
      }), this._closeDialogs(!0);
    }, this.listenOn(window, "detailsCardSelected", this._detailsCardSelected), this.listenOn(window, "allCardsFetched", this._allCardsFetched), this.listenOn(window, "deployAppTabSelected", this._handleDeployAppTabSelected), this.listenOn(window, "deployedCardReady", this._handleDeployedCardReady), this.listenOn(window, "deploymentCompletedWithoutNav", this._handleDeploymentFallback);
  }
  static {
    this.properties = { card: 0, _isDeployDisabled: 16, _isLoaded: 16, _showScreenshotsShowMore: 16, _showYouMayAlsoLikeShowMore: 16, isMobile: 16, _isScreenshotsRowExpanded: 16, _isYouMayAlsoLikeRowExpanded: 16, _itemProperties: 16, _missingPrivilegeMessages: 16, _screenshotsRowBaseHeight: 16, _showLoader: 16, _templates: 16, _translations: 16, _youMayAlsoLikeBaseHeight: 16 };
  }
  static {
    this.styles = W;
  }
  get _telemetry() {
    return this._configContextConsumer.value?.telemetrySession;
  }
  async connectedCallback() {
    super.connectedCallback(), this.listenOn(window, "calciteTabChange", this._cleanupPanel);
  }
  async load() {
    this._isMobileContextConsumer.value && (this.isMobile = this._isMobileContextConsumer.value);
  }
  willUpdate(e) {
    e.has("card") && (this._isDeployDisabled = !1, this._isLoaded = !1, this._showLoader = !1, this._signInParamValue === "deploy" && (this._showLoader = !0));
  }
  loaded() {
    this._signInParamValue === null && this._configContextConsumer.value?.authentication?.SignInParam && (this._signInParamValue = this._configContextConsumer.value.authentication.SignInParam), this._resizeObserver = new ResizeObserver(async () => {
      this._onResize();
    }), this._screenshotsElement.value && this._resizeObserver.observe(this._screenshotsElement.value);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._resizeObserver?.disconnect();
  }
  render() {
    const e = "padding-bottom-1-5", t = this._getRelatedResources(), i = this._getYouMayAlsoLikeCards();
    return l`<calcite-shell class="position-relative background-color-2"><calcite-panel class="panel-background-2 border-none" slot=panel-bottom><div class="margin-top-875 padding-1-5 back-color-override-1 margin-bottom-1-5" id=solution-details-row>${this._getSolutionRow()}</div><div class=${u(e)}>${this._getScreenshotsRow()}</div><div class=${u(e)}>${this._getOverviewRow()}</div><div class=${u(e)}>${this._getReleaseNotesRow()}</div>${t.length > 0 ? l`<div class=${u(e)}>${this._getRelatedResourcesRow(t)}</div>` : ""}${i.length > 0 ? l`<div class=${u(e)}>${this._getYouMayAlsoLikeRow(i)}</div>` : ""}<div class=${u(e)}>${this._getTermsOfUseRow()}</div>${this.isMobile ? "" : l`<solution-deploy-dialog .card=${this.card} @deployCancelled=${this._handleDeployCancelled} @deployFailed=${this._handleDeployFailed} @deployProgressEnd=${this._handleDeploySuccess} @deployProgressStart=${this._deployProgressStart} @deployProgressUpdated=${this._deployProgessUpdated} id=solutionDeployDialog .userOptions=${this._userOptions} ${p(this._deployDialogRef)}></solution-deploy-dialog>`}<solution-snapshot-gallery .card=${this.card} id=solutionSnapshotGallery .itemProperties=${this._itemProperties} ${p(this._screenshotsDialogRef)}></solution-snapshot-gallery><solution-deploying-dialog .card=${this.card} @deploymentProcessCancelled=${this._handleDeploymentProcessCancelled} ${p(this._deployingDialogRef)}></solution-deploying-dialog></calcite-panel></calcite-shell>`;
  }
  updated() {
    setTimeout(() => {
      const e = this._getYouMayAlsoLikeCards();
      let t = 340;
      for (let i = 0; i < e.length; i++) {
        const s = this.el.shadowRoot?.getElementById(`you-may-also-like-${i}`), a = s?.offsetHeight ? s.offsetHeight + 40 : 0;
        a > t && (t = a);
      }
      this._youMayAlsoLikeBaseHeight = t, this._showYouMayAlsoLikeShowMore = (this._youMayAlsoLikeElement.value?.scrollHeight || 0) > this._youMayAlsoLikeBaseHeight, this._showScreenshotsShowMore = (this._screenshotsElement.value?.scrollHeight || 0) > this._screenshotsRowBaseHeight + 2;
    }, 100);
  }
  _checkUrlParametersForAutoDeployment() {
    if (this._signInParamValue === "deploy") {
      const t = this._missingPrivilegeMessages && (this._missingPrivilegeMessages.leadingMessages.length > 0 || this._missingPrivilegeMessages.bulletedMessages.length > 0 || this._missingPrivilegeMessages.trailingMessages.length > 0);
      this._configContextConsumer.value?.authentication?.IsSignedIn && this.card && this._deployDialogRef.value && !t && (this._signInParamValue = null, this._openDeploy());
    }
  }
  _getSolutionRow() {
    const e = this.card?.thumbnailUrl.replace(/w=\d+/, "w=400"), t = this._missingPrivilegeMessages?.leadingMessages || [], i = t.length > 0, s = this._missingPrivilegeMessages?.bulletedMessages || [], a = s.length > 0, o = this._missingPrivilegeMessages?.trailingMessages || [], c = o.length > 0;
    return l`<div class="display-flex flex-direction-row width-full"><div class="padding-end-1-75 image-width"><img alt=${this.card?.title ?? y} src=${e ?? y}></div><div class="display-flex flex-direction-row flex-1">${this._getTextSection(i, a, c, t, s, o)}${this._getButtons()}</div></div>`;
  }
  _getTextSection(e, t, i, s, a, o) {
    return l`<div class="display-flex flex-direction-column padding-end-1 flex-1"><div class="display-flex flex-direction-row align-items-baseline"><h1 class="padding-top-xs title-font margin-top-0 margin-bottom-1-5 line-height-1" tabindex=0>${this.card?.title}</h1>${this.card?.categories?.some((c) => c.includes("New Release")) && l`<calcite-chip class="margin-bottom-1-5 margin-sides-1" kind=brand .label=${this._translations.newChip} scale=m icon=star>${this._translations.newChip}</calcite-chip>` || ""}</div><div class="font-1 padding-end-1 line-height-xxl" tabindex=0>${this.card?.snippet}</div>${this.isMobile ? "" : e || t || i ? l`<div class="display-flex flex-direction-row padding-top-1">${this._getMissingPrivilegesNotice(s, a, o)}</div>` : ""}</div>`;
  }
  _getButtons() {
    const e = this._itemProperties?.demoURL || "";
    return l`<div class="display-flex flex-direction-column button-width">${!this.isMobile && l`<calcite-button class="padding-bottom-1 solution-detail-action" .disabled=${this._isDeployDisabled} icon-flip-rtl=end @click=${() => this._checkPermissionsBeforeDeploy()} scale=m>${this._showLoader ? l`<calcite-loader inline label></calcite-loader>` : this._translations.deployButton}</calcite-button>` || ""}${!this._configContextConsumer.value?.isEnterprise && e && l`<calcite-button appearance=outline-fill kind=neutral class="padding-bottom-1 solution-detail-action" @click=${() => this._handleWatchDemoClick(e)} scale=m>${this._translations.watchDemo}</calcite-button>` || ""}<calcite-button appearance=outline-fill kind=neutral class="padding-bottom-1 solution-detail-action" @click=${() => this._handleLearnMoreClick()} scale=m>${this._translations.openHelp}</calcite-button>${!this._configContextConsumer.value?.isEnterprise && l`<solution-social-share button-appearance=outline-fill class="padding-bottom-1" share-button-kind=neutral .shareButtonText=${this._translations.share} share-button-scale=m .solutionId=${this.card?.deployCommonId || ""} .solutionTitle=${this.card?.title || ""} .solutionVersion=${this.card?.deployVersion || ""}></solution-social-share>` || ""}</div>`;
  }
  _getMissingPrivilegesNotice(e, t, i) {
    const s = "solutions-missing-privileges-notice", a = this._translations.missingPrivilegesPopup.missingLicensingOrPrivileges, o = t.length > 0 ? "" : "display-none", c = t.length > 0 ? "padding-top-sm" : "";
    return l`<div><calcite-notice class="margin-inline-unset" kind=info open><div slot=message>${`${a}`}</div><calcite-action icon=information id=${s} slot=actions-end .text=${a}></calcite-action></calcite-notice><calcite-popover closable label overlay-positioning=fixed placement=bottom reference-element=solutions-missing-privileges-notice ${p(this._privilegePopoverRef)}><div class="padding-1 display-flex flex-direction-column">${// Leading messages
    this._getSpanMessages(e, "padding-bottom-1")}<span class=${`padding-bottom-1-2 ${o}`}>${this._translations.missingPrivilegesPopup.missingPrivilegesListHeading}</span>${// Bulleted messages
    this._getBulletedMessages(t)}${// Trailing messages
    this._getSpanMessages(i, c)}</div></calcite-popover></div>`;
  }
  _getSpanMessages(e, t) {
    return e.length > 0 ? e.map((i) => l`<span class=${u(t)}>${i}</span>`) : "";
  }
  _getBulletedMessages(e) {
    return e.length > 0 ? l`<ul>${e.map((t) => l`<li>${t}</li>`)}</ul>` : "";
  }
  _getScreenshotsRow() {
    const e = this._isScreenshotsRowExpanded ? this._translations.showLess : this._translations.showMore, t = this._isScreenshotsRowExpanded ? "arrow-up" : "arrow-down", i = this._showScreenshotsShowMore ? "" : "display-none";
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._screenshotsAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.solutionOverview}</div><calcite-panel><div class="display-flex flex-direction-column back-color-override-1"><div class="collapsible-div max-height-300" id=screenshots-subsection ${p(this._screenshotsElement)}>${this._getScreenshots()}</div><calcite-fab appearance=outline-fill class=${`align-self-center ${i}`} .icon=${t} kind=neutral @click=${() => {
      this._screenshotsElement.value?.classList.toggle("expanded"), this._isScreenshotsRowExpanded = this._screenshotsElement.value.classList.contains("expanded");
    }} .text=${e} text-enabled></calcite-fab></div></calcite-panel></calcite-accordion-item></calcite-accordion>`;
  }
  _getScreenshots() {
    const e = this._itemProperties?.preview.filter((a) => a.format === "image") || [], t = this._configContextConsumer.value, i = this._isLoaded ? "" : "display-none", s = this._isLoaded ? "display-none" : "";
    return l`<calcite-loader class=${u(s)} label></calcite-loader><calcite-card-group class=${`card-group ${i}`} .label=${this._translations.solutionOverview}>${e.reduce((a, o) => {
      const c = $(this.card?.id || "", o.name, t.authentication);
      let d;
      return t.agoBasedEnterpriseSolutionsGroupId && t.isEnterprise && (d = $(this.card?.id || "", o.name, void 0, t.agolPortalUrl)), this.card?.id ? a.push(l`<calcite-card class=${`${this.isMobile ? "is-mobile" : "cursor-pointer not-mobile"}`} .label=${o.alt} @click=${() => this._openScreenshotGallery(o)} @keydown=${(r) => P(r, () => this._openScreenshotGallery(o))}><div class="card-image-wrap" slot=thumbnail><img alt=${o.alt ?? y} class="thumbnail card-image" slot=thumbnail src=${(d || c) ?? y}>${!this.isMobile && l`<div class="hover-text">${this._translations.openInGallery}</div>` || ""}</div></calcite-card>`) : a.push(""), a;
    }, [])}</calcite-card-group>`;
  }
  _openScreenshotGallery(e) {
    if (!this.isMobile) {
      this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Screenshot Gallery",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || ""
        ]
      });
      const t = this._screenshotsDialogRef.value;
      t && (t.screenshot = e, t.open = !0);
    }
  }
  _getOverviewRow() {
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._overviewAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.solutionDetails}</div>${this._getDescriptionRow()}${this._getInformationProductsRow()}</calcite-accordion-item></calcite-accordion>`;
  }
  _getDescriptionRow() {
    return l`<div class="display-flex flex-direction-column"><div class="font-color-2 font-1 margin-top-0 line-height-xxl padding-bottom-xxl" tabindex=0>${this.card?.snippet}</div><div class="font-color-2 font-1 margin-top-0 line-height-xxl padding-bottom-xxl" .innerHTML=${this.card?.description ?? ""} tabindex=0></div></div>`;
  }
  _getInformationProductsRow() {
    return l`<div class="display-flex flex-direction-column font-1 line-height-xxl font-color-2"><span tabindex=0>${this.card?.title ? this._translations.informationProductsSubText.replace("{{solutionTitle}}", this.card.title) : ""}</span><calcite-table bordered caption class="padding-top-1">${this._getInformationTableHeaderRow()}${this._getInformationTableRows()}</calcite-table><p tabindex=0>${this._translations.informationProductsFooterText}</p></div>`;
  }
  _getInformationTableHeaderRow() {
    return l`<calcite-table-row slot=table-header><calcite-table-header .heading=${this._translations.solutionItem}></calcite-table-header><calcite-table-header .heading=${this._translations.description}></calcite-table-header><calcite-table-header .heading=${this._translations.minimumUserType}></calcite-table-header></calcite-table-row>`;
  }
  _getInformationTableRows() {
    return (this._itemProperties?.infoProducts || []).map((t) => l`<calcite-table-row><calcite-table-cell><p class="table-cell" .innerHTML=${_(t.item) ?? ""}></p></calcite-table-cell><calcite-table-cell><p class="table-cell" .innerHTML=${_(t.description) ?? ""}></p></calcite-table-cell><calcite-table-cell><p class="table-cell" .innerHTML=${_(t.userType) ?? ""}></p></calcite-table-cell></calcite-table-row>`);
  }
  _getReleaseNotesRow() {
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._releaseNotesAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.releaseNotes}</div><div class="display-flex flex-direction-column"><calcite-table bordered caption>${this._getReleaseNotesTableHeaderRow()}${this._getReleaseNotesTableRows()}</calcite-table></div></calcite-accordion-item></calcite-accordion>`;
  }
  _getReleaseNotesTableHeaderRow() {
    return l`<calcite-table-row slot=table-header><calcite-table-header .heading=${this._translations.version}></calcite-table-header><calcite-table-header .heading=${this._translations.description}></calcite-table-header></calcite-table-row>`;
  }
  _getReleaseNotesTableRows() {
    return (this._itemProperties?.releaseNotes || [])?.map((t) => l`<calcite-table-row><calcite-table-cell><p class="table-cell" .innerHTML=${_(t.version) ?? ""}></p></calcite-table-cell><calcite-table-cell><p class="table-cell" .innerHTML=${_(t.description) ?? ""}></p></calcite-table-cell></calcite-table-row>`);
  }
  _getRelatedResourcesRow(e) {
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._relatedResourcesAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.relatedResources}</div><div class="display-flex flex-direction-row">${e.map(() => {
      l`<solution-resource-card></solution-resource-card>`;
    })}</div></calcite-accordion-item></calcite-accordion>`;
  }
  _getRelatedResources() {
    return [];
  }
  _getYouMayAlsoLikeRow(e) {
    const t = this._showYouMayAlsoLikeShowMore ? "" : "display-none", i = this._isYouMayAlsoLikeRowExpanded ? this._translations.showLess : this._translations.showMore, s = this._isYouMayAlsoLikeRowExpanded ? "arrow-up" : "arrow-down", a = this._isYouMayAlsoLikeRowExpanded ? "" : { height: `${this._youMayAlsoLikeBaseHeight}px` };
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._youMayAlsoLikeAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.youMayAlsoLike}</div><div class="display-flex flex-direction-column"><div class="collapsible-div" id=you-may-also-like-subsection style=${D(a)} ${p(this._youMayAlsoLikeElement)}><div class="display-flex flex-direction-row"><calcite-card-group class="card-group" .label=${this._translations.youMayAlsoLike}>${e.map((o, c) => l`<solution-details-card .id=${`you-may-also-like-${c}`} .card=${o} class="padding-2px" source=you-may-also-like .referrerSolutionId=${this.card?.deployCommonId || ""} .referrerSolutionTitle=${this.card?.title || ""} .referrerSolutionVersion=${this.card?.deployVersion || ""}></solution-details-card>`)}</calcite-card-group></div></div><calcite-fab appearance=outline-fill class=${`align-self-center ${t}`} .icon=${s} kind=inverse @click=${() => {
      this._youMayAlsoLikeElement.value?.classList.toggle("expanded"), this._isYouMayAlsoLikeRowExpanded = this._youMayAlsoLikeElement.value.classList.contains("expanded");
    }} .text=${i} text-enabled></calcite-fab></div></calcite-accordion-item></calcite-accordion>`;
  }
  _getYouMayAlsoLikeCards() {
    const e = this._itemProperties?.relatedSolutions || [];
    return this._allCards.filter((t) => e.indexOf(t.deployCommonId) > -1);
  }
  _getTermsOfUseRow() {
    return l`<calcite-accordion class="accordion-bg " icon-position=start scale=l appearance=transparent><calcite-accordion-item class="item-padding" expanded ${p(this._termsOfUseAccordionItemElement)}><div class="margin-block-start-end-0 heading-font" slot=content-start>${this._translations.termsOfUse}</div><div class="font-color-2" .innerHTML=${(this.card?.licenseInfo || "") ?? ""} tabindex=0></div></calcite-accordion-item></calcite-accordion>`;
  }
  _openDeploy() {
    if (this._configContextConsumer.value.authentication.IsSignedIn) {
      const e = this._deployDialogRef.value;
      e && (this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Deploy Dialog Opened",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || ""
        ]
      }), e.userOptions = this._userOptions, e.open = !0);
    } else
      this._configContextConsumer.value.authentication.signIn("deploy");
  }
  _openUrl(e) {
    window.open(e, "_blank");
  }
  _handleWatchDemoClick(e) {
    this._telemetry?.logEvent({
      category: g.SOLUTION_DETAILS,
      action: "Watch Demo",
      dimensions: [
        this.card?.title || "",
        this.card?.deployCommonId || "",
        this.card?.deployVersion || ""
      ]
    }), this._openUrl(e);
  }
  _handleLearnMoreClick() {
    this._telemetry?.logEvent({
      category: g.SOLUTION_DETAILS,
      action: "Open Help",
      dimensions: [
        this.card?.title || "",
        this.card?.deployCommonId || "",
        this.card?.deployVersion || ""
      ]
    }), this._openUrl(this.card?.learnMoreUrl || "");
  }
  async _detailsCardSelected(e) {
    this.card = e.detail, this.el.scrollIntoView(!0), this._onResize(), this._missingPrivilegeMessages = void 0, await this._getItemData(), this._expandAccordions();
  }
  _expandAccordions() {
    this._overviewAccordionItemElement.value && (this._overviewAccordionItemElement.value.expanded = !0), this._releaseNotesAccordionItemElement.value && (this._releaseNotesAccordionItemElement.value.expanded = !0), this._relatedResourcesAccordionItemElement.value && (this._relatedResourcesAccordionItemElement.value.expanded = !0), this._screenshotsAccordionItemElement.value && (this._screenshotsAccordionItemElement.value.expanded = !0), this._termsOfUseAccordionItemElement.value && (this._termsOfUseAccordionItemElement.value.expanded = !0), this._youMayAlsoLikeAccordionItemElement.value && (this._youMayAlsoLikeAccordionItemElement.value.expanded = !0);
  }
  async _getItemData() {
    const e = this._configContextConsumer.value, t = e?.agoBasedEnterpriseSolutionsGroupId && e?.isEnterprise ? e.anonAgolSession : e?.userSession, i = await z(this.card.id, t), s = await B(this.card.id, t);
    this._itemProperties = s.properties, this.itemPropertiesFetched.emit(this._itemProperties);
    const a = A(i, this.card.typeKeywords, e?.authentication);
    this._privileges = t.username ? a : [], this._userPrivileges = e?.authentication && e?.userSession ? await K(e.authentication, e.userSession, e.authentication.PortalUserPrivileges) : [];
    const o = this._privileges.filter((d) => !this._userPrivileges.includes(d));
    this._missingPrivilegeMessages = O(this._translations, o), this._isDeployDisabled = this._missingPrivilegeMessages && (this._missingPrivilegeMessages.leadingMessages.length > 0 || this._missingPrivilegeMessages.bulletedMessages.length > 0 || this._missingPrivilegeMessages.trailingMessages.length > 0);
    const c = i.params ? await this.formatParams(i.params) : [];
    this._userOptions = c, this._templates = i.templates, this.templatesFetched.emit(i.templates), this._checkUrlParametersForAutoDeployment(), this._isLoaded = !0, this._showLoader && (this._showLoader = !1, this._isDeployDisabled || this._openDeploy());
  }
  formatParams(e) {
    const t = this._configContextConsumer.value.userSession, i = [], s = e ? Object.keys(e) : [], a = {
      id: "",
      props: [],
      accordionDisplay: !1
    };
    if (s.length > 0) {
      const o = [];
      return s.forEach((c) => {
        const d = e[c];
        d.valueType && d.valueType.toLowerCase() === "itemid" && o.push(this._findExistingItem(c, "Feature Service", t.username || ""));
      }), Promise.all(o).then((c) => {
        const d = {};
        return c.forEach((r) => {
          if (r.query && r.results && r.results.length > 0) {
            const k = r.query.split(" ")[0].replace("typekeywords:source-", "");
            d[k] = {
              resultId: r.results[0].id,
              response: r.results[0]
            };
          }
        }), s.forEach((r) => {
          if (r === "serviceLearnMore") {
            this._configureLearnMore = e[r], alert(this._configureLearnMore), delete e[r];
            return;
          }
          e[r].enterpriseIDMapping && (this._customDeploymentMappings[r] = e[r].enterpriseIDMapping), a.id = r, d[r] && (e[r].existingItemId = d[r].resultId, this.updateUserProp(e[r], d[r].response)), this.updateOption(e[r], a, r);
        }), i.push(a), Promise.resolve(i);
      }).catch(() => Promise.resolve([]));
    } else
      return Promise.resolve([]);
  }
  _findExistingItem(e, t, i) {
    const s = this._configContextConsumer.value.userSession;
    return G(`typekeywords:source-${e} type:${t} owner:${i}`, s);
  }
  updateUserProp(e, t) {
    const i = e.itemType?.toLowerCase() === "feature service", s = new RegExp(i ? this._regexFsUrl : e.itemType, "iu"), a = M(t, i ? "url" : "type", "") || "", o = a !== "" && s.test(a);
    return e.responseValue = o ? a : "", e.name = o && v(t, "name") || "", e.title = o && v(t, "title") || "", e.itemType = o ? v(t, "type") : e.itemType, e.validId = o, e.itemUrl = U(t.id, this._configContextConsumer.value.authentication), o;
  }
  updateOption(e, t, i) {
    const s = e.default || "", a = typeof s, o = s.toString();
    this._setFeatureServiceProps(e);
    const c = this.getValidation(e, o);
    t.props.push({
      id: i,
      outType: a,
      prop: i,
      itemType: e.itemType || "",
      responseValue: e.responseValue || "",
      label: e.label || "",
      choices: e.choices || [],
      valueType: e.valueType.toLowerCase(),
      attributes: e.attributes || {},
      value: e.existingItemId && e.valueType.toLowerCase() === "itemid" ? e.existingItemId : o,
      default: o,
      srSearchText: o,
      autoSelect: o !== "",
      ...c,
      loading: !1,
      validId: !0,
      tooltip: e.tooltip || "",
      name: e.name || "",
      title: e.title || "",
      itemUrl: e.itemUrl || ""
    });
  }
  _setFeatureServiceProps(e) {
    e.valueType && e.valueType.toLowerCase() === "itemid" && Y(e, "attributes.required", "true");
  }
  getValidation(e, t) {
    let i = "", s = v(e, "validation.message") || "", a = !0;
    return v(e, "attributes.required") === "true" && (i = M(e, "validation.expression", "\\S{1,}"), a = new RegExp(i).test(t)), e.valueType && e.valueType.toLowerCase() === "itemid" && (i = this._regexID, s = this._translations.configure.invalidID), {
      valid: a,
      validation: {
        expression: i,
        message: s
      }
    };
  }
  _allCardsFetched(e) {
    this._allCards = e.detail;
  }
  _onResize() {
    this._showYouMayAlsoLikeShowMore = (this._youMayAlsoLikeElement.value?.scrollHeight || 0) > this._youMayAlsoLikeBaseHeight, this._showScreenshotsShowMore = (this._screenshotsElement.value?.scrollHeight || 0) > this._screenshotsRowBaseHeight + 2;
  }
  _cleanupPanel() {
    this.el.scrollIntoView(!0), this._isScreenshotsRowExpanded = !1, this._showScreenshotsShowMore = !1, this._screenshotsElement.value?.classList.remove("expanded"), this._isYouMayAlsoLikeRowExpanded = !1, this._showYouMayAlsoLikeShowMore = !1, this._youMayAlsoLikeElement.value?.classList.remove("expanded"), this._privilegePopoverRef.value?.open && (this._privilegePopoverRef.value.open = !1), this._isDeployDisabled = !1, this._isLoaded = !1, this._showLoader = !1, this._expandAccordions();
  }
  _deployProgressStart(e) {
    this._deploymentStartTime = Date.now(), this._telemetry?.logEvent({
      category: g.SOLUTION_DETAILS,
      action: "Deploy Started",
      dimensions: [
        this.card?.title || "",
        this.card?.deployCommonId || "",
        this.card?.deployVersion || ""
      ]
    }), this._deployingDialogRef.value && (this._deployingDialogRef.value.open = !0, this._deployingDialogRef.value.abortController = e.detail), this._deployDialogRef.value && this._deployDialogRef.value.classList.add("display-none");
  }
  _deployProgessUpdated(e) {
    const t = e.detail;
    this._deployingDialogRef.value.deploymentProgress = t.progress;
  }
  _closeDialogs(e = !1) {
    if (this._cancellationStartTime !== null) {
      const t = b(this._cancellationStartTime);
      this._telemetry?.logEvent({
        category: g.SOLUTION_DETAILS,
        action: "Deploy Canceled",
        dimensions: [
          this.card?.title || "",
          this.card?.deployCommonId || "",
          this.card?.deployVersion || ""
        ],
        metrics: [this._deployToCancelDuration, t]
      }), this._cancellationStartTime = null, this._deployToCancelDuration = 0;
    }
    this._deployingDialogRef.value.close(), e ? this._deployDialogRef.value.open = !0 : this._deployDialogRef.value.close(), this._deployDialogRef.value.classList.remove("display-none");
  }
  _handleDeployAppTabSelected(e) {
    e.detail === "details" && this.sortTypeChanged.emit("");
  }
  _checkPermissionsBeforeDeploy() {
    this._isLoaded ? this._openDeploy() : this._configContextConsumer.value.authentication?.IsSignedIn ? this._showLoader = !0 : this._openDeploy();
  }
}
S("solution-details-panel", te);
export {
  te as SolutionDetailsPanel
};
