/**
 * Di hostname produksi, jangan memanggil localhost/127.0.0.1 dari browser
 * (sering berasal dari env PM2/shell yang ikut terbaca saat build).
 */
export function normalizeWorkpulseApiBase(raw: string): string {
  let t = String(raw ?? "")
    .trim()
    .replace(/\/$/, "");
  if (!import.meta.client) return t;
  try {
    const h = window.location.hostname;
    const onLoopback = h === "localhost" || h === "127.0.0.1";
    if (onLoopback) return t;
    if (!t || /localhost|127\.0\.0\.1/i.test(t)) return "/workpulse-api";
  } catch {
    /* ignore */
  }
  return t;
}
