-- Copyright © 2024 @Groick (Twitch). All rights reserved.
local function L(key, ...) return EasyOptions:Localize(key, ...) end
function EasyOptions:GetOptionItems_Core(parentOptionItems)
  local optionItems = EasyOptions:GetOptionItems_Core_GetItems()
  optionItems.Name = "EasyOptions" -- L("Core")
  optionItems.Parent = parentOptionItems
  optionItems.Children = nil
  return optionItems
end
function EasyOptions:GetOptionItems_Core_GetItems()
  local dropDownWidth = 150 -- math.max(150, EasyOptions:GetDefaultDropDownWidth())
  local buttonWidth = dropDownWidth
  
  local onOptionValueChangedHandler_ActiveAddon = function()
    -- Update controls.
    EasyOptions:UpdateActiveSaveNameDropDown()
    EasyOptions:UpdateAddonManagerSlashCommandTextBox()
    EasyOptions:UpdateAddonManagerControlStates()
  end
  local onOptionValueChangedHandler_ActiveSaveName = function()
    -- Update controls.
    EasyOptions:UpdateAddonManagerSlashCommandTextBox()
    EasyOptions:UpdateAddonManagerControlStates()
  end
  local onOptionValueChangedHandler_AddonSettingsSlashCommand = function()
    -- Update controls.
    EasyOptions:UpdateAddonManagerControlStates()
  end
  local onTextChangedHandler_AddonSettingsSlashCommand = function()
    -- Update controls.
    EasyOptions:UpdateAddonManagerControlStates()
  end
  --
  local onClickHandler_Save = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    local saveName = EasyOptionsDB["ActiveSaveName"]
    EasyOptions:SaveAddonSettings(addonName, saveName, EasyOptionsDB["PromptBeforeOverwritingExistingSave_EnablePromptIfInitiatedByButton"], EasyOptionsDB["PrintMessageAfterSave_EnableMessageIfInitiatedByButton"])
  end
  local onClickHandler_SaveAs = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    local saveName = EasyOptionsDB["ActiveSaveName"]
    if (saveName == nil) or (saveName == "") then
      saveName = L("SaveName") -- EasyOptions:GetNextAvailableBackupSaveName(addonName)
    end
    --
    local text = "Save As..."
    local uniqueID = "EasyOptions.AddonManager.SaveAs"
    local defaultEditBoxText = saveName
    local onAcceptHandler = function(userText) 
      saveName = userText
      EasyOptions:SaveAddonSettings(addonName, saveName, EasyOptionsDB["PromptBeforeOverwritingExistingSave_EnablePromptIfInitiatedByButton"], EasyOptionsDB["PrintMessageAfterSave_EnableMessageIfInitiatedByButton"])
    end
    local onCancelHandler = nil
    EasyOptions:ShowDialogEditOkCancel(text, uniqueID, defaultEditBoxText, onAcceptHandler, onCancelHandler)
  end
  local onClickHandler_QuickBackup = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    EasyOptions:SaveBackupOfAddonSettings(addonName, EasyOptionsDB["PrintMessageAfterSave_EnableMessageIfInitiatedByButton"])
  end
  local onClickHandler_Load = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    local saveName = EasyOptionsDB["ActiveSaveName"]
    EasyOptions:LoadAddonSettings(EasyOptionsDB["ActiveAddon"], EasyOptionsDB["ActiveSaveName"], EasyOptionsDB["PromptBeforeLoad_EnablePromptIfInitiatedByClickButton"], EasyOptionsDB["PrintMessageAfterLoad_EnableMessageIfInitiatedByButton"])
  end
  local onClickHandler_Delete = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    local saveName = EasyOptionsDB["ActiveSaveName"]
    EasyOptions:DeleteAddonSettings(addonName, saveName, EasyOptionsDB["PromptBeforeDelete_EnablePromptIfInitiatedByClickButton"], EasyOptionsDB["PrintMessageAfterDelete_EnableMessageIfInitiatedByButton"])
  end
  local onClickHandler_DeleteAll = function()
    local addonName = EasyOptionsDB["ActiveAddon"]
    EasyOptions:DeleteAllAddonSettings(addonName)
  end
  local onClickHandler_ResetSlashCommand = function()
    local optionItem = EasyOptions:GetOptionItem("EasyOptions", "AddonSettingsSlashCommand")
    EasyOptionsDB["AddonSettingsSlashCommand"] = optionItem.DefaultValue
    EasyOptions:UpdateControlFromOptionValue("EasyOptions", "AddonSettingsSlashCommand")
  end
  
  return { -- [1] Name, [2] Text, [3] TooltipText, [4] PositionInfo, [5] Type, [6+] [Type Specific]
    {nil, L("Addon Manager"), nil, 0, "GroupTitle", nil, nil, EasyOptions.Fields.DefaultTitleFontSize + 1, nil, false}, 
    {nil, L("The Addon Manager allows you to save or load options for any addon that is managed by EasyOptions."), nil, 0, "Label", EasyOptions:GetOptionPanelWidthExcludingMargins(), nil, nil, EasyOptions.Fields.DefaultGeneralMessageColor}, 
    {nil, L("You can also use the generated slash command in a macro to quickly load settings for different characters or types of content (e.g., PvP, raiding, M+, tanking, gathering, etc.)."), nil, 0, "Label", EasyOptions:GetOptionPanelWidthExcludingMargins(), nil, nil, EasyOptions.Fields.DefaultGeneralMessageColor}, 
    {0.5}, 
    {nil, nil, nil, 0, "StartRow"}, 
    {"ActiveAddon", L("Addon"), L("Select an addon to manage."), 0, "DropDown", nil, nil, dropDownWidth, OnOptionValueChangedHandler = onOptionValueChangedHandler_ActiveAddon}, 
    {"ActiveSaveName", L("Save Name"), L("Contains a list of saved settings for the selected addon."), 0, "DropDown", nil, nil, dropDownWidth, OnOptionValueChangedHandler = onOptionValueChangedHandler_ActiveSaveName}, 
    {"AddonSettingsSlashCommand", L("Slash Command"), L("Specifies a slash command that can be used to load addon settings.\n\nYou can copy this slash command to a macro and then use the macro to quickly load the corresponding settings."), 0, "TextBox", nil, "Fill", OnOptionValueChangedHandler = onOptionValueChangedHandler_AddonSettingsSlashCommand, OnTextChangedHandler = onTextChangedHandler_AddonSettingsSlashCommand}, 
    {nil, nil, nil, 0, "EndRow"}, 
    {nil, nil, nil, 0, "StartRow"}, 
    {"AddonManager_Save", L("Save"), L("Save the current settings for the selected addon to the selected save name.\n\nThis will overwrite the currently saved data for the selected save name and cannot be undone."), 0, "Button", buttonWidth, onClickHandler_Save}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {"AddonManager_SaveAs", L("Save As..."), L("Save the current settings for the selected addon to a specified save name."), 0, "Button", buttonWidth, onClickHandler_SaveAs}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {"AddonManager_QuickBackup", L("Quick Backup"), L("Save the current settings for the selected addon to an automatically generated save name."), 0, "Button", buttonWidth, onClickHandler_QuickBackup}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {"AddonManager_ResetSlashCommand", L("Reset Slash Command"), L("Resets the slash command text so it corresponds to the selected addon and save name."), 0, "Button", "Fill", onClickHandler_ResetSlashCommand}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {nil, nil, nil, 0, "EndRow"}, 
    {nil, nil, nil, 0, "StartRow"}, 
    {"AddonManager_Load", L("Load"), L("Load the selected addon settings.\n\nThis will overwrite the current settings for the selected addon and cannot be undone."), 0, "Button", buttonWidth, onClickHandler_Load}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {"AddonManager_Delete", L("Delete"), L("Delete the selected addon settings.\n\nThis operation cannot be undone."), 0, "Button", buttonWidth, onClickHandler_Delete}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {"AddonManager_DeleteAll", L("Delete All"), L("Delete all saved settings for the selected addon.\n\nThis operation cannot be undone."), 0, "Button", buttonWidth, onClickHandler_DeleteAll}, -- We must specify a Name for this OptionItem so we can get the control that is associated with the OptionItem in order to update the control's Enabled state.
    {nil, nil, nil, 0, "EndRow"}, 
    {}, 
    {nil, L("Notifications"), nil, 0, "StartGroupBox", "Fill"}, 
      {nil, L("Save"), nil, 0, "GroupTitle"}, 
      {"PromptBeforeOverwritingExistingSave", L("Prompt Before Overwriting Existing Save"), L("Indicates whether to show a confirmation dialog before saving addon settings if the save will overwrite existing data."), 0, "CheckBox", true}, 
        {"PromptBeforeOverwritingExistingSave_EnablePromptIfInitiatedByButton", L("Enable Prompt If Initiated By Click Button"), L("Indicates whether the confirmation dialog is allowed if the save was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PromptBeforeOverwritingExistingSave_EnablePromptIfInitiatedBySlashCommand", L("Enable Prompt If Initiated By Slash Command"), L("Indicates whether the confirmation dialog is allowed if the save was initiated from a slash command."), 1, "CheckBox", false}, 
      {"PrintMessageAfterSave", L("Print Message After Save"), L("Indicates whether to print a message after options are saved."), 0, "CheckBox", true}, 
        {"PrintMessageAfterSave_EnableMessageIfInitiatedByButton", L("Enable Message If Initiated By Click Button"), L("Indicates whether the message is allowed if the save was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PrintMessageAfterSave_EnableMessageIfInitiatedBySlashCommand", L("Enable Message If Initiated By Slash Command"), L("Indicates whether the message is allowed if the save was initiated from a slash command."), 1, "CheckBox", true}, 
      {"ShowDialogForErrorMessageDuringSave", L("Show Dialog For Error Message During Save"), L("Indicates whether to show a dialog window if an error occurs while attempting to save addon data."), 0, "CheckBox", true}, 
      {}, 
      {nil, L("Load"), nil, 0, "GroupTitle"}, 
      {"PromptBeforeLoad", L("Prompt Before Load"), L("Indicates whether to show a confirmation dialog before loading addon settings."), 0, "CheckBox", true}, 
        {"PromptBeforeLoad_EnablePromptIfInitiatedByClickButton", L("Enable Prompt If Initiated By Click Button"), L("Indicates whether the confirmation dialog is allowed if the load was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PromptBeforeLoad_EnablePromptIfInitiatedBySlashCommand", L("Enable Prompt If Initiated By Slash Command"), L("Indicates whether the confirmation dialog is allowed if the load was initiated from a slash command."), 1, "CheckBox", false}, 
      {"PrintMessageAfterLoad", L("Print Message After Load"), L("Indicates whether to print a message after options are loaded."), 0, "CheckBox", true}, 
        {"PrintMessageAfterLoad_EnableMessageIfInitiatedByButton", L("Enable Message If Initiated By Click Button"), L("Indicates whether the message is allowed if the load was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PrintMessageAfterLoad_EnableMessageIfInitiatedBySlashCommand", L("Enable Message If Initiated By Slash Command"), L("Indicates whether the message is allowed if the load was initiated from a slash command."), 1, "CheckBox", true}, 
      {"ShowDialogForErrorMessageDuringLoad", L("Show Dialog For Error Message During Load"), L("Indicates whether to show a dialog window if an error occurs while attempting to load addon data."), 0, "CheckBox", true}, 
      {}, 
      {nil, L("Delete"), nil, 0, "GroupTitle"}, 
      {"PromptBeforeDelete", L("Prompt Before Delete"), L("Indicates whether to show a confirmation dialog before deleting addon settings."), 0, "CheckBox", true}, 
        {"PromptBeforeDelete_EnablePromptIfInitiatedByClickButton", L("Enable Prompt If Initiated By Click Button"), L("Indicates whether the confirmation dialog is allowed if the delete was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PromptBeforeDelete_EnablePromptIfInitiatedBySlashCommand", L("Enable Prompt If Initiated By Slash Command"), L("Indicates whether the confirmation dialog is allowed if the delete was initiated from a slash command."), 1, "CheckBox", false}, 
      {"PrintMessageAfterDelete", L("Print Message After Delete"), L("Indicates whether to print a message after options are deleted."), 0, "CheckBox", true}, 
        {"PrintMessageAfterDelete_EnableMessageIfInitiatedByButton", L("Enable Message If Initiated By Click Button"), L("Indicates whether the message is allowed if the delete was initiated by clicking a button."), 1, "CheckBox", true}, 
        {"PrintMessageAfterDelete_EnableMessageIfInitiatedBySlashCommand", L("Enable Message If Initiated By Slash Command"), L("Indicates whether the message is allowed if the delete was initiated from a slash command."), 1, "CheckBox", true}, 
      {"ShowDialogForErrorMessageDuringDelete", L("Show Dialog For Error Message During Delete"), L("Indicates whether to show a dialog window if an error occurs while attempting to delete addon data."), 0, "CheckBox", false}, 
    {nil, nil, nil, 0, "EndGroupBox"}, 
    {}, 
    {nil, L("Save Behavior"), nil, 0, "GroupTitle"}, 
    {"OnlySaveSettingsSetToCustomValues", L("Only Save Settings Set To Custom Values"), L("Indicates whether to exclude settings that are set to the addon's default value when saving an addon's settings.\n\nEnabled Behavior:\n  1. The memory footprint of saved data can be significantly reduced because EasyOptions will only store the values of settings that are not set to their default value.\n  2. Each addon setting that was set to its default value at the time of the save will be set to the addon's current default value for that setting when the saved data are applied to the addon.\n  3. Addon settings that did not exist at the time of the save will be set to the addon's current default value for that setting when the saved data are applied to the addon.\n\nDisabled Behavior:\n  1. All addon settings will be saved which can significantly increase the memory footprint of saved data.\n  2. Addon settings that were set to their default value will be restored to the values at the time of the save even if the addon's author subsequently changes the default values of those settings.\n  3. Addon settings that did not exist at the time of the save will not be changed when saved data are applied to the addon."), 0, "CheckBox", false}, 
  }
end
