import { c as B } from "../../chunks/runtime.js";
import { html as s } from "lit";
import { createRef as f, ref as m } from "lit-html/directives/ref.js";
import { LitElement as L, createEvent as r } from "@arcgis/lumina";
import { css as y } from "@lit/reactive-element/css-tag.js";
/*! All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
v4.33.18 */
const N = y`:host{display:none;background:#bdf2c4}:host([selected]){display:flex}calcite-block{margin-block:0}calcite-pagination{justify-content:center}`;
class U extends L {
  constructor() {
    super(...arguments), this._filterInputElement = f(), this._flowItemElement = f(), this.currentPage = 1, this.selected = !1, this.showBackButton = !1, this.geosceneFlowItemBack = r(), this.geosceneFlowItemClose = r(), this.geosceneGetVersions = r(), this.geosceneManageVersion = r(), this.geosceneNewVersion = r();
  }
  static {
    this.properties = { _filteredVersionInfos: 16, currentPage: 11, selected: 7, showBackButton: 7, versionListElementProps: 0 };
  }
  static {
    this.styles = N;
  }
  load() {
    this._filteredVersionInfos = this.versionListElementProps.versionInfos;
  }
  willUpdate(e) {
    if (e.has("versionListElementProps")) {
      const t = e.get("versionListElementProps"), i = this.versionListElementProps;
      t?.versionInfos !== i.versionInfos && (this._filteredVersionInfos = i.versionInfos, this._filterInputElement.value && this._handleFilterChange());
    }
  }
  updated() {
    this._filterInputElement.value?.setFocus();
  }
  async setFocus() {
    this._flowItemElement.value?.setFocus();
  }
  goBack() {
  }
  _handleFilterChange() {
    const { versionListElementProps: { versionInfos: e } } = this, t = this._filterInputElement.value.value.toUpperCase();
    this._filteredVersionInfos = t === "" ? e : e.filter((i) => i.versionIdentifier.name.toUpperCase().includes(t) || i.versionIdentifier.guid.toUpperCase().includes(t)), this._filteredVersionInfos.length && (this.currentPage = 1);
  }
  _handleNoticeClosed() {
    this.versionListElementProps = { ...this.versionListElementProps, executionError: void 0 };
  }
  _handlePaginationChange(e) {
    this.currentPage = e.target.startItem;
  }
  _getExecutionError(e) {
    const { versionListElementProps: { strings: { executionErrors: t } } } = this;
    switch (e) {
      case "no-feature-service-found":
        return t.noFeatureServiceFound;
      case "no-valid-enterprise-version":
        return t.notValidEnterpriseVersion;
      case "no-valid-version-name":
        return t.invalidVersionName;
      default:
        return e;
    }
  }
  _paginate(e, t, i) {
    return e.slice((i - 1) * t, i * t);
  }
  render() {
    const { currentPage: e, selected: t, showBackButton: i, versionListElementProps: { closable: g, currentUser: p, currentVersionIdentifier: l, executionError: c, heading: u, isVersionAdministrator: v, isVersioningApiAvailable: h, pageSize: o, serviceName: I, serviceUrl: a, state: V, strings: { headers: d }, strings: n, versionInfos: $ } } = this, _ = s`<calcite-block .heading=${d.currentVersion} .description=${l.name} overlay-positioning=fixed></calcite-block>`, E = s`<calcite-action id=actionRefreshVersions icon=refresh text @click=${() => this.geosceneGetVersions.emit({ serviceUrl: a })} slot=header-actions-end><calcite-tooltip overlay-positioning=fixed reference-element=actionRefreshVersions><span>${n.actions.refreshVersions}</span></calcite-tooltip></calcite-action>`;
    this._paginatedVersionInfos = this._filteredVersionInfos.length > o ? this._paginate(this._filteredVersionInfos, o, e) : this._filteredVersionInfos;
    const w = this._filteredVersionInfos.length > o ? s`<calcite-pagination @calcitePaginationChange=${this._handlePaginationChange} page-size=1 .startItem=${e} .totalItems=${Math.ceil(this._filteredVersionInfos.length / o)}></calcite-pagination>` : void 0, P = this._paginate(this._paginatedVersionInfos, o, 1).map((F) => s`<geoscene-version-management-version-item .versionItemElementProps=${{
      currentUser: p,
      currentVersionIdentifier: l,
      isCurrentVersionCard: !1,
      isVersionAdministrator: v,
      isVersioningApiAvailable: h,
      serviceUrl: a,
      strings: n,
      versionInfo: F
    }}></geoscene-version-management-version-item>`), b = $.length > o ? s`<calcite-block heading .label=${d.filterVersions} open><calcite-input-text clearable icon=search @calciteInputTextInput=${this._handleFilterChange} .placeholder=${n.actions.searchVersions} ${m(this._filterInputElement)}></calcite-input-text></calcite-block>` : void 0, k = s`<calcite-list .label=${n.labels.versionList}>${P}</calcite-list>`, x = h ? s`<calcite-fab appearance=outline-fill slot=fab text-enabled .text=${n.actions.newVersion} @click=${() => this.geosceneNewVersion.emit({ serviceUrl: a })}></calcite-fab>` : void 0, C = c ? s`<calcite-notice @calciteNoticeClose=${this._handleNoticeClosed} class="notice" closable kind=warning open scale=s slot=footer width=full><div slot=message>${this._getExecutionError(c)}</div></calcite-notice>` : void 0;
    return s`<calcite-flow-item .closable=${g} .description=${I} .heading=${u} .selected=${t} .showBackButton=${i} @calciteFlowItemBack=${() => this.geosceneFlowItemBack.emit()} @calciteFlowItemClose=${() => this.geosceneFlowItemClose.emit()} ${m(this._flowItemElement)}><calcite-panel .loading=${V === "executing"}>${_}<calcite-panel .heading=${this._filteredVersionInfos.length ? `${n.headers.manageVersions} (${this._filteredVersionInfos.length})` : n.headers.manageVersions}>${E}${b}${k}${x}</calcite-panel>${w}${C}</calcite-panel></calcite-flow-item>`;
  }
}
B("geoscene-version-management-version-list", U);
export {
  U as GeosceneVersionManagementVersionList
};