package eu.gaudian.translator.view.hints

import android.content.Context
import java.util.Locale

/**
 * Internationalization system for Markdown hints.
 *
 * This follows Android's locale-qualified resource pattern:
 * - assets/hints/           - Default (English)
 * - assets/hints-de-rDE/    - German
 * - assets/hints-pt-rBR/    - Portuguese (Brazil)
 * - etc.
 *
 * Usage:
 * val content = MarkdownHintLoader.loadHint(context, "api_key_hint")
 * MarkdownHintLoader.getHintFileName("api_key_hint") // Returns localized filename
 */
object MarkdownHintLoader {


    fun getCurrentLocale(context: Context): Locale {
        return context.resources.configuration.locale
    }

    /**
     * Load content from assets.
     */
    fun loadFromAssets(context: Context, fileName: String): String? {
        return try {
            context.assets.open(fileName).bufferedReader().use { it.readText() }
        } catch (_: Exception) {
            null
        }
    }

    /**
     * Get the locale suffix string.
     */
    fun getLocaleSuffix(locale: Locale): String {
        val language = locale.language
        val country = locale.country

        return buildString {
            if (language.isNotEmpty()) {
                append("-")
                append(language.lowercase())
            }
            if (country.isNotEmpty()) {
                @Suppress("HardCodedStringLiteral")
                append("-r")
                append(country.uppercase())
            }
        }
    }
}

