import { defineComponent, ref, openBlock, createBlock, unref, withCtx, createElementVNode, withModifiers, createVNode, createElementBlock, Fragment, renderList } from "vue";
import { u as useI18n, a as useSettings, b as useAppStore, _ as _sfc_main$1, D as DxForm_1, c as DxTabbedItem_1, d as DxTabPanelOptions_1, e as DxTab_1, f as DxSimpleItem_1, g as DxLabel_1, h as DxButtonItem_1, n as notify } from "./index-8d76cfd8.mjs";
const _hoisted_1 = ["onSubmit"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Tweaks",
  setup(__props) {
    const i18n = useI18n();
    const { t } = i18n;
    const { service, items } = useSettings();
    const appStore = useAppStore();
    const definition = items(i18n);
    const state = ref({});
    const loadSettings = async () => {
      appStore.loading = true;
      try {
        state.value = await service.load();
      } finally {
        appStore.loading = false;
      }
    };
    const onFormSubmit = async () => {
      appStore.loading = true;
      try {
        await service.save(state.value);
        notify(t("message.updateSuccess"), "success");
      } finally {
        appStore.loading = false;
      }
    };
    loadSettings();
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$1, {
        title: unref(t)("tweaks")
      }, {
        default: withCtx(() => [
          createElementVNode("form", {
            onSubmit: withModifiers(onFormSubmit, ["prevent"])
          }, [
            createVNode(unref(DxForm_1), {
              "form-data": state.value,
              "show-colon-after-label": false
            }, {
              default: withCtx(() => [
                createVNode(unref(DxTabbedItem_1), null, {
                  default: withCtx(() => [
                    createVNode(unref(DxTabPanelOptions_1), {
                      "defer-rendering": false,
                      "show-nav-buttons": true
                    }),
                    (openBlock(true), createElementBlock(Fragment, null, renderList(unref(definition), (group) => {
                      return openBlock(), createBlock(unref(DxTab_1), {
                        key: group.text,
                        title: group.text
                      }, {
                        default: withCtx(() => [
                          (openBlock(true), createElementBlock(Fragment, null, renderList(group.items, (item) => {
                            return openBlock(), createBlock(unref(DxSimpleItem_1), {
                              key: item,
                              "editor-type": item.editorType,
                              "editor-options": item.editorOptions || {},
                              "data-field": item.name
                            }, {
                              default: withCtx(() => [
                                createVNode(unref(DxLabel_1), {
                                  text: item.text
                                }, null, 8, ["text"])
                              ]),
                              _: 2
                            }, 1032, ["editor-type", "editor-options", "data-field"]);
                          }), 128))
                        ]),
                        _: 2
                      }, 1032, ["title"]);
                    }), 128))
                  ]),
                  _: 1
                }),
                createVNode(unref(DxButtonItem_1), {
                  "horizontal-alignment": "center",
                  "button-options": {
                    text: unref(t)("save"),
                    type: "success",
                    useSubmitBehavior: true
                  }
                }, null, 8, ["button-options"])
              ]),
              _: 1
            }, 8, ["form-data"])
          ], 40, _hoisted_1)
        ]),
        _: 1
      }, 8, ["title"]);
    };
  }
});
export {
  _sfc_main as default
};
