import { defineComponent as T, ref as v, computed as k, onBeforeMount as U, createBlock as l, openBlock as n, unref as i, withCtx as c, createElementBlock as m, createCommentVNode as C, createVNode as B, createTextVNode as D, toDisplayString as b, resolveDynamicComponent as W, renderSlot as z, Fragment as _, renderList as K, markRaw as H } from "vue";
import { useI18n as F } from "vue-i18n";
import { ae as M, T as L, h as Q, Y, aP as j, aQ as V, aR as q, ad as A, G as J } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
import O from "./SettingsElement-QE_or6_k.js";
const X = {
  key: 0,
  class: "form-title pl-5 py-2"
}, Z = { key: 0 }, x = /* @__PURE__ */ T({
  __name: "SettingSettings",
  props: {
    fieldsEndpoint: {},
    getDataEndpoint: {},
    saveEndpoint: {},
    hierarchyKey: {},
    identifier: {},
    autoload: { type: Boolean },
    namespace: {},
    noHeader: { type: Boolean },
    border: { type: Boolean }
  },
  setup(y) {
    const s = y, { t: h } = F(), g = v(!1), f = v(!1), d = v([]), E = v([]), a = v(), r = k(
      () => E.value.find(({ key: t }) => t === a.value?.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: u }) {
      const e = {};
      t.forEach((o) => {
        e[o.groupId] || (e[o.groupId] = []), e[o.groupId].push({
          ...o,
          path: o.vueImportPath || o.element,
          component: H(
            J({
              name: o.vueComponent ?? o.element,
              url: o.vueImportPath
            })
          )
        });
      });
      const p = e[0] ?? [];
      u.forEach((o) => {
        e[o.id] && p.push(
          { isGroup: !0, name: o.name },
          ...e[o.id]
        );
      }), d.value = p;
    }
    async function R() {
      try {
        f.value = !0;
        const t = await A(
          s.fieldsEndpoint,
          w.value
        );
        P(t);
      } finally {
        f.value = !1;
      }
    }
    async function $() {
      try {
        g.value = !0;
        const { data: t } = await A(
          s.getDataEndpoint,
          N.value
        ), u = d.value.filter(
          ({ key: e }) => e && t.every((p) => p.key !== e)
        );
        E.value = [
          ...t,
          ...u.map(
            ({ key: e }) => ({ key: e, value: void 0 })
          )
        ].map((e, p) => ({ ...e, uniqId: p }));
      } finally {
        g.value = !1;
      }
    }
    async function G() {
      await R(), await $(), S(d.value[0]);
    }
    function S(t) {
      a.value = t;
    }
    return U(() => {
      s.autoload && G();
    }), (t, u) => (n(), l(i(M), { border: t.border }, {
      sidebar: c(() => [
        z(t.$slots, "header", {}, () => [
          t.noHeader ? C("", !0) : (n(), m("h4", X, b(i(h)("setting-plugin.setting-settings.settings")), 1))
        ]),
        f.value ? (n(), m(_, { key: 0 }, K(5, (e) => B(i(L), {
          key: e,
          type: "list-item"
        })), 64)) : (n(), l(i(j), { key: 1 }, {
          default: c(() => [
            d.value.length ? (n(!0), m(_, { key: 1 }, K(d.value, (e) => (n(), m(_, {
              key: e.key
            }, [
              e.isGroup ? (n(), l(i(q), {
                key: 0,
                title: e.name
              }, null, 8, ["title"])) : (n(), l(i(V), {
                key: 1,
                active: a.value === e,
                title: e.name,
                onClick: (p) => S(e)
              }, null, 8, ["active", "title", "onClick"]))
            ], 64))), 128)) : (n(), l(i(V), {
              key: 0,
              disabled: ""
            }, {
              default: c(() => [
                D(b(i(h)("setting-plugin.setting-settings.noSettingsAvailable")), 1)
              ]),
              _: 1
            }))
          ]),
          _: 1
        }))
      ]),
      default: c(() => [
        f.value || d.value.length && (!r.value || !a.value) ? (n(), m("div", Z, [
          B(i(L), { type: "article" })
        ])) : a.value && r.value ? (n(), l(i(Q), {
          key: a.value?.key
        }, {
          default: c(() => [
            a.value.import && !a.value.component ? (n(), l(i(Y), {
              key: 0,
              type: "error",
              color: "error"
            }, {
              default: c(() => [
                D(b(i(h)("setting-plugin.setting-settings.componentNotReady", {
                  component: a.value.element
                })), 1)
              ]),
              _: 1
            })) : a.value.complexLayout ? (n(), l(W(a.value.component), {
              key: 1,
              modelValue: r.value.value,
              "onUpdate:modelValue": u[0] || (u[0] = (e) => r.value.value = e),
              loading: g.value,
              settings: a.value,
              options: a.value.options,
              data: r.value
            }, null, 8, ["modelValue", "loading", "settings", "options", "data"])) : (n(), l(i(O), {
              key: 2,
              modelValue: r.value.value,
              "onUpdate:modelValue": u[1] || (u[1] = (e) => r.value.value = e),
              component: a.value.component,
              loading: g.value,
              settings: a.value,
              options: a.value.options,
              data: r.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
        })) : C("", !0)
      ]),
      _: 3
    }, 8, ["border"]));
  }
});
function I(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 I == "function" && I(x);
export {
  x as default
};
