import { defineComponent as H, ref as c, computed as k, onBeforeMount as T, createBlock as r, openBlock as n, unref as i, withCtx as d, createElementBlock as v, createVNode as C, createTextVNode as A, toDisplayString as _, resolveDynamicComponent as U, renderSlot as x, createCommentVNode as z, Fragment as b, renderList as I, markRaw as W } from "vue";
import { useI18n as F } from "vue-i18n";
import { a6 as J, R as K, f as M, J as j, aG as q, aH as L, aI as O, a5 as V, C as Q, l as X } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import Y from "./SettingsElement-C1Y9C_Fw.mjs";
const Z = {
  key: 0,
  class: "form-title text-body-2 pl-5 py-2"
}, ee = { key: 0 }, D = /* @__PURE__ */ H({
  __name: "SettingSettings",
  props: {
    fieldsEndpoint: {},
    getDataEndpoint: {},
    saveEndpoint: {},
    hierarchyKey: {},
    identifier: {},
    autoload: { type: Boolean },
    namespace: {},
    noHeader: { type: Boolean }
  },
  setup(y) {
    const s = y, { t: h } = F(), m = c(!1), g = c(!1), f = c([]), E = c([]), a = c(), u = k(
      () => E.value.find(({ key: t }) => {
        var l;
        return t === ((l = a.value) == null ? void 0 : l.key);
      })
    ), w = k(() => ({
      hierarchyKey: s.hierarchyKey,
      namespace: s.namespace
    })), N = k(() => ({
      hierarchyKey: s.hierarchyKey,
      namespace: s.namespace,
      identifier: s.identifier
    }));
    function P({ elements: t, groups: l }) {
      const e = {};
      t.forEach((o) => {
        e[o.groupId] || (e[o.groupId] = []), e[o.groupId].push({
          ...o,
          path: o.vueImportPath || o.element,
          component: W(
            Q({
              name: o.vueComponent ?? o.element,
              url: o.vueImportPath
            })
          )
        });
      });
      const p = e[0] ?? [];
      l.forEach((o) => {
        e[o.id] && p.push(
          { isGroup: !0, name: o.name },
          ...e[o.id]
        );
      }), f.value = p;
    }
    async function R() {
      try {
        g.value = !0;
        const t = await V(
          s.fieldsEndpoint,
          w.value
        );
        P(t);
      } finally {
        g.value = !1;
      }
    }
    async function G() {
      try {
        m.value = !0;
        const { data: t } = await V(
          s.getDataEndpoint,
          N.value
        );
        E.value = t.map((l, e) => ({ ...l, uniqId: e }));
      } finally {
        m.value = !1;
      }
    }
    async function $() {
      await Promise.all([R(), G()]), S(f.value[0]);
    }
    function S(t) {
      a.value = t;
    }
    return T(() => {
      s.autoload && $();
    }), (t, l) => (n(), r(i(J), { class: "setting__wrapper" }, {
      sidebar: d(() => [
        x(t.$slots, "header", {}, () => [
          t.noHeader ? z("", !0) : (n(), v("h4", Z, _(i(h)("setting-plugin.setting-settings.settings")), 1))
        ], !0),
        g.value ? (n(), v(b, { key: 0 }, I(5, (e) => C(i(K), {
          key: e,
          type: "list-item"
        })), 64)) : (n(), r(i(q), { key: 1 }, {
          default: d(() => [
            f.value.length ? (n(!0), v(b, { key: 1 }, I(f.value, (e) => (n(), v(b, {
              key: e.key
            }, [
              e.isGroup ? (n(), r(i(O), {
                key: 0,
                title: e.name
              }, null, 8, ["title"])) : (n(), r(i(L), {
                key: 1,
                active: a.value === e,
                title: e.name,
                onClick: (p) => S(e)
              }, null, 8, ["active", "title", "onClick"]))
            ], 64))), 128)) : (n(), r(i(L), {
              key: 0,
              disabled: ""
            }, {
              default: d(() => [
                A(_(i(h)("setting-plugin.setting-settings.noSettingsAvailable")), 1)
              ]),
              _: 1
            }))
          ]),
          _: 1
        }))
      ]),
      default: d(() => {
        var e;
        return [
          g.value || !u.value || !a.value ? (n(), v("div", ee, [
            C(i(K), { type: "article" })
          ])) : (n(), r(i(M), {
            key: (e = a.value) == null ? void 0 : e.key
          }, {
            default: d(() => [
              a.value.import && !a.value.component ? (n(), r(i(j), {
                key: 0,
                type: "error",
                color: "error"
              }, {
                default: d(() => [
                  A(_(i(h)("setting-plugin.setting-settings.componentNotReady", {
                    component: a.value.element
                  })), 1)
                ]),
                _: 1
              })) : a.value.complexLayout ? (n(), r(U(a.value.component), {
                key: 1,
                modelValue: u.value.value,
                "onUpdate:modelValue": l[0] || (l[0] = (p) => u.value.value = p),
                loading: m.value,
                settings: a.value,
                options: a.value.options,
                data: u.value
              }, null, 8, ["modelValue", "loading", "settings", "options", "data"])) : (n(), r(i(Y), {
                key: 2,
                modelValue: u.value.value,
                "onUpdate:modelValue": l[1] || (l[1] = (p) => u.value.value = p),
                component: a.value.component,
                loading: m.value,
                settings: a.value,
                options: a.value.options,
                data: u.value,
                "save-endpoint": t.saveEndpoint,
                "save-props": {
                  hierarchyKey: t.hierarchyKey,
                  namespace: t.namespace,
                  identifier: t.identifier
                }
              }, null, 8, ["modelValue", "component", "loading", "settings", "options", "data", "save-endpoint", "save-props"]))
            ]),
            _: 1
          }))
        ];
      }),
      _: 3
    }));
  }
});
function B(y) {
  const s = y;
  s.__i18n = s.__i18n || [], s.__i18n.push({
    locale: "",
    resource: {
      "en-US": {
        "setting-plugin": {
          "setting-settings": {
            settings: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Settings" } },
            noSettingsAvailable: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "There are no settings available" } },
            componentNotReady: { t: 0, b: { t: 2, i: [{ t: 3, v: "This configuration value can currently not be changed through the user interface (" }, { t: 4, k: "component" }, { t: 3, v: ")" }] } }
          }
        }
      },
      "de-DE": {
        "setting-plugin": {
          "setting-settings": {
            settings: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Einstellungen" } },
            noSettingsAvailable: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Keine Einstellungen verfügbar" } },
            componentNotReady: { t: 0, b: { t: 2, i: [{ t: 3, v: "Dieser Konfigurations-Wert kann derzeit nicht über die Benutzeroberfläche (" }, { t: 4, k: "component" }, { t: 3, v: ") geändert werden." }] } }
          }
        }
      }
    }
  });
}
typeof B == "function" && B(D);
const ue = /* @__PURE__ */ X(D, [["__scopeId", "data-v-47c38bdf"]]);
export {
  ue as default
};
