-- Copyright © 2024 @Groick (Twitch). All rights reserved.

-- Main Table
local AddonName, AddonTable = ...
EasyOptions = AddonTable -- Acts as the main table of this addon.

-- SavedVariables (as specified in the EasyOptions.toc file)
if (EasyOptionsDB == nil) then EasyOptionsDB = {} end -- Stores the Options of this addon.
if (EasyOptionsAddonSettingsDB == nil) then EasyOptionsAddonSettingsDB = {} end -- [addonName][saveName] = table -- Stores the saved settings of the addons that are managed by EasyOptions.
if (EasyOptionsMinimapIconSettingsDB == nil) then EasyOptionsMinimapIconSettingsDB = {} end -- [addonName][optionName] = table -- Stores minimap icon data for the corresponding OptionItem.

function EasyOptions:UseLegacyOptionsMode()
  local version, build, date, tocversion = GetBuildInfo()
  return (tocversion < 110000)
end

function EasyOptions:InitializeOptions()
  local optionalParameters = { 
    OnOptionValueChangedHandler= function(self, optionName)
      -- Reserved.
    end, 
    OnOptionValuesChangingHandler = function(self)
      -- Reserved.
    end, 
    OnOptionValuesChangedHandler = function(self)
      -- Reserved.
    end, 
    OnOptionPanelFrameShowHandler = function(self, categoryName, frame)
      if (categoryName == "EasyOptions") then
        EasyOptions:UpdateAllAddonManagerControls()
      end
    end, 
    OnOptionPanelFrameHideHandler = function(self, categoryName, frame)
      -- Reserved.
    end, 
    IsValidSaveDataVersionProvider = function(self, addonVersion)
      return true
    end, 
  }
  
  local addonName = "EasyOptions"
  local addonDB = EasyOptionsDB
  local optionItems = EasyOptions:GetOptionItems()
  local hasVersionChanged, previousVersion = EasyOptions:BuildOptions(addonName, addonDB, optionItems, optionalParameters)
end
function EasyOptions:GetOptionItems() -- [1] Name, [2] Text, [3] TooltipText, [4] PositionInfo, [5] Type, [6+] [Type Specific]
  local optionItems = EasyOptions:GetOptionItems_GetParentItem()
  optionItems.Children = EasyOptions:GetOptionItems_GetChildItems(optionItems)
  return optionItems
end
function EasyOptions:GetOptionItems_GetParentItem()
  return EasyOptions:GetOptionItems_Core(nil)
end
function EasyOptions:GetOptionItems_GetChildItems(parentOptionItems)
  return {
    EasyOptions:GetOptionItems_General(parentOptionItems), 
    EasyOptions:GetOptionItems_Messages(parentOptionItems), 
    EasyOptions:GetOptionItems_Tooltips(parentOptionItems), 
    EasyOptions:GetOptionItems_DeveloperTools(parentOptionItems), 
  }
end
