import faCommon from "@/locales/fa/common.json";
import faSeo from "@/locales/fa/seo.json";
import enCommon from "@/locales/en/common.json";
import enSeo from "@/locales/en/seo.json";
import {
  DEFAULT_LANGUAGE,
  ENABLED_LANGUAGES,
  type AppLanguage,
} from "./registry";

/** All i18n namespaces — add new namespace here when extending translations */
export const LOCALE_NAMESPACES = ["common", "seo"] as const;

export type LocaleNamespace = (typeof LOCALE_NAMESPACES)[number];

/**
 * Locale bundles — add a new language by importing its JSON files here.
 */
export const LOCALE_BUNDLES: Record<
  AppLanguage,
  Record<LocaleNamespace, Record<string, unknown>>
> = {
  fa: {
    common: faCommon,
    seo: faSeo,
  },
  en: {
    common: enCommon,
    seo: enSeo,
  },
};

export function buildI18nResources() {
  return Object.fromEntries(
    ENABLED_LANGUAGES.map((code) => [code, LOCALE_BUNDLES[code]])
  );
}

export function getLocaleBundle(lang: AppLanguage) {
  return LOCALE_BUNDLES[lang] ?? LOCALE_BUNDLES[DEFAULT_LANGUAGE];
}

export type SeoPageKey = keyof typeof faSeo.pages;

export type SeoSiteMeta = {
  name: string;
  titleSuffix: string;
  defaultDescription: string;
  keywords: string[];
};

export type SeoPageMeta = {
  title: string;
  description: string;
  keywords: string[];
  path: string;
  h1?: string;
};
