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