/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c } from "../../chunks/runtime.js";
import { u as d } from "../../chunks/useT9n.js";
import { LitElement as p, createEvent as o, safeStyleMap as h } from "@arcgis/lumina";
import { useContextConsumer as l } from "@arcgis/lumina/context";
import { css as u, html as i, svg as g } from "lit";
import { c as f, i as b } from "../../chunks/deployAppContexts.js";
import { createRef as s, ref as r } from "lit/directives/ref.js";
import { k as v, l as m } from "../../chunks/helpers.js";
const x = u`calcite-shell-panel{z-index:var(--calcite-z-index-1)}.display-flex{display:flex}.flex-1,.flex-grow{flex:1}.flex-shrink-0{flex:0 0 auto}.leader-1{margin-top:var(--calcite-spacing-xxl)}.trailer-1{margin-bottom:var(--calcite-spacing-xxl)}.warning-text{max-width:35em;margin-left:auto;margin-right:auto;font-size:var(--calcite-font-size-md)}.text-center{text-align:center}.border-override{border-top-width:var(--calcite-border-width-none);border-bottom-width:var(--calcite-border-width-none)}.header-override{--calcite-panel-header-content-space: var(--calcite-spacing-none);--calcite-panel-header-background-color: var(--calcite-color-surface-3)}.panel-override{--calcite-panel-background-color: var(--calcite-color-surface-3);--calcite-panel-border-color: none}.label-override{--calcite-label-margin-bottom: var(--calcite-spacing-none);font-weight:var(--calcite-font-weight-medium)}.header-content-wrapper{padding-inline-start:var(--calcite-spacing-xxs)}.header-button-padding{padding-top:var(--calcite-spacing-sm);padding-bottom:var(--calcite-spacing-sm);padding-inline-start:var(--calcite-spacing-lg);padding-inline-end:var(--calcite-spacing-lg)}.padding-start{padding-inline-start:var(--calcite-spacing-lg)}.align-items-center{align-items:center}.justify-content-end{justify-content:end}.justify-content-start{justify-content:start}.filter-width-350{--calcite-shell-panel-width: 350px}.z-index-2{z-index:2}.mock-fab{--calcite-fab-shadow-internal: 0 6px 20px -4px rgba(0, 0, 0, .1), 0 4px 12px -2px rgba(0, 0, 0, .08);box-shadow:var(--calcite-fab-shadow, var(--calcite-fab-shadow-internal));--calcite-button-background-color: var(--calcite-fab-background-color);--calcite-button-border-color: var(--calcite-fab-border-color);--calcite-button-text-color: var(--calcite-fab-text-color);--calcite-button-loader-color: var(--calcite-fab-loader-color)}.position-relative{position:relative;height:100%;overflow:hidden}.height-100{height:100%}.height-50{height:50px}.sign-in-prompt{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%}.sign-in-icon{transform:translate(-20px)}.height-150{height:150px}.width-150{width:150px}.padding-top-8{padding-top:8px}`;
class _ extends p {
  constructor() {
    super(), this.solutionsCount = 0, this.filterOpen = !0, this.isMobile = !1, this._translations = d({ name: "solutions-deployed-shell", blocking: !0 }), this._configContextConsumer = l({
      context: f,
      subscribe: !0
    }), this._isMobileContextConsumer = l({
      context: b,
      subscribe: !0,
      callback: (e) => this.isMobile = e
    }), this._solutionsDeployedPanelRef = s(), this._mainPanelRef = s(), this._panelFixed = !1, this.filterRemoved = o(), this.tokenRefreshed = o(), this._handleSignIn = () => {
      const e = window.location.pathname.endsWith("deployments") ? "" : "deployments";
      this._configContextConsumer.value?.authentication?.signIn(e);
    }, this.listenOn(window, "deployedCardFetchFailed", (e) => {
      const t = e.detail;
      v({
        kind: "danger",
        icon: "exclamation-mark-triangle",
        title: t.title,
        message: t.message,
        autoClose: !0
      });
    });
  }
  static {
    this.properties = { solutionsCount: 9, filterOpen: 16, isMobile: 16, _translations: 16 };
  }
  static {
    this.styles = x;
  }
  willUpdate(e) {
    e.has("isMobile") && (this.filterOpen = !this.isMobile);
  }
  async searchSolutions(e) {
    this._solutionsDeployedPanelRef.value?.setSearchOptions(e), ("sortType" in e || "searchTerm" in e) && this._solutionsDeployedPanelRef.value?.searchSolutions(e);
  }
  async load() {
    this._isMobileContextConsumer.value && (this.isMobile = this._isMobileContextConsumer.value);
  }
  updated() {
    this._fixPanelContentWrapperFocus();
  }
  _fixPanelContentWrapperFocus() {
    if (!this._panelFixed && this._mainPanelRef.value) {
      const e = this._mainPanelRef.value;
      e.componentOnReady?.().then(() => {
        if (e.shadowRoot) {
          const t = e.shadowRoot.querySelector(".content-wrapper");
          t && (t.tabIndex = -1, this._panelFixed = !0, this._setupPanelObserver());
        }
      }).catch(() => {
        this._panelFixed = !0;
      });
    }
  }
  _setupPanelObserver() {
    if (this._panelObserver)
      return;
    this._panelObserver = new MutationObserver((t) => {
      t.forEach((n) => {
        if (n.type === "attributes" && n.attributeName === "tabindex") {
          const a = n.target;
          a.classList.contains("content-wrapper") && a.tabIndex === 0 && (a.tabIndex = -1);
        }
      });
    });
    const e = this._mainPanelRef.value;
    if (e?.shadowRoot) {
      const t = e.shadowRoot.querySelector(".content-wrapper");
      t && this._panelObserver.observe(t, { attributes: !0, attributeFilter: ["tabindex"] });
    }
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._panelObserver?.disconnect();
  }
  render() {
    if (!this._configContextConsumer.value?.authentication?.IsSignedIn)
      return this._getSignInPrompt();
    const e = this.isMobile ? "justify-content-start" : "";
    return i`<calcite-shell class="position-relative"><calcite-panel class="border-override header-override panel-override z-index-1" ${r(this._mainPanelRef)}><div class=${`display-flex align-items-center height-50 header-content-wrapper ${e}`} slot=header-content><calcite-label class="label-override flex-shrink-0 padding-top-8" layout=inline>${this._translations.numberOfDeployments?.replace("{{count}}", this.solutionsCount.toString())}</calcite-label></div>${this._getSolutionsDeployedPanel()}</calcite-panel></calcite-shell>`;
  }
  _getSignInPrompt() {
    return i`<div class="sign-in-prompt">${this._getSignInIcon()}<div class="text-center leader-1 warning-text trailer-1">${this._translations.signInMessage}</div><calcite-button appearance=outline @click=${this._handleSignIn} @keydown=${(e) => m(e, () => this._handleSignIn())} scale=l>${this._translations.signIn}</calcite-button></div>`;
  }
  _getSolutionsDeployedPanel() {
    const e = this.isMobile && this.filterOpen ? { display: "none" } : "";
    return i`<div><solutions-deployed-panel @deployedCardsFetched=${this._updateSolutionCount} style=${h(e)} ${r(this._solutionsDeployedPanelRef)}></solutions-deployed-panel></div>`;
  }
  _updateSolutionCount(e) {
    this.solutionsCount = e.detail;
  }
  _getSignInIcon() {
    return i`<div class="sign-in-icon"><svg aria-hidden=true viewBox="0 0 64 64" width=200 height=200 xmlns=http://www.w3.org/2000/svg>${g`<path d="M56.9 4.1V60h-.8V4.9H23.3l25.6 7.47v39.26l-28.8 8.4V35h.8v23.97l27.2-7.94V12.97L20.9 5.03V30h-.8V4.1h36.8zM30.735 41.7l.565.566 9.766-9.766-9.766-9.766-.565.567 8.799 8.799H5v.8h34.534l-8.8 8.8z" fill=var(--calcite-color-text-3) />`}</svg></div>`;
  }
}
c("solutions-deployed-shell", _);
export {
  _ as SolutionsDeployedShell
};
