import { r as t, c as i, g as e, h as s, H as a, a as n } from "./p-9b9ccd0c.js";

import { c as o } from "./p-c5196b3b.js";

import { L as r } from "./p-311eedf3.js";

const mapTypeCategoryDataToActionListModel = t => t.map((t => ({
  id: t.id,
  type: "actionable",
  additionalInformation: {
    "stretch-start": {
      center: [ {
        imgSrc: t.icon || undefined
      } ]
    }
  },
  caption: t.name,
  part: `category-${t.id}`
})));

const mapTypeDataToActionListModel = (t, i, e) => t.map((t => ({
  id: `${t.id}`,
  type: "actionable",
  imageSrc: "objects/design",
  selected: e === t.id,
  additionalInformation: {
    "stretch-start": {
      center: [ {
        imgSrc: t.icon
      } ]
    }
  },
  caption: t.name,
  part: `type-${i}-${t.id}`
})));

/**
 * Order the items in the same order as they come.
 */ const sortActionListDefault = t => t;

const l = 'button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%}.main{display:grid;grid-template-rows:1fr max-content max-content}.categories-types-layout{grid-template-columns:1fr 1fr}.api-description-layout{padding-block:calc( 12px * 2 );display:grid;grid-template:"api-description-title api-description-title" "api-name-label api-name-control" "api-description-label api-description-control" "api-module-label api-module-control";grid-template-columns:max-content 1fr}.api-description-title{grid-area:api-description-title;padding-block-end:var(--spacing-padding-m)}.api-name-label{grid-area:api-name-label}.api-name-control{grid-area:api-name-control}.api-description-label{grid-area:api-description-label}.api-description-control{grid-area:api-description-control}.api-module-label{grid-area:api-module-label}.api-module-control{grid-area:api-module-control}';

