// lib/get-runtime-env.ts
export function getRuntimeEnv(key: string): string | undefined {
  /* ---------- 服务器端 (SSR) ---------- */
  if (typeof window === "undefined") {
    const val = process.env[key]
    console.log(`[getRuntimeEnv][SSR] key=${key} -> ${val ?? "undefined"} (process.env)`)
    return val
  }

  /* ---------- 客户端 (CSR) ---------- */
  const val = (window as any).RUNTIME_ENV?.[key]
  console.log(
    `[getRuntimeEnv][CSR] key=${key} -> ${val ?? "undefined"} (window.RUNTIME_ENV)`
  )
  return val
}