/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as $ } from "../../chunks/runtime.js";
import { css as V, html as l } from "lit";
import { LitElement as C, createEvent as p } from "@arcgis/lumina";
import { createRef as u, ref as v } from "lit/directives/ref.js";
const I = V`:host{min-height:var(--arcgis-internal-panel-height-md, 420px);height:100%}`;
class x extends C {
  constructor() {
    super(...arguments), this._flowItemElement = u(), this._switchToVersion = !0, this._switchToVersionCheckboxElement = u(), this._versionNameInputElement = u(), this.selected = !1, this.showBackButton = !1, this.arcgisAlterVersion = p(), this.arcgisCreateVersion = p(), this.arcgisFlowItemBack = p(), this.arcgisFlowItemClose = p();
  }
  static {
    this.properties = { _validationError: 16, selected: 7, showBackButton: 7, versionPropertiesElementProps: 0 };
  }
  static {
    this.styles = I;
  }
  load() {
    const { versionPropertiesElementProps: { versionInfo: t } } = this;
    t ? (this._mode = "edit", this._fullVersionName = t.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.arcgisFlowItemBack.emit();
  }
  _handleChange(t) {
    const { _mode: s, _ownerName: h, _versionName: d, versionPropertiesElementProps: { currentUser: m, isVersionAdministrator: e, serviceUrl: c, versionInfo: i } } = this;
    let { _alterVersionParameters: r, _createVersionParameters: a } = this;
    switch (s === "create" && (a || (a = {
      access: "public",
      description: "",
      featureServerUrl: c,
      ownerName: m,
      versionName: ""
    })), s === "edit" && (r || (r = {
      featureServerUrl: c,
      versionIdentifier: i.versionIdentifier,
      ownerName: h,
      versionName: d,
      access: i.access,
      description: i.description
    })), t.type) {
      case "calciteChipGroupSelect": {
        const o = t.target.label, n = t.target.selectedItems[0].label;
        s === "create" && (a = { ...a, [o]: n }), s === "edit" && (r = { ...r, [o]: n });
        break;
      }
      case "calciteInputTextInput": {
        const o = t.target.name, n = t.target.value;
        s === "create" && (a = { ...a, [o]: n }), s === "edit" && (r = { ...r, [o]: n });
        break;
      }
      case "calciteTextAreaInput": {
        const o = t.target.name;
        if (o != null) {
          const n = t.target.value;
          s === "create" && (a = { ...a, [o]: n }), s === "edit" && (r = { ...r, [o]: n });
        }
        break;
      }
    }
    s === "create" && (a.access !== "public" && m.toUpperCase() !== a.ownerName?.toUpperCase() && !e ? (this._switchToVersionCheckboxElement.value.checked = !1, this._switchToVersionCheckboxElement.value.disabled = !0, this._switchToVersion = !1) : this._switchToVersionCheckboxElement.value.disabled = !1, this._createVersionParameters = a), s === "edit" && (this._alterVersionParameters = r);
  }
  _handleClose() {
    this.arcgisFlowItemClose.emit();
  }
  _handleSave() {
    const { _alterVersionParameters: t, _createVersionParameters: s, _mode: h, _switchToVersion: d, versionPropertiesElementProps: { strings: m } } = this, e = [".", ";", "'", '"'];
    if (e.some((i) => s?.versionName?.includes(i)) || e.some((i) => t?.versionName?.includes(i))) {
      this._validationError = m.validationErrors.invalidCharacters;
      return;
    }
    h === "create" && this.arcgisCreateVersion.emit({
      createVersionParameters: s,
      switchToVersion: d
    }), h === "edit" && this.arcgisAlterVersion.emit({
      alterVersionParameters: t
    });
  }
  _handleSwitchToVersionChange(t) {
    this._switchToVersion = t.target.checked;
  }
  render() {
    const { selected: t, showBackButton: s, versionPropertiesElementProps: { closable: h, currentUser: d, state: m, strings: e, versionInfo: c }, _mode: i, _ownerName: r, _versionName: a } = this, o = l`<calcite-button appearance=outline slot=footer width=full @click=${this._handleCancel}>${e.actions.cancelSave}</calcite-button><calcite-button appearance=solid slot=footer width=full @click=${this._handleSave}>${e.actions.saveVersion}</calcite-button>`, n = l`<calcite-label>${e.input.versionAccess}<calcite-chip-group label=access @calciteChipGroupSelect=${this._handleChange} selection-mode=single-persist><calcite-chip .selected=${i === "edit" && c.access === "public" || i === "create"} label=public>${e.accessLevels.public}</calcite-chip><calcite-chip .selected=${i === "edit" && c.access === "protected"} label=protected>${e.accessLevels.protected}</calcite-chip><calcite-chip .selected=${i === "edit" && c.access === "private"} label=private>${e.accessLevels.private}</calcite-chip></calcite-chip-group></calcite-label>`, f = l`<calcite-label>${e.input.versionDescription}<calcite-text-area limit-text max-length=64 name=description resize=none rows=2 scale=s .value=${i === "edit" ? c.description : ""} @calciteTextAreaInput=${this._handleChange}></calcite-text-area></calcite-label>`, _ = l`<calcite-label>${e.input.versionName}<calcite-input-text max-length=62 name=versionName .value=${i === "edit" ? a : ""} @calciteInputTextInput=${this._handleChange} ${v(this._versionNameInputElement)}></calcite-input-text></calcite-label>`, b = l`<calcite-label>${e.input.versionOwner}<calcite-input-text name=ownerName .value=${i === "edit" ? r : d} @calciteInputTextInput=${this._handleChange}></calcite-input-text></calcite-label>`, g = i === "create" ? l`<calcite-label layout=inline><calcite-checkbox checked name=switchToVersion @calciteCheckboxChange=${this._handleSwitchToVersionChange} ${v(this._switchToVersionCheckboxElement)}></calcite-checkbox>${e.actions.switchToVersion}</calcite-label>` : void 0, w = this._validationError ? l`<calcite-notice closable kind=warning open scale=s width=full @calciteNoticeClose=${() => this._validationError = void 0}><div slot=message>${this._validationError}</div></calcite-notice>` : void 0;
    return l`<calcite-flow-item .closable=${h} .description=${c ? c.versionIdentifier.name : ""} .heading=${c ? e.actions.editVersion : e.actions.newVersion} .selected=${t} .showBackButton=${s} @calciteFlowItemClose=${this._handleClose} ${v(this._flowItemElement)}><calcite-panel .loading=${m === "executing"}><calcite-block expanded .label=${e.headers.versionProperties}>${_}${f}${n}${b}${g}${w}</calcite-block>${o}</calcite-panel></calcite-flow-item>`;
  }
}
$("arcgis-version-management-version-properties", x);
export {
  x as ArcgisVersionManagementVersionProperties
};
