local addonName, ACO = ...

local locale = GetLocale() or "enUS"

local L = {}

L["enUS"] = {
    ADDON_LOADED = "Auto Chest Opener loaded! Type |cff00ccff/aco|r to open options.",
    CANNOT_OPEN_IN_COMBAT = "Cannot open while in combat!",
    SECURE_CLICK_COMBAT = "Can't use secure open in combat.",
        NO_CONTAINERS_FOUND = "No tracked containers found in inventory.",
    ITEM_ALREADY_LISTED = "This item is already in the list.",
    ADDED = "Added: %s",
    REMOVED = "Removed: %s",
    NO_CONTAINERS_TO_REMOVE = "No containers to remove.",
    REMOVED_COUNT = "%d container(s) removed.",
    BLACKLISTED = "Blacklisted: %s",
    REMOVED_FROM_BLACKLIST = "Removed from blacklist: %s",
    STATS_CLEARED = "Statistics reset.",
    HISTORY_CLEARED = "History cleared.",
    USAGE_ADD = "Usage: /aco add <itemID>",
    USAGE_REMOVE = "Usage: /aco remove <itemID>",
    USAGE_INFO = "Usage: /aco info <itemID>",
    ITEM_NOT_LISTED = "This item is not in the list.",
    LIST_CLEARED = "Container list cleared.",
    COMMANDS_AVAILABLE = "Available commands:",
    OPENING_IN_SECONDS = "Opening %s in %d seconds...",
    OPENING_IN_SECONDS_BLOCKED = "Opening %s in %d seconds... (waiting for %s)",
    OPEN_ALL_DEFERRED = "Opening queued (waiting for %s).",

    BLOCK_REASON_COMBAT = "combat",
    BLOCK_REASON_CURSOR = "cursor",
    BLOCK_REASON_MERCHANT = "merchant",
    BLOCK_REASON_TRADE = "trade",
    BLOCK_REASON_AUCTION = "auction house",
    BLOCK_REASON_MAIL = "mailbox",
    BLOCK_REASON_BANK = "bank",
    BLOCK_REASON_GUILDBANK = "guild bank",
    BLOCK_REASON_VOIDSTORAGE = "void storage",
    BLOCK_REASON_LOOT = "looting",
    BLOCK_REASON_SCRAPPING = "scrapping",
    BLOCK_REASON_UNKNOWN = "unknown",
    OPENING = "Opening %s...",
    OPENING_COUNT = "Opening %s (%d/%d)",
    SCAN_DONE = "Bag scan complete!",
    TITLE = "|cff00ccffAuto Chest Opener|r",
    TAB_CONTAINERS = "Containers",
    TAB_STATS = "Statistics",
    TAB_HISTORY = "History",
    TAB_PENDING = "Pending" ,
    OPTIONS_TITLE = "Options",
    ENABLE_AUTO_OPEN = "Enable automatic opening",
    ENABLE_TOOLTIP = "Enable or disable the addon",
    SHOW_NOTIFICATIONS = "Show notifications",
    SHOW_NOTIFICATIONS_TOOLTIP = "Show messages in chat",
    PLAY_SOUNDS = "Play sounds",
    PLAY_SOUNDS_TOOLTIP = "Play a sound when opening",
    DELAY_SLIDER_LABEL = "Delay before opening:",
    DELAY_TOOLTIP = "Wait time before automatic opening",
    ADD_TITLE = "Add a container",
    DROPZONE_EMPTY = "|cff888888Drag an item here|r",
    DROPZONE_ADDED = "|cff00ff80Item added!|r",
    DROPZONE_TOOLTIP = "Drag a chest, bag or container here to add to the list",
    ID_PLACEHOLDER = "Item ID",
    ADD_BTN = "Add",
    INVALID_ID = "Please enter a valid ID.",
    LIST_TITLE = "Tracked containers",
    OPEN_ALL = "Open All",
    OPEN_ALL_T1 = "Open all tracked containers",
    OPEN_ALL_T2 = "Opens all tracked containers in your inventory",
    OPEN_ALL_T3 = "",
    OPEN_ALL_RESULT = "Opening %d container(s)...",
    IMPORT_BTN = "Import",
    IMPORT_T1 = "Import containers",
    IMPORT_T2 = "Paste a list of IDs from Wowhead",
    IMPORT_HELP = "Format: IDs separated by commas (ex: 12345,67890)",
    CLEAR_IMPORT_TOOLTIP = "Clears the current list and imports",
    EXPORT_NONE = "No containers to export.",
    IMPORTED_COUNT = "Imported %d container(s)!",
    IMPORT_EMPTY = "Import string is empty.",
    IMPORT_FRAME_TITLE = "Import containers",
    EXPORT_FRAME_TITLE = "Export containers",
    EXPORT_BTN = "Export",
    EXPORT_T1 = "Export containers",
    EXPORT_T2 = "Copy the list to save it",
    REMOVE_ALL_BTN = "Remove All",
    REMOVE_ALL_T1 = "Remove all containers",
    REMOVE_ALL_T2 = "Removes ALL containers from the list.",
    REMOVE_ALL_T3 = "|cffff8800This action is permanent!|r",
    REMOVE_TOOLTIP = "Remove from the list",
    LOADING = "|cff888888Loading...|r",
    LIST_COUNT = "%d item%s",
    ID_LABEL = "ID: %d",
    STATS_TITLE = "Statistics",
    STATS_TOTAL = "Total opened (all time):",
    STATS_SESSION = "Opened this session:",
    STATS_UNIQUE = "Unique items opened:",
    STATS_TOTALGOLD = "Total gold earned:",
    STATS_SESSIONGOLD = "Gold this session:",
    STATS_FIRST = "First opening:",
    STATS_LAST = "Last opening:",
    TOP_ITEMS_TITLE = "Top 5 most opened items:",
    CLEAR_STATS_BTN = "Reset",
    HISTORY_TITLE = "Opening history",
    CLEAR_HISTORY_BTN = "Clear",
    HISTORY_EMPTY = "|cff666666No openings recorded|r",
    POPUP_CLEAR_STATS_TEXT = "Are you sure you want to reset all statistics?",
    POPUP_CLEAR_HISTORY_TEXT = "Are you sure you want to clear all history?",
    POPUP_REMOVE_ALL_TEXT = "|cffff8800WARNING!|r\n\nThis will remove ALL containers from the list.\n\nDo you want to continue?",
    POPUP_YES = "Yes",
    POPUP_NO = "No",
    MINIMAP_LEFT = "Left-click: Open options",
    MINIMAP_RIGHT = "Right-click: Enable/Disable",
    MINIMAP_STATUS = "Status: %s",
    ENABLED = "Enabled",
    DISABLED = "Disabled",
    HISTORY_GOLD_LINE = "Gold obtained: %s",
    DELAY_SET = "Delay set to %d seconds",
    DELAY_INVALID = "Delay must be between 0 and 30 seconds",
    DEBUG_MODE = "Debug mode: %s",
    PENDING_TITLE = "Pending containers",
    PENDING_HINT = "Click an item to try opening it. If Blizzard requires a secure click, a button will appear.",
    CANNOT_OPEN_AUTO = "Cannot open automatically:",
    -- Auto-discovery
    AUTO_DISCOVER_PROMPT = "%s detected as openable container! Added to tracked list. (/aco remove %d to undo)",
    ENABLE_AUTO_DISCOVER = "Auto-discover containers",
    ENABLE_AUTO_DISCOVER_TOOLTIP = "Automatically track containers when you manually open them",
    -- Batch summary
    BATCH_SUMMARY = "Summary: %d/%d containers opened.",
    BATCH_SUMMARY_GOLD = "Gold earned: %s",
    BATCH_SUMMARY_TIME = "(%ss)",
    -- Queue widget
    QUEUE_OPENING = "Opening...",
    QUEUE_PAUSED = "Paused",
    QUEUE_REMAINING = "%d remaining",
    QUEUE_CANCEL = "Cancel",
    QUEUE_PAUSE = "Pause",
    QUEUE_RESUME = "Resume",
}

