import { redirectToLogin as redirectToSSO } from "@sud-web/utils"
// 重定向到 SSO 登录
interface IRedirectToLoginParams {
  authPath?: string // auth 系统的指定路由（如 "/logout"）
  redirect_uri?: string // 默认 location.href，可指定回跳地址
  scene?: "login" | "logout" // 默认 login；logout 不携带 autoLogin/redirectAction
}
export function redirectToLogin(props: IRedirectToLoginParams = {}) {
  const { authPath = "", redirect_uri, scene = "login" } = props

  const baseParams = {
    authPath,
    authBaseUrl: import.meta.env.VITE_AUTH_BASE_URL,
    // channel 标识接入应用，需替换为你在 auth 系统注册的 channel
    channel: "pink_web",
    redirect_uri
  }

  if (scene === "logout") {
    redirectToSSO({ ...baseParams, showLoginConfirm: "0" })
    return
  }

  redirectToSSO({
    ...baseParams,
    autoLogin: true,
    redirectAction: import.meta.env.VITE_PUBLIC_AUTH_REDIRECT_ACTION
  })
}
