import{W as t}from"./index-BKsb6cIX.js";import{authApi as r}from"./index-DxOMYcp4.js";const n=t("auth",{state:()=>({user:null,accessToken:localStorage.getItem("accessToken")||"",refreshToken:localStorage.getItem("refreshToken")||""}),getters:{isLoggedIn:e=>!!e.accessToken,isAdmin:e=>{var s;return((s=e.user)==null?void 0:s.role)==="SUPER_ADMIN"},isHrAdminOrAbove:e=>{var s;return["SUPER_ADMIN","HR_ADMIN"].includes((s=e.user)==null?void 0:s.role)},isDeptLeaderOrAbove:e=>{var s;return["SUPER_ADMIN","HR_ADMIN","DEPT_LEADER"].includes((s=e.user)==null?void 0:s.role)},roleLabel:e=>{var o;return{EMPLOYEE:"员工",TEAM_LEADER:"团队主管",DEPT_LEADER:"部门负责人",HR_ADMIN:"HR管理员",SUPER_ADMIN:"管理员"}[(o=e.user)==null?void 0:o.role]||"员工"},roleColor:e=>{var o;return{SUPER_ADMIN:"#f56c6c",HR_ADMIN:"#e6a23c",DEPT_LEADER:"#8b5cf6",TEAM_LEADER:"#3ad4d8",EMPLOYEE:"#409eff"}[(o=e.user)==null?void 0:o.role]||"#409eff"}},actions:{async login(e,s){const o=await r.login({username:e,password:s});this.accessToken=o.accessToken,this.refreshToken=o.refreshToken,this.user=o.user,localStorage.setItem("accessToken",o.accessToken),localStorage.setItem("refreshToken",o.refreshToken)},async fetchUser(){try{this.user=await r.me()}catch{this.logout()}},logout(){this.user=null,this.accessToken="",this.refreshToken="",localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken")}}});export{n as u};
