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