L["frFR"] = {
    ADDON_LOADED = "Addon chargé! Tapez |cff00ccff/aco|r pour ouvrir les options.",
    CANNOT_OPEN_IN_COMBAT = "Impossible d'ouvrir en combat!",
    SECURE_CLICK_COMBAT = "Impossible d'utiliser l'ouverture sécurisée en combat.",
        NO_CONTAINERS_FOUND = "Aucun conteneur référencé trouvé dans l'inventaire.",
    ITEM_ALREADY_LISTED = "Cet item est déjà dans la liste.",
    ADDED = "Ajouté: %s",
    REMOVED = "Retiré: %s",
    NO_CONTAINERS_TO_REMOVE = "Aucun conteneur à retirer.",
    REMOVED_COUNT = "%d conteneur(s) retiré(s).",
    BLACKLISTED = "Blacklisté: %s",
    REMOVED_FROM_BLACKLIST = "Retiré de la blacklist: %s",
    STATS_CLEARED = "Statistiques réinitialisées.",
    HISTORY_CLEARED = "Historique effacé.",
    USAGE_ADD = "Usage: /aco add <itemID>",
    USAGE_REMOVE = "Usage: /aco remove <itemID>",
    USAGE_INFO = "Usage: /aco info <itemID>",
    ITEM_NOT_LISTED = "Cet item n'est pas dans la liste.",
    LIST_CLEARED = "Liste des conteneurs vidée.",
    COMMANDS_AVAILABLE = "Commandes disponibles:",
    OPENING_IN_SECONDS = "Ouverture de %s dans %d secondes...",
    OPENING_IN_SECONDS_BLOCKED = "Ouverture de %s dans %d secondes... (en attente : %s)",
    OPEN_ALL_DEFERRED = "Ouverture mise en attente (en attente : %s).",

    BLOCK_REASON_COMBAT = "combat",
    BLOCK_REASON_CURSOR = "curseur",
    BLOCK_REASON_MERCHANT = "marchand",
    BLOCK_REASON_TRADE = "échange",
    BLOCK_REASON_AUCTION = "hôtel des ventes",
    BLOCK_REASON_MAIL = "boîte aux lettres",
    BLOCK_REASON_BANK = "banque",
    BLOCK_REASON_GUILDBANK = "banque de guilde",
    BLOCK_REASON_VOIDSTORAGE = "stockage du Vide",
    BLOCK_REASON_LOOT = "butin en cours",
    BLOCK_REASON_SCRAPPING = "machine de recyclage",
    BLOCK_REASON_UNKNOWN = "inconnu",
    OPENING = "Ouverture de %s...",
    OPENING_COUNT = "Ouverture de %s (%d/%d)",
    SCAN_DONE = "Scan des sacs effectué!",
    TITLE = "|cff00ccffAuto Chest Opener|r",
    TAB_CONTAINERS = "Conteneurs",
    TAB_STATS = "Statistiques",
    TAB_HISTORY = "Historique",
    TAB_PENDING = "En attente" ,
    OPTIONS_TITLE = "Paramètres",
    ENABLE_AUTO_OPEN = "Activer l'ouverture automatique",
    ENABLE_TOOLTIP = "Active ou désactive l'addon",
    SHOW_NOTIFICATIONS = "Afficher les notifications",
    SHOW_NOTIFICATIONS_TOOLTIP = "Affiche les messages dans le chat",
    PLAY_SOUNDS = "Jouer les sons",
    PLAY_SOUNDS_TOOLTIP = "Joue un son lors de l'ouverture",
    DELAY_SLIDER_LABEL = "Délai avant ouverture:",
    DELAY_TOOLTIP = "Temps d'attente avant l'ouverture automatique",
    ADD_TITLE = "Ajouter un conteneur",
    DROPZONE_EMPTY = "|cff888888Glissez un item ici|r",
    DROPZONE_ADDED = "|cff00ff80Item ajouté!|r",
    DROPZONE_TOOLTIP = "Glissez un coffre, sac ou conteneur ici pour l'ajouter à la liste",
    ID_PLACEHOLDER = "Item ID",
    ADD_BTN = "Ajouter",
    INVALID_ID = "Veuillez entrer un ID valide.",
    LIST_TITLE = "Conteneurs enregistrés",
    OPEN_ALL = "Ouvrir tout",
    OPEN_ALL_T1 = "Ouvrir tous les conteneurs référencés",
    OPEN_ALL_T2 = "Ouvre immédiatement tous les conteneurs référencés présents dans votre inventaire",
    OPEN_ALL_T3 = "",
    OPEN_ALL_RESULT = "Ouverture de %d conteneur(s)...",
    IMPORT_BTN = "Importer",
    IMPORT_T1 = "Importer des conteneurs",
    IMPORT_T2 = "Collez une liste d'IDs depuis Wowhead",
    IMPORT_HELP = "Format: IDs séparés par des virgules (ex: 12345,67890)",
    CLEAR_IMPORT_TOOLTIP = "Efface la liste actuelle et importe",
    EXPORT_NONE = "Aucun conteneur à exporter.",
    IMPORTED_COUNT = "Importé %d conteneur(s)!",
    IMPORT_EMPTY = "Chaîne d'import vide.",
    IMPORT_FRAME_TITLE = "Importer des conteneurs",
    EXPORT_FRAME_TITLE = "Exporter les conteneurs",
    EXPORT_BTN = "Exporter",
    EXPORT_T1 = "Exporter les conteneurs",
    EXPORT_T2 = "Copiez la liste pour la sauvegarder",
    REMOVE_ALL_BTN = "Retirer tout",
    REMOVE_ALL_T1 = "Retirer tous les conteneurs",
    REMOVE_ALL_T2 = "Retire TOUS les conteneurs de la liste.",
    REMOVE_ALL_T3 = "|cffff8800Cette action est définitive !|r",
    REMOVE_TOOLTIP = "Retirer de la liste",
    LOADING = "|cff888888Chargement...|r",
    LIST_COUNT = "%d item%s",
    STATS_TITLE = "Statistiques",
    STATS_TOTAL = "Total ouvert (tous temps):",
    STATS_SESSION = "Ouvert cette session:",
    STATS_UNIQUE = "Items uniques ouverts:",
    STATS_TOTALGOLD = "Or total gagné:",
    STATS_SESSIONGOLD = "Or cette session:",
    STATS_FIRST = "Première ouverture:",
    STATS_LAST = "Dernière ouverture:",
    TOP_ITEMS_TITLE = "Top 5 des items les plus ouverts:",
    CLEAR_STATS_BTN = "Réinitialiser",
    HISTORY_TITLE = "Historique des ouvertures",
    CLEAR_HISTORY_BTN = "Effacer",
    HISTORY_EMPTY = "|cff666666Aucune ouverture enregistrée|r",
    POPUP_CLEAR_STATS_TEXT = "Voulez-vous réinitialiser toutes les statistiques ?",
    POPUP_CLEAR_HISTORY_TEXT = "Voulez-vous effacer tout l'historique ?",
    POPUP_REMOVE_ALL_TEXT = "|cffff8800ATTENTION !|r\n\nCette action va retirer TOUS les conteneurs de la liste.\n\nVoulez-vous continuer ?",
    POPUP_YES = "Oui",
    POPUP_NO = "Non",
    MINIMAP_LEFT = "Clic gauche: Ouvrir les options",
    MINIMAP_RIGHT = "Clic droit: Activer/Désactiver",
    MINIMAP_STATUS = "Statut: %s",
    ENABLED = "Activé",
    DISABLED = "Désactivé",
    HISTORY_GOLD_LINE = "Or obtenu: %s",
    DELAY_SET = "Délai réglé à %d secondes",
    DELAY_INVALID = "Le délai doit être entre 0 et 30 secondes",
    DEBUG_MODE = "Mode debug: %s",
    PENDING_TITLE = "Conteneurs en attente",
    PENDING_HINT = "Clique un item pour tenter de l'ouvrir. Si Blizzard exige un clic sécurisé, un bouton apparaîtra.",
    CANNOT_OPEN_AUTO = "Impossible d\'ouvrir automatiquement : ",
    -- Auto-découverte
    AUTO_DISCOVER_PROMPT = "%s détecté comme conteneur ouvrable ! Ajouté à la liste. (/aco remove %d pour annuler)",
    ENABLE_AUTO_DISCOVER = "Auto-découverte des conteneurs",
    ENABLE_AUTO_DISCOVER_TOOLTIP = "Ajoute automatiquement les conteneurs quand vous les ouvrez manuellement",
    -- Résumé de lot
    BATCH_SUMMARY = "Résumé : %d/%d conteneurs ouverts.",
    BATCH_SUMMARY_GOLD = "Or gagné : %s",
    BATCH_SUMMARY_TIME = "(%ss)",
    -- Widget file d'attente
    QUEUE_OPENING = "Ouverture...",
    QUEUE_PAUSED = "En pause",
    QUEUE_REMAINING = "%d restant(s)",
    QUEUE_CANCEL = "Annuler",
    QUEUE_PAUSE = "Pause",
    QUEUE_RESUME = "Reprendre",
}

-- Fallback to enUS for missing keys
ACO.L = setmetatable({}, {
    __index = function(t, k)
        local s = (L[locale] and L[locale][k]) or (L["enUS"] and L["enUS"][k])
        if s then
            rawset(t, k, s)
            return s
        end
        return k
    end
})

-- Convenience global for formatting
function ACO:Translate(key, ...)
    local s = ACO.L[key] or key
    if select('#', ...) > 0 then
        return string.format(s, ...)
    end
    return s
end
