import { c as y } from "../../chunks/runtime.js";
import { once as k, watch as V } from "@arcgis/core/core/reactiveUtils.js";
import E from "@arcgis/core/widgets/VersionManagement/VersionManagementViewModel.js";
import { LitElement as S, createEvent as p, safeClassMap as L } from "@arcgis/lumina";
import { css as P, render as C, html as f } from "lit";
import { createRef as z, ref as N } from "lit/directives/ref.js";
import { u as M } from "../../chunks/useT9n.js";
import { m as F } from "../../chunks/useViewModel.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const $ = P`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{--esri-widget-padding-x: 15px;--esri-widget-padding-y: var(--calcite-spacing-md);--esri-widget-padding: var(--esri-widget-padding-y) var(--esri-widget-padding-x);box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.esri-hidden{display:none!important}[class^=esri-icon-],[class*=" esri-icon-"]{speak:none;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-style:normal;font-weight:var(--calcite-font-weight-normal);line-height:1;font-family:CalciteWebCoreIcons!important}.esri-icon-close:before{content:"";color:inherit}.esri-icon-drag-horizontal:before{content:"";color:inherit}.esri-icon-drag-vertical:before{content:"";color:inherit}.esri-icon-handle-horizontal:before{content:"";color:inherit}.esri-icon-handle-vertical:before{content:"";color:inherit}.esri-icon-check-mark:before{content:"";color:inherit}.esri-icon-left-triangle-arrow:before{content:"";color:inherit}.esri-icon-right-triangle-arrow:before{content:"";color:inherit}.esri-icon-down-arrow:before{content:"";color:inherit}.esri-icon-up-arrow:before{content:"";color:inherit}.esri-icon-overview-arrow-bottom-left:before{content:"";color:inherit}.esri-icon-overview-arrow-bottom-right:before{content:"";color:inherit}.esri-icon-overview-arrow-top-left:before{content:"";color:inherit}.esri-icon-overview-arrow-top-right:before{content:"";color:inherit}.esri-icon-maximize:before{content:"";color:inherit}.esri-icon-minimize:before{content:"";color:inherit}.esri-icon-checkbox-unchecked:before{content:"";color:inherit}.esri-icon-checkbox-checked:before{content:"";color:inherit}.esri-icon-radio-unchecked:before{content:"";color:inherit}.esri-icon-radio-checked:before{content:"";color:inherit}.esri-icon-up-arrow-circled:before{content:"";color:inherit}.esri-icon-down-arrow-circled:before{content:"";color:inherit}.esri-icon-left-arrow-circled:before{content:"";color:inherit}.esri-icon-right-arrow-circled:before{content:"";color:inherit}.esri-icon-zoom-out-fixed:before{content:"";color:inherit}.esri-icon-zoom-in-fixed:before{content:"";color:inherit}.esri-icon-refresh:before{content:"";color:inherit}.esri-icon-edit:before{content:"";color:inherit}.esri-icon-authorize:before{content:"";color:inherit}.esri-icon-map-pin:before{content:"";color:inherit}.esri-icon-blank-map-pin:before{content:"";color:inherit}.esri-icon-table:before{content:"";color:inherit}.esri-icon-plus:before{content:"+";color:inherit}.esri-icon-minus:before{content:"";color:inherit}.esri-icon-beginning:before{content:"";color:inherit}.esri-icon-reverse:before{content:"";color:inherit}.esri-icon-pause:before{content:"";color:inherit}.esri-icon-play:before{content:"";color:inherit}.esri-icon-forward:before{content:"";color:inherit}.esri-icon-end:before{content:"";color:inherit}.esri-icon-erase:before{content:"";color:inherit}.esri-icon-up-down-arrows:before{content:"";color:inherit}.esri-icon-left:before{content:"";color:inherit}.esri-icon-right:before{content:"";color:inherit}.esri-icon-announcement:before{content:"";color:inherit}.esri-icon-notice-round:before{content:"";color:inherit}.esri-icon-notice-triangle:before{content:"";color:inherit}.esri-icon-home:before{content:"";color:inherit}.esri-icon-locate:before{content:"";color:inherit}.esri-icon-expand:before{content:"";color:inherit}.esri-icon-collapse:before{content:"";color:inherit}.esri-icon-layer-list:before{content:"";color:inherit}.esri-icon-basemap:before{content:"";color:inherit}.esri-icon-globe:before{content:"";color:inherit}.esri-icon-applications:before{content:"";color:inherit}.esri-icon-arrow-up-circled:before{content:"";color:inherit}.esri-icon-arrow-down-circled:before{content:"";color:inherit}.esri-icon-arrow-left-circled:before{content:"";color:inherit}.esri-icon-arrow-right-circled:before{content:"";color:inherit}.esri-icon-minus-circled:before{content:"";color:inherit}.esri-icon-plus-circled:before{content:"";color:inherit}.esri-icon-add-attachment:before{content:"";color:inherit}.esri-icon-attachment:before{content:"";color:inherit}.esri-icon-calendar:before{content:"";color:inherit}.esri-icon-close-circled:before{content:"";color:inherit}.esri-icon-browser:before{content:"";color:inherit}.esri-icon-collection:before{content:"";color:inherit}.esri-icon-comment:before{content:"";color:inherit}.esri-icon-configure-popup:before{content:"";color:inherit}.esri-icon-contact:before{content:"";color:inherit}.esri-icon-dashboard:before{content:"";color:inherit}.esri-icon-deny:before{content:"";color:inherit}.esri-icon-description:before{content:"";color:inherit}.esri-icon-directions:before{content:"";color:inherit}.esri-icon-directions2:before{content:"";color:inherit}.esri-icon-documentation:before{content:"";color:inherit}.esri-icon-duplicate:before{content:"";color:inherit}.esri-icon-review:before{content:"";color:inherit}.esri-icon-environment-settings:before{content:"";color:inherit}.esri-icon-error:before{content:"";color:inherit}.esri-icon-error2:before{content:"";color:inherit}.esri-icon-experimental:before{content:"";color:inherit}.esri-icon-feature-layer:before{content:"";color:inherit}.esri-icon-filter:before{content:"";color:inherit}.esri-icon-grant:before{content:"";color:inherit}.esri-icon-group:before{content:"";color:inherit}.esri-icon-key:before{content:"";color:inherit}.esri-icon-labels:before{content:"";color:inherit}.esri-icon-tag:before{content:"";color:inherit}.esri-icon-layers:before{content:"";color:inherit}.esri-icon-left-arrow:before{content:"";color:inherit}.esri-icon-right-arrow:before{content:"";color:inherit}.esri-icon-link-external:before{content:"";color:inherit}.esri-icon-link:before{content:"";color:inherit}.esri-icon-loading-indicator:before{content:"";color:inherit}.esri-icon-maps:before{content:"";color:inherit}.esri-icon-marketplace:before{content:"";color:inherit}.esri-icon-media:before{content:"";color:inherit}.esri-icon-media2:before{content:"";color:inherit}.esri-icon-menu:before{content:"";color:inherit}.esri-icon-mobile:before{content:"";color:inherit}.esri-icon-phone:before{content:"";color:inherit}.esri-icon-navigation:before{content:"";color:inherit}.esri-icon-pan:before{content:"";color:inherit}.esri-icon-printer:before{content:"";color:inherit}.esri-icon-pie-chart:before{content:"";color:inherit}.esri-icon-chart:before{content:"";color:inherit}.esri-icon-line-chart:before{content:"";color:inherit}.esri-icon-question:before{content:"";color:inherit}.esri-icon-resend-invitation:before{content:"";color:inherit}.esri-icon-rotate:before{content:"";color:inherit}.esri-icon-save:before{content:"";color:inherit}.esri-icon-settings:before{content:"";color:inherit}.esri-icon-settings2:before{content:"";color:inherit}.esri-icon-share:before{content:"";color:inherit}.esri-icon-sign-out:before{content:"";color:inherit}.esri-icon-support:before{content:"";color:inherit}.esri-icon-user:before{content:"";color:inherit}.esri-icon-time-clock:before{content:"";color:inherit}.esri-icon-trash:before{content:"";color:inherit}.esri-icon-upload:before{content:"";color:inherit}.esri-icon-download:before{content:"";color:inherit}.esri-icon-zoom-in-magnifying-glass:before{content:"";color:inherit}.esri-icon-search:before{content:"";color:inherit}.esri-icon-zoom-out-magnifying-glass:before{content:"";color:inherit}.esri-icon-locked:before{content:"";color:inherit}.esri-icon-unlocked:before{content:"";color:inherit}.esri-icon-favorites:before{content:"";color:inherit}.esri-icon-compass:before{content:"";color:inherit}.esri-icon-down:before{content:"";color:inherit}.esri-icon-up:before{content:"";color:inherit}.esri-icon-chat:before{content:"";color:inherit}.esri-icon-dock-bottom:before{content:"";color:inherit}.esri-icon-dock-left:before{content:"";color:inherit}.esri-icon-dock-right:before{content:"";color:inherit}.esri-icon-organization:before{content:"";color:inherit}.esri-icon-north-navigation:before{content:"";color:inherit}.esri-icon-locate-circled:before{content:"";color:inherit}.esri-icon-dial:before{content:"";color:inherit}.esri-icon-polygon:before{content:"";color:inherit}.esri-icon-polyline:before{content:"";color:inherit}.esri-icon-visible:before{content:"";color:inherit}.esri-icon-non-visible:before{content:"";color:inherit}.esri-icon-link-vertical:before{content:"";color:inherit}.esri-icon-unlocked-link-vertical:before{content:"";color:inherit}.esri-icon-link-horizontal:before{content:"";color:inherit}.esri-icon-unlocked-link-horizontal:before{content:"";color:inherit}.esri-icon-swap:before{content:"";color:inherit}.esri-icon-cta-link-external:before{content:"";color:inherit}.esri-icon-reply:before{content:"";color:inherit}.esri-icon-public:before{content:"";color:inherit}.esri-icon-share2:before{content:"";color:inherit}.esri-icon-launch-link-external:before{content:"";color:inherit}.esri-icon-rotate-back:before{content:"";color:inherit}.esri-icon-pan2:before{content:"";color:inherit}.esri-icon-tracking:before{content:"";color:inherit}.esri-icon-expand2:before{content:"";color:inherit}.esri-icon-arrow-down:before{content:"";color:inherit}.esri-icon-arrow-up:before{content:"";color:inherit}.esri-icon-hollow-eye:before{content:"";color:inherit}.esri-icon-play-circled:before{content:"";color:inherit}.esri-icon-volume-off:before{content:"";color:inherit}.esri-icon-volume-on:before{content:"";color:inherit}.esri-icon-bookmark:before{content:"";color:inherit}.esri-icon-lightbulb:before{content:"";color:inherit}.esri-icon-sketch-rectangle:before{content:"";color:inherit}.esri-icon-north-navigation-filled:before{content:"";color:inherit}.esri-icon-default-action:before{content:"";color:inherit}.esri-icon-undo:before{content:"";color:inherit}.esri-icon-redo:before{content:"";color:inherit}.esri-icon-cursor:before{content:"";color:inherit}.esri-icon-cursor-filled:before{content:"";color:inherit}.esri-icon-measure:before{content:"";color:inherit}.esri-icon-measure-line:before{content:"";color:inherit}.esri-icon-measure-area:before{content:"";color:inherit}.esri-icon-legend:before{content:"";color:inherit}.esri-icon-sliders:before{content:"";color:inherit}.esri-icon-sliders-horizontal:before{content:"";color:inherit}.esri-icon-cursor-marquee:before{content:"";color:inherit}.esri-icon-lasso:before{content:"";color:inherit}.esri-icon-elevation-profile:before{content:"";color:inherit}.esri-icon-slice:before{content:"";color:inherit}.esri-icon-line-of-sight:before{content:"";color:inherit}.esri-icon-zoom-to-object:before{content:"";color:inherit}.esri-icon-urban-model:before{content:"";color:inherit}.esri-icon-measure-building-height-shadow:before{content:"";color:inherit}.esri-icon-partly-cloudy:before{content:"";color:inherit}:host{max-width:fit-content}.arcgis-version-management{.component-container-flow{width:350px}.invalid-initial-version-notice{margin-bottom:1rem}.service-items-panel{z-index:unset!important}calcite-block{margin:0}}`, A = F(E), u = "map-components:version-management";
class T extends S {
  constructor() {
    super(...arguments), this.flowElement = z(), this.messages = M({ blocking: !0 }), this.viewModel = A(this), this._isInitialVersionInvalid = /* @__PURE__ */ new Map(), this._initialVersionInfos = [], this._showInvalidFeatureServiceNotice = !1, this.allowEditingDisabled = !1, this.autoDestroyDisabled = !1, this.closable = !1, this.pageSize = 5, this.state = this.viewModel.state, this.versioningStates = this.viewModel.versioningStates, this.view = this.viewModel.view, this.arcgisReady = p(), this.arcgisVersioningStateChanged = p();
  }
  static {
    this.properties = { versionList: 16, _showInvalidFeatureServiceNotice: 16, allowEditingDisabled: 5, autoDestroyDisabled: 5, closable: 7, initialVersionInfos: 0, icon: 1, label: 3, messageOverrides: 0, mode: 1, pageSize: 9, position: 1, referenceElement: 1, state: 3, versioningStates: 0, view: 0 };
  }
  static {
    this.styles = $;
  }
  get initialVersionInfos() {
    return this._initialVersionInfos;
  }
  set initialVersionInfos(e) {
    this._initialVersionInfos = e.map((i) => ({
      ...i,
      url: this._removeTrailingSlash(i.url)
    }));
  }
  async destroy() {
    await this.manager.destroy();
  }
  async load() {
    k(() => this.viewModel.state === "ready").then(() => {
      this.initialVersionInfos.forEach((e) => {
        try {
          this._changeToInitialVersion(e);
        } catch (i) {
          console.error(i);
        }
      });
    }), this.manager.onLifecycle(() => [
      V(() => this.viewModel.state, (e) => {
        const { flowElement: { value: i }, versionList: r } = this, o = i?.getElementsByTagName("arcgis-version-management-version-properties")[0];
        if (e === "disabled" && i) {
          o && this._removeVersionPropertiesFlowItem(i), r && this._removeVersionListFlowItem(i);
          return;
        }
        r && (r.versionListElementProps = {
          ...r.versionListElementProps,
          executionError: this.viewModel.executionError
        }, r.versionListElementProps = { ...r.versionListElementProps, state: e }), o && (o.versionPropertiesElementProps = {
          ...o.versionPropertiesElementProps,
          state: e
        });
      })
    ]);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.versionPropertiesContainer?.remove();
  }
  _removeTrailingSlash(e) {
    return e.replace(/\/+$/u, "");
  }
  _createVersionPropertiesFlowItem(e, i) {
    const { closable: r, viewModel: o, viewModel: { state: n } } = this, c = {
      closable: r,
      currentUser: o.userLookup.get(e),
      isVersionAdministrator: o.versionAdministratorLookup.get(e),
      serviceUrl: e,
      state: n,
      strings: this.messages,
      versionInfo: i
    };
    this.versionPropertiesContainer = document.createElement("div");
    const t = C(f`<arcgis-version-management-version-properties .versionPropertiesElementProps=${c} selected show-back-button></arcgis-version-management-version-properties>`, this.versionPropertiesContainer), s = Array.from(t.parentNode.childNodes).find((a) => a.nodeName.toUpperCase() === "ARCGIS-VERSION-MANAGEMENT-VERSION-PROPERTIES");
    return this.listenOn(s, "arcgisFlowItemBack", () => {
      this._removeVersionPropertiesFlowItem(this.flowElement.value);
    }), this.listenOn(s, "calciteFlowItemBack", (a) => {
      a.preventDefault(), this._removeVersionPropertiesFlowItem(this.flowElement.value), this.versionList && (this.versionList.selected = !0);
    }), this.listenOn(s, "calciteFlowItemClose", this._handleFlowItemClose), this.listenOn(s, "arcgisCreateVersion", this._handleCreateVersion), this.listenOn(s, "arcgisAlterVersion", this._handleAlterVersion), s;
  }
  _getLoadError(e) {
    const { messages: i } = this;
    switch (e) {
      case "no-feature-services":
        return i.loadErrors.noFeatureServices;
      case "no-view-property":
        return i.loadErrors.noViewProperty;
      default:
        return e;
    }
  }
  async _handleAlterVersion(e) {
    const { flowElement: { value: i }, viewModel: r } = this, { alterVersionParameters: o } = e.detail;
    await r.alterVersion(o).then(async (n) => {
      n && this.arcgisVersioningStateChanged.emit({
        type: "version-changed",
        versionIdentifier: o.versionIdentifier,
        versioningState: r.versioningStateLookup.get(o.featureServerUrl)
      }), await this._refreshVersionList(o.featureServerUrl);
    }).finally(() => {
      i && this._removeVersionPropertiesFlowItem(i);
    });
  }
  _handleCreateVersion(e) {
    const { flowElement: { value: i }, viewModel: r } = this, { createVersionParameters: o, switchToVersion: n } = e.detail;
    r.createVersion(o).then(async (c) => {
      c && this.arcgisVersioningStateChanged.emit({
        type: "version-created",
        versionIdentifier: c.versionIdentifier,
        versioningState: r.versioningStateLookup.get(o.featureServerUrl)
      }), n && await this.viewModel.changeVersion(o.featureServerUrl, c.versionIdentifier.name, c.versionIdentifier.guid).then((t) => {
        t && this.arcgisVersioningStateChanged.emit({
          type: "version-switched",
          versionIdentifier: c.versionIdentifier,
          versioningState: r.versioningStateLookup.get(o.featureServerUrl)
        });
      }), await this._refreshVersionList(o.featureServerUrl);
    }).finally(() => {
      i && this._removeVersionPropertiesFlowItem(i);
    });
  }
  _changeToInitialVersion(e) {
    const { _isInitialVersionInvalid: i, viewModel: r } = this, { url: o, name: n } = e, c = r.versioningStateLookup.get(o);
    if (!c)
      throw this._showInvalidFeatureServiceNotice = !0, new Error(`${u} - no versioning state found for feature service ${o}`);
    const t = c?.versionInfos.find((g) => g.versionIdentifier.name === n);
    if (!t)
      throw i.set(o, !0), new Error(`${u} - version ${n} not found in the versioning state for feature service ${o}`);
    const s = t.versionIdentifier, a = c?.currentVersionInfo?.versionIdentifier;
    s.guid !== a?.guid && r.changeVersion(o, s.name, s.guid);
  }
  _handleFlowItemClose() {
    const e = document.querySelector("arcgis-version-management");
    e.parentElement?.removeChild(e);
  }
  async _handleNewVersionAction(e) {
    const i = this._createVersionPropertiesFlowItem(e.detail.serviceUrl, void 0);
    this.flowElement.value?.appendChild(i), this.versionList && (this.versionList.selected = !1);
  }
  async _handleManageVersionAction(e) {
    const { actionType: i, serviceUrl: r, versionInfo: o } = e.detail, { viewModel: n, flowElement: c } = this;
    switch (i) {
      case "changeVersion": {
        n.changeVersion(r, o.versionIdentifier.name, o.versionIdentifier.guid).then((t) => {
          t && this.arcgisVersioningStateChanged.emit({
            type: "version-switched",
            versionIdentifier: o.versionIdentifier,
            versioningState: n.versioningStateLookup.get(r)
          });
          const { versionList: s } = this;
          s && (s.versionListElementProps = {
            ...s.versionListElementProps,
            currentVersionIdentifier: n.versioningStateLookup.get(r).currentVersionInfo.versionIdentifier
          });
        });
        break;
      }
      case "deleteVersion": {
        n.deleteVersion(r, o.versionIdentifier.name, o.versionIdentifier.guid).then(async (t) => {
          t && this.arcgisVersioningStateChanged.emit({
            type: "version-deleted",
            versionIdentifier: o.versionIdentifier,
            versioningState: n.versioningStateLookup.get(r)
          }), await this._refreshVersionList(r);
        });
        break;
      }
      case "editVersion": {
        const t = this._createVersionPropertiesFlowItem(r, o);
        c.value?.appendChild(t), this.versionList && (this.versionList.selected = !1);
        break;
      }
    }
  }
  async _refreshVersionList(e) {
    const { flowElement: { value: i }, versionList: r, viewModel: o } = this;
    if (i) {
      const n = await o.getVersionInfos(e), c = i.getElementsByTagName("arcgis-version-management-service-item");
      for (const t of c)
        t.serviceItemElementProps.serviceUrl === e && (t.serviceItemElementProps = { ...t.serviceItemElementProps, versionInfos: n });
      r && (r.versionListElementProps = {
        ...r.versionListElementProps,
        currentVersionIdentifier: o.versioningStateLookup.get(e).currentVersionInfo.versionIdentifier,
        versionInfos: n
      });
    }
  }
  _removeVersionListFlowItem(e) {
    for (const i of e.childNodes)
      i.nodeName.toUpperCase() === "ARCGIS-VERSION-MANAGEMENT-VERSION-LIST" && (e.removeChild(i), this.versionList = void 0), i.nodeName.toUpperCase() === "CALCITE-FLOW-ITEM" && (i.hidden = !1);
  }
  _removeVersionPropertiesFlowItem(e) {
    for (const i of e.childNodes)
      i.nodeName.toUpperCase() === "ARCGIS-VERSION-MANAGEMENT-VERSION-PROPERTIES" && e.removeChild(i);
  }
  render() {
    const { allowEditingDisabled: e, closable: i, flowElement: { value: r }, initialVersionInfos: o, _isInitialVersionInvalid: n, label: c, messages: t, mode: s, pageSize: a, versionList: g, viewModel: d, viewModel: { loadError: v, state: h } } = this, w = Array.from(d.serviceNameLookup, ([l, m]) => ({ url: l, name: m })), _ = h !== "disabled" ? w.map((l) => {
      const m = {
        allowEditing: !e,
        closable: i,
        currentUser: d.userLookup.get(l.url),
        currentVersionIdentifier: d.versioningStateLookup.get(l.url).currentVersionInfo.versionIdentifier,
        executionError: void 0,
        flowElement: r,
        heading: c,
        initialVersionInfos: o,
        isInitialVersionInvalid: n,
        isVersionAdministrator: d.versionAdministratorLookup.get(l.url),
        isVersioningApiAvailable: (d.serverVersionLookup.get(l.url) ?? 0) >= 11.2,
        mode: s,
        pageSize: a,
        serviceName: l.name,
        state: h,
        serviceUrl: l.url,
        strings: t,
        versionInfos: d.versioningStateLookup.get(l.url)?.versionInfos ?? []
      };
      return f`<arcgis-version-management-service-item .serviceItemElementProps=${m} @arcgisFlowItemBack=${() => {
        r && (this._removeVersionListFlowItem(r), this.versionList = void 0);
      }} @arcgisFlowItemClose=${() => this._handleFlowItemClose()} @arcgisGetVersions=${async (b) => {
        await this._refreshVersionList(b.detail.serviceUrl);
      }} @arcgisManageVersion=${this._handleManageVersionAction} @arcgisNewVersion=${this._handleNewVersionAction} @arcgisCreateVersionList=${(b) => this.versionList = b.detail}></arcgis-version-management-service-item>`;
    }) : void 0, x = h === "disabled" && v != null ? f`<calcite-notice class="notice" kind=warning open scale=s slot=footer width=full><div slot=message>${this._getLoadError(v)}</div></calcite-notice>` : void 0, I = this._showInvalidFeatureServiceNotice ? f`<calcite-notice closable kind=warning open scale=s slot=content-top width=full icon @calciteNoticeClose=${() => this._showInvalidFeatureServiceNotice = !1}><div slot=title>${t.headers.invalidInitialFeatureService}</div><div slot=message>${t.loadErrors.invalidInitialFeatureService}</div></calcite-notice>` : void 0;
    return f`<div class="arcgis-version-management"><calcite-flow custom-item-selectors="arcgis-version-management-version-list, arcgis-version-management-version-properties" class=${L(this.mode === "dialog" ? "" : "component-container-flow")} ${N(this.flowElement)}><calcite-flow-item .closable=${this.closable} .heading=${c ?? void 0} @calciteFlowItemClose=${() => this._handleFlowItemClose()} .selected=${!g}>${I}<calcite-panel class="service-items-panel" .loading=${h === "loading" || h === "executing"}>${_}${x}</calcite-panel></calcite-flow-item></calcite-flow></div>`;
  }
}
y("arcgis-version-management", T);
export {
  T as ArcgisVersionManagement
};
