-------------------------------------------------------------------------------
-- Project: AscensionBars
-- Author: Aka-DoctorCode 
-- File: Config.lua
-- Version: 20
-------------------------------------------------------------------------------
-- Copyright (c) 2025–2026 Aka-DoctorCode. All Rights Reserved.
--
-- This software and its source code are the exclusive property of the author.
-- No part of this file may be copied, modified, redistributed, or used in 
-- derivative works without express written permission.
-------------------------------------------------------------------------------
local AB = LibStub("AceAddon-3.0"):GetAddon("AscensionBars")
local L = LibStub("AceLocale-3.0"):GetLocale("AscensionBars")

function AB:GetOptionsTable()
    local CONSTANTS = AB.constants
    local options = {
        name = "Ascension Bars",
        type = "group",
        childGroups = "tab",
        args = {
            configMode = {
                name = L["CONFIG_MODE"],
                desc = L["CONFIG_MODE_DESC"],
                type = "toggle",
                order = 0,
                get = function() return self.state.isConfigMode end,
                set = function(_, val)
                    self.state.isConfigMode = val
                    self:UpdateDisplay()
                end,
            },
            general = {
                name = L["APPEARANCE"],
                type = "group",
                order = 10,
                args = {
                    headerPos = { type = "header", name = L["POSITION_SIZE"], order = 1 },
                    barAnchor = {
                        name = L["BAR_ANCHOR"],
                        desc = L["ANCHOR_DESC"],
                        type = "select",
                        order = 1.5,
                        values = {
                            ["TOP"] = L["ANCHOR_TOP"],
                            ["BOTTOM"] = L["ANCHOR_BOTTOM"],
                        },
                        get = function() return self.db.profile.barAnchor end,
                        set = function(_, v)
                            self.db.profile.barAnchor = v
                            self:UpdateDisplay()
                        end,
                    },
                    yOffset = {
                        name = L["VERTICAL_POSITION"],
                        type = "range",
                        min = -1080,
                        max = 1080,
                        step = 1,
                        bigStep = 10,
                        order = 2,
                        get = function() return self.db.profile.yOffset end,
                        set = function(_, v)
                            self.db.profile.yOffset = v
                            self:UpdateDisplay()
                        end,
                    },
                    textGap = {
                        name = L["TEXT_GAP"],
                        type = "range",
                        min = -50,
                        max = 100,
                        step = 0.5,
                        order = 2.5,
                        get = function() return self.db.profile.textGap end,
                        set = function(_, v)
                            self.db.profile.textGap = v
                            self:UpdateDisplay()
                        end,
                    },
                    barHeightXP = {
                        name = L["XP_BAR_HEIGHT"],
                        type = "range",
                        min = CONSTANTS.MIN_BAR_HEIGHT,
                        max = CONSTANTS.MAX_BAR_HEIGHT,
                        step = 1,
                        order = 3,
                        get = function() return self.db.profile.barHeightXP end,
                        set = function(_, v)
                            self.db.profile.barHeightXP = v
                            self:UpdateDisplay()
                        end,
                    },
                    barHeightRep = {
                        name = L["REP_BAR_HEIGHT"],
                        type = "range",
                        min = CONSTANTS.MIN_BAR_HEIGHT,
                        max = CONSTANTS.MAX_BAR_HEIGHT,
                        step = 1,
                        order = 4,
                        get = function() return self.db.profile.barHeightRep end,
                        set = function(_, v)
                            self.db.profile.barHeightRep = v
                            self:UpdateDisplay()
                        end,
                    },
                    textSize = {
                        name = L["FONT_SIZE"],
                        type = "range",
                        min = CONSTANTS.MIN_TEXT_SIZE,
                        max = CONSTANTS.MAX_TEXT_SIZE,
                        step = 1,
                        order = 5,
                        get = function() return self.db.profile.textSize end,
                        set = function(_, v)
                            self.db.profile.textSize = v
                            self:UpdateDisplay()
                        end,
                    },
                    globalColor = {
                        name = L["TEXT_COLOR"],
                        type = "color",
                        hasAlpha = true,
                        order = 6,
                        get = function()
                            local t = self.db.profile.textColor
                            return t.r, t.g, t.b, t.a
                        end,
                        set = function(_, r, g, b, a)
                            local t = self.db.profile.textColor
                            t.r, t.g, t.b, t.a = r, g, b, a
                            self:UpdateDisplay()
                        end,
                    },
                }
            },
            behavior = {
                name = L["VISIBILITY"],
                type = "group",
                order = 20,
                args = {
                    showOnMouseover = {
                        name = L["SHOW_ON_MOUSEOVER"],
                        type = "toggle",
                        order = 1,
                        get = function() return self.db.profile.showOnMouseover end,
                        set = function(_, v)
                            self.db.profile.showOnMouseover = v
                            self:UpdateDisplay()
                        end,
                    },
                    hideInCombat = {
                        name = L["HIDE_IN_COMBAT"],
                        type = "toggle",
                        order = 2,
                        get = function() return self.db.profile.hideInCombat end,
                        set = function(_, v)
                            self.db.profile.hideInCombat = v
                            self:UpdateDisplay()
                        end,
                    },
                    hideAtMaxLevel = {
                        name = L["HIDE_AT_MAX_LEVEL"],
                        type = "toggle",
                        order = 3,
                        get = function() return self.db.profile.hideAtMaxLevel end,
                        set = function(_, v)
                            self.db.profile.hideAtMaxLevel = v
                            self:UpdateDisplay()
                        end,
                    },
                }
            },
            colors = {
                name = L["COLORS"],
                type = "group",
                order = 30,
                args = {
                    headerXP = { type = "header", name = L["EXPERIENCE"], order = 1 },
                    useClassColorXP = {
                        name = L["USE_CLASS_COLOR"],
                        type = "toggle",
                        order = 2,
                        width = "full",
                        get = function() return self.db.profile.useClassColorXP end,
                        set = function(_, v)
                            self.db.profile.useClassColorXP = v
                            self:UpdateDisplay()
                        end,
                    },
                    xpBarColor = {
                        name = L["CUSTOM_XP_COLOR"],
                        type = "color",
                        hasAlpha = true,
                        order = 3,
                        disabled = function() return self.db.profile.useClassColorXP end,
                        get = function()
                            local c = self.db.profile.xpBarColor
                            return c.r, c.g, c.b, c.a
                        end,
                        set = function(_, r, g, b, a)
                            local c = self.db.profile.xpBarColor
                            c.r, c.g, c.b, c.a = r, g, b, a
                            self:UpdateDisplay()
                        end,
                    },
                    showRestedBar = {
                        name = L["SHOW_RESTED_BAR"],
                        type = "toggle",
                        order = 4,
                        get = function() return self.db.profile.showRestedBar end,
                        set = function(_, v)
                            self.db.profile.showRestedBar = v
                            self:UpdateDisplay()
                        end,
                    },
                    restedBarColor = {
                        name = L["RESTED_COLOR"],
                        type = "color",
                        hasAlpha = true,
                        order = 5,
                        disabled = function() return not self.db.profile.showRestedBar end,
                        get = function()
                            local c = self.db.profile.restedBarColor
                            return c.r, c.g, c.b, c.a
                        end,
                        set = function(_, r, g, b, a)
                            local c = self.db.profile.restedBarColor
                            c.r, c.g, c.b, c.a = r, g, b, a
                            self:UpdateDisplay()
                        end,
                    },
                    headerRep = { type = "header", name = L["REPUTATION"], order = 10 },
                    useReactionColorRep = {
                        name = L["USE_REACTION_COLORS"],
                        type = "toggle",
                        order = 11,
                        width = "full",
                        get = function() return self.db.profile.useReactionColorRep end,
                        set = function(_, v)
                            self.db.profile.useReactionColorRep = v
                            self:UpdateDisplay()
                        end,
                    },
                    repBarColor = {
                        name = L["CUSTOM_REP_COLOR"],
                        type = "color",
                        hasAlpha = true,
                        order = 12,
                        disabled = function() return self.db.profile.useReactionColorRep end,
                        get = function()
                            local c = self.db.profile.repBarColor
                            return c.r, c.g, c.b, c.a
                        end,
                        set = function(_, r, g, b, a)
                            local c = self.db.profile.repBarColor
                            c.r, c.g, c.b, c.a = r, g, b, a
                            self:UpdateDisplay()
                        end,
                    },
                }
            },
            paragonSettings = {
                name = L["PARAGON_ALERTS"],
                type = "group",
                order = 40,
                args = {
                    paragonOnTop = {
                        name = L["SHOW_ON_TOP"],
                        type = "toggle",
                        order = 1,
                        get = function() return self.db.profile.paragonOnTop end,
                        set = function(_, v)
                            self.db.profile.paragonOnTop = v
                            self:UpdateDisplay()
                        end,
                    },
                    split = {
                        name = L["SPLIT_LINES"],
                        type = "toggle",
                        order = 2,
                        get = function() return self.db.profile.splitParagonText end,
                        set = function(_, v)
                            self.db.profile.splitParagonText = v
                            self:UpdateDisplay()
                        end,
                    },
                    paragonTextSize = {
                        name = L["TEXT_SIZE"],
                        type = "range",
                        min = 10,
                        max = 40,
                        step = 1,
                        order = 3,
                        get = function() return self.db.profile.paragonTextSize end,
                        set = function(_, v)
                            self.db.profile.paragonTextSize = v
                            self:UpdateDisplay()
                        end,
                    },
                    paragonTextYOffset = {
                        name = L["VERTICAL_OFFSET_Y"],
                        type = "range",
                        min = -1000,
                        max = 500,
                        step = 5,
                        order = 4,
                        get = function() return self.db.profile.paragonTextYOffset end,
                        set = function(_, v)
                            self.db.profile.paragonTextYOffset = v
                            self:UpdateDisplay()
                        end,
                    },
                    pColor = {
                        name = L["ALERT_COLOR"],
                        type = "color",
                        order = 5,
                        get = function()
                            local c = self.db.profile.paragonPendingColor
                            return c.r, c.g, c.b
                        end,
                        set = function(_, r, g, b)
                            local c = self.db.profile.paragonPendingColor
                            c.r, c.g, c.b = r, g, b
                            self:UpdateDisplay()
                        end,
                    },
                }
            },
            standingColors = {
                name = L["FACTION_COLORS"],
                type = "group",
                order = 50,
                args = {}
            },
            advanced = {
                name = L["ADVANCED"],
                type = "group",
                order = 60,
                args = {
                    showPercentage = {
                        name = L["SHOW_PERCENTAGE"],
                        type = "toggle",
                        order = 1,
                        get = function() return self.db.profile.showPercentage end,
                        set = function(_, v)
                            self.db.profile.showPercentage = v
                            self:UpdateDisplay()
                        end,
                    },
                    showAbsoluteValues = {
                        name = L["SHOW_ABSOLUTE_VALUES"],
                        type = "toggle",
                        order = 2,
                        get = function() return self.db.profile.showAbsoluteValues end,
                        set = function(_, v)
                            self.db.profile.showAbsoluteValues = v
                            self:UpdateDisplay()
                        end,
                    },
                    sparkEnabled = {
                        name = L["SHOW_SPARK"],
                        type = "toggle",
                        order = 3,
                        get = function() return self.db.profile.sparkEnabled end,
                        set = function(_, v)
                            self.db.profile.sparkEnabled = v
                            self:UpdateDisplay()
                        end,
                    },
                }
            },
        }
    }

    local labels = {
        L["HATED"], L["HOSTILE"], L["UNFRIENDLY"], L["NEUTRAL"], L["FRIENDLY"],
        L["HONORED"], L["REVERED"], L["EXALTED"], L["PARAGON"], L["MAXED"], L["RENOWN"]
    }

    for i = 1, 11 do
        options.args.standingColors.args["rank" .. i] = {
            name = labels[i],
            type = "color",
            hasAlpha = true,
            order = i,
            get = function()
                local c = self.db.profile.repColors[i]
                return c.r, c.g, c.b, c.a
            end,
            set = function(_, r, g, b, a)
                local c = self.db.profile.repColors[i]
                c.r, c.g, c.b, c.a = r, g, b, a
                self:UpdateDisplay()
            end,
        }
    end

    return options
end
