import { defineComponent as R, computed as $, watch as B, createBlock as b, openBlock as g, unref as e, withCtx as o, createVNode as t, withModifiers as D, createCommentVNode as C, isRef as T, createTextVNode as M, toDisplayString as H } from "vue";
import { useI18n as F } from "vue-i18n";
import { storeToRefs as P } from "pinia";
import { aH as j, ak as G, h as q, i as O, c as r, e as v, d as z, a as c } from "./start-CE9SawgU.js";
import { c as J, L as K } from "./header-Bn1EKnBE.js";
import { c as Q, d as W } from "./topBarRoutes-CBd5qLxn.js";
import { _ as X } from "./KeyTextField.vue_vue_type_script_setup_true_lang-CeedcDGI.js";
import { _ as Y } from "./TreeView.vue_vue_type_style_index_0_scoped_0bd14ef7_lang-CZieIjgg.js";
const ie = /* @__PURE__ */ R({
  __name: "EditBasicView",
  props: {
    id: {},
    disableCustomSelection: { type: Boolean },
    pluginName: {}
  },
  setup(_) {
    const y = _;
    let p = [];
    const { t: m } = F(), N = Q(y.pluginName), {
      selectedAttributeSet: a,
      attributeSetHeritages: I,
      entityTypes: f,
      isLoadingEntityTypes: V
    } = P(N), { attributesApi: A, attributeSetsApi: U } = N, w = $(
      () => Object.entries(J).map(([u, l]) => ({
        value: Number(u),
        title: m(l)
      }))
    ), E = {
      active: {},
      heritageMode: {},
      parentSetId: {},
      entityTypeClassName: {},
      syncConfiguration: {}
    }, { v$: d, markTouched: k, resetValidation: S } = j(
      `${y.pluginName}-attribute-sets`,
      {
        form: a,
        rules: E,
        formId: `${y.pluginName}-attribute-sets-basic`,
        onSubmit: L
      }
    );
    B(
      () => a.value?.id,
      (u) => {
        u && S();
      }
    );
    const h = $(() => !!(!a.value?.parentSetId || a.value?.readOnly));
    async function L() {
      try {
        const u = a.value.parentSetId ? {
          heritageMode: Number(a.value.heritageMode),
          parentSetId: a.value.parentSetId,
          syncConfiguration: a.value.syncConfiguration
        } : void 0, l = Object.fromEntries(
          Object.entries(a.value).filter(
            ([i]) => p.includes(i)
          )
        ), s = {
          id: a.value.id,
          active: a.value.active,
          entityTypeClassName: a.value.entityTypeClassName,
          ...l,
          ...u
        };
        return await U.save(s), S(), !0;
      } catch {
        return !1;
      }
    }
    return (u, l) => (g(), b(W, {
      controller: e(K).ATTRIBUTES,
      api: e(A).getListOfLanguagesScopesAndFields,
      "disable-custom-selection": u.disableCustomSelection,
      "plugin-name": u.pluginName
    }, {
      default: o(({ selected: s, loading: i }) => [
        t(e(G), {
          readonly: e(a)?.readOnly,
          class: "h-100 overflow-auto",
          onSubmit: l[9] || (l[9] = D(() => {
          }, ["prevent"]))
        }, {
          default: o(() => [
            t(e(q), { fluid: "" }, {
              default: o(() => [
                t(e(O), null, {
                  default: o(() => [
                    t(e(r), { cols: "4" }, {
                      default: o(() => [
                        t(e(O), null, {
                          default: o(() => [
                            t(e(r), null, {
                              default: o(() => [
                                t(e(v), {
                                  modelValue: e(d).active.$model,
                                  "onUpdate:modelValue": l[0] || (l[0] = (n) => e(d).active.$model = n),
                                  label: u.$t("datahub-ui.dh-table.isActive"),
                                  readonly: e(a)?.readOnly,
                                  loading: i
                                }, null, 8, ["modelValue", "label", "readonly", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            t(e(r), null, {
                              default: o(() => [
                                t(X, {
                                  "model-value": e(a)?.key,
                                  loading: i,
                                  readonly: ""
                                }, null, 8, ["model-value", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            s?.attributes?.length ? (g(), b(Y, {
                              key: 0,
                              modelValue: e(a),
                              "onUpdate:modelValue": l[1] || (l[1] = (n) => T(a) ? a.value = n : null),
                              attributes: s?.attributes,
                              readonly: e(a)?.readOnly,
                              scopes: s?.scopes,
                              languages: s?.languages,
                              selection: s?.custom,
                              loading: i,
                              onUpdated: e(k),
                              onFieldNames: l[2] || (l[2] = (n) => T(p) ? p.value = n : p = n)
                            }, null, 8, ["modelValue", "attributes", "readonly", "scopes", "languages", "selection", "loading", "onUpdated"])) : C("", !0),
                            t(e(r), null, {
                              default: o(() => [
                                t(e(v), {
                                  "model-value": e(a)?.readOnly,
                                  label: u.$t("datahub-ui.dh-table.readOnly"),
                                  loading: i,
                                  readonly: "",
                                  "onUpdate:modelValue": l[3] || (l[3] = (n) => e(a).readOnly = n)
                                }, null, 8, ["model-value", "label", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            t(e(r), null, {
                              default: o(() => [
                                t(e(z), {
                                  "model-value": e(a)?.ownerPluginName,
                                  label: u.$t("datahub-ui.dh-table.ownerPluginName"),
                                  loading: i,
                                  readonly: "",
                                  "onUpdate:modelValue": l[4] || (l[4] = (n) => e(a).ownerPluginName = n)
                                }, null, 8, ["model-value", "label", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            !e(V) && !i && e(f).length ? (g(), b(e(r), { key: 1 }, {
                              default: o(() => [
                                t(e(c), {
                                  modelValue: e(d).entityTypeClassName.$model,
                                  "onUpdate:modelValue": l[5] || (l[5] = (n) => e(d).entityTypeClassName.$model = n),
                                  items: e(f),
                                  label: e(m)("datahub-ui.dh-shared.entityType"),
                                  loading: e(V) || i,
                                  readonly: e(a)?.readOnly || e(f).length <= 1,
                                  "item-title": "name",
                                  "item-value": "className"
                                }, null, 8, ["modelValue", "items", "label", "loading", "readonly"])
                              ]),
                              _: 2
                            }, 1024)) : C("", !0),
                            t(e(r), { class: "form-title" }, {
                              default: o(() => [
                                M(H(e(m)("datahub-ui.dh-shared.inheritanceTitle")), 1)
                              ]),
                              _: 1
                            }),
                            t(e(r), null, {
                              default: o(() => [
                                t(e(c), {
                                  modelValue: e(d).parentSetId.$model,
                                  "onUpdate:modelValue": l[6] || (l[6] = (n) => e(d).parentSetId.$model = n),
                                  items: e(I),
                                  label: e(m)("datahub-ui.dh-shared.from"),
                                  readonly: e(a)?.readOnly,
                                  loading: i,
                                  "item-title": "name",
                                  "item-value": "id"
                                }, null, 8, ["modelValue", "items", "label", "readonly", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            t(e(r), null, {
                              default: o(() => [
                                t(e(v), {
                                  modelValue: e(d).syncConfiguration.$model,
                                  "onUpdate:modelValue": l[7] || (l[7] = (n) => e(d).syncConfiguration.$model = n),
                                  label: e(m)("datahub-ui.dh-shared.inheritConfiguration"),
                                  readonly: h.value,
                                  loading: i
                                }, null, 8, ["modelValue", "label", "readonly", "loading"])
                              ]),
                              _: 2
                            }, 1024),
                            t(e(r), null, {
                              default: o(() => [
                                t(e(c), {
                                  modelValue: e(d).heritageMode.$model,
                                  "onUpdate:modelValue": l[8] || (l[8] = (n) => e(d).heritageMode.$model = n),
                                  items: w.value,
                                  label: e(m)("datahub-ui.dh-shared.inheritCopy"),
                                  readonly: h.value,
                                  loading: i
                                }, null, 8, ["modelValue", "items", "label", "readonly", "loading"])
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 2
            }, 1024)
          ]),
          _: 2
        }, 1032, ["readonly"])
      ]),
      _: 1
    }, 8, ["controller", "api", "disable-custom-selection", "plugin-name"]));
  }
});
export {
  ie as default
};
