-------------------------
-- AiB Core Config
-------------------------
-- Version 2.1.0.0 für WoW 12.0.1 (Midnight)

AiB = AiB or {}
AiB.Config = {}

-- Version Info
AiB.Config.VERSION = "2.1.3.0"
AiB.Config.BUILD   = "120001"
AiB.Config.AUTHOR  = "Rinova"

-- Schriftarten
AiB.Config.FONTS = {
    PRIMARY   = "Fonts\\ARIALN.TTF",
    SECONDARY = "Interface\\AddOns\\aib\\fonts\\Fast_Respond.otf",
    HEADER    = "Fonts\\FRIZQT__.TTF",
}

-- UI Dimensionen
AiB.Config.UI = {
    MAIN_WIDTH   = 1200,
    MAIN_HEIGHT  = 900,
    BANNER_HEIGHT = 175,
    TAB_HEIGHT   = 28,
    TAB_SPACING  = 2,
    BUTTON_SIZE  = 30,
    MINIMAP_SIZE = 32,
}

-- Animation Settings
AiB.Config.ANIMATION = {
    FADE_DURATION     = 0.3,
    SLIDE_DURATION    = 0.25,
    TAB_HOVER_SCALE   = 1.05,
    BUTTON_HOVER_SCALE = 1.1,
}

-- Raid Tabs (Midnight Expansion)
AiB.Config.RAID_TABS = {
    "Raid Allgemein",
    "Imperator Averzian",
    "Vorasius",
    "Fallen King Salhadaar",
    "Vaelgor & Ezzorak",
    "Lightblinded Vanguard",
    "Crown of the Cosmos",
    "Chimaerus the Undreamt God",
    "Belo'ren, Child of Al'ar",
    "Midnight Falls"
}

-- Dungeon Tabs (Midnight Dungeons)
AiB.Config.DUNGEON_TABS = {
    "Dungeon Allgemein",
    "Magister's Terrace",
    "Maisara Caverns",
    "Nexus-Point Xenas",
    "Windrunner Spire",
    "Algeth'ar Academy",
    "Seat of the Triumvirate",
    "Skyreach",
    "Pit of Saron"
}

AiB.Config.MIDNIGHT_SEASON = {
    NAME     = "Midnight Season 1",
    DUNGEONS = {},
    RAID     = "To be announced",
}

-- Default Settings
AiB.Config.DEFAULTS = {
    mode  = "Raid",
    theme = "Dark",
    animations_enabled = true,
    background_enabled = true,
    minimap_position   = 0,
    window_scale       = 1.0,
    blur_enabled       = true,
    roles = { tank = true, healer = false, dps = false }
}

-- Portal Categories
AiB.Config.PORTAL_CATEGORIES = {
    "Season 2",
    "The War Within",
    "Dragonflight",
    "Shadowlands",
    "Battle for Azeroth",
    "Legion",
    "Warlords of Draenor",
    "Mists of Pandaria",
    "Cataclysm"
}

