export const getSEOConfig = () => {
  const isProduction = process.env.NEXT_PUBLIC_ENV === 'production';
  const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000';
  const isTest = process.env.NEXT_PUBLIC_ENV === 'test' || baseUrl.includes('test.');

  return {
    shouldIndex: isProduction && !isTest,
    baseUrl,
  };
};

/**
 * Generates a canonical URL that respects the localePrefix: "as-needed" configuration.
 *
 * With "as-needed":
 * - Default locale (hu): no prefix → https://azopus.hu/path
 * - Other locales (en): with prefix → https://azopus.hu/en/path
 *
 * @param locale - The current locale
 * @param slug - The page slug (pathname without locale)
 * @param baseUrl - The base URL (default: from env or https://azopus.hu)
 * @returns The canonical URL
 */
export function getCanonicalUrl(locale: string, slug: string, baseUrl?: string): string {
  const { baseUrl: defaultBaseUrl } = getSEOConfig();
  const finalBaseUrl = baseUrl || defaultBaseUrl;

  // For default locale (hu), don't include locale prefix
  const localePath = locale === 'hu' ? '' : `/${locale}`;

  // Ensure slug starts with /
  const normalizedSlug = slug.startsWith('/') ? slug : `/${slug}`;

  return `${finalBaseUrl}${localePath}${normalizedSlug}`;
}
