namespace ClaudeDo.Localization;

public static class CultureResolver
{
    public static string Resolve(string cultureName, IReadOnlyCollection<string> available, string fallback = "en")
    {
        if (string.IsNullOrWhiteSpace(cultureName)) return fallback;

        var exact = available.FirstOrDefault(c => string.Equals(c, cultureName, StringComparison.OrdinalIgnoreCase));
        if (exact is not null) return exact;

        var primary = cultureName.Split('-')[0];
        var byPrimary = available.FirstOrDefault(c => string.Equals(c, primary, StringComparison.OrdinalIgnoreCase));
        return byPrimary ?? fallback;
    }
}