var h = undefined && undefined.__classPrivateFieldGet || function(t, i, e, s) {
  if (e === "a" && !s) throw new TypeError("Private accessor was defined without a getter");
  if (typeof i === "function" ? t !== i || !s : !i.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return e === "m" ? s : e === "a" ? s.call(t) : s ? s.value : i.get(t);
};

var c = undefined && undefined.__classPrivateFieldSet || function(t, i, e, s, a) {
  if (s === "m") throw new TypeError("Private method is not writable");
  if (s === "a" && !a) throw new TypeError("Private accessor was defined without a setter");
  if (typeof i === "function" ? t !== i || !a : !i.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return s === "a" ? a.call(t, e) : a ? a.value = e : i.set(t, e), e;
};

var d, f, p, u, b, m, w, g, y, k, v, M, W, x, C, j, I, S, E, F, T, $, _, P, z, D, L, N;

const A = [ "resets/box-sizing", "components/button", "components/edit", "components/icon", "components/tooltip", "components/list-box", "utils/form", "utils/layout", "utils/spacing", "utils/typography" ];

const B = class {
  constructor(a) {
    t(this, a);
    this.cancel = i(this, "cancel", 7);
    this.create = i(this, "create", 7);
    this.validateName = i(this, "validateName", 7);
    d.add(this);
    /**
         * The component hard-coded strings translations.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        f.set(this, void 0);
    p.set(this, e(`./gx-ide-assets/new-object/shortcuts.json`));
    /* References needed to collect data on "Create" button submit */    u.set(this, void 0);
    b.set(this, void 0);
    m.set(this, void 0);
    w.set(this, false);
    g.set(this, void 0);
    y.set(this, void 0);
    k.set(this, false);
    // - - - - - - - - - - -
        v.set(this, (async () => {
      await this.cancelCallback();
    }));
    M.set(this, (t => {
      const i = t.detail;
      if (i.length > 0) {
        const t = this.typeCategories.find((t => t.id === i[0].item.id));
        if (t) {
          this.selectedCategory = t;
          if (t.types.length > 0) {
            this.selectedType = t.types.find((i => i.id === this.selectedTypeMap.get(t.id)));
          }
        }
      }
    }));
    W.set(this, (async () => {
      var t, i, e;
      // validate name first
            const s = await this.validateNameCallback(h(this, y, "f").value);
      if (!!s) {
        // name is invalid
        h(this, N, "f").call(this, s);
        return;
      }
      const a = {
        typeId: (t = this.selectedType) === null || t === void 0 ? void 0 : t.id,
        name: h(this, y, "f").value,
        description: !h(this, w, "f") ? undefined : h(this, m, "f").value,
        moduleId: (e = (i = h(this, g, "f")) === null || i === void 0 ? void 0 : i.value) === null || e === void 0 ? void 0 : e.id
      };
      const n = await this.createCallback(a);
      h(this, N, "f").call(this, n);
    }));
    x.set(this, (() => {
      var t;
      if (h(this, k, "f") || h(this, w, "f")) {
        return h(this, m, "f").value;
      } else {
        // First try to get suggested description if callback exists
        if (this.suggestCallback) {
          return (t = this.description) !== null && t !== void 0 ? t : this.selectedType.name;
        }
        return this.selectedType.name;
      }
    }));
    /**
         * Resolves the suggested name based on the context
         * @param selectedType The currently selected type
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        C.set(this, (async (t, i) => {
      if (i) {
        return i.replace(/\s/g, "");
      }
      return t.name.replace(/\s/g, "");
    }));
    /**
         * Gets the suggested description based on the context
         * @param selectedType The currently selected type
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        j.set(this, (async (t, i) => {
      if (i) {
        return i;
      }
      return t.name;
    }));
    /**
         * Updates both name and description suggestions
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        I.set(this, (async () => {
      if (!this.selectedType) {
        return;
      }
      if (h(this, k, "f") && h(this, w, "f")) return;
      const t = await this.suggestCallback(this.selectedType.id);
      if (!h(this, k, "f")) {
        this.name = await h(this, C, "f").call(this, this.selectedType, t.name);
      }
      if (!h(this, w, "f")) {
        this.description = await h(this, j, "f").call(this, this.selectedType, t.description);
      }
    }));
    /**
         * This method defines the initial selected category and type, and it then
         * initializes the name and description values.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        S.set(this, (async () => {
      const t = h(this, z, "f").call(this, this.defaultTypeId);
      if (!t) {
        this.selectedCategory = this.typeCategories[0];
        this.selectedType = this.selectedCategory.types[0];
      }
      await h(this, I, "f").call(this);
    }));
    F.set(this, (async () => {
      if (h(this, y, "f").value) {
        const t = await this.validateNameCallback(h(this, y, "f").value);
        h(this, N, "f").call(this, t);
      }
    }));
    T.set(this, (t => {
      this.description = t.detail;
      c(this, w, true, "f");
    }));
    $.set(this, (async t => {
      const i = t.detail;
      if (!h(this, w, "f")) {
        // Description should be equal to name, unless the description was already
        // modified by the user.
        h(this, m, "f").value = i;
      }
      c(this, k, true, "f");
    }));
    _.set(this, (async t => {
      const i = t.detail;
      if (i) {
        const t = await this.validateNameCallback(i);
        h(this, N, "f").call(this, t);
      }
    }));
    P.set(this, (() => {
      if (this.selectedType.hasModule || this.selectedType.hasFolder) {
        let t = h(this, f, "f").moduleFolder;
        if (!this.selectedType.hasFolder) {
          t = h(this, f, "f").moduleOnly;
        } else if (!this.selectedType.hasModule) {
          t = h(this, f, "f").folderOnly;
        }
        return [ s("label", {
          // Module/folder
          class: "label api-module-label",
          htmlFor: "module"
        }, t), s("gx-ide-entity-selector", {
          id: "module",
          class: "api-module-control",
          part: "module",
          labelPosition: "none",
          value: this.parent,
          defaultValue: this.defaultParent,
          selectEntityCallback: this.selectModuleCallback,
          ref: t => c(this, g, t, "f")
        }) ];
      }
      return null;
    }));
    z.set(this, (t => {
      if (!t) {
        return false;
      }
      let i = false;
      t: for (let e = 0; e < this.typeCategories.length; e++) {
        for (let s = 0; s < this.typeCategories[e].types.length; s++) {
          const a = this.typeCategories[e].types[s].id;
          if (a === t) {
            this.selectedCategory = this.typeCategories[e];
            this.selectedType = this.typeCategories[e].types[s];
            i = true;
            break t;
          }
        }
      }
      return i;
    }));
    D.set(this, (() => {
      if (this.selectedCategory) {
        // update model by setting the selected category
        h(this, u, "f").updateItemProperties(this.selectedCategory.id, {
          selected: true,
          type: "actionable"
        });
      }
    }));
    L.set(this, (async t => {
      const i = t.detail;
      if (i.length > 0) {
        this.selectedType = this.selectedCategory.types.find((t => t.id === i[0].item.id));
        this.selectedTypeMap.set(this.selectedCategory.id, this.selectedType.id);
        await h(this, I, "f").call(this);
      }
    }));
    /**
         * If the parameter is undefined, it means the name is valid. Otherwise, if it
         * receives a string, it indicates that the name is not valid. The string is the
         * error message to display.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        N.set(this, (t => {
      this.nameValidationErrorMessage = t;
    }));
    this.description = undefined;
    this.name = undefined;
    this.nameValidationErrorMessage = undefined;
    this.selectedCategory = undefined;
    this.selectedType = undefined;
    this.typeCategoriesActionListModel = [];
    this.typesActionListModel = [];
    this.selectedTypeMap = new Map;
    this.defaultTypeId = undefined;
    this.defaultParent = undefined;
    this.displayTitle = false;
    this.cancelCallback = undefined;
    this.createCallback = undefined;
    this.shadow = false;
    this.typeCategories = undefined;
    this.parent = undefined;
    this.selectModuleCallback = undefined;
    this.validateNameCallback = undefined;
    this.suggestCallback = undefined;
  }
  typeCategoriesChanged(t) {
    if (t === null || t === void 0 ? void 0 : t.length) {
      this.typeCategoriesActionListModel = mapTypeCategoryDataToActionListModel(this.typeCategories);
    }
  }
  connectedCallback() {
    // this.#validateInitialName();
  }
  async componentWillLoad() {
    await h(this, S, "f").call(this);
    c(this, f, await r.getComponentStrings(this.el), "f");
    this.typeCategoriesChanged(this.typeCategories);
    h(this, d, "m", E).call(this);
  }
  componentDidLoad() {
    h(this, D, "f").call(this);
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(t) {
    if (t) {
      h(this, b, "f").suspend = true;
    } else {
      h(this, b, "f").suspend = false;
    }
  }
  render() {
    var t;
    return s(a, {
      class: "widget"
    }, s("ch-theme", {
      model: A
    }), s("ch-shortcuts", {
      src: h(this, p, "f"),
      ref: t => c(this, b, t, "f")
    }), s("section", {
      class: "main"
    }, s("section", {
      class: "field-group categories-types-layout spacing-body-inline spacing-body-block-start"
    }, s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label"
    }, h(this, f, "f").categorySelectionTitle), s("ch-action-list-render", {
      // #select a category
      // TODO: The "scrollable" class is a WA since the action-list currently does not support scrollbar customization
      class: "list-box",
      selection: "single",
      model: this.typeCategoriesActionListModel,
      sortItemsCallback: sortActionListDefault,
      onSelectedItemsChange: h(this, M, "f"),
      ref: t => c(this, u, t, "f")
    })), s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label"
    }, this.selectedCategory.name ? `${this.selectedCategory.name} ${h(this, f, "f").typeSelectionTitleSuffix}` : h(this, f, "f").typeSelectionTitle), s("ch-action-list-render", {
      // #data management types
      // TODO: The "scrollable" class is a WA since the action-list currently does not support scrollbar customization
      class: "list-box",
      selection: "single",
      sortItemsCallback: sortActionListDefault,
      model: mapTypeDataToActionListModel(this.selectedCategory.types, this.selectedCategory.id, this.selectedType.id),
      onSelectedItemsChange: h(this, L, "f")
    }))), s("section", {
      class: "api-description-layout field-group-justified-start spacing-body-inline"
    }, s("h2", {
      // API Description
      class: "text-align-center api-description-title subtitle-regular-xs\t"
    }, (t = this.selectedType) === null || t === void 0 ? void 0 : t.description), s("label", {
      // Name
      class: "label api-name-label",
      htmlFor: "name"
    }, h(this, f, "f").objectName), s("div", null, s("ch-edit", {
      autoFocus: true,
      class: {
        input: true,
        "api-name-control": true,
        "input-error": !!this.nameValidationErrorMessage
      },
      placeholder: "Name",
      value: this.name,
      ref: t => c(this, y, t, "f"),
      onChange: h(this, _, "f"),
      onInput: h(this, $, "f"),
      onBlur: h(this, F, "f"),
      part: "name"
    }), this.nameValidationErrorMessage && s("ch-tooltip", {
      class: "tooltip",
      actionElement: h(this, y, "f"),
      blockAlign: o.tooltipSettings.blockAlign,
      inlineAlign: o.tooltipSettings.inlineAlign,
      delay: o.tooltipSettings.delay
    }, this.nameValidationErrorMessage)), s("label", {
      // Description
      class: "label api-description-label",
      htmlFor: "description"
    }, h(this, f, "f").objectDescription), s("ch-edit", {
      autoFocus: true,
      class: "input api-description-control",
      placeholder: "Description",
      value: h(this, x, "f").call(this),
      // TODO: toolTip={config.tooltip}
      ref: t => c(this, m, t, "f"),
      onInput: h(this, T, "f"),
      part: "description"
    }), h(this, P, "f").call(this)), s("footer", {
      class: "footer dialog-footer-with-border spacing-body-inline spacing-body-block-end "
    }, s("div", {
      class: "buttons-spacer"
    }, s("button", {
      // cancel
      class: "button-secondary",
      onClick: h(this, v, "f"),
      part: "button button-cancel"
    }, h(this, f, "f").footer.btnCancel), s("button", {
      // create
      class: "button-primary",
      onClick: h(this, W, "f"),
      disabled: !!this.nameValidationErrorMessage,
      part: "button button-create"
    }, h(this, f, "f").footer.btnCreate)))));
  }
  static get delegatesFocus() {
    return true;
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/new-object" ];
  }
  get el() {
    return n(this);
  }
  static get watchers() {
    return {
      typeCategories: [ "typeCategoriesChanged" ]
    };
  }
};

f = new WeakMap, p = new WeakMap, u = new WeakMap, b = new WeakMap, m = new WeakMap, 
w = new WeakMap, g = new WeakMap, y = new WeakMap, k = new WeakMap, v = new WeakMap, 
M = new WeakMap, W = new WeakMap, x = new WeakMap, C = new WeakMap, j = new WeakMap, 
I = new WeakMap, S = new WeakMap, F = new WeakMap, T = new WeakMap, $ = new WeakMap, 
_ = new WeakMap, P = new WeakMap, z = new WeakMap, D = new WeakMap, L = new WeakMap, 
N = new WeakMap, d = new WeakSet, E = function _GxIdeNewObject_initializeSelectedTypeMap() {
  this.typeCategories.forEach((t => {
    if (this.defaultTypeId && t.id === this.selectedCategory.id) {
      this.selectedTypeMap.set(t.id, this.selectedType.id);
    } else {
      this.selectedTypeMap.set(t.id, t.types[0].id);
    }
  }));
};

B.style = l;

export { B as gx_ide_new_object };
//# sourceMappingURL=p-73d848a6.entry.js.map