"use strict";
const common_vendor = require("../../common/vendor.js");
require("../../common/libraries/request.js");
require("../../common/store/useWatermarkStore.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 ME_update_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 handleChangeUserInfo = (data) => {
  common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.ChangeAvatar, data).then((res) => {
    auth.data.user = {
      ...auth.data.user,
      ...data
    };
    ME_update_model.useModel.formData.value = {
      ...auth.data.user,
      ...data
    };
    common_vendor.index.showToast({
      icon: "success",
      title: "编辑成功！",
      duration: 2e3
    });
    console.log(res);
  });
};
const method = {
  init() {
    var _a;
    ME_update_model.useModel.formData.value = ((_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.user) || {};
  },
  handleChooseAvatar: async (e) => {
    var _a, _b;
    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);
      handleChangeUserInfo({ avatar: data });
      console.log(data, "filePath");
    }
    console.log(e, "eeeee");
  },
  handleConfirm(e) {
    handleChangeUserInfo({ name: e });
    console.log(e, "eeeee");
  },
  handleLogout() {
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Logout, {}).then((res) => {
      auth.data = {
        user: void 0
      };
      common_libraries_naviHelper.showToastBack("退出成功！", 1, true);
      console.log(res);
    });
  }
};
exports.method = method;
