import{A as e,l as t,n,p as r}from"./index-jy40eMQa.js";import{t as i}from"./admin-CqpMrZ_s.js";import{t as a}from"./types-WIP_Oieg.js";const o=t(`auth`,()=>{let t=e(null),o=e(!1),s=r(()=>!!n.getAccessToken()&&!n.isTokenExpired()),c=r(()=>t.value&&t.value.role>=a.Admin),l=r(()=>t.value?.role===a.SuperAdmin);async function u(e,r){o.value=!0;try{let o=await i.login(e,r);if(o.success&&o.user){if(o.user.role<a.Admin)return n.clearTokens(),{success:!1,message:`您没有管理员权限`};t.value=o.user}return o}finally{o.value=!1}}async function d(){o.value=!0;try{await i.logout()}finally{t.value=null,o.value=!1}}function f(e){t.value=e}return{user:t,loading:o,isLoggedIn:s,isAdmin:c,isSuperAdmin:l,login:u,logout:d,setUser:f}});export{o as t};