import { _ as u, f as a } from "./import-file-r6B0-WFX.js";
import "./user-DCzCj0wb.js";
import { resolveComponent as m, createElementBlock as p, openBlock as c, createElementVNode as r, createTextVNode as d, toDisplayString as b, createBlock as h, createCommentVNode as f } from "vue";
const g = {
  data() {
    return {
      formScheme: null,
      uid: null,
      userData: null
    };
  },
  async created() {
    await this.getUserData(), await this.getFormScheme();
  },
  methods: {
    async getUserData() {
      var o;
      const { data: e } = await a.get("/user");
      this.uid = (o = e == null ? void 0 : e.user) == null ? void 0 : o.uid;
      const { data: t } = await a.get(`/api/table/admin.users.table/${this.uid}`);
      this.userData = t;
    },
    async updateUser() {
      try {
        await a.put(`/api/user/${this.uid}`, this.userData), await this.$notify({
          title: "Успішно!",
          message: "Дані успішно оновлені",
          type: "success"
        });
      } catch (e) {
        this.$notify({
          title: "Помилка!",
          message: `Сталася помилка редагування.
${e.toString()}`,
          type: "error"
        });
      }
    },
    async getFormScheme() {
      try {
        const { data: e } = await a.get(
          "/api/template/form/admin.profile.form"
        );
        this.formScheme = e.schema;
      } catch (e) {
        console.error(e);
      }
    }
  }
}, x = { class: "flex justify-center pt-[20px] pb-[20px] pl-[20px] h-[calc(100vh-58px)]" }, w = { class: "bg-white rounded-xl p-[20px]" }, y = { class: "flex-1 overflow-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500" }, k = { class: "flex" };
function _(e, t, o, D, s, i) {
  const n = m("VsForm");
  return c(), p("div", x, [
    r("div", w, [
      d(b(e.user) + " ", 1),
      t[2] || (t[2] = r("h2", { class: "mb-[20px] text-center" }, "Профіль", -1)),
      r("div", y, [
        s.formScheme ? (c(), h(n, {
          key: 0,
          scheme: s.formScheme,
          modelValue: s.userData,
          "onUpdate:modelValue": t[0] || (t[0] = (l) => s.userData = l),
          class: "pb-0"
        }, null, 8, ["scheme", "modelValue"])) : f("", !0),
        r("div", k, [
          r("button", {
            onClick: t[1] || (t[1] = (...l) => i.updateUser && i.updateUser(...l)),
            class: "ml-auto text-[18px] bg-blue-500 text-white px-[8px] py-[4px] rounded hover:bg-blue-700 duration-300"
          }, " Зберегти ")
        ])
      ])
    ])
  ]);
}
const U = /* @__PURE__ */ u(g, [["render", _]]);
export {
  U as default
};
