import{D as t}from"./index-BQtfiLxw.js";import{authApi as s}from"./index-CuBy5RvH.js";const n=t("auth",{state:()=>({user:null,accessToken:localStorage.getItem("accessToken")||"",refreshToken:localStorage.getItem("refreshToken")||""}),getters:{isLoggedIn:e=>!!e.accessToken,isAdmin:e=>{var r;return((r=e.user)==null?void 0:r.role)==="SUPER_ADMIN"},isHrAdminOrAbove:e=>{var r;return["SUPER_ADMIN","HR_ADMIN"].includes((r=e.user)==null?void 0:r.role)},isDeptLeaderOrAbove:e=>{var r;return["SUPER_ADMIN","HR_ADMIN","DEPT_LEADER"].includes((r=e.user)==null?void 0:r.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:"var(--color-danger)",HR_ADMIN:"var(--color-warning)",DEPT_LEADER:"var(--color-brand)",TEAM_LEADER:"var(--color-accent-strong)",EMPLOYEE:"var(--color-info)"}[(o=e.user)==null?void 0:o.role]||"var(--color-info)"}},actions:{async login(e,r){const o=await s.login({username:e,password:r});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 s.me()}catch{this.logout()}},logout(){this.user=null,this.accessToken="",this.refreshToken="",localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken")}}});export{n as u};
