local _, addon = ...
local HLY = addon.HLY

local anchorPoints = {
    TOPLEFT = "TOPLEFT",
    TOP = "TOP",
    TOPRIGHT = "TOPRIGHT",
    LEFT = "LEFT",
    CENTER = "CENTER",
    RIGHT = "RIGHT",
    BOTTOMLEFT = "BOTTOMLEFT",
    BOTTOM = "BOTTOM",
    BOTTOMRIGHT = "BOTTOMRIGHT",
}

local soundChannels = {
    Master = "Master",
    SFX = "SFX",
    Music = "Music",
    Ambience = "Ambience",
    Dialog = "Dialog",
}

local markerMarkValues = {
    ["0"] = "Kein Mark",
    ["1"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:0|t Stern",
    ["2"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_2:0|t Kreis",
    ["3"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_3:0|t Diamant",
    ["4"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_4:0|t Dreieck",
    ["5"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_5:0|t Mond",
    ["6"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_6:0|t Quadrat",
    ["7"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_7:0|t Kreuz",
    ["8"] = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:0|t Totenkopf",
}
local markerMarkOrder = { "0", "1", "2", "3", "4", "5", "6", "7", "8" }

local lootDecorActionOrder = { "need", "greed", "pass" }
local lootDecorActions = {
    need = "Need",
    greed = "Greed",
    pass = "Pass",
}

local trackOrder = { "explorer", "adventurer", "veteran", "champion", "hero", "mythic" }
local trackLabels = {
    explorer = "Explorer",
    adventurer = "Adventurer",
    veteran = "Veteran",
    champion = "Champion",
    hero = "Hero",
    mythic = "Mythic",
}

local function makeTrackColorArgs()
    local args = {}

    for index, key in ipairs(trackOrder) do
        args[key] = {
            order = index,
            type = "color",
            name = trackLabels[key],
            hasAlpha = false,
            get = function()
                local color = HLY.db.bagText.colors[key]
                return color.r, color.g, color.b
            end,
            set = function(_, r, g, b)
                local color = HLY.db.bagText.colors[key]
                color.r, color.g, color.b = r, g, b
                HLY:RefreshAllSlots()
                HLY:RefreshCharacterSlots()
                HLY:RefreshInspectSlots()
            end,
        }
    end

    return args
end

function HLY:GetOptions()
    if self.options then
        return self.options
    end

    local fontValues = function()
        return self:GetFontList()
    end

    local hlyStatsToggleArgs = function()
        local args = {}

        for index, def in ipairs(self:GetHLYstatsDefinitions()) do
            args[def.key] = {
                order = index,
                type = "toggle",
                name = def.label,
                get = function()
                    self:EnsureHLYstatsDefaults()
                    return self.db.hlyStats.statsEnabled[def.key]
                end,
                set = function(_, value)
                    self:EnsureHLYstatsDefaults()
                    self.db.hlyStats.statsEnabled[def.key] = value
                    self:RefreshHLYstatsLines()
                end,
            }
        end

        return args
    end

    self.options = {
        type = "group",
        name = string.format("%s |cff808080v%s|r", addon.displayName, addon.version or "?"),
        childGroups = "tab",
        args = {
            general = {
                order = 1,
                type = "group",
                name = "General",
                args = {
                    minimapGroup = {
                        order = 1,
                        type = "group",
                        name = "Minimap Button",
                        inline = true,
                        args = {
                            minimapButton = {
                                order = 1,
                                type = "toggle",
                                name = "Show Minimap Button",
                                get = function() return not self.db.minimap.hide end,
                                set = function(_, value)
                                    self.db.minimap.hide = not value
                                    self:UpdateMinimapButton()
                                end,
                            },
                        },
                    },
                    description = {
                        order = 2,
                        type = "description",
                        name = "|cffffd100Info:|r\n\n|cff00ff00HLY|r|cffffffffqol|r bündelt kleine Raid-, Dungeon-, Loot-, Ausrüstungs- und UI-Helfer in einem konfigurierbaren Addon. Die Module sind in eigene Tabs aufgeteilt, damit jede Funktion optional bleibt und schnell deaktiviert werden kann.\n ",
                        fontSize = "medium",
                    },
                    changelogHeader = {
                        order = 3,
                        type = "description",
                        name = "|cffffd100Changelog:|r\n ",
                        fontSize = "medium",
                    },
                    v162 = {
                        order = 4,
                        type = "group",
                        name = "v1.6.2",
                        inline = true,
                        args = {
                            text = {
                                order = 1,
                                type = "description",
                                name = "|cffff4444Fixed|r HLYstats: Off-by-one-Fehler bei GetSpecializationInfoByID behoben (primaryStat war immer nil, führte zu Taint-Fehler beim UnitStat-Vergleich).",
                                fontSize = "medium",
                            },
                        },
                    },
                    v161 = {
                        order = 5,
                        type = "group",
                        name = "v1.6.1",
                        inline = true,
                        args = {
                            text = {
                                order = 1,
                                type = "description",
                                name = "|cffff4444Fixed|r HLYstats: Falschen Mainstat bei Specs mit Intellect behoben.\n|cff00aaffChanged|r Join Reminder: Position jetzt per X/Y-Offset-Slider einstellbar.\n|cff00aaffChanged|r Join Reminder, Tank Marker, PvP Gear Check: Live-Vorschau beim Öffnen des jeweiligen Optionsabschnitts.\n|cffaaaaaaRemoved|r Tank Marker: 'Show Reminder'-Option entfernt, Enable-Toggle reicht.\n|cffaaaaaaRemoved|r PvP Gear Check: Test-Button entfernt.",
                                fontSize = "medium",
                            },
                        },
                    },
                    v160 = {
                        order = 6,
                        type = "group",
                        name = "v1.6",
                        inline = true,
                        args = {
                            text = {
                                order = 1,
                                type = "description",
                                name = "|cff00ff00Added|r Tank Marker: markiert den ersten zugewiesenen Tank in normalen Gruppen und pflegt das Makro 'HLYmarkerTank'.\n|cff00ff00Added|r Statistik-Modul: accountweite Spielzeit, Spielzeit pro Klasse, Charaktergold, Warbank-Gold und Gesamtgold.",
                                fontSize = "medium",
                            },
                        },
                    },
                    v152 = {
                        order = 7,
                        type = "group",
                        name = "v1.5.2",
                        inline = true,
                        args = {
                            text = {
                                order = 1,
                                type = "description",
                                name = "|cff00aaffChanged|r Retail-TOC auf Interface-Version 120005 für WoW 12.0.5 aktualisiert.\n|cff00aaffChanged|r Kompatibilität mit WoW 12.x Einschränkungen für Einheiten-, Statistik- und LFG-Daten verbessert.",
                                fontSize = "medium",
                            },
                        },
                    },
                    v151 = {
                        order = 8,
                        type = "group",
                        name = "v1.5.1",
                        inline = true,
                        args = {
                            text = {
                                order = 1,
                                type = "description",
                                name = "|cff00ff00Added|r Need als Loot-Aktion (WIP) für House-Decor-Würfe hinzugefügt.\n|cff00aaffChanged|r Need fällt auf Greed zurück, wenn Need nicht verfügbar ist, danach auf Pass.\n|cff00aaffChanged|r Loot in den Misc-Tab neben Auto Role, Join Reminder und French Connection verschoben.",
                                fontSize = "medium",
                            },
                        },
                    },
                },
            },
            bagText = {
                order = 3,
                type = "group",
                name = "Gear QoL",
                args = {
                    upgradeTrack = {
                        order = 1,
                        name = "Upgrade Track",
                        type = "group",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nZeigt Aufwertungsstufen auf Taschen-, Charakter- und Inspect-Itemslots an.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.enabled end,
                                        set = function(_, value)
                                            self.db.enabled = value
                                            self:RefreshAllSlots()
                                            self:RefreshCharacterSlots()
                                            self:RefreshInspectSlots()
                                        end,
                                    },
                                },
                            },
                            bags = {
                                order = 3,
                                type = "group",
                                name = "Bags",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.bagText.enabled end,
                                        set = function(_, value) self.db.bagText.enabled = value self:RefreshAllSlots() end,
                                    },
                                    showInitial = {
                                        order = 2,
                                        type = "toggle",
                                        name = "Show Track Letter",
                                        get = function() return self.db.bagText.showInitial end,
                                        set = function(_, value) self.db.bagText.showInitial = value self:RefreshAllSlots() end,
                                    },
                                    anchor = {
                                        order = 3,
                                        type = "select",
                                        name = "Anchor",
                                        values = anchorPoints,
                                        get = function() return self.db.bagText.anchor end,
                                        set = function(_, value) self.db.bagText.anchor = value self:RefreshAllSlots() end,
                                    },
                                    xOffset = {
                                        order = 4,
                                        type = "range",
                                        name = "X Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.bagText.xOffset end,
                                        set = function(_, value) self.db.bagText.xOffset = value self:RefreshAllSlots() end,
                                    },
                                    yOffset = {
                                        order = 5,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.bagText.yOffset end,
                                        set = function(_, value) self.db.bagText.yOffset = value self:RefreshAllSlots() end,
                                    },
                                    font = {
                                        order = 6,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function() return self.db.bagText.font end,
                                        set = function(_, value) self.db.bagText.font = value self:RefreshAllSlots() end,
                                    },
                                    fontSize = {
                                        order = 7,
                                        type = "range",
                                        name = "Font Size",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return self.db.bagText.fontSize end,
                                        set = function(_, value) self.db.bagText.fontSize = value self:RefreshAllSlots() end,
                                    },
                                },
                            },
                            character = {
                                order = 4,
                                type = "group",
                                name = "Character / Inspect",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.characterText.enabled end,
                                        set = function(_, value) self.db.characterText.enabled = value self:RefreshCharacterSlots() end,
                                    },
                                    showInitial = {
                                        order = 2,
                                        type = "toggle",
                                        name = "Show Track Letter",
                                        get = function() return self.db.characterText.showInitial end,
                                        set = function(_, value) self.db.characterText.showInitial = value self:RefreshCharacterSlots() end,
                                    },
                                    anchor = {
                                        order = 3,
                                        type = "select",
                                        name = "Anchor",
                                        values = anchorPoints,
                                        get = function() return self.db.characterText.anchor end,
                                        set = function(_, value) self.db.characterText.anchor = value self:RefreshCharacterSlots() end,
                                    },
                                    xOffset = {
                                        order = 4,
                                        type = "range",
                                        name = "X Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.characterText.xOffset end,
                                        set = function(_, value) self.db.characterText.xOffset = value self:RefreshCharacterSlots() end,
                                    },
                                    yOffset = {
                                        order = 5,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.characterText.yOffset end,
                                        set = function(_, value) self.db.characterText.yOffset = value self:RefreshCharacterSlots() end,
                                    },
                                    font = {
                                        order = 6,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function() return self.db.characterText.font end,
                                        set = function(_, value) self.db.characterText.font = value self:RefreshCharacterSlots() end,
                                    },
                                    fontSize = {
                                        order = 7,
                                        type = "range",
                                        name = "Font Size",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return self.db.characterText.fontSize end,
                                        set = function(_, value) self.db.characterText.fontSize = value self:RefreshCharacterSlots() end,
                                    },
                                },
                            },
                            trackColors = {
                                order = 5,
                                type = "group",
                                name = "Track Colors",
                                inline = true,
                                args = makeTrackColorArgs(),
                            },
                        },
                    },
                    boeText = {
                        order = 2,
                        type = "group",
                        name = "BoE/WuE",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nZeigt den BoE/WuE-Bindungsstatus auf Taschen-Itemslots an.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.boeText.enabled end,
                                        set = function(_, value)
                                            self.db.boeText.enabled = value
                                            self:RefreshBindSlots()
                                        end,
                                    },
                                    anchor = {
                                        order = 2,
                                        type = "select",
                                        name = "Anchor",
                                        values = anchorPoints,
                                        get = function() return self.db.boeText.anchor end,
                                        set = function(_, value) self.db.boeText.anchor = value self:RefreshBindSlots() end,
                                    },
                                    xOffset = {
                                        order = 3,
                                        type = "range",
                                        name = "X Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.boeText.xOffset end,
                                        set = function(_, value) self.db.boeText.xOffset = value self:RefreshBindSlots() end,
                                    },
                                    yOffset = {
                                        order = 4,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -30,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.boeText.yOffset end,
                                        set = function(_, value) self.db.boeText.yOffset = value self:RefreshBindSlots() end,
                                    },
                                    font = {
                                        order = 5,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function() return self.db.boeText.font end,
                                        set = function(_, value) self.db.boeText.font = value self:RefreshBindSlots() end,
                                    },
                                    fontSize = {
                                        order = 6,
                                        type = "range",
                                        name = "Font Size",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return self.db.boeText.fontSize end,
                                        set = function(_, value) self.db.boeText.fontSize = value self:RefreshBindSlots() end,
                                    },
                                },
                            },
                        },
                    },
                    compareStats = {
                        order = 3,
                        type = "group",
                        name = "Compare Stats",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nZeigt einen Statistikvergleich zwischen deinem Charakter und dem inspizierten Charakter.\n ",
                                fontSize = "medium",
                            },
                            enabled = {
                                order = 2,
                                type = "toggle",
                                name = "Enable",
                                get = function() return self.db.compareStats.enabled end,
                                set = function(_, value) self.db.compareStats.enabled = value self:RefreshCompareStats() end,
                            },
                            text = {
                                order = 3,
                                type = "group",
                                name = "Text",
                                inline = true,
                                args = {
                                    font = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function() return self.db.compareStats.text.font end,
                                        set = function(_, value) self.db.compareStats.text.font = value self:RefreshCompareStats() end,
                                    },
                                    fontSize = {
                                        order = 2,
                                        type = "range",
                                        name = "Font Size",
                                        min = 8,
                                        max = 24,
                                        step = 1,
                                        get = function() return self.db.compareStats.text.fontSize end,
                                        set = function(_, value) self.db.compareStats.text.fontSize = value self:RefreshCompareStats() end,
                                    },
                                },
                            },
                            comparison = {
                                order = 4,
                                type = "group",
                                name = "Comparison",
                                inline = true,
                                args = {
                                    hideIfBothZero = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Hide If Both Zero",
                                        get = function() return self.db.compareStats.comparison.hideIfBothZero end,
                                        set = function(_, value) self.db.compareStats.comparison.hideIfBothZero = value self:RefreshCompareStats() end,
                                    },
                                    higherColor = {
                                        order = 2,
                                        type = "color",
                                        name = "Higher Color",
                                        hasAlpha = false,
                                        get = function()
                                            local c = self.db.compareStats.comparison.higherColor
                                            return c.r, c.g, c.b
                                        end,
                                        set = function(_, r, g, b)
                                            local c = self.db.compareStats.comparison.higherColor
                                            c.r, c.g, c.b = r, g, b
                                            self:RefreshCompareStats()
                                        end,
                                    },
                                    lowerColor = {
                                        order = 3,
                                        type = "color",
                                        name = "Lower Color",
                                        hasAlpha = false,
                                        get = function()
                                            local c = self.db.compareStats.comparison.lowerColor
                                            return c.r, c.g, c.b
                                        end,
                                        set = function(_, r, g, b)
                                            local c = self.db.compareStats.comparison.lowerColor
                                            c.r, c.g, c.b = r, g, b
                                            self:RefreshCompareStats()
                                        end,
                                    },
                                },
                            },
                        },
                    },
                },
            },
            misc = {
                order = 6,
                type = "group",
                name = "Misc",
                args = {
                    autoRole = {
                        order = 1,
                        type = "group",
                        name = "Auto Role",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nAkzeptiert Rollenabfragen automatisch für deine aktuell ausgewählte Rolle.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.autoAccept.enabled end,
                                        set = function(_, value) self.db.autoAccept.enabled = value end,
                                    },
                                },
                            },
                        },
                    },
                    joinReminder = {
                        order = 2,
                        type = "group",
                        name = "Join Reminder",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nZeigt beim Beitritt zu einer Gruppe eine sichere Erinnerung im Chat und auf dem Bildschirm.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.joinReminder.enabled end,
                                        set = function(_, value)
                                            self.db.joinReminder.enabled = value
                                            self:UpdateJoinReminderPreview()
                                        end,
                                    },
                                    showChat = {
                                        order = 2,
                                        type = "toggle",
                                        name = "Show In Chat",
                                        get = function() return self.db.joinReminder.showChat end,
                                        set = function(_, value) self.db.joinReminder.showChat = value end,
                                    },
                                    showScreen = {
                                        order = 3,
                                        type = "toggle",
                                        name = "Show On Screen",
                                        get = function() return self.db.joinReminder.showScreen end,
                                        set = function(_, value)
                                            self.db.joinReminder.showScreen = value
                                            self:UpdateJoinReminderPreview()
                                        end,
                                    },
                                    duration = {
                                        order = 4,
                                        type = "range",
                                        name = "Display Duration",
                                        min = 5,
                                        max = 30,
                                        step = 1,
                                        get = function() return self.db.joinReminder.duration end,
                                        set = function(_, value) self.db.joinReminder.duration = value end,
                                    },
                                    font = {
                                        order = 5,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function() return self.db.joinReminder.text.font end,
                                        set = function(_, value)
                                            self.db.joinReminder.text.font = value
                                            self:UpdateJoinReminderFrameStyle()
                                        end,
                                    },
                                    fontSize = {
                                        order = 6,
                                        type = "range",
                                        name = "Font Size",
                                        min = 10,
                                        max = 36,
                                        step = 1,
                                        get = function() return self.db.joinReminder.text.fontSize end,
                                        set = function(_, value)
                                            self.db.joinReminder.text.fontSize = value
                                            self:UpdateJoinReminderFrameStyle()
                                        end,
                                    },
                                    color = {
                                        order = 8,
                                        type = "color",
                                        name = "Text Color",
                                        hasAlpha = false,
                                        get = function()
                                            local color = self.db.joinReminder.text.color
                                            local defaultColor = addon.P.hlyqol.joinReminder.text.color
                                            return color.r, color.g, color.b, nil, defaultColor.r, defaultColor.g, defaultColor.b, nil
                                        end,
                                        set = function(_, r, g, b)
                                            local color = self.db.joinReminder.text.color
                                            color.r, color.g, color.b = r, g, b
                                            self:UpdateJoinReminderFrameStyle()
                                        end,
                                    },
                                    xOffset = {
                                        order = 9,
                                        type = "range",
                                        name = "X Offset",
                                        min = -1000,
                                        max = 1000,
                                        step = 1,
                                        get = function() return self.db.joinReminder.xOffset or 0 end,
                                        set = function(_, value)
                                            self.db.joinReminder.xOffset = value
                                            self:UpdateJoinReminderFrameStyle()
                                        end,
                                    },
                                    yOffset = {
                                        order = 10,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -1000,
                                        max = 1000,
                                        step = 1,
                                        get = function() return self.db.joinReminder.yOffset or 180 end,
                                        set = function(_, value)
                                            self.db.joinReminder.yOffset = value
                                            self:UpdateJoinReminderFrameStyle()
                                        end,
                                    },
                                    resetPosition = {
                                        order = 11,
                                        type = "execute",
                                        name = "Reset Position",
                                        func = function() self:ResetJoinReminderPosition() end,
                                    },
                                },
                            },
                        },
                    },
                    frenchConnection = {
                        order = 3,
                        type = "group",
                        name = "French Connection",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nEine Alternative zu Länderflaggen.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.frenchConnection.enabled end,
                                        set = function(_, value)
                                            self.db.frenchConnection.enabled = value
                                            self:RefreshFrenchConnection()
                                        end,
                                    },
                                    playSound = {
                                        order = 2,
                                        type = "toggle",
                                        name = "Sound",
                                        get = function() return self.db.frenchConnection.playSound end,
                                        set = function(_, value)
                                            self.db.frenchConnection.playSound = value
                                        end,
                                    },
                                    showBaguette = {
                                        order = 3,
                                        type = "toggle",
                                        name = "Icon",
                                        get = function() return self.db.frenchConnection.showBaguette end,
                                        set = function(_, value)
                                            self.db.frenchConnection.showBaguette = value
                                            self:RefreshFrenchConnection()
                                        end,
                                    },
                                },
                            },
                        },
                    },
                    loot = {
                        order = 4,
                        type = "group",
                        name = "Loot (WIP)",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nBehandelt ausgewählte Gruppenloot-Würfe in Dungeons und Raids automatisch. Unterstützt aktuell House-Decor-Items und kann dafür Need, Greed oder Pass wählen. Wenn Need nicht verfügbar ist, wird auf Greed zurückgefallen.\n ",
                                fontSize = "medium",
                            },
                            enabled = {
                                order = 3,
                                type = "toggle",
                                name = "Enable",
                                get = function() return self.db.loot.enabled end,
                                set = function(_, value) self.db.loot.enabled = value end,
                            },
                            houseDecor = {
                                order = 4,
                                type = "group",
                                name = "House Decor",
                                inline = true,
                                args = {
                                    decorAction = {
                                        order = 1,
                                        type = "select",
                                        name = "Action",
                                        values = lootDecorActions,
                                        sorting = lootDecorActionOrder,
                                        get = function() return self.db.loot.decorAction end,
                                        set = function(_, value) self.db.loot.decorAction = value end,
                                    },
                                },
                            },
                        },
                    },
                },
            },
            hlyStats = {
                order = 4,
                type = "group",
                name = "HLYstats",
                args = {
                    description = {
                        order = 1,
                        type = "description",
                        name = "|cffffd100Info:|r\n\nZeigt deine aktuellen Kampfwerte in einem verschiebbaren Fenster.",
                        fontSize = "medium",
                    },
                    general = {
                        order = 2,
                        type = "group",
                        name = " ",
                        inline = true,
                        args = {
                            enabled = {
                                order = 1,
                                type = "toggle",
                                name = "Enable",
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.enabled
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.enabled = value
                                    self:RefreshHLYstats()
                                end,
                            },
                            locked = {
                                order = 2,
                                type = "toggle",
                                name = "Lock Frame",
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.locked
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.locked = value
                                    self:ApplyHLYstatsLockState()
                                end,
                            },
                            reset = {
                                order = 3,
                                type = "execute",
                                name = "Reset Position",
                                func = function() self:ResetHLYstatsPosition() end,
                            },
                        },
                    },
                    text = {
                        order = 3,
                        type = "group",
                        name = "Text",
                        inline = true,
                        args = {
                            showItemLevel = {
                                order = 1,
                                type = "toggle",
                                name = "Show Item Level",
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.showItemLevel
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.showItemLevel = value
                                    self:RefreshHLYstatsLines()
                                end,
                            },
                            font = {
                                order = 2,
                                type = "select",
                                dialogControl = "LSM30_Font",
                                name = "Font",
                                values = fontValues,
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.font
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.font = value
                                    self:RefreshHLYstatsLines()
                                end,
                            },
                            fontSize = {
                                order = 3,
                                type = "range",
                                name = "Font Size",
                                min = 8,
                                max = 24,
                                step = 1,
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.fontSize
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.fontSize = value
                                    self:RefreshHLYstatsLines()
                                end,
                            },
                        },
                    },
                    background = {
                        order = 4,
                        type = "group",
                        name = "Background",
                        inline = true,
                        args = {
                            showBackground = {
                                order = 1,
                                type = "toggle",
                                name = "Show Background",
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.showBackground
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.showBackground = value
                                    self:ApplyHLYstatsBackdrop()
                                end,
                            },
                            backgroundAlpha = {
                                order = 2,
                                type = "range",
                                name = "Background Alpha",
                                min = 0,
                                max = 1,
                                step = 0.05,
                                isPercent = true,
                                get = function()
                                    self:EnsureHLYstatsDefaults()
                                    return self.db.hlyStats.backgroundAlpha
                                end,
                                set = function(_, value)
                                    self:EnsureHLYstatsDefaults()
                                    self.db.hlyStats.backgroundAlpha = value
                                    self:ApplyHLYstatsBackdrop()
                                end,
                            },
                        },
                    },
                    stats = {
                        order = 5,
                        type = "group",
                        name = "Stats",
                        inline = true,
                        args = hlyStatsToggleArgs(),
                    },
                },
            },
            alerts = {
                order = 2,
                type = "group",
                name = "Alerts",
                args = {
                    deathAlert = {
                        order = 1,
                        type = "group",
                        name = "Death Alert",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nSpielt einen rollenbasierten Warnsound ab, wenn ein Tank, Heiler oder Schadensausteiler stirbt.",
                                fontSize = "medium",
                            },
                            enabledGroup = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.deathAlert.enabled end,
                                        set = function(_, value) self.db.deathAlert.enabled = value end,
                                    },
                                },
                            },
                            separatorOne = {
                                order = 3,
                                type = "header",
                                name = " ",
                            },
                            channelGroup = {
                                order = 4,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    channel = {
                                        order = 1,
                                        type = "select",
                                        name = "Audio Channel",
                                        values = soundChannels,
                                        get = function() return self.db.deathAlert.channel end,
                                        set = function(_, value) self.db.deathAlert.channel = value end,
                                    },
                                },
                            },
                            separatorTwo = {
                                order = 5,
                                type = "header",
                                name = " ",
                            },
                            testGroup = {
                                order = 6,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    dpsTest = {
                                        order = 1,
                                        type = "execute",
                                        name = "Test DPS Sound",
                                        func = function() self:PlayDeathAlert("DAMAGER") end,
                                    },
                                    healerTest = {
                                        order = 2,
                                        type = "execute",
                                        name = "Test Healer Sound",
                                        func = function() self:PlayDeathAlert("HEALER") end,
                                    },
                                    tankTest = {
                                        order = 3,
                                        type = "execute",
                                        name = "Test Tank Sound",
                                        func = function() self:PlayDeathAlert("TANK") end,
                                    },
                                },
                            },
                        },
                    },
                    trinketAlert = {
                        order = 2,
                        type = "group",
                        name = "Trinket Alert",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nSpielt getrennte Sounds ab, wenn deine Schmuckstücke wieder bereit sind.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.trinketAlert.enabled end,
                                        set = function(_, value)
                                            self.db.trinketAlert.enabled = value
                                            self:PrimeTrinketStates()
                                        end,
                                    },
                                },
                            },
                            separatorOne = {
                                order = 3,
                                type = "header",
                                name = " ",
                            },
                            channelGroup = {
                                order = 4,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    channel = {
                                        order = 1,
                                        type = "select",
                                        name = "Audio Channel",
                                        values = function() return self:GetTrinketAlertChannels() end,
                                        get = function() return self.db.trinketAlert.channel end,
                                        set = function(_, value) self.db.trinketAlert.channel = value end,
                                    },
                                },
                            },
                            separatorTwo = {
                                order = 5,
                                type = "header",
                                name = " ",
                            },
                            trinketSounds = {
                                order = 6,
                                type = "group",
                                name = "Trinket Sounds",
                                inline = true,
                                args = {
                                    trinket1Sound = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Sound",
                                        name = "Trinket 1",
                                        width = 1.3,
                                        values = function() return self:GetSoundList() end,
                                        get = function() return self.db.trinketAlert.sounds.trinket1 end,
                                        set = function(_, value) self.db.trinketAlert.sounds.trinket1 = value end,
                                    },
                                    trinket2Sound = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Sound",
                                        name = "Trinket 2",
                                        width = 1.3,
                                        values = function() return self:GetSoundList() end,
                                        get = function() return self.db.trinketAlert.sounds.trinket2 end,
                                        set = function(_, value) self.db.trinketAlert.sounds.trinket2 = value end,
                                    },
                                },
                            },
                        },
                    },
                    lustAlert = {
                        order = 3,
                        type = "group",
                        name = "Lust Alert",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nSpielt einen Sound ab, wenn Bloodlust, Heroism, Time Warp, Trommeln oder vergleichbare Effekte genutzt werden.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function() return self.db.lustAlert.enabled end,
                                        set = function(_, value) self.db.lustAlert.enabled = value end,
                                    },
                                },
                            },
                            sound = {
                                order = 3,
                                type = "group",
                                name = "Sound",
                                inline = true,
                                args = {
                                    sound = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Sound",
                                        name = "Sound",
                                        values = function() return self:GetLustAlertSoundList() end,
                                        get = function() return self.db.lustAlert.sound end,
                                        set = function(_, value) self.db.lustAlert.sound = value end,
                                    },
                                    channel = {
                                        order = 2,
                                        type = "select",
                                        name = "Audio Channel",
                                        values = soundChannels,
                                        get = function() return self.db.lustAlert.channel end,
                                        set = function(_, value) self.db.lustAlert.channel = value end,
                                    },
                                    testSound = {
                                        order = 3,
                                        type = "execute",
                                        name = "Test Sound",
                                        func = function() self:TestLustAlert() end,
                                    },
                                },
                            },
                            timer = {
                                order = 4,
                                type = "group",
                                name = "Timer Text",
                                inline = true,
                                args = {
                                    showTimer = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Show Timer",
                                        get = function() return self.db.lustAlert.showTimer end,
                                        set = function(_, value)
                                            self.db.lustAlert.showTimer = value
                                            if not value then
                                                self:HideLustAlertTimer()
                                            end
                                        end,
                                    },
                                    font = {
                                        order = 2,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            return self.db.lustAlert.timer.font
                                        end,
                                        set = function(_, value)
                                            self:EnsureLustAlertDefaults()
                                            self.db.lustAlert.timer.font = value
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    labelFontSize = {
                                        order = 3,
                                        type = "range",
                                        name = "Label Size",
                                        min = 8,
                                        max = 36,
                                        step = 1,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            return self.db.lustAlert.timer.labelFontSize
                                        end,
                                        set = function(_, value)
                                            self:EnsureLustAlertDefaults()
                                            self.db.lustAlert.timer.labelFontSize = value
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    timerFontSize = {
                                        order = 4,
                                        type = "range",
                                        name = "Timer Size",
                                        min = 10,
                                        max = 48,
                                        step = 1,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            return self.db.lustAlert.timer.timerFontSize
                                        end,
                                        set = function(_, value)
                                            self:EnsureLustAlertDefaults()
                                            self.db.lustAlert.timer.timerFontSize = value
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    labelColor = {
                                        order = 6,
                                        type = "color",
                                        name = "Label Color",
                                        hasAlpha = false,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            local c = self.db.lustAlert.timer.labelColor
                                            return c.r, c.g, c.b
                                        end,
                                        set = function(_, r, g, b)
                                            self:EnsureLustAlertDefaults()
                                            local c = self.db.lustAlert.timer.labelColor
                                            c.r, c.g, c.b = r, g, b
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    timerColor = {
                                        order = 7,
                                        type = "color",
                                        name = "Timer Color",
                                        hasAlpha = false,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            local c = self.db.lustAlert.timer.timerColor
                                            return c.r, c.g, c.b
                                        end,
                                        set = function(_, r, g, b)
                                            self:EnsureLustAlertDefaults()
                                            local c = self.db.lustAlert.timer.timerColor
                                            c.r, c.g, c.b = r, g, b
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    xOffset = {
                                        order = 8,
                                        type = "range",
                                        name = "X Offset",
                                        min = -600,
                                        max = 600,
                                        step = 1,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            return self.db.lustAlert.timer.xOffset
                                        end,
                                        set = function(_, value)
                                            self:EnsureLustAlertDefaults()
                                            self.db.lustAlert.timer.xOffset = value
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    yOffset = {
                                        order = 9,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -400,
                                        max = 400,
                                        step = 1,
                                        get = function()
                                            self:EnsureLustAlertDefaults()
                                            return self.db.lustAlert.timer.yOffset
                                        end,
                                        set = function(_, value)
                                            self:EnsureLustAlertDefaults()
                                            self.db.lustAlert.timer.yOffset = value
                                            self:UpdateLustAlertTimerStyle()
                                        end,
                                    },
                                    testTimer = {
                                        order = 10,
                                        type = "execute",
                                        name = "Test Timer",
                                        func = function() self:TestLustAlertTimer() end,
                                    },
                                },
                            },
                        },
                    },
                    gearCheck = {
                        order = 4,
                        type = "group",
                        name = "PVP Gear Check",
                        args = {
                            description = {
                                order = 1,
                                type = "description",
                                name = "|cffffd100Info:|r\n\nPrüft beim Start eines Bereitschaftschecks die angelegte PvP-Ausrüstung, auch bekannt als Jane Mode. Läuft nur in Dungeon- und Raidinstanzen.",
                                fontSize = "medium",
                            },
                            general = {
                                order = 2,
                                type = "group",
                                name = " ",
                                inline = true,
                                args = {
                                    enabled = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Enable",
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.enabled
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.enabled = value
                                            self:UpdateGearCheckPreview()
                                        end,
                                    },
                                },
                            },
                            output = {
                                order = 3,
                                type = "group",
                                name = "Output",
                                inline = true,
                                args = {
                                    showChat = {
                                        order = 1,
                                        type = "toggle",
                                        name = "Chat Message",
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.showChat
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.showChat = value
                                        end,
                                    },
                                    showScreen = {
                                        order = 2,
                                        type = "toggle",
                                        name = "Screen Message",
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.showScreen
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.showScreen = value
                                            self:UpdateGearCheckPreview()
                                        end,
                                    },
                                    duration = {
                                        order = 3,
                                        type = "range",
                                        name = "Duration",
                                        min = 1,
                                        max = 15,
                                        step = 0.5,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.duration
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.duration = value
                                        end,
                                    },
                                },
                            },
                            sound = {
                                order = 4,
                                type = "group",
                                name = "Sound",
                                inline = true,
                                args = {
                                    sound = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Sound",
                                        name = "Sound",
                                        values = function() return self:GetSoundList() end,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.sound
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.sound = value
                                        end,
                                    },
                                    channel = {
                                        order = 2,
                                        type = "select",
                                        name = "Audio Channel",
                                        values = soundChannels,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.channel
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.channel = value
                                        end,
                                    },
                                },
                            },
                            text = {
                                order = 5,
                                type = "group",
                                name = "Screen Text",
                                inline = true,
                                args = {
                                    font = {
                                        order = 1,
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        name = "Font",
                                        values = fontValues,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.text.font
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.text.font = value
                                            self:UpdateGearCheckFrameStyle()
                                        end,
                                    },
                                    fontSize = {
                                        order = 2,
                                        type = "range",
                                        name = "Font Size",
                                        min = 8,
                                        max = 48,
                                        step = 1,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.text.fontSize
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.text.fontSize = value
                                            self:UpdateGearCheckFrameStyle()
                                        end,
                                    },
                                    color = {
                                        order = 4,
                                        type = "color",
                                        name = "Color",
                                        hasAlpha = false,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            local c = self.db.gearCheck.text.color
                                            return c.r, c.g, c.b
                                        end,
                                        set = function(_, r, g, b)
                                            self:EnsureGearCheckDefaults()
                                            local c = self.db.gearCheck.text.color
                                            c.r, c.g, c.b = r, g, b
                                            self:UpdateGearCheckFrameStyle()
                                        end,
                                    },
                                    xOffset = {
                                        order = 6,
                                        type = "range",
                                        name = "X Offset",
                                        min = -600,
                                        max = 600,
                                        step = 1,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.xOffset
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.xOffset = value
                                            self:UpdateGearCheckFrameStyle()
                                        end,
                                    },
                                    yOffset = {
                                        order = 7,
                                        type = "range",
                                        name = "Y Offset",
                                        min = -400,
                                        max = 400,
                                        step = 1,
                                        get = function()
                                            self:EnsureGearCheckDefaults()
                                            return self.db.gearCheck.yOffset
                                        end,
                                        set = function(_, value)
                                            self:EnsureGearCheckDefaults()
                                            self.db.gearCheck.yOffset = value
                                            self:UpdateGearCheckFrameStyle()
                                        end,
                                    },
                                },
                            },
                        },
                    },
                },
            },
            marker = {
                order = 5,
                type = "group",
                name = "Tank Marker",
                args = {
                    description = {
                        order = 1,
                        type = "description",
                        name = "|cffffd100Info:|r\n\nMarkiert den ersten zugewiesenen Tank in normalen Gruppen (nicht in Raids) mit einem Schlachtzugsymbol. Erstellt und pflegt automatisch das Makro 'HLYmarkerTank'; nutze es manuell, um die Markierung zu setzen.\n ",
                        fontSize = "medium",
                    },
                    general = {
                        order = 2,
                        type = "group",
                        name = " ",
                        inline = true,
                        args = {
                            enabled = {
                                order = 1,
                                type = "toggle",
                                name = "Enable",
                                get = function() return self.db.marker.enabled end,
                                set = function(_, value)
                                    self.db.marker.enabled = value
                                    self:QueueMarkerMacroUpdate()
                                    self:RefreshMarkerReminder()
                                end,
                            },
                            updateMacro = {
                                order = 2,
                                type = "execute",
                                name = "Update Macro Now",
                                func = function() self:UpdateMarkerMacroNow() end,
                            },
                        },
                    },
                    markGroup = {
                        order = 3,
                        type = "group",
                        name = "Tank Mark",
                        inline = true,
                        args = {
                            mark = {
                                order = 1,
                                type = "select",
                                name = "Icon",
                                values = markerMarkValues,
                                sorting = markerMarkOrder,
                                get = function() return tostring(self.db.marker.mark) end,
                                set = function(_, value)
                                    self.db.marker.mark = tonumber(value) or 6
                                    self:QueueMarkerMacroUpdate()
                                    self:RefreshMarkerReminder()
                                end,
                            },
                        },
                    },
                    reminder = {
                        order = 4,
                        type = "group",
                        name = "Reminder",
                        inline = true,
                        args = {
                            reminderFontSize = {
                                order = 1,
                                type = "range",
                                name = "Font Size",
                                min = 10,
                                max = 36,
                                step = 1,
                                get = function() return self.db.marker.reminderFontSize end,
                                set = function(_, value)
                                    self.db.marker.reminderFontSize = value
                                    self:RefreshMarkerReminder()
                                end,
                            },
                            reminderX = {
                                order = 3,
                                type = "range",
                                name = "X Offset",
                                min = -2000,
                                max = 2000,
                                step = 1,
                                get = function() return self.db.marker.reminderX end,
                                set = function(_, value)
                                    self.db.marker.reminderX = value
                                    self:RefreshMarkerReminder()
                                end,
                            },
                            reminderY = {
                                order = 4,
                                type = "range",
                                name = "Y Offset",
                                min = -1200,
                                max = 1200,
                                step = 1,
                                get = function() return self.db.marker.reminderY end,
                                set = function(_, value)
                                    self.db.marker.reminderY = value
                                    self:RefreshMarkerReminder()
                                end,
                            },
                        },
                    },
                },
            },
            statistics = {
                order = 7,
                type = "group",
                name = "Statistics",
                args = {
                    general = {
                        order = 1,
                        type = "group",
                        name = " ",
                        inline = true,
                        args = {
                            reset = {
                                order = 1,
                                type = "execute",
                                name = "Reset Data",
                                confirm = true,
                                confirmText = "Reset all stored Statistics data?",
                                func = function() self:ResetStatisticsData() end,
                            },
                        },
                    },
                    playedSummary = {
                        order = 2,
                        type = "group",
                        name = " ",
                        inline = true,
                        args = {
                            summary = {
                                order = 1,
                                type = "description",
                                name = function()
                                    self:EnsureStatisticsDefaults()
                                    return self:GetStatisticsPlayedSummaryText()
                                end,
                                fontSize = "medium",
                            },
                        },
                    },
                    goldSummary = {
                        order = 3,
                        type = "group",
                        name = " ",
                        inline = true,
                        args = {
                            summary = {
                                order = 1,
                                type = "description",
                                name = function()
                                    self:EnsureStatisticsDefaults()
                                    return self:GetStatisticsGoldSummaryText()
                                end,
                                fontSize = "medium",
                            },
                        },
                    },
                },
            },
        },
    }

    return self.options
