
-- rChat: config
-- Configuration and default settings

local A, L = ...

L.defaults = {
    -- Minimap icon settings
    minimap = {
        hide = false,
    },
    -- Chicchai settings
    chicchai = {
        enabled = false,
        animTime = 0.3,
        minimizeTime = 10,
        minimizedLines = 2,
        maximizeOnEnter = true,
        waitAfterEnter = 0,
        waitAfterLeave = 0,
        lockInCombat = false,
        maximizeCombatLog = true,
    },
    -- Chat settings
    chat = {
        alwaysShowTabs = false,
        showTimestamp = true,
        showPlayerLevel = true,
        editboxPosition = "top", -- "top" or "bottom"
        enableURLCopy = true,
        enableChatCopyButton = true,
        chatFadeTime = 20, -- seconds until chat fades out
    },
}

-- Initialize saved variables on first load
function L:InitConfig()
    if not rChatDB then
        rChatDB = CopyTable(self.defaults)
    else
        -- Merge new defaults with existing settings (including nested keys)
        for category, values in pairs(self.defaults) do
            if not rChatDB[category] then
                rChatDB[category] = CopyTable(values)
            else
                -- Also merge individual keys within category
                for key, defaultValue in pairs(values) do
                    if rChatDB[category][key] == nil then
                        rChatDB[category][key] = defaultValue
                    end
                end
            end
        end
    end
end

-- Reset to defaults
function L:ResetConfig()
    rChatDB = CopyTable(self.defaults)
    print("|cff33ff99rChat:|r " .. L.Strings["CONFIG_RESET_RELOAD"])
    ReloadUI()
end

-- Get config value
function L:GetConfig(category, key)
    if not rChatDB or not rChatDB[category] then
        return self.defaults[category] and self.defaults[category][key]
    end
    return rChatDB[category][key]
end

-- Set config value
function L:SetConfig(category, key, value)
    if not rChatDB then
        self:InitConfig()
    end
    if not rChatDB[category] then
        rChatDB[category] = {}
    end
    rChatDB[category][key] = value
end
