import { defineComponent as _, mergeModels as N, useModel as O, createBlock as y, openBlock as v, withCtx as p, createVNode as m, createSlots as k, renderList as M, renderSlot as B, mergeProps as D, createElementBlock as G, Fragment as P, createElementVNode as b, createCommentVNode as F, toDisplayString as T, inject as W, computed as q, ref as V, onMounted as H, unref as r, isRef as j } from "vue";
import { useRouter as z } from "vue-router";
import { useI18n as J } from "vue-i18n";
import { storeToRefs as K } from "pinia";
import { l as I, ae as Q, E as L } from "./start-BYfL32Oe.mjs";
import { L as X } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { L as Y } from "./localPluginIntercom-Q4ih1XJC.mjs";
import { g as Z, c as x, p as ee, R as te } from "./topBarRoutes-0VuQ_i6D.mjs";
import { g as ae, c as oe, a as ne } from "./DatahubDataTypeEditor.vue_vue_type_script_setup_true_lang-WxvRaHzL.mjs";
import { T as le, _ as ie } from "./TreeItemLoading.vue_vue_type_script_setup_true_lang-CjeeWuly.mjs";
const re = /* @__PURE__ */ _({
  __name: "TreeViewWithLangAndScopes",
  props: /* @__PURE__ */ N({
    controller: {},
    api: { type: Function },
    loading: { type: Boolean },
    filterPredicate: { type: Function },
    addTitle: {},
    itemId: {},
    maxLevel: {},
    createItem: { type: Function },
    pluginName: {}
  }, {
    modelValue: { default: () => [] },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ N(["updated", "selected", "delete"], ["update:modelValue"]),
  setup(g) {
    const o = O(g, "modelValue");
    return (e, a) => (v(), y(Z, {
      controller: e.controller,
      api: e.api,
      "disable-custom-selection": "",
      "plugin-name": e.pluginName
    }, {
      default: p(({ selected: i, loading: d }) => [
        m(le, {
          modelValue: o.value,
          "onUpdate:modelValue": a[0] || (a[0] = (t) => o.value = t),
          "remote-scopes": i.scopes,
          "remote-languages": i.languages,
          "remote-attributes": i.attributes,
          loading: e.loading || d,
          "filter-predicate": e.filterPredicate,
          "add-title": e.addTitle,
          "item-id": e.itemId,
          "max-level": e.maxLevel,
          "create-item": e.createItem,
          onUpdated: a[1] || (a[1] = (t) => e.$emit("updated")),
          onSelected: a[2] || (a[2] = (t, n) => e.$emit("selected", t, n)),
          onDelete: a[3] || (a[3] = (t) => e.$emit("delete", t))
        }, k({ _: 2 }, [
          M(e.$slots, (t, n) => ({
            name: n,
            fn: p((f) => [
              B(e.$slots, n, D({ key: n }, f), void 0, !0)
            ])
          }))
        ]), 1032, ["modelValue", "remote-scopes", "remote-languages", "remote-attributes", "loading", "filter-predicate", "add-title", "item-id", "max-level", "create-item"])
      ]),
      _: 3
    }, 8, ["controller", "api", "plugin-name"]));
  }
}), se = /* @__PURE__ */ I(re, [["__scopeId", "data-v-329d9e27"]]), ue = { class: "text-truncate" }, de = { class: "text-truncate" }, me = {
  key: 0,
  class: "text-truncate text-body-2"
}, pe = /* @__PURE__ */ _({
  __name: "GroupItemTitle",
  props: {
    node: {},
    active: { type: Boolean }
  },
  setup(g) {
    return (o, e) => {
      var a, i;
      return v(), G(P, null, [
        b("div", ue, [
          b("b", null, T(o.node.title), 1)
        ]),
        b("div", de, T((a = o.node) == null ? void 0 : a.key), 1),
        !o.active && ((i = o.node.children) != null && i.length) ? (v(), G("div", me, T(o.$t("datahub-ui.dh-shared.nOfSubGroups", {
          n: o.node.children.length
        })), 1)) : F("", !0)
      ], 64);
    };
  }
}), ce = /* @__PURE__ */ _({
  __name: "ManageAttributeGroupsView",
  props: {
    pluginName: {}
  },
  setup(g) {
    const o = g, e = z(), { t: a, locale: i } = J(), d = x(o.pluginName), { groups: t, isGroupsLoading: n } = K(d), { groupsApi: f } = d, { navigationItem: S } = W(Y), $ = q(
      () => ee(S.name, te.ATTRIBUTE_GROUPS)
    ), c = V(!1), w = V(!1), h = V([]);
    function A() {
      e.push({ name: $.value });
    }
    function R(l) {
      c.value = !0;
      const u = {
        id: ae(t.value),
        title: a("datahub-ui.dh-shared.newGroup"),
        children: [],
        name: "",
        active: !0
      };
      return l.push(u), u;
    }
    function C({ id: l }) {
      c.value = !0, h.value.push({ id: l });
    }
    async function U() {
      try {
        const l = i.value.replace("-", "_"), s = {
          created: ne(t.value, l),
          modified: oe(t.value, l),
          deleted: h.value
        };
        n.value = !0, await f.saveTree(s), h.value = [], c.value = !1, await d.fetchAttributeGroups();
      } catch {
        n.value = !1;
      }
    }
    return H(d.fetchAttributeGroups), (l, s) => (v(), y(r(Q), {
      title: l.$t("datahub-ui.dh-shared.manageGroups"),
      class: "app-sheet",
      "hide-routes": "",
      level: "1"
    }, {
      actions: p(() => [
        m(r(L), {
          class: "mr-4",
          color: "primary",
          variant: "flat",
          text: l.$t("common.saveChanges"),
          loading: w.value,
          disabled: !c.value || r(n),
          onClick: U
        }, null, 8, ["text", "loading", "disabled"]),
        m(r(L), {
          color: "on_light",
          class: "mr-4",
          icon: "md:clear",
          onClick: A
        })
      ]),
      default: p(() => [
        m(se, {
          modelValue: r(t),
          "onUpdate:modelValue": s[0] || (s[0] = (u) => j(t) ? t.value = u : null),
          controller: r(X).ATTRIBUTE_GROUPS,
          api: r(f).getListOfLanguagesScopesAndFields,
          loading: r(n),
          "add-title": "datahub-ui.dh-shared.newGroup",
          "max-level": 2,
          "create-item": R,
          "plugin-name": l.pluginName,
          class: "group-tree-view",
          onUpdated: s[1] || (s[1] = (u) => c.value = !0),
          onDelete: C
        }, {
          "item-loading": p(() => [
            m(ie)
          ]),
          "item-title": p(({ node: u, active: E }) => [
            m(pe, {
              node: u,
              active: E
            }, null, 8, ["node", "active"])
          ]),
          _: 1
        }, 8, ["modelValue", "controller", "api", "loading", "plugin-name"])
      ]),
      _: 1
    }, 8, ["title"]));
  }
}), ye = /* @__PURE__ */ I(ce, [["__scopeId", "data-v-89dbd50c"]]);
export {
  ye as default
};