end

function HLY:SetupOptionsPreviewHooks()
    if self.optionsPreviewHooked then return end
    local ACD = LibStub("AceConfigDialog-3.0", true)
    if not ACD then return end
    self.optionsPreviewHooked = true

    local function updatePreviews(path)
        local n = path and #path or 0

        -- Marker: top-level tab only (n==1). Ignore root (n==0) and nested paths.
        if n == 1 then
            if path[1] == "marker" then
                self:ShowMarkerReminderPreview()
            else
                self:HideMarkerReminderPreview()
            end
        end

        -- JoinReminder: misc sub-section leaf (n>=2). Skip n==1 ["misc"] (intermediate parent).
        if n >= 2 and path[1] == "misc" then
            if path[2] == "joinReminder" then
                self:ShowJoinReminderPreview()
            else
                self:HideJoinReminderPreview()
            end
        elseif n == 1 and path[1] ~= "misc" then
            self:HideJoinReminderPreview()
        end

        -- GearCheck: alerts sub-section leaf (n>=2). Skip n==1 ["alerts"] (intermediate parent).
        if n >= 2 and path[1] == "alerts" then
            if path[2] == "gearCheck" then
                self:ShowGearCheckPreview()
            else
                self:HideGearCheckPreview()
            end
        elseif n == 1 and path[1] ~= "alerts" then
            self:HideGearCheckPreview()
        end
    end

    hooksecurefunc(ACD, "FeedGroup", function(_, appName, _, _, _, path)
        if appName ~= addon.addonName then return end
        updatePreviews(path)

        local dialog = ACD.OpenFrames[addon.addonName]
        if dialog and dialog.frame and not dialog.frame.hlyPreviewHooked then
            dialog.frame.hlyPreviewHooked = true
            dialog.frame:HookScript("OnHide", function()
                self:HideJoinReminderPreview()
                self:HideMarkerReminderPreview()
                self:HideGearCheckPreview()
            end)
        end
    end)
end
