"use strict";
const common_vendor = require("../vendor.js");
const gen_Apis = require("../../gen/Apis.js");
const common_libraries_apiLoading = require("../libraries/apiLoading.js");
const useWeAppAuthStore = common_vendor.defineStore("we_app_auth", () => {
  const loading = common_vendor.ref(true);
  const hasError = common_vendor.ref(false);
  const data = common_vendor.ref({
    user: { id: 0, username: "" }
  });
  function login(app) {
    common_vendor.index.login({
      provider: "weixin",
      //使用微信登录
      success: function(loginRes) {
        console.log(loginRes.code);
        return false;
      }
    });
  }
  function me() {
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Me, {}).then((res) => {
      data.value.user = res.data.user;
      console.log("me", res.data);
      loading.value = false;
      hasError.value = false;
    });
  }
  const handleUserLogin = async (from_data) => {
    common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.BindPhoneNumber, from_data).then((res) => {
      me();
    });
  };
  return {
    loading,
    hasError,
    data,
    login,
    me,
    handleUserLogin
  };
});
exports.useWeAppAuthStore = useWeAppAuthStore;
