import { c as g } from "../../chunks/runtime.js";
import { html as l } from "lit-html";
import { createRef as u, ref as f } from "lit-html/directives/ref.js";
import { LitElement as V, createEvent as d, noShadowRoot as $ } from "@arcgis/lumina";
import { css as I } 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 x = I`@layer{:host{display:none;background:#bdf2c4}:host([selected]){display:flex}.properties-buttons{display:flex}}`;
class C extends V {
  constructor() {
    super(...arguments), this._flowItemElement = u(), this._switchToVersion = !0, this._switchToVersionCheckboxElement = u(), this._versionNameInputElement = u(), this.selected = !1, this.showBackButton = !1, this.geosceneAlterVersion = d(), this.geosceneCreateVersion = d(), this.geosceneFlowItemBack = d(), this.geosceneFlowItemClose = d();
  }
  static {
    this.properties = { selected: 7, showBackButton: 7, versionPropertiesElementProps: 0 };
  }
  static {
    this.shadowRootOptions = $;
  }
  static {
    this.styles = x;
  }
  load() {
    const { versionPropertiesElementProps: { versionInfo: e } } = this;
    e ? (this._mode = "edit", this._fullVersionName = e.versionIdentifier.name, this._ownerName = this._fullVersionName.substring(0, this._fullVersionName.lastIndexOf(".")), this._versionName = this._fullVersionName.substring(this._fullVersionName.lastIndexOf(".") + 1)) : this._mode = "create";
  }
  updated() {
    this._mode === "create" && this._versionNameInputElement.value?.setFocus();
  }
  async setFocus() {
    this._flowItemElement.value?.setFocus();
  }
  goBack() {
  }
  _handleCancel() {
    this.geosceneFlowItemBack.emit();
  }
  _handleChange(e) {
    const { _mode: i, _ownerName: h, _versionName: m, versionPropertiesElementProps: { currentUser: p, isVersionAdministrator: t, serviceUrl: r, versionInfo: a } } = this;
    let { _alterVersionParameters: c, _createVersionParameters: s } = this;
    switch (i === "create" && (s || (s = {
      access: "public",
      description: "",
      featureServerUrl: r,
      ownerName: p,
      versionName: ""
    })), i === "edit" && (c || (c = {
      featureServerUrl: r,
      versionIdentifier: a.versionIdentifier,
      ownerName: h,
      versionName: m,
      access: a.access,
      description: a.description
    })), e.type) {
      case "calciteChipGroupSelect": {
        const o = e.target.label, n = e.target.selectedItems[0].label;
        i === "create" && (s = { ...s, [o]: n }), i === "edit" && (c = { ...c, [o]: n });
        break;
      }
      case "calciteInputTextInput": {
        const o = e.target.name, n = e.target.value;
        i === "create" && (s = { ...s, [o]: n }), i === "edit" && (c = { ...c, [o]: n });
        break;
      }
      case "calciteTextAreaInput": {
        const o = e.target.name, n = e.target.value;
        i === "create" && (s = { ...s, [o]: n }), i === "edit" && (c = { ...c, [o]: n });
        break;
      }
    }
    i === "create" && (s.access !== "public" && p.toUpperCase() !== s.ownerName?.toUpperCase() && !t ? (this._switchToVersionCheckboxElement.value.checked = !1, this._switchToVersionCheckboxElement.value.disabled = !0, this._switchToVersion = !1) : this._switchToVersionCheckboxElement.value.disabled = !1, this._createVersionParameters = s), i === "edit" && (this._alterVersionParameters = c);
  }
  _handleClose() {
    this.geosceneFlowItemClose.emit();
  }
  _handleSave() {
    const { _alterVersionParameters: e, _createVersionParameters: i, _mode: h, _switchToVersion: m } = this;
    h === "create" && this.geosceneCreateVersion.emit({
      createVersionParameters: i,
      switchToVersion: m
    }), h === "edit" && this.geosceneAlterVersion.emit({
      alterVersionParameters: e
    });
  }
  _handleSwitchToVersionChange(e) {
    this._switchToVersion = e.target.checked;
  }
  render() {
    const { selected: e, showBackButton: i, versionPropertiesElementProps: { closable: h, currentUser: m, state: p, strings: t, versionInfo: r }, _mode: a, _ownerName: c, _versionName: s } = this, o = l`<div class="properties-buttons"><calcite-button appearance=outline width=half @click=${this._handleCancel}>${t.actions.cancelSave}</calcite-button><calcite-button width=half @click=${this._handleSave}>${t.actions.saveVersion}</calcite-button></div>`, n = l`<calcite-label>${t.input.versionAccess}<calcite-chip-group label=access @calciteChipGroupSelect=${this._handleChange} selection-mode=single-persist><calcite-chip .selected=${a === "edit" && r.access === "public" || a === "create"} label=public>${t.accessLevels.public}</calcite-chip><calcite-chip .selected=${a === "edit" && r.access === "protected"} label=protected>${t.accessLevels.protected}</calcite-chip><calcite-chip .selected=${a === "edit" && r.access === "private"} label=private>${t.accessLevels.private}</calcite-chip></calcite-chip-group></calcite-label>`, v = l`<calcite-label>${t.input.versionDescription}<calcite-text-area name=description @calciteTextAreaInput=${this._handleChange} resize=vertical .value=${a === "edit" ? r.description : ""}></calcite-text-area></calcite-label>`, b = l`<calcite-label>${t.input.versionName}<calcite-input-text name=versionName @calciteInputTextInput=${this._handleChange} max-length=62 .value=${a === "edit" ? s : ""} ${f(this._versionNameInputElement)}></calcite-input-text></calcite-label>`, _ = l`<calcite-label>${t.input.versionOwner}<calcite-input-text name=ownerName @calciteInputTextInput=${this._handleChange} .value=${a === "edit" ? c : m}></calcite-input-text></calcite-label>`, w = a === "create" ? l`<calcite-label layout=inline><calcite-checkbox checked name=switchToVersion @calciteCheckboxChange=${this._handleSwitchToVersionChange} ${f(this._switchToVersionCheckboxElement)}></calcite-checkbox>${t.actions.switchToVersion}</calcite-label>` : void 0;
    return l`<calcite-flow-item .closable=${h} .description=${r ? r.versionIdentifier.name : ""} .heading=${r ? t.actions.editVersion : t.actions.newVersion} .selected=${e} .showBackButton=${i} @calciteFlowItemClose=${this._handleClose} ${f(this._flowItemElement)}><calcite-panel .loading=${p === "executing"}><calcite-block .label=${t.headers.versionProperties} open>${b}${v}${n}${_}${w}${o}</calcite-block></calcite-panel></calcite-flow-item>`;
  }
}
g("geoscene-version-management-version-properties", C);
export {
  C as GeosceneVersionManagementVersionProperties
};