import { defineComponent as h, mergeModels as B, useModel as g, ref as c, computed as E, watch as p, createElementBlock as D, openBlock as r, createElementVNode as y, createBlock as m, createCommentVNode as f, toDisplayString as w, unref as n, withCtx as C, createTextVNode as S, resolveDynamicComponent as U } from "vue";
import { useI18n as M } from "vue-i18n";
import { c as F } from "./index-fFOslvm5.mjs";
import { a8 as N, E as O, _ as A, a5 as I } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
const P = { class: "d-flex align-center pl-5 py-2" }, _ = { class: "mr-auto" }, $ = /* @__PURE__ */ h({
  __name: "SettingsElement",
  props: /* @__PURE__ */ B({
    modelValue: {},
    data: {},
    options: {},
    settings: {},
    loading: { type: Boolean },
    readonly: { type: Boolean },
    isDefault: { type: Boolean },
    component: {},
    saveProps: {},
    saveEndpoint: {}
  }, {
    modelValue: {},
    modelModifiers: {},
    valid: { type: Boolean, default: !0 },
    validModifiers: {}
  }),
  emits: ["update:modelValue", "update:valid"],
  setup(o) {
    const t = o, u = g(o, "modelValue"), i = g(o, "valid");
    i.value = !0;
    const { t: v } = M(), a = c(!1), d = c(!1), b = E(
      () => a.value && t.data.hasDefault
    );
    async function k() {
      const e = {
        ...t.saveProps,
        settingsKey: t.settings.key,
        data: [
          {
            key: t.settings.key,
            value: a.value ? void 0 : u.value
          }
        ]
      };
      try {
        d.value = !0, await I(t.saveEndpoint, e);
      } finally {
        d.value = !1;
      }
    }
    return p(
      () => t.data.overwritten,
      (e) => {
        d.value = !!e;
      },
      { immediate: !0 }
    ), p(
      () => t.data.isDefault,
      (e) => {
        a.value = !!e;
      },
      { immediate: !0 }
    ), p(
      a,
      (e) => {
        e && (i.value = !0, u.value = F(t.data.defaultValue));
      },
      { immediate: !0 }
    ), (e, l) => (r(), D("div", null, [
      y("div", P, [
        y("h4", _, w(e.settings.name), 1),
        e.data.hasDefault && !e.data.overwritten ? (r(), m(n(N), {
          key: 0,
          modelValue: a.value,
          "onUpdate:modelValue": l[0] || (l[0] = (s) => a.value = s),
          label: n(v)("setting-plugin.setting-element.inheritFrom", {
            origin: e.data.origin
          }),
          color: "primary",
          class: "mr-2",
          "hide-details": ""
        }, null, 8, ["modelValue", "label"])) : f("", !0),
        e.saveEndpoint ? (r(), m(n(O), {
          key: 1,
          text: n(v)("common.save"),
          disabled: d.value || !i.value,
          color: "primary",
          onClick: k
        }, null, 8, ["text", "disabled"])) : f("", !0)
      ]),
      e.data.overwritten ? (r(), m(n(A), {
        key: 0,
        icon: "lock"
      }, {
        default: C(() => [
          S(w(n(v)("setting-plugin.setting-element.alwaysOverwritten")), 1)
        ]),
        _: 1
      })) : f("", !0),
      (r(), m(U(e.component), {
        modelValue: u.value,
        "onUpdate:modelValue": l[1] || (l[1] = (s) => u.value = s),
        valid: i.value,
        "onUpdate:valid": l[2] || (l[2] = (s) => i.value = s),
        readonly: b.value,
        settings: e.settings,
        options: e.options,
        data: e.data,
        loading: e.loading,
        "is-default": a.value
      }, null, 40, ["modelValue", "valid", "readonly", "settings", "options", "data", "loading", "is-default"]))
    ]));
  }
});
function V(o) {
  const t = o;
  t.__i18n = t.__i18n || [], t.__i18n.push({
    locale: "",
    resource: {
      "en-US": {
        "setting-plugin": {
          "setting-element": {
            inheritFrom: { t: 0, b: { t: 2, i: [{ t: 3, v: "Inherit from '" }, { t: 4, k: "origin" }, { t: 3, v: "'" }] } },
            alwaysOverwritten: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Setting will be always overwritten" } }
          }
        }
      },
      "de-DE": {
        "setting-plugin": {
          "setting-element": {
            inheritFrom: { t: 0, b: { t: 2, i: [{ t: 3, v: "Von '" }, { t: 4, k: "origin" }, { t: 3, v: "' übernehmen" }] } },
            alwaysOverwritten: { t: 0, b: { t: 2, i: [{ t: 3 }], s: "Einstellung wird immer überschrieben" } }
          }
        }
      }
    }
  });
}
typeof V == "function" && V($);
export {
  $ as default
};
