import { getRequestConfig } from "next-intl/server";
import { I18N_CONFIG } from "./lib/config";
import { headers } from "next/headers";
import { loadMergedTranslations } from "./lib/translations/registry";
import { getUserLocale } from "./lib/locale";
const NAMESPACE_GROUPS = {
  // Páginas públicas iniciales: incluye auth para login/signup
  PUBLIC_INITIAL: ["common", "public", "auth"],
  // Dashboard: incluye public para navegación pero no auth (ya autenticado)
  DASHBOARD_AUTHENTICATED: ["common", "dashboard", "settings", "public", "teams"],
  // Solo autenticación: para páginas específicas de auth
  AUTH_ONLY: ["common", "auth", "validation"],
  // Fallback completo para casos edge
  ALL: ["common", "dashboard", "settings", "auth", "public", "validation", "teams"]
};
function getPageNamespaces(pathname) {
  console.log(`[i18n] \u{1F50D} Analyzing pathname: "${pathname}"`);
  if (pathname.startsWith("/dashboard")) {
    console.log(`[i18n] \u{1F4F1} Dashboard detected \u2192 Loading authenticated user namespaces`);
    return NAMESPACE_GROUPS.DASHBOARD_AUTHENTICATED;
  }
  const isAuthPage = pathname.startsWith("/auth") || pathname === "/login" || pathname === "/signup" || pathname === "/forgot-password" || pathname === "/reset-password" || pathname === "/verify-email" || pathname.includes("login") || pathname.includes("signup") || pathname.includes("auth");
  if (isAuthPage) {
    console.log(`[i18n] \u{1F510} Auth page detected \u2192 Loading auth-only namespaces`);
    return NAMESPACE_GROUPS.AUTH_ONLY;
  }
  if (pathname === "/" || pathname.startsWith("/pricing") || pathname.startsWith("/docs") || pathname.startsWith("/support") || pathname.startsWith("/features")) {
    console.log(`[i18n] \u{1F310} Public page detected \u2192 Loading public + auth namespaces`);
    return NAMESPACE_GROUPS.PUBLIC_INITIAL;
  }
  if (!pathname || pathname === "") {
    console.log(`[i18n] \u2753 Empty pathname \u2192 Using context-aware fallback`);
    if (typeof window !== "undefined") {
      const currentPath = window.location.pathname;
      console.log(`[i18n] \u{1F310} Client-side pathname detected: "${currentPath}"`);
      if (currentPath.startsWith("/dashboard")) {
        console.log(`[i18n] \u{1F4F1} Client-side dashboard detected`);
        return NAMESPACE_GROUPS.DASHBOARD_AUTHENTICATED;
      }
      if (currentPath.includes("login") || currentPath.includes("signup") || currentPath.includes("auth")) {
        console.log(`[i18n] \u{1F510} Client-side auth detected`);
        return NAMESPACE_GROUPS.AUTH_ONLY;
      }
      if (currentPath === "/" || currentPath.startsWith("/pricing") || currentPath.startsWith("/features")) {
        console.log(`[i18n] \u{1F310} Client-side public detected`);
        return NAMESPACE_GROUPS.PUBLIC_INITIAL;
      }
    }
    console.log(`[i18n] \u{1F504} Server-side empty pathname \u2192 Loading public as default`);
    return NAMESPACE_GROUPS.PUBLIC_INITIAL;
  }
  console.log(`[i18n] \u{1F504} Unknown route \u2192 Loading public as fallback`);
  return NAMESPACE_GROUPS.PUBLIC_INITIAL;
}
async function getServerLocale() {
  try {
    return await getUserLocale();
  } catch {
    return I18N_CONFIG.defaultLocale;
  }
}
var i18n_default = getRequestConfig(async () => {
  let locale;
  try {
    locale = await getServerLocale();
  } catch {
    console.debug("[i18n] Using fallback locale (client context)");
    locale = I18N_CONFIG.defaultLocale;
  }
  try {
    let pathname = "";
    try {
      const headersList = await headers();
      pathname = headersList.get("x-pathname") || headersList.get("x-url") || "";
      if (!pathname) {
        const referer = headersList.get("referer") || "";
        if (referer) {
          try {
            const url = new URL(referer);
            pathname = url.pathname;
            console.log(`[i18n] \u{1F504} Extracted pathname from referer: "${pathname}"`);
          } catch {
          }
        }
      }
    } catch {
      console.debug("[i18n] Headers not available, using fallback namespace strategy");
    }
    const messages = await loadMergedTranslations(locale);
    console.log(`[i18n] Loaded merged translations for ${locale} with ${Object.keys(messages).length} namespaces`);
    return {
      locale,
      messages
    };
  } catch (error) {
    console.error(`[i18n] Failed to load translations for ${locale}:`, error);
    return {
      locale: I18N_CONFIG.defaultLocale,
      messages: {}
    };
  }
});
import { loadOptimizedTranslations } from "./lib/translations/i18n-integration";
export {
  NAMESPACE_GROUPS,
  i18n_default as default,
  getPageNamespaces,
  loadOptimizedTranslations
};
