import{t as e}from"./http-BdoVLsWz.js";import{n as t,t as n}from"./notification-BM55Quw3.js";import{t as r}from"./error-handling-CuGxlkPL.js";var i=(i=!1)=>{let a=i?window.pinia.defineStore:t,{global:o}=window.i18n;return a(`user`,{state:()=>({currentUser:null,currentAbilities:[],currentUserSettings:{},userForm:{name:``,email:``,password:``,confirm_password:``,language:``}}),getters:{currentAbilitiesCount:e=>e.currentAbilities.length},actions:{updateCurrentUser(t){return new Promise((i,a)=>{e.put(`/api/v1/me`,t).then(e=>{this.currentUser=e.data.data,Object.assign(this.userForm,e.data.data),n().showNotification({type:`success`,message:o.t(`settings.account_settings.updated_message`)}),i(e)}).catch(e=>{r(e),a(e)})})},fetchCurrentUser(t){return new Promise((n,i)=>{e.get(`/api/v1/me`,t).then(e=>{this.currentUser=e.data.data,this.userForm=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},uploadAvatar(t){return new Promise((n,i)=>{e.post(`/api/v1/me/upload-avatar`,t).then(e=>{this.currentUser.avatar=e.data.data.avatar,n(e)}).catch(e=>{r(e),i(e)})})},fetchUserSettings(t){return new Promise((n,i)=>{e.get(`/api/v1/me/settings`,{params:{settings:t}}).then(e=>{n(e)}).catch(e=>{r(e),i(e)})})},updateUserSettings(t){return new Promise((n,i)=>{e.put(`/api/v1/me/settings`,t).then(e=>{t.settings.language&&(this.currentUserSettings.language=t.settings.language,o.locale.value=t.settings.language),t.settings.default_estimate_template&&(this.currentUserSettings.default_estimate_template=t.settings.default_estimate_template),t.settings.default_invoice_template&&(this.currentUserSettings.default_invoice_template=t.settings.default_invoice_template),n(e)}).catch(e=>{r(e),i(e)})})},hasAbilities(e){return!!this.currentAbilities.find(t=>t.name===`*`?!0:typeof e==`string`?t.name===e:!!e.find(e=>t.name===e))},hasAllAbilities(e){let t=!0;return this.currentAbilities.filter(n=>{e.find(e=>n.name===e)||(t=!1)}),t}}})()};export{i as t};