import enUS from "./en-US";
import esES from "./es-ES";

export type SupportedLanguage = "en-US" | "es-ES";

export const LOCALE_STORAGE_KEY = "cloud-reader.locale";

export const locales = {
  "en-US": enUS,
  "es-ES": esES,
};

export function resolveDefaultLanguage(): SupportedLanguage {
  try {
    const saved = localStorage.getItem(LOCALE_STORAGE_KEY);
    if (saved === "en-US" || saved === "es-ES") return saved;
  } catch {
    // ignore storage errors
  }
  if (typeof navigator !== "undefined" && navigator.language.toLowerCase().startsWith("es")) {
    return "es-ES";
  }
  return "en-US";
}

export function readingStatusKey(status: string): string {
  const map: Record<string, string> = {
    want_to_read: "library.readingStatus.wantToRead",
    reading: "library.readingStatus.reading",
    finished: "library.readingStatus.finished",
    dnf: "library.readingStatus.dnf",
    uploaded: "library.readingStatus.uploaded",
  };
  return map[status] ?? "library.readingStatus.uploaded";
}
