"use strict";const e=require("../../common/vendor.js"),t=require("../platform/share.js"),o=require("./cart.js");require("./app.js");const s=require("../hooks/useModal.js"),a=require("../api/member/user.js"),r=require("../api/pay/wallet.js"),n=require("../api/trade/order.js"),i=require("../api/promotion/coupon.js"),u={avatar:"",nickname:"",gender:0,mobile:"",point:0,username:"",socialStatusLevel:"",socialStatusLevelName:"",socialStatusPoint:0,socialUpNeed:0},d={integralDO:{currentQuota:0,highQuota:0,freezeQuota:0},descNo:0,descPrice:0,descTotalPrice:0},l={unusedCouponCount:0,orderCount:{allCount:0,unpaidCount:0,undeliveredCount:0,deliveredCount:0,uncommentedCount:0,afterSaleCount:0}},c=e.defineStore({id:"user",state:()=>({userInfo:e.lodashExports.clone(u),userWallet:e.lodashExports.clone(d),isLogin:!!e.index.getStorageSync("token"),numData:e.lodashExports.cloneDeep(l),lastUpdateTime:0}),actions:{async getInfo(){const{code:e,data:t}=await a.UserApi.getUserInfo();if(0===e)return this.userInfo=t,s.autoSign(),Promise.resolve(t)},async getWallet(){const{code:t,data:o}=await r.PayWalletApi.getDuserInfo();0===t&&(this.userWallet=o,this.userWallet.descNo=o.descNo+1,e.index.setStorageSync("isSign",o.isSign))},getNumData(){n.OrderApi.getOrderCount().then((e=>{0===e.code&&(this.numData.orderCount=e.data)})),i.CouponApi.getUnusedCouponCount().then((e=>{0===e.code&&(this.numData.unusedCouponCount=e.data)}))},async addShareLog(t){const{error:o}=await userApi.addShareLog(t);0===o&&e.index.removeStorageSync("shareLog")},setToken(t="",o=""){return""===t?(this.isLogin=!1,e.index.removeStorageSync("token"),e.index.removeStorageSync("refresh-token")):(this.isLogin=!0,e.index.setStorageSync("token",t),e.index.setStorageSync("refresh-token",o),this.loginAfter()),this.isLogin},async updateUserData(){if(!this.isLogin)return void this.resetUserData();const e=(new Date).getTime();return this.lastUpdateTime+5e3>e?void 0:(this.lastUpdateTime=e,await this.getInfo(),this.getWallet(),this.getNumData(),this.userInfo)},resetUserData(){this.setToken(),this.userInfo=e.lodashExports.clone(u),this.userWallet=e.lodashExports.clone(d),this.numData=e.lodashExports.cloneDeep(l),o.cart().emptyList(),s.cancelAutoSign(),e.index.removeStorageSync("isSign")},async loginAfter(){await this.updateUserData(),o.cart().getList(),t.$share.getShareInfo();const s=e.index.getStorageSync("shareLog");e.lodashExports.isEmpty(s)||this.addShareLog({...s})},async logout(){return this.resetUserData(),!this.isLogin}},persist:{enabled:!0,strategies:[{key:"user-store"}]}}),g=Object.freeze(Object.defineProperty({__proto__:null,default:c},Symbol.toStringTag,{value:"Module"}));exports.__vite_glob_0_4=g,exports.user=c;
