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