---@diagnostic disable: undefined-field, undefined-global
---@class Private
local Private = select(2, ...)

local windowWidth = 250
local windowHeight = 176

local padding = 8
local spacing = 4 -- Spacing between UI elements
local checkButtons = {}

local function AddCheckButton(title, tooltip, isChecked, OnValueChanged)
    local checkButton = Private:CreateCheckButton(
        Private.settingsWindow,
        title,
        OnValueChanged
    )

    if next(checkButtons) then
        checkButton:SetPoint("TOPLEFT", checkButtons[#checkButtons], "BOTTOMLEFT", 0, -spacing)
    else
        checkButton:SetPoint("TOPLEFT", Private.settingsWindow, "TOPLEFT", padding, -padding)
    end

    checkButton:SetChecked(isChecked)
    checkButton:SetSize(20, 20)
    checkButton.title:SetFontObject(WildThingsFont15)

    Private.WildThingsUI:AddTooltip(checkButton, tooltip)
    Private.WildThingsUI:AddTooltip(checkButton.title, tooltip)

    table.insert(checkButtons, checkButton)
end

-- This can be set from the popup window, so needs a generic function that can be used in both places
function Private:SetNotifyOnReadyCheck(checked)
    checkButtons[2]:SetChecked(checked)
end

function Private:InitializeSettings()
    Private.settingsWindow = Private:CreateWindow()
    Private.settingsWindow:SetParent(Private.window)
    Private.settingsWindow:SetPoint("TOPLEFT", Private.window, "TOPRIGHT", 4, 0)
    Private.settingsWindow:SetSize(windowWidth, windowHeight)
    Private.settingsWindow:Hide()

    AddCheckButton(
        "Auto open on Update available",
        "Automatically opens the Wild Things Updater window when an update is available.",
        WildThingsSavedVars.update.auto_open,
        function(toggleAutoOpenOnUpdate)
            WildThingsSavedVars.update.auto_open = toggleAutoOpenOnUpdate
        end
    )

    AddCheckButton(
        "Hide minimap icon when up to date",
        "Hides the minimap icon when all your auras (and the addon itself) are up to date.",
        WildThingsSavedVars.settings.hideMinimapIcon,
        function(hideMinimapIcon)
            WildThingsSavedVars.settings.hideMinimapIcon = hideMinimapIcon

            Private:UpdateMinimapIcon()
        end
    )

    AddCheckButton(
        "Notify on ready check",
        "If your addon or any of your auras are out of date, show a popup window on ready check.",
        WildThingsSavedVars.settings.readyCheckPopup,
        function(readyCheckPopup)
            WildThingsSavedVars.settings.readyCheckPopup = readyCheckPopup
        end
    )

    AddCheckButton(
        "Party Mode",
        "Activate the Wild Things Party Mode. Includes cringe moments. Note: Only works, if the Raid Leader has this option enabled.",
        WildThingsSavedVars.update.party_mode,
        function(togglePartyMode)
            WildThingsSavedVars.update.party_mode = togglePartyMode
        end
    )

    AddCheckButton(
        "Memes",
        "Activate to receive memes sent by others (Yell or Raid Chat).",
        WildThingsSavedVars.update.memes,
        function(toggleMemes)
            WildThingsSavedVars.update.memes = toggleMemes
        end
    )


end
