import { defineComponent as z, createElementBlock as b, createCommentVNode as V, openBlock as i, createVNode as L, unref as m, withCtx as f, createTextVNode as j, toDisplayString as E, createElementVNode as O, normalizeProps as R, guardReactiveProps as M, createBlock as B, mergeProps as _, mergeModels as I, useModel as F, ref as C, watch as T, computed as S, renderSlot as U, watchEffect as W, Fragment as w, renderList as P, createSlots as q } from "vue";
import { L as G, o as D, O as H, Q as J, R as K, c as N, T as X, i as Y, U as Z, V as x, W as ee } from "./start-CE9SawgU.js";
import "vue-i18n";
import { storeToRefs as te } from "pinia";
import "./header-Bn1EKnBE.js";
import { b as ae, _ as le, d as oe } from "./DatahubDataTypeEditor.vue_vue_type_script_setup_true_lang-Blx83HK-.js";
const ne = {
  key: 0,
  class: "scope-icon icon-slot"
}, ie = {
  key: 1,
  class: "icon-slot"
}, se = /* @__PURE__ */ z({
  __name: "ScopeIcon",
  props: {
    scope: { default: void 0 },
    scopable: { type: Boolean, default: !0 }
  },
  setup(y) {
    return (r, e) => r.scope?.name ? (i(), b("div", ne, [
      L(m(G), null, {
        activator: f(({ props: n }) => [
          O("span", R(M(n)), E(m(ae)(r.scope.name)), 17)
        ]),
        default: f(() => [
          j(" " + E(r.scope.name), 1)
        ]),
        _: 1
      })
    ])) : r.scopable ? (i(), b("div", ie)) : V("", !0);
  }
}), ue = /* @__PURE__ */ D(se, [["__scopeId", "data-v-63f3a0ed"]]), de = {
  key: 1,
  class: "icon-slot"
}, re = /* @__PURE__ */ z({
  __name: "LanguageIcon",
  props: {
    language: { default: void 0 },
    multilanguage: { type: Boolean, default: !0 }
  },
  setup(y) {
    const r = H(), { getCountryFlag: e } = te(r);
    return r.ensureCountries(), (n, o) => n.language?.key ? (i(), B(m(G), { key: 0 }, {
      activator: f(({ props: v }) => [
        L(m(J), _({
          icon: m(e)(n.language.key),
          class: "icon-slot"
        }, v), null, 16, ["icon"])
      ]),
      default: f(() => [
        j(" " + E(n.language.description), 1)
      ]),
      _: 1
    })) : n.multilanguage ? (i(), b("div", de)) : V("", !0);
  }
}), pe = /* @__PURE__ */ D(re, [["__scopeId", "data-v-376ef6b5"]]), ce = { class: "d-flex align-center justify-center ga-2" }, me = {
  key: 2,
  class: "icon-slot"
}, ge = {
  key: 3,
  class: "flex-grow-1 attribute-label"
}, fe = {
  key: 0,
  class: "mt-2"
}, ye = /* @__PURE__ */ z({
  __name: "LangScopeRow",
  props: /* @__PURE__ */ I({
    attribute: {},
    blockedAttribute: {},
    scope: {},
    language: {},
    selection: {},
    prefix: {},
    readonly: { type: Boolean },
    loading: { type: Boolean },
    scopable: { type: Boolean },
    multilanguage: { type: Boolean }
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ I(["edited", "initialized"], ["update:modelValue"]),
  setup(y, { emit: r }) {
    const e = y, n = r, o = F(y, "modelValue"), v = C(!1);
    T(
      o,
      (l) => {
        l || (o.value = {});
      },
      { immediate: !0 }
    );
    const u = S(
      () => e.attribute ? K({
        key: e.attribute.key,
        scope: e.scope?.key,
        language: e.language?.normalizedKey,
        attribute: e.attribute,
        prefix: e.prefix
      }) : ""
    ), k = S(
      () => e.blockedAttribute?.[0]?.[0] || e.blockedAttribute?.[e.scope?.id || 0]?.[e.language?.id || 0]
    ), p = S(
      () => e.readonly || e.attribute.readOnly || k.value
    );
    T(
      () => o.value?.[u.value],
      (l) => {
        !e.loading && u.value && v.value && n("edited", u.value, l);
      },
      { deep: !0 }
    );
    function h() {
      setTimeout(() => {
        v.value = !0;
      }, 200);
    }
    return (l, t) => l.attribute && !l.loading ? (i(), B(m(N), { key: 0 }, {
      default: f(() => [
        O("div", ce, [
          l.scope?.key ? (i(), B(ue, {
            key: 0,
            scope: l.scope,
            scopable: l.scopable
          }, null, 8, ["scope", "scopable"])) : V("", !0),
          l.language?.key ? (i(), B(pe, {
            key: 1,
            language: l.language,
            multilanguage: l.multilanguage
          }, null, 8, ["language", "multilanguage"])) : V("", !0),
          l.$slots.prepend ? (i(), b("div", me, [
            U(l.$slots, "prepend", R(M({ ...e, isBlocked: k.value })), void 0, !0)
          ])) : V("", !0),
          o.value ? (i(), b("div", ge, E(l.attribute.name), 1)) : V("", !0)
        ]),
        o.value ? (i(), b("div", fe, [
          L(le, {
            modelValue: o.value[u.value],
            "onUpdate:modelValue": t[0] || (t[0] = (s) => o.value[u.value] = s),
            attribute: l.attribute,
            "data-type-instance": l.attribute.dataTypeInstance,
            label: "",
            "field-name": u.value,
            "read-only": p.value,
            loading: l.loading,
            onLoaded: h,
            onInitialized: t[1] || (t[1] = (s) => l.$emit("initialized", u.value))
          }, null, 8, ["modelValue", "attribute", "data-type-instance", "field-name", "read-only", "loading"])
        ])) : V("", !0)
      ]),
      _: 3
    })) : (i(), B(m(N), { key: 1 }, {
      default: f(() => [
        L(m(X), { type: "avatar, avatar, text" })
      ]),
      _: 1
    }));
  }
}), ve = /* @__PURE__ */ D(ye, [["__scopeId", "data-v-0d553e27"]]), be = /* @__PURE__ */ z({
  __name: "MultiLangScopeEditor",
  props: /* @__PURE__ */ I({
    attribute: {},
    blockedAttributes: {},
    scopes: {},
    languages: {},
    selection: {},
    prefix: {},
    readonly: { type: Boolean },
    loading: { type: Boolean },
    scopable: { type: Boolean },
    multilanguage: { type: Boolean }
  }, {
    modelValue: { default: () => ({}) },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ I(["updated", "field-names", "edited", "initialized"], ["update:modelValue"]),
  setup(y, { emit: r }) {
    const e = y, n = r, o = F(y, "modelValue");
    T(
      o,
      (t) => {
        t || (o.value = {});
      },
      { immediate: !0 }
    );
    const v = S(
      () => e.attribute?.scopable && e.scopes?.length ? e.scopes : [{ key: "", name: "" }]
    ), u = S(
      () => e.attribute?.multilanguage && e.languages?.length ? e.languages : [{ key: "", normalizedKey: "" }]
    ), k = S(
      () => (!e.attribute?.scopable || !e.scopes?.length) && (!e.attribute?.multilanguage || !e.languages?.length)
    ), p = S(() => k.value ? [""] : v.value.flatMap(
      ({ key: t }) => u.value.map(
        ({ normalizedKey: s }) => K({
          key: e.attribute?.key,
          scope: t,
          language: s,
          attribute: e.attribute
        })
      )
    ));
    function h(t, s) {
      return !t && !s || !e.selection?.length ? !0 : e.selection.some(
        ({ scope: $, language: A }) => (!$ || !t || $.key === t) && (!A || !s || A.key === s)
      );
    }
    function l(t, s) {
      e.loading || n("edited", t, s);
    }
    return T(
      () => p.value.map((t) => o.value?.[t]).filter(Boolean).join(),
      () => n("updated")
    ), W(() => {
      p.value.filter(Boolean).length && n("field-names", p.value);
    }), (t, s) => (i(), B(m(N), null, {
      default: f(() => [
        L(m(Y), null, {
          default: f(() => [
            (i(!0), b(w, null, P(v.value, ($, A) => (i(), b(w, {
              key: $.key || A
            }, [
              (i(!0), b(w, null, P(u.value, (a, d) => (i(), b(w, {
                key: a.key || d
              }, [
                h($.key, a.key) ? (i(), B(ve, {
                  key: 0,
                  modelValue: o.value,
                  "onUpdate:modelValue": s[0] || (s[0] = (c) => o.value = c),
                  scope: $,
                  language: a,
                  selection: t.selection,
                  attribute: t.attribute,
                  "blocked-attribute": t.blockedAttributes?.[t.attribute?.id],
                  readonly: t.readonly,
                  loading: t.loading,
                  scopable: t.scopable,
                  multilanguage: t.multilanguage,
                  prefix: t.prefix,
                  class: "mb-2",
                  onEdited: l,
                  onInitialized: s[1] || (s[1] = (c) => t.$emit("initialized", c))
                }, q({ _: 2 }, [
                  t.$slots.prepend ? {
                    name: "prepend",
                    fn: f((c) => [
                      U(t.$slots, "prepend", _({ ref_for: !0 }, c))
                    ]),
                    key: "0"
                  } : void 0
                ]), 1032, ["modelValue", "scope", "language", "selection", "attribute", "blocked-attribute", "readonly", "loading", "scopable", "multilanguage", "prefix"])) : V("", !0)
              ], 64))), 128))
            ], 64))), 128))
          ]),
          _: 3
        })
      ]),
      _: 3
    }));
  }
}), Le = /* @__PURE__ */ z({
  inheritAttrs: !0,
  __name: "MultiLangScopeEditorsList",
  props: /* @__PURE__ */ I({
    attributes: { default: () => Array(5).fill(null) },
    blockedAttributes: { default: void 0 },
    scopes: { default: void 0 },
    languages: { default: void 0 },
    selection: { default: void 0 },
    prefix: { default: void 0 },
    readonly: { type: Boolean },
    loading: { type: Boolean },
    scopable: { type: Boolean },
    multilanguage: { type: Boolean }
  }, {
    modelValue: { default: () => ({}) },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ I(["field-names", "edited", "validated", "updated", "initialized", "active-attribute"], ["update:modelValue"]),
  setup(y, { expose: r, emit: e }) {
    const n = y, o = e, v = F(y, "modelValue");
    let u = [];
    const k = C(), p = C(), { y: h } = Z(() => p.value?.$el), l = S(
      () => n.loading && !n.attributes?.length ? Array(5).fill(null) : n.attributes
    );
    function t(a) {
      u = [.../* @__PURE__ */ new Set([...u, ...a])].filter(Boolean), o("field-names", u);
    }
    function s(a, d) {
      !n.loading && !n.readonly && o("edited", a, d);
    }
    function $(a) {
      n.readonly || o("validated", !!(a?.detail ?? a));
    }
    function A(a) {
      p.value?.scrollToIndex(a);
    }
    return x(
      h,
      () => {
        let a;
        try {
          if (!p.value?.$el)
            return;
          const d = p.value.$el.getBoundingClientRect().top ?? 0, c = p.value.$el.querySelectorAll(".v-virtual-scroll__item"), g = Array.from(c).find(
            (Q) => Q.getBoundingClientRect().bottom > d
          );
          g && (a = g.children[0].dataset.key);
        } finally {
          k.value !== a && (k.value = a, o("active-attribute", k.value));
        }
      },
      { debounce: 100 }
    ), r({
      scrollToIndex: A
    }), (a, d) => (i(), B(m(ee), {
      ref_key: "virtualScroll",
      ref: p,
      items: l.value
    }, {
      default: f(({ item: c }) => [
        L(be, _({
          id: m(oe)(c?.id),
          modelValue: v.value,
          "onUpdate:modelValue": d[0] || (d[0] = (g) => v.value = g),
          "field-name": c?.key,
          "data-key": c?.key,
          attribute: c,
          "blocked-attributes": a.blockedAttributes,
          scopes: a.scopes,
          languages: a.languages,
          selection: a.selection,
          readonly: a.readonly,
          loading: a.loading,
          scopable: a.scopable,
          multilanguage: a.multilanguage,
          prefix: a.prefix
        }, a.$attrs, {
          onFieldNames: t,
          onEdited: s,
          onValidatedEvent: $,
          onValidated: d[1] || (d[1] = (g) => a.$emit("validated", g)),
          onUpdated: d[2] || (d[2] = (g) => o("updated")),
          onInitialized: d[3] || (d[3] = (g) => a.$emit("initialized", g))
        }), q({ _: 2 }, [
          a.$slots.prepend ? {
            name: "prepend",
            fn: f((g) => [
              U(a.$slots, "prepend", R(M(g)))
            ]),
            key: "0"
          } : void 0
        ]), 1040, ["id", "modelValue", "field-name", "data-key", "attribute", "blocked-attributes", "scopes", "languages", "selection", "readonly", "loading", "scopable", "multilanguage", "prefix"])
      ]),
      _: 3
    }, 8, ["items"]));
  }
});
export {
  pe as L,
  ue as S,
  Le as _,
  be as a
};