-- =========================================================
-- AceDB-3.0 Defaults (alle Module zusammengefasst)
-- =========================================================
AiB.DB_DEFAULTS = {
    profile = {
        -- Allgemeine Einstellungen (früher AiB_Settings + AiB_ThemeSettings)
        settings = {
            auto_accept              = false,
            animations_enabled       = true,
            blur_enabled             = true,
            roles                    = { tank = false, healer = false, dps = false },
            hide_unlearned_portals   = false,
            hearthstone_toy          = nil,
            hearthstone_random       = false,
            season_frame_enabled     = true,
            minimap_button           = { x = 0, y = -65 },
            positions                = {},
        },

        -- Cursor (früher AiB_CursorConfig – SavedVariablesPerCharacter)
        cursor = {
            enabled           = true,
            scale             = 1.0,
            transparency      = 1.0,
            showOnlyInCombat  = false,
            enableTrail       = false,
            trailDuration     = 0.4,
            trailDensity      = 0.008,
            trailScale        = 1.0,
            colors = {
                mainRing = { r = 1.0, g = 1.0, b = 1.0 },
                gcdRing  = { r = 1.0, g = 1.0, b = 0.0 },
                castRing = { r = 1.0, g = 0.8, b = 0.0 },
                trail    = { r = 1.0, g = 1.0, b = 1.0 },
            },
        },

        -- Fadenkreuz (früher AiB_CrosshairConfig – SavedVariablesPerCharacter)
        crosshair = {
            enabled          = false,
            scale            = 1.0,
            alpha            = 1.0,
            thickness        = 5,
            yOffset          = -46,
            showOnlyInCombat = false,
            lineColor        = { r = 0.129, g = 1.0, b = 0.0 },
            borderColor      = { r = 0.0,   g = 0.0, b = 0.0 },
        },

        -- BreakTimer (früher AiB_BreakTimerConfig – global)
        breaktimer = {
            enabled      = true,
            width        = 300,
            height       = 25,
            barColor     = { r = 1, g = 0.7, b = 0, a = 1 },
            position     = { point = "CENTER", x = 0, y = 200 },
            locked       = true,
            soundEnabled = true,
            soundFile    = "Interface\\AddOns\\AiB\\sounds\\break_default.ogg",
            memesEnabled = true,
            memeInterval = 30,
            memeWidth    = 600,
            memeHeight   = 400,
        },

        -- Call to Arms (früher AiB_CallToArmsConfig – SavedVariablesPerCharacter)
        calltoarms = {
            enabled  = true,
            testMode = false,
            soundId  = 1,
            roles    = { tank = true, healer = true, damage = true },
            position = { point = "CENTER", x = 0, y = 0 },
        },

        -- Don't Release (früher AiB_DontReleaseConfig – global)
        dontrelease = {
            enabled     = true,
            modKey      = 2,
            timeout     = 1.0,
            autoRelease = false,
            difficulties = {
                [0]  = true, [8]  = true, [14] = true, [15] = true,
                [16] = true, [17] = true, [23] = true,
            },
        },

        -- Gear Check (früher AiB_GearCheckConfig – SavedVariablesPerCharacter)
        gearcheck = {
            enabled           = false,
            showOnInstance    = true,
            showOnReadyCheck  = true,
            autoHideDelay     = 10,
            iconSize          = 40,
            ecEnabled         = false,
            ecUseAllSpecs     = true,
            ecSpecRules       = {},
        },

        -- Buff Watcher (früher AiB_BuffWatcherConfig – global)
        buffwatcher = {
            enabled = true,
            userEntries = {
                raidBuffs     = { spellIDs   = {} },
                consumables   = { spellIDs   = {} },
                shamanImbues  = { enchantIDs = {} },
                roguePoisons  = { enchantIDs = {} },
                shamanShields = { spellIDs   = {} },
            },
            categoryEnabled = {
                raidBuffs     = true,
                consumables   = true,
                shamanImbues  = true,
                roguePoisons  = true,
                shamanShields = true,
            },
            thresholds = {
                dungeon = 2400,
                raid    = 900,
                other   = 300,
            },
            talentMods = {
                roguePoisons = {
                    { type = "requireCount", talentID = 381802, count = 4 },
                },
            },
            disabledDefaults = {},
            consumableGroupEnabled = {
                flask = true, food = true, rune = true, weaponBuff = true,
            },
            consumableAutoUse = {
                flask = nil, food = nil, rune = nil, weaponBuff = nil,
            },
            inventoryGroupEnabled = {
                dpsPotion      = true,
                healthPotion   = true,
                healthstone    = true,
                gatewayControl = true,
                manaBun        = false,
            },
            classBuffs = {
                WARRIOR     = { enabled = true, groups = {} },
                PALADIN     = { enabled = true, groups = {} },
                HUNTER      = { enabled = true, groups = {} },
                ROGUE       = { enabled = true, groups = {} },
                PRIEST      = { enabled = true, groups = {} },
                DEATHKNIGHT = { enabled = true, groups = {} },
                SHAMAN      = { enabled = true, groups = {} },
                MAGE        = { enabled = true, groups = {} },
                WARLOCK     = { enabled = true, groups = {} },
                MONK        = { enabled = true, groups = {} },
                DRUID       = { enabled = true, groups = {} },
                DEMONHUNTER = { enabled = true, groups = {} },
                EVOKER      = { enabled = true, groups = {} },
            },
            reportCardPosition       = nil,
            buffDropPosition         = nil,
            reportCardIconSize       = 32,
            reportCardUnlock         = false,
            reportCardScale          = 1.0,
            reportCardAutoCloseDelay = 5,
            scanOnLogin              = false,
            lastSection              = "classBuffs",
            chatReportEnabled        = false,
            buffDropReminder         = true,
            buffDropIconSize         = 32,
            buffDropScale            = 1.0,
            buffDropUnlock           = false,
            buffDropGlowR            = 0.95,
            buffDropGlowG            = 0.95,
            buffDropGlowB            = 0.32,
            buffDropGlowUseClassColor   = false,
            buffDropAlertInstanceOnly   = false,
            buffDropAlertDisableRested  = false,
            buffDropTextFontSize        = 11,
            raidBuffAlwaysCheck      = false,
            classBuffAlwaysCheck     = false,
            consumableAlwaysCheck    = false,
            inventoryAlwaysCheck     = false,
        },

        -- QoL (früher AiBQOL – global)
        coTank = {
            enabled            = false,
            unlock             = false,
            width              = 150,
            height             = 20,
            bgAlpha            = 0.8,
            useClassColor      = false,
            healthColorR       = 1.0,
            healthColorG       = 0.0,
            healthColorB       = 0.0,
            showName           = true,
            nameFormat         = "abbreviated",
            nameLength         = 6,
            nameFontSize       = 12,
            nameColorUseClassColor = false,
            nameColorR         = 1.0,
            nameColorG         = 1.0,
            nameColorB         = 1.0,
            point              = "CENTER",
            x                  = 200,
            y                  = 0,
        },

        -- Combat Alert (flash notification on combat state change)
        combatAlert = {
            enabled             = false,
            unlock              = false,
            width               = 300,
            height              = 80,
            point               = "CENTER",
            x                   = 0,
            y                   = 200,
            -- Enter combat
            enterText           = "++ Combat",
            enterR              = 0,
            enterG              = 1,
            enterB              = 0,
            enterUseClassColor  = false,
            enterAudioMode      = "none",
            enterTtsMessage     = "Combat",
            enterTtsVolume      = 50,
            enterTtsRate        = 0,
            enterTtsVoiceID     = 0,
            -- Leave combat
            leaveText           = "-- Combat",
            leaveR              = 1,
            leaveG              = 0.2,
            leaveB              = 0.2,
            leaveUseClassColor  = false,
            leaveAudioMode      = "none",
            leaveTtsMessage     = "Safe",
            leaveTtsVolume      = 50,
            leaveTtsRate        = 0,
            leaveTtsVoiceID     = 0,
        },

        -- Combat Timer (tracks elapsed combat time with HUD display)
        combatTimer = {
            enabled         = false,
            unlock          = false,
            width           = 400,
            height          = 100,
            point           = "CENTER",
            x               = 0,
            y               = -200,
            colorR          = 1,
            colorG          = 0.8,
            colorB          = 0,
            useClassColor   = false,
            hidePrefix      = false,
            showBackground  = false,
            instanceOnly    = false,
            stickyTimer     = false,
            chatReport      = true,
            combatText      = nil,
        },

        qol = {
            misc = {
                fasterLoot           = true,
                suppressLootWarnings = true,
                autoFillDelete       = true,
                autoSlotKeystone     = true,
                ahCurrentExpansion   = false,
                ahCraftingExpansion  = false,
                cancelProfBuffs      = false,
                ignoreDecor          = true,
                durabilityWarning    = true,
                durabilityThreshold  = 50,
                autoRepair           = true,
                guildRepair          = true,
            },
        },
    },

    char = {
        -- Nur wirklich Charakter-spezifisches (z.B. letzter Modus)
        mode = "Raid",
    },
}

-- Utility Functions
function AiB.Config:GetFont(fontType)
    return self.FONTS[fontType] or self.FONTS.PRIMARY
end

function AiB.Config:GetUIValue(key)
    return self.UI[key] or 0
end

function AiB.Config:GetAnimationDuration(type)
    return self.ANIMATION[type] or 0.3
end

-- Debug Mode
AiB.Config.DEBUG = false

function AiB.Config:Print(msg)
    if self.DEBUG then
        print("|cFF00FF00[AiB Debug]|r " .. tostring(msg))
    end
end

function AiB.Config:Log(category, msg)
    if self.DEBUG then
        print(string.format("|cFF00FF00[AiB %s]|r %s", category, tostring(msg)))
    end
end

-- Event System
AiB.Events = CreateFrame("Frame")
AiB.Events.listeners = {}

function AiB.Events:RegisterCallback(event, callback)
    if not self.listeners[event] then
        self.listeners[event] = {}
    end
    table.insert(self.listeners[event], callback)
end

function AiB.Events:FireCallback(event, ...)
    if self.listeners[event] then
        for _, callback in ipairs(self.listeners[event]) do
            callback(...)
        end
    end
end
