import { defineComponent as D, ref as R, computed as _, watch as T, createBlock as y, openBlock as v, unref as a, withCtx as i, createVNode as t, withModifiers as h, createCommentVNode as C, isRef as I } from "vue";
import { storeToRefs as F } from "pinia";
import { az as H, ad as K, f as P, g as U, a as m, c as V, h as G } from "./start-BYfL32Oe.mjs";
import "vue-i18n";
import "vue-router";
import { L as M } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { c as j, g as z, h as Y } from "./topBarRoutes-0VuQ_i6D.mjs";
import { D as q } from "./constants-CwfsvyFM.mjs";
import { _ as J } from "./KeyTextField.vue_vue_type_script_setup_true_lang-CZdba5bh.mjs";
import { j as Q } from "./DatahubDataTypeEditor.vue_vue_type_script_setup_true_lang-WxvRaHzL.mjs";
import { _ as W } from "./MultiLangScopeEditorsList.vue_vue_type_script_setup_true_lang-CWQeDnSm.mjs";
const ma = /* @__PURE__ */ D({
  __name: "EditBasicView",
  props: {
    id: {},
    attribute: {},
    readonly: { type: Boolean },
    disableCustomSelection: { type: Boolean },
    pluginName: {}
  },
  setup(A) {
    const p = A, $ = j(p.pluginName), { isLoadingDataTypes: N, dataTypes: S, selectedAttribute: n } = F(
      $
    ), { attributesApi: g } = $, b = R(!1), w = _(
      () => {
        var e, l;
        return (l = Q(
          (e = n.value) == null ? void 0 : e.dataTypeInstance,
          q.CONFIG
        )) == null ? void 0 : l.name;
      }
    ), s = _(
      () => {
        var e;
        return !!(p.readonly || (e = n.value) != null && e.readOnly);
      }
    ), B = {
      dataType: {},
      multilanguage: {},
      scopable: {},
      active: {},
      config: {}
    }, { v$: r, markTouched: E, resetValidation: c } = H({
      form: n,
      rules: B,
      formId: "attributes-basic",
      onSubmit: L
    });
    async function L() {
      try {
        return await g.save(n.value), c(), !0;
      } catch {
        return !1;
      }
    }
    async function O(e) {
      try {
        b.value = !0;
        const { data: l } = await g.changeKey(Number(p.id), e);
        n.value = l;
      } finally {
        b.value = !1;
      }
    }
    return T(
      () => {
        var e;
        return (e = n.value) == null ? void 0 : e.id;
      },
      (e) => {
        e && (n.value.config = void 0, c());
      }
    ), T(
      () => p.attribute,
      (e) => {
        e && (n.value = e);
      },
      { immediate: !0 }
    ), (e, l) => (v(), y(z, {
      controller: a(M).ATTRIBUTES,
      api: a(g).getListOfLanguagesScopesAndFields,
      "disable-custom-selection": e.disableCustomSelection,
      "plugin-name": e.pluginName
    }, {
      default: i(({ selected: o, loading: d }) => [
        t(a(K), {
          readonly: s.value,
          class: "h-100 overflow-auto",
          onSubmit: l[7] || (l[7] = h(() => {
          }, ["prevent"]))
        }, {
          default: i(() => [
            t(a(P), { fluid: "" }, {
              default: i(() => [
                t(a(U), null, {
                  default: i(() => [
                    t(a(m), {
                      md: "6",
                      lg: "4"
                    }, {
                      default: i(() => [
                        t(a(U), null, {
                          default: i(() => {
                            var f;
                            return [
                              t(a(m), null, {
                                default: i(() => [
                                  t(a(V), {
                                    modelValue: a(r).active.$model,
                                    "onUpdate:modelValue": l[0] || (l[0] = (u) => a(r).active.$model = u),
                                    label: e.$t("datahub-ui.dh-table.isActive"),
                                    readonly: s.value,
                                    loading: d
                                  }, null, 8, ["modelValue", "label", "readonly", "loading"])
                                ]),
                                _: 2
                              }, 1024),
                              t(a(m), null, {
                                default: i(() => {
                                  var u;
                                  return [
                                    t(J, {
                                      "model-value": (u = a(n)) == null ? void 0 : u.key,
                                      readonly: s.value,
                                      loading: b.value || d,
                                      "onUpdate:modelValue": l[1] || (l[1] = (k) => a(n).key = k),
                                      onUpdated: O
                                    }, null, 8, ["model-value", "readonly", "loading"])
                                  ];
                                }),
                                _: 2
                              }, 1024),
                              (f = o == null ? void 0 : o.attributes) != null && f.length ? (v(), y(W, {
                                key: 0,
                                modelValue: a(n),
                                "onUpdate:modelValue": l[2] || (l[2] = (u) => I(n) ? n.value = u : null),
                                attributes: o == null ? void 0 : o.attributes,
                                readonly: s.value,
                                scopes: o == null ? void 0 : o.scopes,
                                languages: o == null ? void 0 : o.languages,
                                selection: o == null ? void 0 : o.custom,
                                loading: d,
                                onUpdated: a(E)
                              }, null, 8, ["modelValue", "attributes", "readonly", "scopes", "languages", "selection", "loading", "onUpdated"])) : C("", !0),
                              t(a(m), null, {
                                default: i(() => [
                                  t(a(G), {
                                    modelValue: a(r).dataType.$model,
                                    "onUpdate:modelValue": l[3] || (l[3] = (u) => a(r).dataType.$model = u),
                                    label: e.$t("datahub-ui.dh-table.dataType"),
                                    loading: a(N) || d,
                                    items: a(S),
                                    "item-title": "name",
                                    "item-value": "id",
                                    readonly: ""
                                  }, null, 8, ["modelValue", "label", "loading", "items"])
                                ]),
                                _: 2
                              }, 1024),
                              t(a(m), { cols: "6" }, {
                                default: i(() => [
                                  t(a(V), {
                                    modelValue: a(r).scopable.$model,
                                    "onUpdate:modelValue": l[4] || (l[4] = (u) => a(r).scopable.$model = u),
                                    label: e.$t("datahub-ui.dh-table.scopable"),
                                    loading: d,
                                    readonly: ""
                                  }, null, 8, ["modelValue", "label", "loading"])
                                ]),
                                _: 2
                              }, 1024),
                              t(a(m), { cols: "6" }, {
                                default: i(() => [
                                  t(a(V), {
                                    modelValue: a(r).multilanguage.$model,
                                    "onUpdate:modelValue": l[5] || (l[5] = (u) => a(r).multilanguage.$model = u),
                                    label: e.$t("datahub-ui.dh-table.multiLanguage"),
                                    loading: d,
                                    readonly: ""
                                  }, null, 8, ["modelValue", "label", "loading"])
                                ]),
                                _: 2
                              }, 1024)
                            ];
                          }),
                          _: 2
                        }, 1024)
                      ]),
                      _: 2
                    }, 1024),
                    w.value && a(r).config ? (v(), y(a(m), {
                      key: 0,
                      md: "6",
                      lg: "8"
                    }, {
                      default: i(() => [
                        t(Y, {
                          modelValue: a(r).config.$model,
                          "onUpdate:modelValue": l[6] || (l[6] = (f) => a(r).config.$model = f),
                          attribute: a(n),
                          "data-type-instance": a(n).dataTypeInstance,
                          "remote-scopes": o.scopes,
                          "remote-languages": o.languages,
                          "remote-attributes": o.attributes,
                          readonly: s.value
                        }, null, 8, ["modelValue", "attribute", "data-type-instance", "remote-scopes", "remote-languages", "remote-attributes", "readonly"])
                      ]),
                      _: 2
                    }, 1024)) : C("", !0)
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 2
            }, 1024)
          ]),
          _: 2
        }, 1032, ["readonly"])
      ]),
      _: 1
    }, 8, ["controller", "api", "disable-custom-selection", "plugin-name"]));
  }
});
export {
  ma as _
};
