-- =========================================================================
-- LOCALIZATION MASTER FILE
-- This file sets up the localization system and English defaults
-- All other language files populate NS.Locales[locale] tables
-- =========================================================================
local addonName, NS = ...

-- Master locale storage - each language populates this
NS.Locales = {}

-- Active localization table (populated after ADDON_LOADED)
NS.L = {}

-- =========================================================================
-- ENGLISH DEFAULT STRINGS (Master Reference)
-- =========================================================================
NS.Locales["enUS"] = {
    -- ===========================================
    -- ADDON IDENTITY
    -- ===========================================
    ["ADDON_NAME"] = "A.X.I.O.M.",
    ["ADDON_FULL_NAME"] = "A.X.I.O.M. | Automated Xenial Index & Operations Matrix",
    
    -- ===========================================
    -- TAB TITLES (Constants.lua)
    -- ===========================================
    ["TAB_GUILD_RECRUITER"] = "Guild Recruiter System",
    ["TAB_BLACKLIST"] = "Recruitment Blacklist",
    ["TAB_REQUIREMENTS"] = "Recruitment Requirements",
    ["TAB_HISTORY"] = "Recruitment History",
    ["TAB_GUILD_ROSTER"] = "Guild Roster",
    ["TAB_RAID_ROSTER"] = "Raid Roster",
    ["TAB_SETTINGS"] = "Settings",
    ["TAB_MVP"] = "MVP",
    
    -- ===========================================
    -- COMMON ACTIONS / BUTTONS
    -- ===========================================
    ["SEARCH"] = "Search",
    ["SEARCH_PLAYERS"] = "Search Players",
    ["APPLY"] = "Apply",
    ["CANCEL"] = "Cancel",
    ["SAVE"] = "Save",
    ["DELETE"] = "Delete",
    ["EDIT"] = "Edit",
    ["CREATE"] = "Create",
    ["REFRESH"] = "Refresh",
    ["CLOSE"] = "Close",
    ["IMPORT"] = "Import",
    ["EXPORT"] = "Export",
    ["SET"] = "Set",
    ["TEST"] = "Test",
    ["RESET"] = "Reset",
    ["SEND"] = "Send",
    ["ADD"] = "Add",
    ["REMOVE"] = "Remove",
    ["SELECT_ALL"] = "Select All",
    ["DESELECT_ALL"] = "Deselect All",
    ["CLEAR"] = "Clear",
    ["OK"] = "OK",
    ["YES"] = "Yes",
    ["NO"] = "No",
    ["ON"] = "ON",
    ["OFF"] = "OFF",
    ["NEW"] = "New",
    ["HELP"] = "HELP",
    ["SEARCH_FILTERS"] = "SEARCH FILTERS",
    ["MESSAGE_TEMPLATES"] = "MESSAGE TEMPLATES",
    ["WELCOME_MESSAGES"] = "Welcome Messages",
    ["TEMPLATE_NAME"] = "Template Name...",
    ["TEST_ME"] = "TEST ME",
    
    -- ===========================================
    -- SETTINGS PANEL - General Settings
    -- ===========================================
    ["GENERAL_SETTINGS"] = "General Settings",
    ["UI_SCALE"] = "UI Scale",
    ["COMPACT_MODE"] = "Enable Compact Mode",
    ["BYPASS_FILTER"] = "Bypass class rotation filter",
    ["RELOAD_UI"] = "Reload UI",
    ["RELOAD_UI_NOTE"] = "Reload UI for scale/theme changes",
    ["SETTINGS_APPLIED"] = "Settings Applied.",
    
    -- ===========================================
    -- SETTINGS PANEL - Theme/Colors
    -- ===========================================
    ["HEADER_SIDEBAR"] = "Header / Sidebar",
    ["TITLE_SIDEBAR_COLORS"] = "Title Bar & Sidebar Colors",
    ["BACKGROUND_PANE"] = "Background Pane",
    ["BUTTONS_TEXT"] = "Buttons & Text",
    ["RED"] = "Red",
    ["GREEN"] = "Green",
    ["BLUE"] = "Blue",
    ["ALPHA"] = "Alpha",
    
    -- ===========================================
    -- SETTINGS PANEL - Advanced Tools
    -- ===========================================
    ["ADVANCED_TOOLS"] = "Advanced Tools",
    ["ENABLE_MACRO_TOOLS"] = "Enable Macro Tools",
    ["SOCIAL_GUILD_ACTIVITIES"] = "Social Guild Activities",
    ["SOCIAL_NOTE"] = "Enables birthdates, anniversaries, and custom social notes for guild members.",
    ["ADVANCED_INSPECTION"] = "Advanced character inspection",
    ["IMPORT_FROM_GRM"] = "Import from GRM",
    ["EXPORT_TO_GRM"] = "Export to GRM",
    
    -- ===========================================
    -- SETTINGS PANEL - Custom Background
    -- ===========================================
    ["CUSTOM_BACKGROUND"] = "Custom Background",
    ["ENABLE_CUSTOM_BG"] = "Enable Custom Background",
    ["SET_DIRECTORY"] = "Set directory",
    
    -- ===========================================
    -- SETTINGS PANEL - Language
    -- ===========================================
    ["LANGUAGE"] = "Language",
    ["APPLY_LANGUAGE"] = "Apply Language",
    ["LANGUAGE_SET_TO"] = "Language set to:",
    ["LANGUAGE_AUTO_DETECTED"] = "Language auto-detected:",
    ["NO_LANGUAGE_SELECTED"] = "No language selected.",
    ["USING_DEFAULT_ENGLISH"] = "Using default English.",
    
    -- ===========================================
    -- HOME TAB - Controls
    -- ===========================================
    ["FILTER"] = "Filter",
    ["FILTER_DEFAULT_ALL"] = "Filter: Default (All)",
    ["LEVEL_RANGE"] = "Level Range",
    ["MIN_LEVEL"] = "Min Level",
    ["MAX_LEVEL"] = "Max Level",
    ["CLASSES"] = "Classes",
    ["RACES"] = "Races",
    ["ZONES"] = "Zones",
    ["REALM"] = "Realm",
    ["CURRENT_REALM"] = "Current Realm",
    ["ANY_REALM"] = "Any Realm",
    ["TEMPLATE"] = "Template",
    ["SELECT_TEMPLATE"] = "Select Template",
    ["CONFIGURE_TEMPLATES"] = "Configure Templates",
    ["WHISPER_TEMPLATE"] = "Whisper Template",
    
    -- ===========================================
    -- HOME TAB - Results
    -- ===========================================
    ["UNGUILDED_PLAYERS"] = "Unguilded Players",
    ["CURRENT_FILTER"] = "Current Filter",
    ["RESET_LIST"] = "Reset List",
    ["LIST_DISCARDED"] = "List Discarded.",
    ["SEND_BATCH"] = "Send Batch",
    ["SEND_MODE_MESSAGE"] = "Message Only",
    ["SEND_MODE_INVITE"] = "Guild Invite Only",
    ["SEND_MODE_BOTH"] = "Message + G-Invite",
    ["BLACKLIST_SELECTED"] = "Blacklist Selected",
    ["READY"] = "Ready.",
    ["MSG_DELAY"] = "Msg Delay",
    ["ACTIVE"] = "Active:",
    
    -- ===========================================
    -- HOME TAB - Results Table Headers
    -- ===========================================
    ["NAME"] = "Name",
    ["LEVEL"] = "Level",
    ["CLASS"] = "Class",
    ["RACE"] = "Race",
    ["ZONE"] = "Zone",
    ["MAX_KEY"] = "M+",
    ["SCORE"] = "Score",
    ["STATUS"] = "Status",
    ["HEROIC"] = "Heroic",
    ["MYTHIC"] = "Mythic",
    ["UNKNOWN"] = "Unknown",
    
    -- ===========================================
    -- HOME TAB - Chat Panel
    -- ===========================================
    ["WHISPER"] = "Whisper",
    ["REPLIES_ONLY"] = "Replies Only",
    ["CONVERSATION"] = "Conversation",
    ["TYPE_MESSAGE"] = "Type a message...",
    ["GUILD_CHAT"] = "Guild Chat",
    ["SEND_WHISPER"] = "Send Whisper",
    
    -- ===========================================
    -- BLACKLIST MODULE
    -- ===========================================
    ["BLACKLIST"] = "Blacklist",
    ["TEMPORARY_BLACKLIST"] = "Temporary Blacklist",
    ["PERMANENT_BLACKLIST"] = "Permanent Blacklist",
    ["ADD_TO_BLACKLIST"] = "Add to Blacklist",
    ["REMOVE_FROM_BLACKLIST"] = "Remove from Blacklist",
    ["MAKE_PERMANENT"] = "Make Permanent",
    ["MAKE_TEMPORARY"] = "Make Temporary",
    ["SYNC_BLACKLIST"] = "Sync Blacklist",
    ["PRUNE_BLACKLIST"] = "Prune Blacklist",
    ["PLAYER_NAME"] = "Player Name",
    ["REASON"] = "Reason",
    ["DATE_ADDED"] = "Date Added",
    ["EXPIRES"] = "Expires",
    ["NEVER"] = "Never",
    ["MANUAL_ADD"] = "MANUAL ADD",
    ["ENTER_PLAYER_NAME"] = "Enter player name...",
    ["ENTER_REASON"] = "Enter reason...",
    ["MANAGE_BLACKLIST"] = "MANAGE BLACKLIST",
    ["RESET_ENTIRE_NORMAL"] = "Reset Entire Normal List",
    ["RESET_SELECTION_BOTH"] = "Reset Selection (Both)",
    ["ADD_TO_NORMAL"] = "Add to Normal",
    ["AUTOMATE_RESET"] = "AUTOMATE RESET",
    ["GUILD_SYNC"] = "GUILD SYNC",
    ["SYNC_WITH_GUILD"] = "Sync with Guild",
    ["TEMPORARILY_BLACKLISTED"] = "Temporarily Blacklisted",
    ["EXPORT_IMPORT"] = "EXPORT / IMPORT",
    
    -- ===========================================
    -- REQUIREMENTS MODULE
    -- ===========================================
    ["REQUIREMENTS"] = "Requirements",
    ["RECRUITMENT_REQUIREMENTS"] = "Recruitment Requirements",
    ["CLASS_REQUIREMENTS"] = "Class Requirements",
    ["RACE_REQUIREMENTS"] = "Race Requirements",
    ["LEVEL_REQUIREMENTS"] = "Level Requirements",
    ["REALM_REQUIREMENTS"] = "Realm Requirements",
    ["RAIDER_IO_SCORE"] = "Raider.IO Score",
    ["MIN_SCORE"] = "Min Score",
    ["PROGRESSION"] = "Progression",
    ["REQUIRED"] = "Required",
    ["OPTIONAL"] = "Optional",
    ["EXCLUDED"] = "Excluded",
    ["ENABLE_REQUIREMENT"] = "Enable Requirement",
    ["SAVE_REQUIREMENTS"] = "Save Requirements",
    
    -- ===========================================
    -- RECRUITMENT HISTORY
    -- ===========================================
    ["HISTORY"] = "History",
    ["RECRUITMENT_HISTORY"] = "Recruitment History",
    ["PLAYER"] = "Player",
    ["ACTION"] = "Action",
    ["DATE"] = "Date",
    ["TIME"] = "Time",
    ["WHISPERED"] = "Whispered",
    ["INVITED"] = "Invited",
    ["BLACKLISTED"] = "Blacklisted",
    ["CLEAR_HISTORY"] = "Clear History",
    ["EXPORT_HISTORY"] = "Export History",
    
    -- ===========================================
    -- GUILD ROSTER MODULE
    -- ===========================================
    ["GUILD_ROSTER"] = "Guild Roster",
    ["MEMBER"] = "Member",
    ["RANK"] = "Rank",
    ["NOTE"] = "Note",
    ["OFFICER_NOTE"] = "Officer Note",
    ["LAST_ONLINE"] = "Last Online",
    ["TOTAL_MEMBERS"] = "Total Members",
    ["ONLINE"] = "Online",
    ["OFFLINE"] = "Offline",
    ["SHOW_OFFLINE"] = "Show Offline",
    ["HIDE_OFFLINE"] = "Hide Offline",
    ["SORT_BY"] = "Sort by",
    ["INVITE_TO_GROUP"] = "Invite to Group",
    ["GUILD_INVITE"] = "Guild Invite",
    ["PROMOTE"] = "Promote",
    ["DEMOTE"] = "Demote",
    ["KICK"] = "Kick",
    
    -- ===========================================
    -- RAID ROSTER MODULE
    -- ===========================================
    ["RAID_ROSTER"] = "Raid Roster",
    ["SIGN_UPS"] = "Sign-Ups",
    ["INSPECT"] = "Inspect",
    ["SIGN_UP"] = "Sign-Up",
    ["TANKS"] = "Tanks",
    ["HEALERS"] = "Healers",
    ["DPS"] = "DPS",
    ["BENCH"] = "Bench",
    ["TENTATIVE"] = "Tentative",
    ["ABSENT"] = "Absent",
    ["NO_SHOW"] = "No Show",
    ["EVENT"] = "Event",
    ["EVENTS"] = "Events",
    ["CREATE_EVENT"] = "Create Event",
    ["EDIT_EVENT"] = "Edit Event",
    ["DELETE_EVENT"] = "Delete Event",
    ["EVENT_NAME"] = "Event Name",
    ["EVENT_DATE"] = "Event Date",
    ["EVENT_TIME"] = "Event Time",
    ["START_TIME"] = "Start Time",
    ["END_TIME"] = "End Time",
    ["DESCRIPTION"] = "Description",
    ["ROSTER"] = "Roster",
    ["ATTENDANCE"] = "Attendance",
    ["ATTENDANCE_HISTORY"] = "Attendance History",
    ["TRACKING"] = "Tracking",
    ["PANEL"] = "Panel",
    ["RAID_TOOLS"] = "Raid Tools",
    ["RAID_MAP"] = "Raid Map",
    ["IMPORT_WCL"] = "Import WCL",
    ["LOG"] = "Log",
    ["SNAPSHOT"] = "Snapshot",
    ["RESET_HISTORY"] = "Reset History",
    ["CONFIGURE_PANEL"] = "Configure Panel",
    
    -- ===========================================
    -- POPUPS / DIALOGS
    -- ===========================================
    ["CONFIGURE_WELCOME"] = "Configure Welcome Messages",
    ["AUTOMATE_WELCOME"] = "Automate Welcome message",
    ["TEST_G_MESSAGE"] = "Test G message",
    ["TEMPLATE_HELP"] = "Template Help",
    ["CONFIRMATION"] = "Confirmation",
    ["ARE_YOU_SURE"] = "Are you sure?",
    ["THIS_CANNOT_BE_UNDONE"] = "This cannot be undone.",
    ["CONFIRM_DELETE"] = "Confirm Delete",
    ["SUCCESS"] = "Success",
    ["ERROR"] = "Error",
    ["WARNING"] = "Warning",
    
    -- ===========================================
    -- MVP TAB
    -- ===========================================
    ["MVP_TITLE"] = "MVP's",
    ["MVP_SUBTITLE"] = "A special thank you to the legends who helped shape this project.\nYour support has been invaluable.",
    
    -- ===========================================
    -- STATUS MESSAGES
    -- ===========================================
    ["SCANNING"] = "Scanning...",
    ["PROCESSING"] = "Processing...",
    ["SENDING"] = "Sending...",
    ["COMPLETE"] = "Complete",
    ["FAILED"] = "Failed",
    ["CANCELLED"] = "Cancelled",
    ["NO_RESULTS"] = "No Results",
    ["LOADING"] = "Loading...",
    ["SYNCING"] = "Syncing...",
    ["ENABLED"] = "Enabled",
    ["DISABLED"] = "Disabled",
    ["RAIDERIO_ACTIVE"] = "Raider.IO addon active. Data retrieved",
    ["RAIDERIO_MISSING"] = "Raider.IO missing or not loaded. Check addons load list.",
    ["GREETINGS"] = "Greetings",
    ["NO_GUILD_DETECTED"] = "No Guild detected.",
    ["RECRUITER_MODE_ACTIVE"] = "Recruiter mode Active",
    ["SCAN_COMPLETE_ADDED"] = "Scan Complete. Added %d new players.",
    
    -- ===========================================
    -- WHISPER / CHAT PANEL
    -- ===========================================
    ["ACTIVE_WHISPERS"] = "ACTIVE WHISPERS",
    ["PRUNE_INACTIVE"] = "Prune Inactive",
    ["INACTIVE"] = "Inactive",
    ["REPLY_PLACEHOLDER"] = "Reply...",
    ["PAGE_FORMAT"] = "Page %d / %d",
    
    -- ===========================================
    -- RECRUITMENT HISTORY
    -- ===========================================
    ["PLAYER"] = "Player",
    ["CONTEXT"] = "Context",
    ["INVITES"] = "Invites",
    ["PROMOTIONS"] = "Promotions",
    ["DEPARTURES"] = "Departures",
    ["FORCE_REFRESH"] = "Force Refresh",
    ["PLEASE_WAIT"] = "Please wait (%d)",
    ["JOINED"] = "Joined",
    ["LEFT_GUILD"] = "Left Guild",
    ["KICKED_BY"] = "Kicked by %s",
    ["PROMOTED_TO"] = "Promoted to %s",
    ["DEMOTED_TO"] = "Demoted to %s",
    ["BY"] = "by %s",
    
    -- ===========================================
    -- DEV MODE
    -- ===========================================
    ["DEV_OFFICER_OVERRIDE"] = "Dev: Officer Override",
    ["DEV_OFFICER_OVERRIDE_DESC"] = "Toggles artificial officer status for UI development.",
    
    -- ===========================================
    -- UI HOME RESULTS / ENGINE
    -- ===========================================
    ["UNGUILDED_PLAYERS_HEADER"] = "Unguilded Players - Current Filter: Default (All)",
    ["UNGUILDED_PLAYERS_FILTER"] = "Unguilded Players - Current Filter: %s + %s",
    ["MSG_DELAY"] = "Msg Delay: 0.8s",
    ["MSG_DELAY_FORMAT"] = "Msg Delay: %ss",
    ["COOLDOWN_FOR_SEARCH"] = "Cooldown for search",
    ["SCAN_TIMED_OUT"] = "Scan Timed Out - Ready",
    ["SCANNING_QUERY"] = "Scanning: %s...",
    ["WORLD"] = "World",
    ["ALL_ZONES"] = "All Zones",
    
    -- ===========================================
    -- REQUIREMENTS TAB (Tab 3)
    -- ===========================================
    ["CLASS_PRIORITY"] = "Class Priority",
    ["RACE_SELECT"] = "Race Select",
    ["LOW"] = "Low",
    ["MED"] = "Med",
    ["HIGH"] = "High",
    ["RECRUITER_ASSIGNED"] = "Recruiter Assigned",
    ["RECRUITER_NAME"] = "Recruiter Name:",
    ["RAID"] = "Raid",
    ["SOCIAL"] = "Social",
    ["VIEW_AUDIT_LOG"] = "View Audit Log",
    ["SYNC_WITH_GUILD"] = "Sync with Guild",
    ["REQUIREMENT_AUDIT_LOG"] = "Requirement Audit Log",
    ["US_SERVERS"] = "US Servers",
    ["KR_SERVERS"] = "KR Servers",
    ["EU_SERVERS"] = "EU Servers",
    ["TW_SERVERS"] = "TW Servers",
    ["CN_SERVERS"] = "CN Servers",
    
    -- ===========================================
    -- GUILD ROSTER TAB (Tab 5)
    -- ===========================================
    ["RANK"] = "Rank",
    ["LAST_ONLINE"] = "Last Online",
    ["LVL"] = "Lvl",
    ["ACHV"] = "Achv",
    ["ILVL"] = "ilvl",
    ["M_PLUS_SCORE"] = "M+ Sc",
    ["IDENTITY"] = "Identity",
    ["CLICK_TO_INSPECT"] = "Click to Inspect",
    ["NO_MOTD"] = "No Message of the Day",
    ["INVITE_MEMBER"] = "Invite Member",
    ["GUILD_SETTINGS"] = "Guild Settings",
    ["RECRUITMENT"] = "Recruitment",
    ["REPLACE_NATIVE_FRAME"] = "Replace Native Frame",
    ["TOGGLE_OFFLINE_MEMBERS"] = "Toggle Offline Members",
    ["MEMBER_DETAILS"] = "Member Details",
    ["PUBLIC_NOTE"] = "Public Note:",
    ["OFFICER_NOTE"] = "Officer Note:",
    ["SOCIAL_ACTIVITY"] = "Social Activity",
    
    -- ===========================================
    -- RAID ROSTER TAB (Tab 6)
    -- ===========================================
    ["SIGN_UPS"] = "Sign-Ups",
    ["SIGN_UP"] = "Sign-Up",
    ["CREATE"] = "Create",
    ["EDIT"] = "Edit",
    ["DELETE"] = "Delete",
    ["INSPECT"] = "Inspect",
    ["SHOW_OFFLINE"] = "Show Offline",
    ["ROSTER_AUDIT_LOG"] = "Roster Audit Log",
    ["CREATE_EVENT"] = "Create Event",
    ["EDIT_EVENT"] = "Edit Event",
    ["RAID_TOOLS"] = "Raid Tools: ",
    ["RAID_MAP"] = "Raid Map",
    
    -- ===========================================
    -- TOOLTIPS
    -- ===========================================
    ["TT_OFFICER_OVERRIDE"] = "Dev: Officer Override",
    ["TT_CLICK_TO_SELECT"] = "Click to select",
    ["TT_RIGHT_CLICK_OPTIONS"] = "Right-click for options",
    ["TT_SHIFT_CLICK_LINK"] = "Shift-click to link",
    ["TT_CONFIGURE_SETTINGS"] = "Configure Panel Settings",
    ["TT_SNAPSHOT_STATUS"] = "Snapshot Status",
    ["TT_RESET_HISTORY_WARN"] = "Permanently clear all saved attendance data.",
    ["TT_OPEN_AUDIT_LOG"] = "Open Audit Log",
    ["TT_IMPORT_WCL"] = "Import Warcraft Logs",
    ["TT_IMPORT_WCL_DESC"] = "Paste CSV data to populate raid attendance.",
    
    -- ===========================================
    -- MISC / COMPACT MODE
    -- ===========================================
    ["COMPACT_MODE_TITLE"] = "Compact Mode",
    ["EXPAND"] = "Expand",
    ["COLLAPSE"] = "Collapse",
    ["MINIMIZE"] = "Minimize",
    ["MAXIMIZE"] = "Maximize",
    
    -- ===========================================
    -- IDENTITY (Main/Alt)
    -- ===========================================
    ["MAIN"] = "Main",
    ["ALT_OF"] = "Alt of",
}

