local GSE = GSE
local Statics = GSE.Static
GSE.DebugProfile("End Patrons")
-- These are overridden when the saved variables are loaded in

function GSE.resetMacroResetModifiers()
    GSEOptions.MacroResetModifiers = {}
    GSEOptions.MacroResetModifiers["LeftButton"] = false
    GSEOptions.MacroResetModifiers["RightButton"] = false
    GSEOptions.MacroResetModifiers["MiddleButton"] = false
    GSEOptions.MacroResetModifiers["Button4"] = false
    GSEOptions.MacroResetModifiers["Button5"] = false
    GSEOptions.MacroResetModifiers["LeftAlt"] = false
    GSEOptions.MacroResetModifiers["RightAlt"] = false
    GSEOptions.MacroResetModifiers["Alt"] = false
    GSEOptions.MacroResetModifiers["LeftControl"] = false
    GSEOptions.MacroResetModifiers["RightControl"] = false
    GSEOptions.MacroResetModifiers["Control"] = false
    GSEOptions.MacroResetModifiers["LeftShift"] = false
    GSEOptions.MacroResetModifiers["RightShift"] = false
    GSEOptions.MacroResetModifiers["Shift"] = false
    GSEOptions.MacroResetModifiers["LeftAlt"] = false
    GSEOptions.MacroResetModifiers["RightAlt"] = false
    GSEOptions.MacroResetModifiers["AnyMod"] = false
end

function GSE.SetDefaultOptions()
    GSEOptions.saveAllMacrosLocal = true
    GSEOptions.initialised = true
    GSEOptions.deleteOrphansOnLogout = false
    GSEOptions.debug = false
    GSEOptions.sendDebugOutputToChat = nil
    GSEOptions.sendDebugOutputToChatWindow = false
    GSEOptions.sendDebugOutputToDebugOutput = false
    GSEOptions.setDefaultIconQuestionMark = true
    GSEOptions.TitleColour = "|cFFFF0000"
    GSEOptions.AuthorColour = "|cFF00D1FF"
    GSEOptions.CommandColour = "|cFF00FF00"
    GSEOptions.NormalColour = "|cFFFFFFFF"
    GSEOptions.EmphasisColour = "|cFFFFFF00"
    GSEOptions.KEYWORD = "|cff88bbdd"
    GSEOptions.UNKNOWN = "|cffff6666"
    GSEOptions.CONCAT = "|cffcc7777"
    GSEOptions.NUMBER = "|cffffaa00"
    GSEOptions.STRING = "|cff888888"
    GSEOptions.COMMENT = "|cff55cc55"
    GSEOptions.EQUALS = "|cffccddee"
    GSEOptions.STANDARDFUNCS = "|cff55ddcc"
    GSEOptions.WOWSHORTCUTS = "|cffddaaff"
    GSEOptions.overflowPersonalMacros = false
    GSEOptions.RealtimeParse = false
    GSEOptions.ActiveSequenceVersions = {}
    GSEOptions.DisabledSequences = {}
    GSEOptions.DebugModules = {}
    GSEOptions.shownew = true

    GSEOptions.DebugModules[Statics.DebugModules["Translator"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["Editor"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["Viewer"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["Storage"]] = false
    GSEOptions.DebugModules[Statics.DebugModules[Statics.SourceTransmission]] = false
    GSEOptions.DebugModules[Statics.DebugModules["API"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["GUI"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["Versions"]] = false
    GSEOptions.DebugModules[Statics.DebugModules["Startup"]] = false

    GSEOptions.filterList = {}
    GSEOptions.filterList[Statics.Spec] = true
    GSEOptions.filterList[Statics.Class] = true
    GSEOptions.filterList[Statics.All] = true
    GSEOptions.filterList[Statics.Global] = true
    GSEOptions.autoCreateMacroStubsClass = true
    GSEOptions.autoCreateMacroStubsGlobal = false
    GSEOptions.resetOOC = true
    GSEOptions.DefaultDisabledMacroIcon = "Interface\\Icons\\INV_MISC_BOOK_08"
    GSEOptions.CreateGlobalButtons = false
    GSEOptions.HideLoginMessage = false
    GSEOptions.DebugPrintModConditionsOnKeyPress = false
    GSEOptions.showGSEUsers = false
    GSEOptions.showGSEoocqueue = true
    GSEOptions.UseVerboseExportFormat = false
    GSEOptions.DefaultImportAction = "MERGE"
    GSEOptions.DefaultHumanReadableExportFormat = true
    GSEOptions.PromptSample = true
    GSEOptions.msClickRate = 250
    GSEOptions.showMiniMap = {
        hide = true
    }
    GSEOptions.showCurrentSpells = true
    GSEOptions.OOCQueueDelay = 7
    GSE.resetMacroResetModifiers()
    GSEOptions.frameLocations = {
        sequenceeditor = {height = 500, width = 700, treeWidth = 150}
    }
    GSEOptions.Multiclick = true
    GSEOptions.SyncWoWMacros = false
end

if GSE.isEmpty(GSEOptions) then
    GSEOptions = {}
end

if not GSEOptions.DebugModules then
    GSE.SetDefaultOptions()
end

-- Migrate editor dimensions from old flat keys to frameLocations.sequenceeditor.
do
    if GSE.isEmpty(GSEOptions.frameLocations) then
        GSEOptions.frameLocations = {}
    end
    if GSE.isEmpty(GSEOptions.frameLocations.sequenceeditor) then
        GSEOptions.frameLocations.sequenceeditor = {}
    end
    local se = GSEOptions.frameLocations.sequenceeditor
    if GSEOptions.editorHeight and GSE.isEmpty(se.height) then
        se.height = GSEOptions.editorHeight
        GSEOptions.editorHeight = nil
    end
    if GSEOptions.editorWidth and GSE.isEmpty(se.width) then
        se.width = GSEOptions.editorWidth
        GSEOptions.editorWidth = nil
    end
    if GSEOptions.editorTreeWidth and GSE.isEmpty(se.treeWidth) then
        se.treeWidth = GSEOptions.editorTreeWidth
        GSEOptions.editorTreeWidth = nil
    end
    -- Ensure defaults are always stored explicitly so the sliders always
    -- reflect a real saved value rather than a scattered fallback.
    if GSE.isEmpty(se.height)    then se.height    = 500 end
    if GSE.isEmpty(se.width)     then se.width     = 700 end
    if GSE.isEmpty(se.treeWidth) then se.treeWidth = 150 end
end

GSE.OOCQueue = {}
GSE.UnsavedOptions = {}
GSE.UnsavedOptions["DebugSequenceExecution"] = false
GSE.TranslatorLanguageTables = {}
GSE.AdditionalLanguagesAvailable = false

local Translator = GSE.TranslatorLanguageTables

Translator[Statics.TranslationKey] = {}
Translator[Statics.TranslationHash] = {}
Translator[Statics.TranslationShadow] = {}

GSE.PrintAvailable = false
GSE.StandardAddInPacks = {}
GSE.UsedSequences = {}
GSE.SequencesExec = {}
GSE.UnsavedOptions["PartyUsers"] = {}
GSE.UnsavedOptions["GUI"] = false

GSE.DebugProfile("InitialOptions")
