import { defineComponent as h, mergeModels as B, useModel as g, ref as c, computed as D, watch as p, createElementBlock as E, openBlock as r, createElementVNode as y, createBlock as m, createCommentVNode as f, toDisplayString as b, 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-C0QCq-hK.js";
import { ag as I, I as N, b as O, ad as _ } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
const $ = { class: "d-flex align-center pl-5 py-2" }, P = { class: "mr-auto" }, q = /* @__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), V = D(
      () => 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 _(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(), E("div", null, [
      y("div", $, [
        y("h4", P, b(e.settings.name), 1),
        e.data.hasDefault && !e.data.overwritten ? (r(), m(n(I), {
          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"
        }, null, 8, ["modelValue", "label"])) : f("", !0),
        e.saveEndpoint ? (r(), m(n(N), {
          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(O), {
        key: 0,
        icon: "lucide:lock"
      }, {
        default: C(() => [
          S(b(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: V.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 w(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 w == "function" && w(q);
export {
  q as default
};
