import { defineComponent as E, ref as A, computed as b, watch as K, createBlock as y, openBlock as m, unref as s, withCtx as f, createElementBlock as T, createCommentVNode as k, createVNode as p, renderSlot as V, createElementVNode as P, normalizeClass as z, Fragment as D, withModifiers as w, mergeModels as B, useModel as _, mergeProps as M, renderList as F, createSlots as G } from "vue";
import { D as W, f as Y, g as j, a as J, E as S, F as O, i as Q, G as X, l as Z, H as R } from "./start-BYfL32Oe.mjs";
import { useI18n as U } from "vue-i18n";
import "pinia";
import "vue-router";
import { K as q } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { _ as x } from "./KeyTextField.vue_vue_type_script_setup_true_lang-CZdba5bh.mjs";
import { k as ee } from "./validation-BkM0nwzq.mjs";
import { _ as te } from "./MultiLangScopeEditorsList.vue_vue_type_script_setup_true_lang-CWQeDnSm.mjs";
const ae = {
  minRowCount: 0,
  hidePagination: !0,
  canReorderHeaders: !1,
  hideNoData: !0,
  hideRemove: !0,
  rowHeight: "auto",
  columns: [
    {
      id: "item",
      header: ""
    }
  ]
}, oe = { class: "d-flex w-100 align-center overflow-hidden" }, le = {
  key: 0,
  class: "text-wrap"
}, ie = /* @__PURE__ */ E({
  __name: "TreeViewItem",
  props: {
    node: {},
    active: { type: Boolean },
    remoteScopes: {},
    remoteLanguages: {},
    remoteAttributes: {},
    readonly: { type: Boolean }
  },
  emits: ["save", "delete", "edited"],
  setup(c, { emit: v }) {
    const o = c, $ = v, { locale: u } = U(), r = A(!1), d = A(), h = b(() => {
      var t;
      return (t = d.value) == null ? void 0 : t.key;
    }), I = b(ee(h, q)), L = b(() => I.value ? "text-error" : ""), C = b(() => o.active ? "selected" : void 0);
    function e() {
      r.value = !1;
      const a = `_datahub_translatable_name__${u.value.replace("-", "_")}`, i = d.value[a];
      d.value.title = i, d.value.name = i, $("save", d.value);
    }
    function l() {
      d.value = { ...o.node }, r.value = !1;
    }
    return K(() => o.node, l, { immediate: !0 }), (t, a) => (m(), y(s(W), {
      "bg-color": C.value,
      "collapse-icon": "",
      "expand-icon": "",
      class: "my-2",
      value: t.node.id
    }, {
      title: f(({ expanded: i }) => [
        P("div", oe, [
          P("div", {
            class: z(["flex-grow-1 text-truncate", L.value])
          }, [
            V(t.$slots, "title", {
              node: t.node,
              active: t.active
            })
          ], 2),
          P("div", null, [
            r.value ? (m(), T(D, { key: 0 }, [
              p(s(S), {
                text: t.$t("common.saveChanges"),
                variant: "text",
                color: "primary",
                disabled: !!I.value,
                onClick: w(e, ["stop"])
              }, null, 8, ["text", "disabled"]),
              p(s(S), {
                icon: "cancel",
                variant: "text",
                onClick: w(l, ["stop"])
              })
            ], 64)) : i && !t.readonly ? (m(), y(s(S), {
              key: 1,
              icon: "edit",
              variant: "text",
              onClick: a[0] || (a[0] = w((n) => r.value = !0, ["stop"]))
            })) : k("", !0),
            t.readonly ? k("", !0) : (m(), y(s(S), {
              key: 2,
              icon: "delete",
              variant: "text",
              color: "alert",
              onClick: a[1] || (a[1] = w((n) => t.$emit("delete"), ["stop"]))
            }))
          ])
        ])
      ]),
      default: f(() => [
        d.value ? (m(), T("div", le, [
          p(s(Y), { fluid: "" }, {
            default: f(() => [
              p(s(j), null, {
                default: f(() => {
                  var i, n, g;
                  return [
                    p(s(J), null, {
                      default: f(() => [
                        p(x, {
                          modelValue: d.value.key,
                          "onUpdate:modelValue": a[2] || (a[2] = (N) => d.value.key = N),
                          readonly: !r.value,
                          editable: r.value
                        }, null, 8, ["modelValue", "readonly", "editable"])
                      ]),
                      _: 1
                    }),
                    (i = t.remoteAttributes) != null && i.length && ((n = t.remoteLanguages) != null && n.length || (g = t.remoteScopes) != null && g.length) ? (m(), y(te, {
                      key: 0,
                      modelValue: d.value,
                      "onUpdate:modelValue": a[3] || (a[3] = (N) => d.value = N),
                      attributes: t.remoteAttributes,
                      scopes: t.remoteScopes,
                      languages: t.remoteLanguages,
                      readonly: !r.value,
                      onEdited: a[4] || (a[4] = (N, H) => t.$emit("edited", N, H))
                    }, null, 8, ["modelValue", "attributes", "scopes", "languages", "readonly"])) : k("", !0),
                    V(t.$slots, "default", {
                      node: t.node,
                      active: t.active
                    })
                  ];
                }),
                _: 3
              })
            ]),
            _: 3
          })
        ])) : k("", !0)
      ]),
      _: 3
    }, 8, ["bg-color", "value"]));
  }
}), de = /* @__PURE__ */ E({
  __name: "TreeViewColumn",
  props: /* @__PURE__ */ B({
    title: { default: void 0 },
    remoteScopes: { default: void 0 },
    remoteLanguages: { default: void 0 },
    remoteAttributes: { default: void 0 },
    active: { default: void 0 },
    level: { default: void 0 },
    loading: { type: Boolean },
    readonly: { type: Boolean },
    filterPredicate: { type: Function, default: void 0 },
    addTitle: { default: void 0 },
    itemId: { default: "id" }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ B(["create", "selected", "delete"], ["update:modelValue"]),
  setup(c, { emit: v }) {
    const o = c, $ = v, u = _(c, "modelValue"), { t: r } = U(), d = A(""), h = b({
      get: () => {
        if (!d.value || !o.filterPredicate)
          return u.value;
        const e = o.filterPredicate(d.value);
        return u.value.filter(e);
      },
      set: (e) => {
        u.value = e;
      }
    }), I = b(() => ({
      tableName: o.title ? r(o.title) : r("datahub-ui.dh-shared.levelN", { level: o.level ?? 1 }),
      isLoading: o.loading,
      createActions: [{ title: o.addTitle, icon: "add_circle" }],
      canReorderRows: !d.value,
      hideGlobalSearch: !o.filterPredicate,
      readonly: o.readonly,
      ...ae
    }));
    function L({ query: e }) {
      d.value = e == null ? void 0 : e.trim().toLocaleLowerCase(), d.value && $("selected");
    }
    function C(e, l) {
      u.value = u.value.map(
        (t, a) => a !== e ? t : { ...t, ...l, updated: !0 }
      );
    }
    return (e, l) => (m(), y(s(O), { class: "pr-5 mr-1" }, {
      default: f(() => [
        p(s(Q), M({
          data: h.value,
          "onUpdate:data": l[0] || (l[0] = (t) => h.value = t)
        }, I.value, {
          onClickedRow: l[1] || (l[1] = (t) => e.$emit("selected", t)),
          onCreate: l[2] || (l[2] = (t) => e.$emit("create")),
          onRecalculate: L
        }), {
          "cell-item": f(({
            rowIndex: t,
            row: a,
            isLoading: i
          }) => [
            i ? V(e.$slots, "item-loading", {
              key: 0,
              node: a,
              active: a[e.itemId] === e.active
            }) : (m(), y(ie, {
              key: 1,
              node: a,
              active: a[e.itemId] === e.active,
              "remote-scopes": e.remoteScopes,
              "remote-languages": e.remoteLanguages,
              "remote-attributes": e.remoteAttributes,
              readonly: e.readonly,
              onDelete: (n) => e.$emit("delete", a),
              onSave: (n) => C(t, n)
            }, {
              title: f(({ node: n, active: g }) => [
                V(e.$slots, "item-title", {
                  node: n,
                  active: g
                })
              ]),
              default: f(({ node: n, active: g }) => [
                V(e.$slots, "item-content", {
                  node: n,
                  active: g
                })
              ]),
              _: 2
            }, 1032, ["node", "active", "remote-scopes", "remote-languages", "remote-attributes", "readonly", "onDelete", "onSave"]))
          ]),
          _: 3
        }, 16, ["data"])
      ]),
      _: 3
    }));
  }
}), ne = /* @__PURE__ */ E({
  __name: "TreeView",
  props: /* @__PURE__ */ B({
    remoteScopes: { default: void 0 },
    remoteLanguages: { default: void 0 },
    remoteAttributes: { default: void 0 },
    loading: { type: Boolean },
    readonly: { type: Boolean },
    filterPredicate: { type: Function, default: (c) => ({ key: v, name: o }) => (v == null ? void 0 : v.includes(c)) || (o == null ? void 0 : o.toLocaleLowerCase().includes(c)) },
    addTitle: { default: void 0 },
    itemId: { default: "id" },
    maxLevel: { default: 1 / 0 },
    createItem: {}
  }, {
    modelValue: { default: () => [] },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ B(["updated", "selected", "delete"], ["update:modelValue"]),
  setup(c, { emit: v }) {
    const o = c, $ = v, u = _(c, "modelValue"), r = A([]), d = b(
      () => r.value.reduce(
        (e, l) => {
          var a;
          const t = (a = e.at(-1)) == null ? void 0 : a.find((i) => i[o.itemId] === l);
          return t != null && t.children && e.push(t.children), e;
        },
        [u.value]
      ).slice(0, o.maxLevel)
    );
    function h(e, l) {
      e && !e.children && (e.children = []), r.value = r.value.slice(0, l).concat(e[o.itemId]).slice(0, o.maxLevel), $("selected", e, l);
    }
    function I(e) {
      const l = o.createItem(d.value[e]);
      h(l, e);
    }
    function L(e, l) {
      if ($("updated"), !l) {
        u.value = e;
        return;
      }
      const t = r.value[l - 1], a = d.value[l - 1].find(
        (i) => i[o.itemId] === t
      );
      a && (a.children = e);
    }
    function C(e, l) {
      var i;
      if ($("delete", e), !l) {
        u.value = u.value.filter(
          (n) => n[o.itemId] !== e[o.itemId]
        );
        return;
      }
      const t = r.value[l - 1], a = d.value[l - 1].find(
        (n) => n[o.itemId] === t
      );
      a && (a.children = (i = a.children) == null ? void 0 : i.filter(
        (n) => n[o.itemId] !== e[o.itemId]
      ));
    }
    return (e, l) => (m(), y(s(X), { class: "tree-view-list pa-6" }, {
      default: f(() => [
        (m(!0), T(D, null, F(d.value, (t, a) => (m(), y(de, {
          key: a,
          "model-value": t,
          "remote-scopes": e.remoteScopes,
          "remote-languages": e.remoteLanguages,
          "remote-attributes": e.remoteAttributes,
          active: r.value[a],
          level: a + 1,
          loading: e.loading,
          readonly: e.readonly,
          "filter-predicate": e.filterPredicate,
          "add-title": e.addTitle,
          "item-id": e.itemId,
          class: "tree-view",
          "onUpdate:modelValue": (i) => L(i, a),
          onCreate: (i) => I(a),
          onSelected: (i) => h(i, a),
          onDelete: (i) => C(i, a)
        }, G({ _: 2 }, [
          F(e.$slots, (i, n) => ({
            name: n,
            fn: f((g) => [
              V(e.$slots, n, M({
                key: n,
                ref_for: !0
              }, g), void 0, !0)
            ])
          }))
        ]), 1032, ["model-value", "remote-scopes", "remote-languages", "remote-attributes", "active", "level", "loading", "readonly", "filter-predicate", "add-title", "item-id", "onUpdate:modelValue", "onCreate", "onSelected", "onDelete"]))), 128))
      ]),
      _: 3
    }));
  }
}), he = /* @__PURE__ */ Z(ne, [["__scopeId", "data-v-8eae1950"]]), re = { class: "d-flex align-center my-2" }, be = /* @__PURE__ */ E({
  __name: "TreeItemLoading",
  setup(c) {
    return (v, o) => (m(), T("div", re, [
      p(s(R), {
        type: "icon",
        width: "24",
        height: "24",
        class: "mr-3"
      }),
      p(s(R), {
        width: "380",
        height: "60",
        class: "mr-3"
      }),
      p(s(R), {
        type: "icon",
        width: "24",
        height: "24"
      }),
      V(v.$slots, "default")
    ]));
  }
});
export {
  he as T,
  be as _
};