-- Alias enGB to enUS
NS.Locales["enGB"] = NS.Locales["enUS"]

-- =========================================================================
-- LOCALE APPLICATION FUNCTION
-- Called after ADDON_LOADED when SavedVariables are available
-- =========================================================================
function NS.ApplyLocale()
    -- Determine which locale to use
    local selectedLocale = nil
    
    -- Priority 1: User's manual selection
    if _G.GRS_DB and _G.GRS_DB.selectedLanguage then
        selectedLocale = _G.GRS_DB.selectedLanguage
    end
    
    -- Priority 2: Game client locale
    if not selectedLocale then
        selectedLocale = GetLocale()
        if selectedLocale == "enGB" then
            selectedLocale = "enUS"
        end
    end
    
    -- Check if we have translations for this locale
    if NS.Locales[selectedLocale] then
        -- Start with English defaults
        for key, value in pairs(NS.Locales["enUS"]) do
            NS.L[key] = value
        end
        -- Overlay selected language
        if selectedLocale ~= "enUS" and NS.Locales[selectedLocale] then
            for key, value in pairs(NS.Locales[selectedLocale]) do
                NS.L[key] = value
            end
        end
    else
        -- Fall back to English
        for key, value in pairs(NS.Locales["enUS"]) do
            NS.L[key] = value
        end
    end
end

-- =========================================================================
-- HELPER FUNCTION
-- =========================================================================
function NS.GetL(key)
    return NS.L[key] or key
end
