"use strict";const e=require("../vendor.js"),o=require("../../gen/Apis.js"),i=require("../libraries/setTabBar.js"),u=require("../libraries/apiLoading.js"),a="wx31500e871924b903",n=e.defineStore("we_app_auth",(()=>{const n=e.ref(!1),s=e.ref(!1),t=e.ref(0),l=e.ref({user:{id:0,name:""},work_info:{session_key:"",openid:""},selected_house:{},environment:"",house_occupant:!1,house_register:!1,is_house_exist:0,config:{}});const r=(u,t)=>{o.Apis.Login.Auth.Login({code:t,app_id:a}).then((o=>{var a,t,r,v,c,g;console.log("登录",null==o?void 0:o.data),e.index.setStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER",null==(t=null==(a=null==o?void 0:o.data)?void 0:a.token)?void 0:t.token),null==u||u.appContext.config.globalProperties.$isResolve(),setTimeout((()=>{n.value=!1,s.value=!1}),300),l.value.selected_house=null==(r=o.data)?void 0:r.selected_house,l.value.user=null==(v=o.data)?void 0:v.user,l.value.config=null==(c=o.data)?void 0:c.config,i.setTabBar(null==(g=null==o?void 0:o.data)?void 0:g.config),l.value.user&&d()})).catch((()=>{n.value=!1,s.value=!0}))},d=()=>{o.Apis.Archive.HouseOccupants.GetCustomerHouseIsExist().then((e=>{var o,i;l.value.house_occupant=(null==(o=e.data)?void 0:o.house_occupant)||!1,l.value.house_register=(null==(i=e.data)?void 0:i.house_register)||!1,l.value.is_house_exist=t.value+1}))};function v(e){u.getApiLoading(o.Apis.Login.Auth.Me,{}).then((o=>{var u,a,t;return l.value.user=o.data.user,l.value.config=null==(u=o.data)?void 0:u.config,l.value.selected_house=null==(a=o.data)?void 0:a.selected_house,console.log("me",o.data),l.value.user&&d(),setTimeout((()=>{n.value=!1,s.value=!1}),300),i.setTabBar(null==(t=null==o?void 0:o.data)?void 0:t.config),null==e?void 0:e()}))}return{loading:n,hasError:s,data:l,login:function(o){e.index.login({provider:"weixin",success:function(e){console.log(e),r(o,e.code)}})},me:v,handleUserLogin:async i=>{u.getApiLoading(o.Apis.Login.Auth.BindPhoneNumber,{app_id:a,...i}).then((o=>{v((()=>{e.index.navigateBack({delta:1})}))}))},getIsHouseExist:d}}));exports.useWeAppAuthStore=n;
