"use strict";
const common_vendor = require("../../common/vendor.js");
require("../../common/libraries/request.js");
const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js");
require("../../common/store/useWorkStore.js");
const common_libraries_apiLoading = require("../../common/libraries/apiLoading.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
const INDEX_me_model = require("./model.js");
const gen_Apis = require("../../gen/Apis.js");
const common_libraries_upload = require("../../common/libraries/upload.js");
const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
const method = {
  init() {
    var _a;
    INDEX_me_model.useModel.formData.value = JSON.parse(JSON.stringify(((_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.user) || {}));
  },
  handleChooseAvatar: async (e) => {
    var _a, _b;
    console.log(e, "eeeee");
    if ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.avatarUrl) {
      let data = await common_libraries_upload.avatarUpload((_b = e == null ? void 0 : e.detail) == null ? void 0 : _b.avatarUrl);
      INDEX_me_model.useModel.formData.value.avatar = data;
      console.log(data, "filePath");
    }
  },
  handleConfirm() {
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.ChangeName, INDEX_me_model.useModel.formData.value).then((res) => {
      common_vendor.index.showToast({
        icon: "success",
        title: "编辑成功！",
        duration: 1e3,
        success: () => {
          setTimeout(() => {
            auth.data.user = {
              ...auth.data.user,
              ...INDEX_me_model.useModel.formData.value
            };
          }, 1e3);
        }
      });
      console.log(res);
    });
  },
  handleLogout() {
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Logout, {}).then((res) => {
      common_libraries_naviHelper.showToastBack("退出成功！", 1, true);
      setTimeout(() => {
        auth.data = {
          user: void 0,
          selected_house: void 0,
          config: void 0
        };
      }, 1e3);
      console.log(res);
    });
  }
};
exports.method = method;
