import{h as n}from"./axios.config-ca0d2d18.js";import{y as o,E as c,ag as m}from"./index-ece68a0b.js";import{c as i}from"./currencies.state-5aa95c1c.js";import{c as u}from"./dateTime-1069f6fe.js";const p={async getCurrencies(){return i.currencies=await n.get("/currencies"),i.currenciesMap.clear(),i.currencies.forEach(s=>{i.currenciesMap.set(s.id,s)}),i.currencies}},f={async login(s){try{return await n.post("/user/login",s)}catch(a){throw a}},getUserStatistics(s,a){var r,g;const t={};return t.from_date=u(a[0],(r=o.userInfo)==null?void 0:r.time_zone),t.to_date=u(a[1],(g=o.userInfo)==null?void 0:g.time_zone),n.get("/user/statistics",{params:t})},async logout(){return await n.delete("/user/logout")},async getMe(){return new Promise(async s=>{const a=await p.getCurrencies(),t=await n.get("/user");o.userInfo={...t,currency:a.find(r=>r.id===t.currency_id)},s()})},changeDeductFromIncome(s){return n.patch("/user",{deduct_from_income:s})},getTrustHistory(s){return n.get("/user/account/operations",{params:s})},async changePassword(s){var a,t;try{await n.patch("/user/password",s),c.success({message:"Password has been successfully changed"})}catch(r){throw c.error({message:((t=(a=r==null?void 0:r.response)==null?void 0:a.data)==null?void 0:t.message)||"Something went wrong"}),console.log(r),r}},async get2faQr(){return await n.post("/user/2fa")},async confirm2faInit(s){var a,t;try{return await n.patch("/user/2fa",{totp:s})}catch(r){throw c.error({message:((t=(a=r==null?void 0:r.response)==null?void 0:a.data)==null?void 0:t.message)||"Something went wrong"}),r}},async disconnect2fa(){await n.delete("/user/2fa"),await this.getMe()},async getOperationTypes(){try{const s=await n.get("/user/account/operation/types");o.operationTypes=s}catch{console.log(e)}},async getTimezones(){var s,a;try{const t=await n.get("/user/time-zones");o.timezones=t.map(r=>({label:r.label,value:r.time_zone}))}catch(t){c.error({message:((a=(s=t==null?void 0:t.response)==null?void 0:s.data)==null?void 0:a.message)||"Something went wrong"}),console.log("getTimezones",t)}},async updateTimezone(s){var a,t;try{await n.patch("/user/time-zone",s),o.userInfo&&(o.userInfo.time_zone=s.time_zone),c.success({message:"Time zone successfully changed."})}catch(r){throw c.error({message:((t=(a=r==null?void 0:r.response)==null?void 0:a.data)==null?void 0:t.message)||"Something went wrong"}),console.log("getTimezones",r),r}},getStatisticsExpand(s){var t,r;const a={};return a.from_date=u(s[0],(t=o.userInfo)==null?void 0:t.time_zone),a.to_date=u(s[1],(r=o.userInfo)==null?void 0:r.time_zone),n.get("/user/statistics-expand",{params:a})},generateReferralUrl(){return n.post("/user/referral-url")},addFeedback(s){return n.post("/user/feedback",s)},async checkPermissionPayoutsService(){var s,a;try{const t=await n.get("/user/account/has-withdrawal-request");o.isPermissionPayoutsService=t.has_withdrawal_request,m(o.isPermissionPayoutsService)}catch(t){c.error(((a=(s=t.response)==null?void 0:s.data)==null?void 0:a.message)||"Something went wrong"),o.isPermissionPayoutsService=!1}}};export{f as u};
