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