import request from "@/utils/request";

// 登录（使用租户名称）
export function login(account, password) {
  return request({
    url: `/admin/login`,
    method: "post",
    data: {
      account: account,
      password: password,
    },
  });
}
// 登出
export function logout(userInfo = null) {
  // 如果没有传入 userInfo，尝试从 localStorage 获取
  if (!userInfo) {
    const cachedUserInfo = localStorage.getItem('userInfo');
    if (cachedUserInfo) {
      try {
        userInfo = JSON.parse(cachedUserInfo);
      } catch (e) {
        console.error('Failed to parse userInfo from localStorage:', e);
      }
    }
  }
  
  return request({
    url: `/admin/logout`,
    method: "post",
    data: userInfo ? { userInfo: userInfo } : {},
  });
}