import type { ItemLabel } from "@ax/constants";

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

const currentLocale = "en-US";

const allLocales = {
	"en-US": enUS,
	"es-ES": esES,
} as const;

/**
 * Obtiene la traducción correcta basada en la cantidad.
 * @param entry La entrada del objeto de locales
 * @param count El número de elementos (por defecto 1)
 */
export function pluralize(entry: ItemLabel, count: number = 1) {
	return count === 1 ? entry.one : entry.other;
}

/**
 * Converts a given string to Title Case, capitalizing the first letter of every word.
 * @param text - The input string to format.
 * @returns The transformed string with every word capitalized.
 */
export function toTitleCase(text: string) {
	if (!text) return text;

	return text
		.toLowerCase()
		.split(" ")
		.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
		.join(" ");
}

export const LOCALE = allLocales[currentLocale as keyof typeof allLocales];
