local ADDON_NAME, NS = ...
local L = LibStub("AceLocale-3.0"):GetLocale("MDungeonTeleports")
local AceGUI = LibStub("AceGUI-3.0")
local LSM = LibStub("LibSharedMedia-3.0")
local LibDBIcon = LibStub("LibDBIcon-1.0")
local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
-------------------------------------------------
local addonName = "MDungeonTeleports"
local version = C_AddOns.GetAddOnMetadata(addonName, "Version") or "Unknown"
local IsAddOnLoaded = IsAddOnLoaded or C_AddOns.IsAddOnLoaded
-------------------------------------------------
local MDTHideSettingsButton
-------------------------------------------------
-- Font RegisterEvent
LSM:Register("font", "Expressway", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\expressway.ttf")
LSM:Register("font", "SarasaSC", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_sc.ttf")
LSM:Register("font", "SarasaTC", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_tc.ttf")
LSM:Register("font", "Wanted", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\wanted.ttf")
LSM:Register("font", "Lato", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\lato.ttf")
LSM:Register("font", "Montserrat", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\montserrat.ttf")
LSM:Register("font", "Avalon", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\avalon.ttf")
LSM:Register("font", "Geo Sans Light", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\geosans.ttf")
LSM:Register("font", "JetBrains", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\jetbrains.ttf")
LSM:Register("font", "Accia", "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\accia.ttf")
-------------------------------------------------
-- MARK: Set Defaults
local defaultSettings = {
    Season1Pos = {x = 392, y = -98, anchor = "TOPRIGHT"},
    PortalLibraryPos = {x = 781, y = -98, anchor = "TOPRIGHT"},
    PortalLibraryRaidPos = {x = 909, y = -98, anchor = "TOPRIGHT"},
    KeyTrackerPos = {x = 794, y = -206, anchor = "TOPLEFT"},
    showTooltips = false,
    ShiftDragToggle = false,
    isRespondChecked = true,
    isSeason1PortalsShown = true,
    isPortalLibraryShown = true,
    isPortalLibraryRaidShown = true,
    isKeyFrameShown = true,
    loginMessage = true,
    frameScale = 1,
    KeyTrackerFrameScale = 1,
    borderColor = { r = 0.05, g = 0.05, b = 0.05, a = 0.8 },
    backgroundColor = { r = 0, g = 0, b = 0, a = 0.6 },
    expansionColor = { r = 0, g = 1, b = 0.6 },
    titleColor = { r = 1, g = 1, b = 1 },
    buttonTextColor = { r = 1, g = 1, b = 1 },
    borderThickness = 2,
    customFontName = "Expressway",
    customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\expressway.ttf",
    settingsScale = 1,
    announcePort = false,
    LockIcons = false,
    DarkenText = false,
    rioScore = true,
    realmName = false,
    dragHandle = true,
    selectedPreset = 1,
    buttonBorderColor = { r = 0.05, g = 0.05, b = 0.05, a = 0.8 },
    KeyTrackerWidth = 160,
    lastVersionCheck = nil,
    expansionVisibility = {
        MID = true,
        TWW = true,
        DF = true,
        SL = true,
        BFA = true,
        Legion = true,
        WOD = true,
        MOP = true,
        CATA = true,
        WRATH = true,
    },
    raidExpansionVisibility = {
        TWW = true,
        DF = true,
        SL = true,
    },
    lastLogin = "2026-02-01",
    teleportsTab = true,
    mythicTabButtons = true,
    mythicTabVertical = true,
    worldMapTab = true,
    selectedHearthstoneId = 6948,
    TextSizeButton = 11,
    TextSizeExpansion = 12,
    TextSizeTitle = 12,
    HideSettingsButton = false,
    minimapButton = { hide = false },
    MapSeason1 = true,
    MapMidnight = true,
    ClassTeleports = true,
    RaceTeleports = true,
    randomHearthstone = false,
    ShowDalaranHS = true,
    ShowGarrisonHS = true,
    ShowPlotTeleport = true,
    ShowArcantina = true,
    centerDungeonPortals = false,
    centerRaidPortals = false,
    hideMissingPortals = false,
}

if MDungeonTeleports == nil then MDungeonTeleports = {} end

if MDungeonTeleports.customFont == nil or MDungeonTeleports.customFontName == nil then
    local locale = GetLocale and GetLocale() or "enUS"
    if locale == "zhCN" then
        defaultSettings.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_sc.ttf"
        defaultSettings.customFontName = "SarasaSC"
    elseif locale == "koKR" then
        defaultSettings.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\wanted.ttf"
        defaultSettings.customFontName = "Wanted"
    elseif locale == "zhTW" then
        defaultSettings.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_tc.ttf"
        defaultSettings.customFontName = "SarasaTC"
    else
        defaultSettings.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\expressway.ttf"
        defaultSettings.customFontName = "Expressway"
    end
end

MDungeonTeleports.Season1Pos = MDungeonTeleports.Season1Pos or defaultSettings.Season1Pos
MDungeonTeleports.PortalLibraryPos = MDungeonTeleports.PortalLibraryPos or defaultSettings.PortalLibraryPos
MDungeonTeleports.PortalLibraryRaidPos = MDungeonTeleports.PortalLibraryRaidPos or defaultSettings.PortalLibraryRaidPos
MDungeonTeleports.KeyTrackerPos = MDungeonTeleports.KeyTrackerPos or defaultSettings.KeyTrackerPos
MDungeonTeleports.showTooltips = MDungeonTeleports.showTooltips or defaultSettings.showTooltips
MDungeonTeleports.ShiftDragToggle = MDungeonTeleports.ShiftDragToggle or defaultSettings.ShiftDragToggle
MDungeonTeleports.isRespondChecked = MDungeonTeleports.isRespondChecked or defaultSettings.isRespondChecked
MDungeonTeleports.isSeason1PortalsShown = MDungeonTeleports.isSeason1PortalsShown or defaultSettings.isSeason1PortalsShown
MDungeonTeleports.isPortalLibraryShown = MDungeonTeleports.isPortalLibraryShown or defaultSettings.isPortalLibraryShown
MDungeonTeleports.isPortalLibraryRaidShown = MDungeonTeleports.isPortalLibraryRaidShown or defaultSettings.isPortalLibraryRaidShown
MDungeonTeleports.isKeyFrameShown = MDungeonTeleports.isKeyFrameShown or defaultSettings.isKeyFrameShown
MDungeonTeleports.loginMessage = MDungeonTeleports.loginMessage or defaultSettings.loginMessage
MDungeonTeleports.frameScale = MDungeonTeleports.frameScale or defaultSettings.frameScale
MDungeonTeleports.KeyTrackerFrameScale = MDungeonTeleports.KeyTrackerFrameScale or defaultSettings.KeyTrackerFrameScale
MDungeonTeleports.borderColor = MDungeonTeleports.borderColor or defaultSettings.borderColor
MDungeonTeleports.backgroundColor = MDungeonTeleports.backgroundColor or defaultSettings.backgroundColor
MDungeonTeleports.expansionColor = MDungeonTeleports.expansionColor or defaultSettings.expansionColor
MDungeonTeleports.titleColor = MDungeonTeleports.titleColor or defaultSettings.titleColor
MDungeonTeleports.buttonTextColor = MDungeonTeleports.buttonTextColor or defaultSettings.buttonTextColor
MDungeonTeleports.borderThickness = MDungeonTeleports.borderThickness or defaultSettings.borderThickness
MDungeonTeleports.customFontName = MDungeonTeleports.customFontName or defaultSettings.customFontName
MDungeonTeleports.customFont = MDungeonTeleports.customFont or defaultSettings.customFont
MDungeonTeleports.settingsScale = MDungeonTeleports.settingsScale or defaultSettings.settingsScale
MDungeonTeleports.announcePort = MDungeonTeleports.announcePort or defaultSettings.announcePort
MDungeonTeleports.LockIcons = MDungeonTeleports.LockIcons or defaultSettings.LockIcons
MDungeonTeleports.DarkenText = MDungeonTeleports.DarkenText or defaultSettings.DarkenText
MDungeonTeleports.rioScore = MDungeonTeleports.rioScore or defaultSettings.rioScore
MDungeonTeleports.realmName = MDungeonTeleports.realmName or defaultSettings.realmName
MDungeonTeleports.dragHandle = MDungeonTeleports.dragHandle or defaultSettings.dragHandle
MDungeonTeleports.selectedPreset = MDungeonTeleports.selectedPreset or defaultSettings.selectedPreset
MDungeonTeleports.buttonBorderColor = MDungeonTeleports.buttonBorderColor or defaultSettings.buttonBorderColor
MDungeonTeleports.KeyTrackerWidth = MDungeonTeleports.KeyTrackerWidth or defaultSettings.KeyTrackerWidth
MDungeonTeleports.lastVersionCheck = MDungeonTeleports.lastVersionCheck or defaultSettings.lastVersionCheck
MDungeonTeleports.expansionVisibility = MDungeonTeleports.expansionVisibility or defaultSettings.expansionVisibility
MDungeonTeleports.raidExpansionVisibility = MDungeonTeleports.raidExpansionVisibility or defaultSettings.raidExpansionVisibility
MDungeonTeleports.lastLogin = MDungeonTeleports.lastLogin or defaultSettings.lastLogin
MDungeonTeleports.teleportsTab = MDungeonTeleports.teleportsTab or defaultSettings.teleportsTab
MDungeonTeleports.mythicTabButtons = MDungeonTeleports.mythicTabButtons or defaultSettings.mythicTabButtons
MDungeonTeleports.mythicTabVertical = MDungeonTeleports.mythicTabVertical or defaultSettings.mythicTabVertical
MDungeonTeleports.worldMapTab = MDungeonTeleports.worldMapTab or defaultSettings.worldMapTab
MDungeonTeleports.selectedHearthstoneId = MDungeonTeleports.selectedHearthstoneId or defaultSettings.selectedHearthstoneId
MDungeonTeleports.TextSizeButton = MDungeonTeleports.TextSizeButton or defaultSettings.TextSizeButton
MDungeonTeleports.TextSizeExpansion = MDungeonTeleports.TextSizeExpansion or defaultSettings.TextSizeExpansion
MDungeonTeleports.TextSizeTitle = MDungeonTeleports.TextSizeTitle or defaultSettings.TextSizeTitle
MDungeonTeleports.HideSettingsButton = MDungeonTeleports.HideSettingsButton or defaultSettings.HideSettingsButton
MDungeonTeleports.minimapButton = MDungeonTeleports.minimapButton or defaultSettings.minimapButton
MDungeonTeleports.MapSeason1 = MDungeonTeleports.MapSeason1 or defaultSettings.MapSeason1
MDungeonTeleports.MapMidnight = MDungeonTeleports.MapMidnight or defaultSettings.MapMidnight
MDungeonTeleports.ClassTeleports = MDungeonTeleports.ClassTeleports or defaultSettings.ClassTeleports
MDungeonTeleports.RaceTeleports = MDungeonTeleports.RaceTeleports or defaultSettings.RaceTeleports
MDungeonTeleports.randomHearthstone = MDungeonTeleports.randomHearthstone or defaultSettings.randomHearthstone
MDungeonTeleports.ShowDalaranHS = MDungeonTeleports.ShowDalaranHS or defaultSettings.ShowDalaranHS
MDungeonTeleports.ShowGarrisonHS = MDungeonTeleports.ShowGarrisonHS or defaultSettings.ShowGarrisonHS
MDungeonTeleports.ShowPlotTeleport = MDungeonTeleports.ShowPlotTeleport or defaultSettings.ShowPlotTeleport
MDungeonTeleports.ShowArcantina = MDungeonTeleports.ShowArcantina or defaultSettings.ShowArcantina
MDungeonTeleports.centerDungeonPortals = MDungeonTeleports.centerDungeonPortals or defaultSettings.centerDungeonPortals
MDungeonTeleports.centerRaidPortals = MDungeonTeleports.centerRaidPortals or defaultSettings.centerRaidPortals
MDungeonTeleports.hideMissingPortals = MDungeonTeleports.hideMissingPortals or defaultSettings.hideMissingPortals
-------------------------------------------------
-- MARK: Settings Frame
local Settings = CreateFrame("Frame", "MDTSettingsFrame", UIParent)
Settings:SetSize(670, 400)
Settings:SetPoint("CENTER")
Settings:SetMovable(true)
Settings:EnableMouse(true)
Settings:RegisterForDrag("LeftButton")
Settings:SetScript("OnDragStart", Settings.StartMoving)
Settings:SetScript("OnDragStop", Settings.StopMovingOrSizing)
Settings:Hide()
Settings:SetFrameStrata("DIALOG")
Settings:EnableKeyboard(true)
Settings:SetClampedToScreen(true)
Settings:SetScript(
    "OnKeyDown",
    function(self, key)
        if key == "ESCAPE" then
            self:Hide()
        else
            if not InCombatLockdown() then
                self:SetPropagateKeyboardInput(true)
            end
        end
    end
)
-------------------------------------------------
-- Settings Background
local SettingsBackdrop = Settings:CreateTexture(nil, "BACKGROUND")
SettingsBackdrop:SetAllPoints(Settings)
SettingsBackdrop:SetColorTexture(0, 0, 0, 0.75)

local borderColor = {0, 0, 0, 0.6}
local borderThickness = 3

local borderTop = Settings:CreateTexture(nil, "OVERLAY")
borderTop:SetColorTexture(unpack(borderColor))
borderTop:SetPoint("TOPLEFT", Settings, "TOPLEFT", 0, 0)
borderTop:SetPoint("TOPRIGHT", Settings, "TOPRIGHT", 0, 0)
borderTop:SetHeight(borderThickness)

local borderBottom = Settings:CreateTexture(nil, "OVERLAY")
borderBottom:SetColorTexture(unpack(borderColor))
borderBottom:SetPoint("BOTTOMLEFT", Settings, "BOTTOMLEFT", 0, 0)
borderBottom:SetPoint("BOTTOMRIGHT", Settings, "BOTTOMRIGHT", 0, 0)
borderBottom:SetHeight(borderThickness)

local borderLeft = Settings:CreateTexture(nil, "OVERLAY")
borderLeft:SetColorTexture(unpack(borderColor))
borderLeft:SetPoint("TOPLEFT", Settings, "TOPLEFT", 0, 0)
borderLeft:SetPoint("BOTTOMLEFT", Settings, "BOTTOMLEFT", 0, 0)
borderLeft:SetWidth(borderThickness)

local borderRight = Settings:CreateTexture(nil, "OVERLAY")
borderRight:SetColorTexture(unpack(borderColor))
borderRight:SetPoint("TOPRIGHT", Settings, "TOPRIGHT", 0, 0)
borderRight:SetPoint("BOTTOMRIGHT", Settings, "BOTTOMRIGHT", 0, 0)
borderRight:SetWidth(borderThickness)
-------------------------------------------------
-- MARK: Visibility Toggles
local function Season1Vis(show)
    if MDTSeason1_UpdateVisibility then MDTSeason1_UpdateVisibility(show) end
end
local function DungeonVis(show)
    if MDTPortalLibrary_UpdateVisibility then MDTPortalLibrary_UpdateVisibility(show) end
end
local function RaidVis(show)
    if MDTPortalLibraryRaid_UpdateVisibility then MDTPortalLibraryRaid_UpdateVisibility(show) end
end
local function KeyTVis(show)
    if MDTKeyFrame_UpdateVisibility then MDTKeyFrame_UpdateVisibility(show) end
end
-------------------------------------------------
-- MARK: Frames Scale Update
function UpdateFrameScale(scale)
    scale = scale or 1
    if Season1 then Season1:SetScale(scale) end
    if PortalLibrary then PortalLibrary:SetScale(scale) end
    if PortalLibraryRaid then PortalLibraryRaid:SetScale(scale) end
    MDungeonTeleports.frameScale = scale
end
-------------------------------------------------
-- MARK: Key Tracker Frame Scale
function UpdateKeyTrackerFrameScale(keyscalescale)
    keyscalescale = keyscalescale or 1
    if KeyTrackerFrame then KeyTrackerFrame:SetScale(keyscalescale) end
    MDungeonTeleports.KeyTrackerFrameScale = keyscalescale
end
-------------------------------------------------
-- MARK: Settings Frame Scale
local function UpdateSettingsFrameScale(scalesettings)
    scalesettings = scalesettings or 1
    if Settings then Settings:SetScale(scalesettings) end
    MDungeonTeleports.settingsScale = scalesettings
end

-- Variables
local defaultFont = GameFontNormal:GetFont()
local ContainerWidths = 200
local WidgetWidths = 200
local TitleFontSize = 12
-------------------------------------------------
-- MARK: Titles Frame
local TitleFrame = CreateFrame("Frame", nil, Settings)
TitleFrame:SetAllPoints(Settings)
TitleFrame:SetFrameStrata(Settings:GetFrameStrata())
TitleFrame:SetFrameLevel(Settings:GetFrameLevel() + 5)
-------------------------------------------------
-- MARK: Main Title
local SettingsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
SettingsTitle:SetPoint("TOP", Settings, "TOP", 0, -7)
SettingsTitle:SetFont(defaultFont, 13, "OUTLINE")
SettingsTitle:SetText(L["SETTINGS"])
-------------------------------------------------
-- MARK: Seasons
local SeasonsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
SeasonsTitle:SetPoint("TOP", Settings, "TOP", -210, -70)
SeasonsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
SeasonsTitle:SetTextColor(124/255, 79/255 ,214/255)
SeasonsTitle:SetText(L["SEASONS"])
-------------------------------------------------
-- MARK: Libraries
local LibrariesTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
LibrariesTitle:SetPoint("TOP", Settings, "TOP", -210, -110)
LibrariesTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
LibrariesTitle:SetTextColor(124/255, 79/255 ,214/255)
LibrariesTitle:SetText(L["LIBRARIES"])
-------------------------------------------------
-- MARK: Key Tracker Module
local KeyTrackerModuleTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
KeyTrackerModuleTitle:SetPoint("TOP", Settings, "TOP", -210, -180)
KeyTrackerModuleTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
KeyTrackerModuleTitle:SetTextColor(124/255, 79/255 ,214/255)
KeyTrackerModuleTitle:SetText(L["KEYTRACKER"])
-------------------------------------------------
-- MARK: Expansions Dropdown
local ExpansionsDropTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
ExpansionsDropTitle:SetPoint("TOP", Settings, "TOP", 0, -70)
ExpansionsDropTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
ExpansionsDropTitle:SetTextColor(124/255, 79/255 ,214/255)
ExpansionsDropTitle:SetText(L["EXPANSIONS_DROP"])
-------------------------------------------------
-- MARK: Features // renamed to modules
local FeaturesTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
FeaturesTitle:SetPoint("TOP", Settings, "TOP", 0, -240) --170
FeaturesTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
FeaturesTitle:SetTextColor(124/255, 79/255 ,214/255)
FeaturesTitle:SetText(L["MORE_FEATURES"])
-------------------------------------------------
-- MARK: Utilities
local UtilitiesTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
UtilitiesTitle:SetPoint("TOP", Settings, "TOP", 210, -70)
UtilitiesTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
UtilitiesTitle:SetTextColor(124/255, 79/255 ,214/255)
UtilitiesTitle:SetText(L["UTILITIES"])
-------------------------------------------------
-- MARK: Misc Options
local MiscTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
MiscTitle:SetPoint("TOP", Settings, "TOP", 210, -140)
MiscTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
MiscTitle:SetTextColor(124/255, 79/255 ,214/255)
MiscTitle:SetText(L["MISC_OPTIONS"])
-------------------------------------------------
-- MARK: Appearance Dropdown for Presets
local AppearanceTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
AppearanceTitle:SetPoint("TOP", Settings, "TOP", -210, -70)
AppearanceTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
AppearanceTitle:SetTextColor(124/255, 79/255 ,214/255)
AppearanceTitle:SetText(L["APPEARANCE"])
-------------------------------------------------
-- MARK: Font Options
local CustomFontsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
CustomFontsTitle:SetPoint("TOP", Settings, "TOP", 0, -70)
CustomFontsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
CustomFontsTitle:SetTextColor(124/255, 79/255 ,214/255)
CustomFontsTitle:SetText(L["FONT_OPTIONS"])
-------------------------------------------------
-- MARK: Window Options
local CustomWindowsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
CustomWindowsTitle:SetPoint("TOP", Settings, "TOP", 210, -70)
CustomWindowsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
CustomWindowsTitle:SetTextColor(124/255, 79/255 ,214/255)
CustomWindowsTitle:SetText(L["WINDOW_OPTIONS"])
-------------------------------------------------
-- MARK: Other Customs
local CustomFeedbackTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
CustomFeedbackTitle:SetPoint("TOP", Settings, "TOP", 210, -245)
CustomFeedbackTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
CustomFeedbackTitle:SetTextColor(124/255, 79/255 ,214/255)
CustomFeedbackTitle:SetText(L["FEEDBACK"])
-------------------------------------------------
-- MARK: World Map Tab
local WorldMapTabTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WorldMapTabTitle:SetPoint("TOP", Settings, "TOP", -210, -70)
WorldMapTabTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WorldMapTabTitle:SetTextColor(124/255, 79/255 ,214/255)
WorldMapTabTitle:SetText(L["WORLD_MAP_TAB"])
-------------------------------------------------
-- MARK: Hearthstone Options
local WMTHearthstoneOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTHearthstoneOptionsTitle:SetPoint("TOP", Settings, "TOP", -210, -110)
WMTHearthstoneOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTHearthstoneOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTHearthstoneOptionsTitle:SetText(L["HEARTHSTONE_OPTIONS"])
-------------------------------------------------
-- MARK: Plot Options
local WMTPlotOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTPlotOptionsTitle:SetPoint("TOP", Settings, "TOP", -210, -240)
WMTPlotOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTPlotOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTPlotOptionsTitle:SetText(L["PLOT_OPTIONS"])
-------------------------------------------------
-- MARK: Arcantina Options
local WMTArcantinaOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTArcantinaOptionsTitle:SetPoint("TOP", Settings, "TOP", -210, -280)
WMTArcantinaOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTArcantinaOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTArcantinaOptionsTitle:SetText(L["ARCANTINA_OPTIONS"])
-------------------------------------------------
-- MARK: Class Race
local WMTClassRaceOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTClassRaceOptionsTitle:SetPoint("TOP", Settings, "TOP", 0, -70)
WMTClassRaceOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTClassRaceOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTClassRaceOptionsTitle:SetText(L["CLASSRACE_OPTIONS"])
-------------------------------------------------
-- MARK: Season Options
local WMTSeasonOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTSeasonOptionsTitle:SetPoint("TOP", Settings, "TOP", 0, -140)
WMTSeasonOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTSeasonOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTSeasonOptionsTitle:SetText(L["SEASON_OPTIONS"])
-------------------------------------------------
-- MARK: Expansion Options
local WMTExpansionOptionsTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
WMTExpansionOptionsTitle:SetPoint("TOP", Settings, "TOP", 0, -180)
WMTExpansionOptionsTitle:SetFont(defaultFont, TitleFontSize, "OUTLINE")
WMTExpansionOptionsTitle:SetTextColor(124/255, 79/255 ,214/255)
WMTExpansionOptionsTitle:SetText(L["WMT_EXPANSION_OPTIONS"])
-------------------------------------------------
-- MARK: Info Tab Title
local InfoTitle = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
InfoTitle:SetPoint("TOP", Settings, "TOP", 0, -70)
InfoTitle:SetFont(defaultFont, 14, "OUTLINE")
InfoTitle:SetTextColor(124/255, 79/255 ,214/255)
InfoTitle:SetText(L["FEATURE_TITLE"])
-- MARK: Label Info
local InfoLabel = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
InfoLabel:SetPoint("TOP", Settings, "TOP", 0, -300)
InfoLabel:SetFont(defaultFont, 12, "OUTLINE")
InfoLabel:SetTextColor(1, 1, 1)
InfoLabel:SetText(L["INFO_LABEL"])
-------------------------------------------------
-- MARK: Center Image for Info Tab
local InfoTabImage = TitleFrame:CreateTexture(nil, "ARTWORK")
InfoTabImage:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\info.blp")
InfoTabImage:SetSize(1024, 512)
InfoTabImage:SetPoint("TOP", InfoTitle, "TOP", 0, -5)
InfoTabImage:SetScale(0.5)
InfoTabImage:SetAlpha(0.5)
-------------------------------------------------
-- MARK: Addon Info Footer
local AddonInfo = TitleFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
AddonInfo:SetPoint("BOTTOM", Settings, "BOTTOM", 0, 13)
AddonInfo:SetFont(defaultFont, 9, "OUTLINE")
AddonInfo:SetText("|cff7c4fd6M+ Dungeon Teleports|r by peepoStudy // " .. version .. "")
-------------------------------------------------
-- MARK: Containers
-- Container Windows
local ContainerSeasons = AceGUI:Create("SimpleGroup")
ContainerSeasons:SetWidth(200)
ContainerSeasons:SetHeight(100)
ContainerSeasons.frame:SetParent(Settings)
ContainerSeasons.frame:SetPoint("TOP", SeasonsTitle, "TOP", 0, -15)
ContainerSeasons.frame:Show()
-------------------------------------------------
-- MARK: Libraries
local ContainerLibraries = AceGUI:Create("SimpleGroup")
ContainerLibraries:SetWidth(200)
ContainerLibraries:SetHeight(100)
ContainerLibraries.frame:SetParent(Settings)
ContainerLibraries.frame:SetPoint("TOP", LibrariesTitle, "TOP", 0, -15)
ContainerLibraries.frame:Show()
-------------------------------------------------
-- MARK: Key Tracker
local ContainerKeyTrackerModule = AceGUI:Create("SimpleGroup")
ContainerKeyTrackerModule:SetWidth(ContainerWidths)
ContainerKeyTrackerModule:SetHeight(200)
ContainerKeyTrackerModule.frame:SetParent(Settings)
ContainerKeyTrackerModule.frame:SetPoint("TOP", KeyTrackerModuleTitle, "TOP", 0, -15)
ContainerKeyTrackerModule.frame:Show()
-------------------------------------------------
-- MARK: Customizations/Dropdown for Preset
local ContainerPresetCustomizations = AceGUI:Create("SimpleGroup")
ContainerPresetCustomizations:SetWidth(ContainerWidths)
ContainerPresetCustomizations:SetHeight(50)
ContainerPresetCustomizations.frame:SetParent(Settings)
ContainerPresetCustomizations.frame:SetPoint("TOP", AppearanceTitle, "TOP", 0, -15)
ContainerPresetCustomizations.frame:Show()
-------------------------------------------------
-- MARK: Font Options
local ContainerFontOptions = AceGUI:Create("SimpleGroup")
ContainerFontOptions:SetWidth(ContainerWidths)
ContainerFontOptions:SetHeight(50)
ContainerFontOptions.frame:SetParent(Settings)
ContainerFontOptions.frame:SetPoint("TOP", CustomFontsTitle, "TOP", 0, -15)
ContainerFontOptions.frame:Show()
-------------------------------------------------
-- MARK: Window Options
local ContainerWindowOptions = AceGUI:Create("SimpleGroup")
ContainerWindowOptions:SetWidth(ContainerWidths)
ContainerWindowOptions:SetHeight(50)
ContainerWindowOptions.frame:SetParent(Settings)
ContainerWindowOptions.frame:SetPoint("TOP", CustomWindowsTitle, "TOP", 0, -15)
ContainerWindowOptions.frame:Show()
-------------------------------------------------
-- MARK: Customs other.
local ContainerFeedbackOptions = AceGUI:Create("SimpleGroup")
ContainerFeedbackOptions:SetWidth(ContainerWidths)
ContainerFeedbackOptions:SetHeight(50)
ContainerFeedbackOptions.frame:SetParent(Settings)
ContainerFeedbackOptions.frame:SetPoint("TOP", CustomFeedbackTitle, "TOP", 0, -15)
ContainerFeedbackOptions.frame:Show()
-------------------------------------------------
-- MARK: Features
local ContainerFeatures = AceGUI:Create("SimpleGroup")
ContainerFeatures:SetWidth(ContainerWidths)
ContainerFeatures:SetHeight(600)
ContainerFeatures.frame:SetParent(Settings)
ContainerFeatures.frame:SetPoint("TOP", FeaturesTitle, "TOP", 0, -15)
ContainerFeatures.frame:Show()
-------------------------------------------------
-- MARK: Expansions Dropdown
local ContainerDungeonExp = AceGUI:Create("SimpleGroup")
ContainerDungeonExp:SetWidth(ContainerWidths)
ContainerDungeonExp:SetHeight(600)
ContainerDungeonExp.frame:SetParent(Settings)
ContainerDungeonExp.frame:SetPoint("TOP", ExpansionsDropTitle, "TOP", 0, -15)
ContainerDungeonExp.frame:Show()
-------------------------------------------------
-- MARK: Utilities
local ContainerUtilities = AceGUI:Create("SimpleGroup")
ContainerUtilities:SetWidth(ContainerWidths)
ContainerUtilities:SetHeight(400)
ContainerUtilities.frame:SetParent(Settings)
ContainerUtilities.frame:SetPoint("TOP", UtilitiesTitle, "TOP", 0, -15)
ContainerUtilities.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab
local ContainerWorldMapTab = AceGUI:Create("SimpleGroup")
ContainerWorldMapTab:SetWidth(ContainerWidths)
ContainerWorldMapTab:SetHeight(400)
ContainerWorldMapTab.frame:SetParent(Settings)
ContainerWorldMapTab.frame:SetPoint("TOP", WorldMapTabTitle, "TOP", 0, -15)
ContainerWorldMapTab.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Hearthstones
local ContainerWorldMapTabHearthstones = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabHearthstones:SetWidth(ContainerWidths)
ContainerWorldMapTabHearthstones:SetHeight(400)
ContainerWorldMapTabHearthstones.frame:SetParent(Settings)
ContainerWorldMapTabHearthstones.frame:SetPoint("TOP", WMTHearthstoneOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabHearthstones.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Plot
local ContainerWorldMapTabPlot = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabPlot:SetWidth(ContainerWidths)
ContainerWorldMapTabPlot:SetHeight(400)
ContainerWorldMapTabPlot.frame:SetParent(Settings)
ContainerWorldMapTabPlot.frame:SetPoint("TOP", WMTPlotOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabPlot.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Arcantina
local ContainerWorldMapTabArcantina = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabArcantina:SetWidth(ContainerWidths)
ContainerWorldMapTabArcantina:SetHeight(400)
ContainerWorldMapTabArcantina.frame:SetParent(Settings)
ContainerWorldMapTabArcantina.frame:SetPoint("TOP", WMTArcantinaOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabArcantina.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Class Race
local ContainerWorldMapTabClassRace = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabClassRace:SetWidth(ContainerWidths)
ContainerWorldMapTabClassRace:SetHeight(400)
ContainerWorldMapTabClassRace.frame:SetParent(Settings)
ContainerWorldMapTabClassRace.frame:SetPoint("TOP", WMTClassRaceOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabClassRace.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Seasons
local ContainerWorldMapTabSeasons = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabSeasons:SetWidth(ContainerWidths)
ContainerWorldMapTabSeasons:SetHeight(400)
ContainerWorldMapTabSeasons.frame:SetParent(Settings)
ContainerWorldMapTabSeasons.frame:SetPoint("TOP", WMTSeasonOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabSeasons.frame:Show()
-------------------------------------------------
-- MARK: World Map Tab Expansions
local ContainerWorldMapTabExpansions = AceGUI:Create("SimpleGroup")
ContainerWorldMapTabExpansions:SetWidth(ContainerWidths)
ContainerWorldMapTabExpansions:SetHeight(400)
ContainerWorldMapTabExpansions.frame:SetParent(Settings)
ContainerWorldMapTabExpansions.frame:SetPoint("TOP", WMTExpansionOptionsTitle, "TOP", 0, -15)
ContainerWorldMapTabExpansions.frame:Show()
-------------------------------------------------
-- MARK: Misc
local ContainerMisc = AceGUI:Create("SimpleGroup")
ContainerMisc:SetWidth(ContainerWidths)
ContainerMisc:SetHeight(400)
ContainerMisc.frame:SetParent(Settings)
ContainerMisc.frame:SetPoint("TOP", MiscTitle, "TOP", 0, -15)
ContainerMisc.frame:Show()
-------------------------------------------------
-- MARK: Discord
local ContainerInfoDiscord = AceGUI:Create("SimpleGroup")
ContainerInfoDiscord:SetWidth(ContainerWidths)
ContainerInfoDiscord:SetHeight(400)
ContainerInfoDiscord.frame:SetParent(Settings)
ContainerInfoDiscord.frame:SetPoint("TOP", InfoTitle, "TOP", -180, -245)
ContainerInfoDiscord.frame:Show()
-------------------------------------------------
-- MARK: CurseForge
local ContainerInfoCurseForge = AceGUI:Create("SimpleGroup")
ContainerInfoCurseForge:SetWidth(ContainerWidths)
ContainerInfoCurseForge:SetHeight(400)
ContainerInfoCurseForge.frame:SetParent(Settings)
ContainerInfoCurseForge.frame:SetPoint("TOP", InfoTitle, "TOP", 30, -245)
ContainerInfoCurseForge.frame:Show()
-------------------------------------------------
-- MARK: Wago
local ContainerInfoWago = AceGUI:Create("SimpleGroup")
ContainerInfoWago:SetWidth(ContainerWidths)
ContainerInfoWago:SetHeight(400)
ContainerInfoWago.frame:SetParent(Settings)
ContainerInfoWago.frame:SetPoint("TOP", InfoTitle, "TOP", 240, -245)
ContainerInfoWago.frame:Show()
-------------------------------------------------
-- MARK: Settings Slider UI Size
local ContainerSettingsSlider = AceGUI:Create("SimpleGroup")
ContainerSettingsSlider:SetWidth(ContainerWidths)
ContainerSettingsSlider:SetHeight(400)
ContainerSettingsSlider.frame:SetParent(Settings)
ContainerSettingsSlider.frame:SetPoint("TOP", SettingsTitle, "TOP", 340, 14)
ContainerSettingsSlider.frame:Show()
-------------------------------------------------
-- MARK: Season 1
local Season1CheckBox = AceGUI:Create("CheckBox")
Season1CheckBox:SetLabel(L["SHOW_CURRENT_SEASON"])
Season1CheckBox:SetWidth(WidgetWidths) 
Season1CheckBox:SetValue(MDungeonTeleports.isSeason1PortalsShown)
Season1CheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.isSeason1PortalsShown = val
    Season1Vis(val)
end)
ContainerSeasons:AddChild(Season1CheckBox)
-------------------------------------------------
-- MARK: Dungeon Library
local PortalLibraryCheckBox = AceGUI:Create("CheckBox")
PortalLibraryCheckBox:SetLabel(L["SHOW_DUNGEON_LIBRARY"])
PortalLibraryCheckBox:SetWidth(WidgetWidths) 
PortalLibraryCheckBox:SetValue(MDungeonTeleports.isPortalLibraryShown)
PortalLibraryCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.isPortalLibraryShown = val
    DungeonVis(val)
end)
ContainerLibraries:AddChild(PortalLibraryCheckBox)
-------------------------------------------------
-- MARK: Raid Library
local PortalLibraryRaidCheckBox = AceGUI:Create("CheckBox")
PortalLibraryRaidCheckBox:SetLabel(L["SHOW_RAID_LIBRARY"])
PortalLibraryRaidCheckBox:SetWidth(WidgetWidths)
PortalLibraryRaidCheckBox:SetValue(MDungeonTeleports.isPortalLibraryRaidShown)
PortalLibraryRaidCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.isPortalLibraryRaidShown = val
    RaidVis(val)
end)
ContainerLibraries:AddChild(PortalLibraryRaidCheckBox)
-------------------------------------------------
-- MARK: Key Tracker
local ToggleKeyFrameCheckBox = AceGUI:Create("CheckBox")
ToggleKeyFrameCheckBox:SetLabel(L["SHOW_KEY_TRACKER"])
ToggleKeyFrameCheckBox:SetWidth(WidgetWidths)
ToggleKeyFrameCheckBox:SetValue(MDungeonTeleports.isKeyFrameShown)
ToggleKeyFrameCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.isKeyFrameShown = val
    KeyTVis(val)
end)
ContainerKeyTrackerModule:AddChild(ToggleKeyFrameCheckBox)
-------------------------------------------------
-- MARK: Rio Score
local RioScoreCheckBox = AceGUI:Create("CheckBox")
RioScoreCheckBox:SetLabel(L["SHOW_RIO_SCORE"])
RioScoreCheckBox:SetWidth(WidgetWidths)
RioScoreCheckBox:SetValue(MDungeonTeleports.rioScore)
RioScoreCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.rioScore = val
    MDTUpdateScoreNameKT()
end)
ContainerKeyTrackerModule:AddChild(RioScoreCheckBox)
-------------------------------------------------
-- MARK: Realm Name
local RealmNameCheckBox = AceGUI:Create("CheckBox")
RealmNameCheckBox:SetLabel(L["SHOW_REALM_NAME"])
RealmNameCheckBox:SetWidth(WidgetWidths)
RealmNameCheckBox:SetValue(MDungeonTeleports.realmName)
RealmNameCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.realmName = val
    MDTUpdateScoreNameKT()
end)
ContainerKeyTrackerModule:AddChild(RealmNameCheckBox)
-------------------------------------------------
-- MARK: Drag Handle
local DragHandleCheckBox = AceGUI:Create("CheckBox")
DragHandleCheckBox:SetLabel(L["SHOW_RESIZE_HANDLE"])
DragHandleCheckBox:SetWidth(WidgetWidths)
DragHandleCheckBox:SetValue(MDungeonTeleports.dragHandle)
DragHandleCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.dragHandle = val
    MDTKTToggleDragHandle()
end)
ContainerKeyTrackerModule:AddChild(DragHandleCheckBox)
-------------------------------------------------
-- MARK: Key TrackerFrame Size Slider
local KeyTrackerUIScaleSlider = AceGUI:Create("Slider")
KeyTrackerUIScaleSlider:SetLabel(L["KEY_SCALE_SLIDER"])
KeyTrackerUIScaleSlider:SetWidth(WidgetWidths)
KeyTrackerUIScaleSlider:SetSliderValues(0.75, 1.25, 0.01)
KeyTrackerUIScaleSlider:SetValue(MDungeonTeleports.KeyTrackerFrameScale or 1)
KeyTrackerUIScaleSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.KeyTrackerFrameScale = val
    UpdateKeyTrackerFrameScale(val)
end)
ContainerKeyTrackerModule:AddChild(KeyTrackerUIScaleSlider)
-------------------------------------------------
-- MARK: Font Dropdown
local fontDropdown = AceGUI:Create("LSM30_Font")
fontDropdown:SetLabel(L["SELECT_FONT"])
fontDropdown:SetWidth(WidgetWidths)
fontDropdown:SetList(LSM:HashTable("font"))
if MDungeonTeleports.customFontName then
    fontDropdown:SetValue(MDungeonTeleports.customFontName)
    MDungeonTeleports.customFont = LSM:Fetch("font", MDungeonTeleports.customFontName)
end
fontDropdown:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.customFontName = val
    local fontPath = LSM:Fetch("font", val)
    if fontPath then
        MDungeonTeleports.customFont = fontPath
    end
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
    if MDTUpdateFontKT then MDTUpdateFontKT() end
    if MDTUpdateMythicVerticalFont then MDTUpdateMythicVerticalFont() end
end)
ContainerFontOptions:AddChild(fontDropdown)
--------------------------------------------------
-- MARK: Font Size Expansion Slider
local FontSizeExpansionSlider = AceGUI:Create("Slider")
FontSizeExpansionSlider:SetLabel(L["EXPANSION_FONT_SIZE"])
FontSizeExpansionSlider:SetWidth(WidgetWidths)
FontSizeExpansionSlider:SetSliderValues(8, 16, 1)
FontSizeExpansionSlider:SetValue(MDungeonTeleports.TextSizeExpansion or 12)
FontSizeExpansionSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.TextSizeExpansion = val
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
    
end)
ContainerFontOptions:AddChild(FontSizeExpansionSlider)
--------------------------------------------------
-- MARK: Font Size Title Slider
local FontSizeTitleSlider = AceGUI:Create("Slider")
FontSizeTitleSlider:SetLabel(L["TITLE_FONT_SIZE"])
FontSizeTitleSlider:SetWidth(WidgetWidths)
FontSizeTitleSlider:SetSliderValues(8, 16, 1)
FontSizeTitleSlider:SetValue(MDungeonTeleports.TextSizeTitle or 12)
FontSizeTitleSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.TextSizeTitle = val
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
end)
ContainerFontOptions:AddChild(FontSizeTitleSlider)
--------------------------------------------------
-- MARK: Font Size Buttons Slider
local FontSizeButtonsSlider = AceGUI:Create("Slider")
FontSizeButtonsSlider:SetLabel(L["BUTTON_FONT_SIZE"])
FontSizeButtonsSlider:SetWidth(WidgetWidths)
FontSizeButtonsSlider:SetSliderValues(7, 15, 1)
FontSizeButtonsSlider:SetValue(MDungeonTeleports.TextSizeButton or 11)
FontSizeButtonsSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.TextSizeButton = val
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
end)
ContainerFontOptions:AddChild(FontSizeButtonsSlider)
-------------------------------------------------
-- MARK: Expansion Title Text Colour Picker
local expansionColorPicker = AceGUI:Create("ColorPicker")
expansionColorPicker:SetLabel(L["EXPANSION_COLOR"])
expansionColorPicker:SetWidth(WidgetWidths)
expansionColorPicker:SetHasAlpha(false)
expansionColorPicker:SetColor(
    MDungeonTeleports.expansionColor.r,
    MDungeonTeleports.expansionColor.g,
    MDungeonTeleports.expansionColor.b
)
expansionColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b)
    MDungeonTeleports.expansionColor = { r = r, g = g, b = b }
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
end)
ContainerFontOptions:AddChild(expansionColorPicker)
-------------------------------------------------
-- MARK: Title Text Colour Picker
local titleColorPicker = AceGUI:Create("ColorPicker")
titleColorPicker:SetLabel(L["TITLE_COLOR"])
titleColorPicker:SetWidth(WidgetWidths)
titleColorPicker:SetHasAlpha(false)
titleColorPicker:SetColor(
    MDungeonTeleports.titleColor.r,
    MDungeonTeleports.titleColor.g,
    MDungeonTeleports.titleColor.b
)
titleColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b)
    MDungeonTeleports.titleColor = { r = r, g = g, b = b }
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
    if MDTUpdateFontKT then MDTUpdateFontKT() end
end)
ContainerFontOptions:AddChild(titleColorPicker)
-------------------------------------------------
-- MARK: Button Text Colour Picker  
local buttonTextColorPicker = AceGUI:Create("ColorPicker")
buttonTextColorPicker:SetLabel(L["PORTAL_COLOR"])
buttonTextColorPicker:SetWidth(WidgetWidths)
buttonTextColorPicker:SetHasAlpha(false)
buttonTextColorPicker:SetColor(
    MDungeonTeleports.buttonTextColor.r,
    MDungeonTeleports.buttonTextColor.g,
    MDungeonTeleports.buttonTextColor.b
)
buttonTextColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b)
    MDungeonTeleports.buttonTextColor = { r = r, g = g, b = b }
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
    if MDTUpdateFontKT then MDTUpdateFontKT() end
end)
ContainerFontOptions:AddChild(buttonTextColorPicker)
-------------------------------------------------
-- MARK: Window Size Slider
local UIScaleSlider = AceGUI:Create("Slider")
UIScaleSlider:SetLabel(L["SCALE_SLIDER"])
UIScaleSlider:SetWidth(WidgetWidths)
UIScaleSlider:SetSliderValues(0.75, 1.45, 0.01)
UIScaleSlider:SetValue(MDungeonTeleports.frameScale or 1)
UIScaleSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.frameScale = val
    UpdateFrameScale(val)
end)
ContainerWindowOptions:AddChild(UIScaleSlider)
--------------------------------------------------
-- MARK: Window Border Thickness Slider
local BorderSlider = AceGUI:Create("Slider")
BorderSlider:SetLabel(L["SCALE_SLIDER_BORDER"])
BorderSlider:SetWidth(WidgetWidths)
BorderSlider:SetSliderValues(0, 5, 1)
BorderSlider:SetValue(1)
BorderSlider:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.borderThickness = val
    if MDTUpdateSeason1Border then MDTUpdateSeason1Border() end
    if MDTUpdatePortalLibraryBorder then MDTUpdatePortalLibraryBorder() end
    if MDTUpdatePortalLibraryRaidBorder then MDTUpdatePortalLibraryRaidBorder() end
    if MDTUpdateKeyTrackerBorder then MDTUpdateKeyTrackerBorder() end
end)
ContainerWindowOptions:AddChild(BorderSlider)
-------------------------------------------------
-- MARK: Button Border Colour
local ButtonBorderColorPicker = AceGUI:Create("ColorPicker")
ButtonBorderColorPicker:SetLabel(L["BUTTON_BORDER_COLOR"])
ButtonBorderColorPicker:SetWidth(WidgetWidths)
ButtonBorderColorPicker:SetHasAlpha(true)
ButtonBorderColorPicker:SetColor(
    MDungeonTeleports.buttonBorderColor.r,
    MDungeonTeleports.buttonBorderColor.g,
    MDungeonTeleports.buttonBorderColor.b,
    MDungeonTeleports.buttonBorderColor.a
)
ButtonBorderColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b, a)
    if r == 0 and g == 0 and b == 0 then
        r, g, b = 0.05, 0.05, 0.05
    end
    MDungeonTeleports.buttonBorderColor = { r = r, g = g, b = b, a = a }
    if MDTUpdateSeason1Colors then MDTUpdateSeason1Colors() end
    if MDTUpdatePortalLibraryColors then MDTUpdatePortalLibraryColors() end
    if MDTUpdatePortalLibraryRaidColors then MDTUpdatePortalLibraryRaidColors() end
    if MDTUpdateKeyTrackerColors then MDTUpdateKeyTrackerColors() end
end)
ContainerWindowOptions:AddChild(ButtonBorderColorPicker)
-------------------------------------------------
-- MARK: Window Border Colour
local borderColorPicker = AceGUI:Create("ColorPicker")
borderColorPicker:SetLabel(L["BORDER_COLOR"])
borderColorPicker:SetWidth(WidgetWidths)
borderColorPicker:SetHasAlpha(true)
borderColorPicker:SetColor(
    MDungeonTeleports.borderColor.r,
    MDungeonTeleports.borderColor.g,
    MDungeonTeleports.borderColor.b,
    MDungeonTeleports.borderColor.a
)
borderColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b, a)
    if r == 0 and g == 0 and b == 0 then
        r, g, b = 0.05, 0.05, 0.05
    end
    MDungeonTeleports.borderColor = { r = r, g = g, b = b, a = a }
    if MDTUpdateSeason1Colors then MDTUpdateSeason1Colors() end
    if MDTUpdatePortalLibraryColors then MDTUpdatePortalLibraryColors() end
    if MDTUpdatePortalLibraryRaidColors then MDTUpdatePortalLibraryRaidColors() end
    if MDTUpdateKeyTrackerColors then MDTUpdateKeyTrackerColors() end
end)
ContainerWindowOptions:AddChild(borderColorPicker)
-------------------------------------------------
-- MARK: Window Background Colour
local backgroundColorPicker = AceGUI:Create("ColorPicker")
backgroundColorPicker:SetLabel(L["BACKGROUND_COLOR"])
backgroundColorPicker:SetWidth(WidgetWidths)
backgroundColorPicker:SetHasAlpha(true)
backgroundColorPicker:SetColor(
    MDungeonTeleports.backgroundColor.r,
    MDungeonTeleports.backgroundColor.g,
    MDungeonTeleports.backgroundColor.b,
    MDungeonTeleports.backgroundColor.a
)
backgroundColorPicker:SetCallback("OnValueChanged", function(_, _, r, g, b, a)
    MDungeonTeleports.backgroundColor = { r = r, g = g, b = b, a = a }
    if MDTUpdateSeason1Colors then MDTUpdateSeason1Colors() end
    if MDTUpdatePortalLibraryColors then MDTUpdatePortalLibraryColors() end
    if MDTUpdatePortalLibraryRaidColors then MDTUpdatePortalLibraryRaidColors() end
    if MDTUpdateKeyTrackerColors then MDTUpdateKeyTrackerColors() end
end)
ContainerWindowOptions:AddChild(backgroundColorPicker)
-------------------------------------------------
-- MARK: Frame Presets Dropdown
local presetDropdown = AceGUI:Create("Dropdown")
presetDropdown:SetLabel(L["SELECT_PRESET"])
presetDropdown:SetWidth(WidgetWidths)

local presetList = {}
for _, preset in ipairs(MDT_ColourPresets) do
    presetList[preset.text] = preset.text
end
presetDropdown:SetList(presetList)
presetDropdown:SetValue(MDT_ColourPresets[1].text)
MDungeonTeleports.selectedPreset = 1
presetDropdown:SetCallback("OnValueChanged", function(_, _, val)
    collectgarbage("collect")
    local selectedPreset
    for i, preset in ipairs(MDT_ColourPresets) do
        if preset.text == val then
            selectedPreset = preset
            MDungeonTeleports.selectedPreset = i
            break
        end
    end
    if selectedPreset then
        local back = selectedPreset.back
        if back then
            MDungeonTeleports.backgroundColor = { r = back.r, g = back.g, b = back.b, a = back.a }
        end
        local border = selectedPreset.border
        if border then
            MDungeonTeleports.borderColor = { r = border.r, g = border.g, b = border.b, a = border.a }
        end
        local title = selectedPreset.title
        if title then
            MDungeonTeleports.titleColor = { r = title.r, g = title.g, b = title.b }
        end
        local expansion = selectedPreset.expansion
        if expansion then
            MDungeonTeleports.expansionColor = { r = expansion.r, g = expansion.g, b = expansion.b }
        end
        local buttonX = selectedPreset.button
        if buttonX then
            MDungeonTeleports.buttonTextColor = { r = buttonX.r, g = buttonX.g, b = buttonX.b }
        end
        local buttonborderx = selectedPreset.buttonborder
        if buttonborderx then
            MDungeonTeleports.buttonBorderColor = { r = buttonborderx.r, g = buttonborderx.g, b = buttonborderx.b, a = buttonborderx.a }
        end

        if MDTUpdateFontS1 then MDTUpdateFontS1() end
        if MDTUpdateFontPL then MDTUpdateFontPL() end
        if MDTUpdateFontPLR then MDTUpdateFontPLR() end
        if MDTUpdateFontKT then MDTUpdateFontKT() end
        
        if MDTUpdateSeason1Border then MDTUpdateSeason1Border() end
        if MDTUpdatePortalLibraryBorder then MDTUpdatePortalLibraryBorder() end
        if MDTUpdatePortalLibraryRaidBorder then MDTUpdatePortalLibraryRaidBorder() end
        if MDTUpdateKeyTrackerBorder then MDTUpdateKeyTrackerBorder() end

        if MDTUpdateSeason1Colors then MDTUpdateSeason1Colors() end
        if MDTUpdatePortalLibraryColors then MDTUpdatePortalLibraryColors() end
        if MDTUpdatePortalLibraryRaidColors then MDTUpdatePortalLibraryRaidColors() end
        if MDTUpdateKeyTrackerColors then MDTUpdateKeyTrackerColors() end

        borderColorPicker:SetColor(MDungeonTeleports.borderColor.r, MDungeonTeleports.borderColor.g, MDungeonTeleports.borderColor.b, MDungeonTeleports.borderColor.a)
        backgroundColorPicker:SetColor(MDungeonTeleports.backgroundColor.r, MDungeonTeleports.backgroundColor.g, MDungeonTeleports.backgroundColor.b, MDungeonTeleports.backgroundColor.a)
        expansionColorPicker:SetColor(MDungeonTeleports.expansionColor.r, MDungeonTeleports.expansionColor.g, MDungeonTeleports.expansionColor.b)
        titleColorPicker:SetColor(MDungeonTeleports.titleColor.r, MDungeonTeleports.titleColor.g, MDungeonTeleports.titleColor.b)
        buttonTextColorPicker:SetColor(MDungeonTeleports.buttonTextColor.r, MDungeonTeleports.buttonTextColor.g, MDungeonTeleports.buttonTextColor.b)   
        ButtonBorderColorPicker:SetColor(MDungeonTeleports.buttonBorderColor.r, MDungeonTeleports.buttonBorderColor.g, MDungeonTeleports.buttonBorderColor.b, MDungeonTeleports.buttonBorderColor.a)
    end
end)
ContainerPresetCustomizations:AddChild(presetDropdown)
-------------------------------------------------
-- MARK: Show Tooltips
local ToggleTooltipsCheckBox = AceGUI:Create("CheckBox")
ToggleTooltipsCheckBox:SetLabel(L["TOOLTIPS"])
ToggleTooltipsCheckBox:SetWidth(WidgetWidths)
ToggleTooltipsCheckBox:SetValue(MDungeonTeleports.showTooltips)
ToggleTooltipsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.showTooltips = val
end)
ContainerFeedbackOptions:AddChild(ToggleTooltipsCheckBox)
-------------------------------------------------
-- MARK: Locked Icons
local LockIconsCheckBox = AceGUI:Create("CheckBox")
LockIconsCheckBox:SetLabel(L["LOCK_ICONS"])
LockIconsCheckBox:SetWidth(WidgetWidths)
LockIconsCheckBox:SetValue(MDungeonTeleports.LockIcons)
LockIconsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.LockIcons = val
    if MDTUpdateS1ButtonTexture then MDTUpdateS1ButtonTexture() end
    if MDTUpdatePLButtonTexture then MDTUpdatePLButtonTexture() end
    if MDTUpdatePLRButtonTexture then MDTUpdatePLRButtonTexture() end
end)
ContainerFeedbackOptions:AddChild(LockIconsCheckBox)
-------------------------------------------------
-- MARK: Greyed out Text
local DarkenCheckBox = AceGUI:Create("CheckBox")
DarkenCheckBox:SetLabel(L["DARKEN_TEXT"])
DarkenCheckBox:SetWidth(WidgetWidths)
DarkenCheckBox:SetValue(MDungeonTeleports.DarkenText)
DarkenCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.DarkenText = val
    if MDTUpdateFontS1 then MDTUpdateFontS1() end
    if MDTUpdateFontPL then MDTUpdateFontPL() end
    if MDTUpdateFontPLR then MDTUpdateFontPLR() end
end)
ContainerFeedbackOptions:AddChild(DarkenCheckBox)
-------------------------------------------------
-- MARK: Shift Drag Frames
local ShiftMoveCheckBox = AceGUI:Create("CheckBox")
ShiftMoveCheckBox:SetLabel(L["LOCK_FRAMES"])
ShiftMoveCheckBox:SetWidth(WidgetWidths)
ShiftMoveCheckBox:SetValue(MDungeonTeleports.ShiftDragToggle)
ShiftMoveCheckBox.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_SHIFT"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_SHIFT_SUB"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ShiftMoveCheckBox.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ShiftMoveCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ShiftDragToggle = val
    if MDTShiftDragToggleS1 then MDTShiftDragToggleS1() end
    if MDTShiftDragToggleDL then MDTShiftDragToggleDL() end
    if MDTShiftDragToggleRL then MDTShiftDragToggleRL() end
    if MDTShiftDragToggleKT then MDTShiftDragToggleKT() end
end)
ContainerFeedbackOptions:AddChild(ShiftMoveCheckBox)
-------------------------------------------------
-- MARK: Dungeon Expansion Visibility Multi-Select Dropdown
local ExpansionMultiSelect = AceGUI:Create("Dropdown")
ExpansionMultiSelect:SetLabel(L["SHOWHIDE_EXPANSIONS_DUNGEON"])
ExpansionMultiSelect:SetWidth(WidgetWidths)
ExpansionMultiSelect:SetMultiselect(true)
ExpansionMultiSelect:SetList({
    MID = L["EXP_MID"],
    TWW = L["EXP_TWW"],
    DF = L["EXP_DF"],
    SL = L["EXP_SL"],
    BFA = L["EXP_BFA"],
    Legion = L["EXP_LEG"],
    WOD = L["EXP_WOD"],
    MOP = L["EXP_MOP"],
    CATA = L["EXP_CATA"],
    WRATH = L["EXP_WRATH"],
}, {"MID", "TWW", "DF", "SL", "BFA", "Legion", "WOD", "MOP", "CATA", "WRATH"})

-- Set initial values
for key, value in pairs(MDungeonTeleports.expansionVisibility) do
    ExpansionMultiSelect:SetItemValue(key, value)
end

ExpansionMultiSelect:SetCallback("OnValueChanged", function(_, _, key, checked)
    if MDTToggleExpansionVisibility then 
        MDTToggleExpansionVisibility(key)
    end
end)
ContainerDungeonExp:AddChild(ExpansionMultiSelect)
-------------------------------------------------
-- MARK: Raid Expansion Visibility Multi-Select Dropdown
local RaidExpansionMultiSelect = AceGUI:Create("Dropdown")
RaidExpansionMultiSelect:SetLabel(L["SHOWHIDE_EXPANSIONS_RAID"])
RaidExpansionMultiSelect:SetWidth(WidgetWidths)
RaidExpansionMultiSelect:SetMultiselect(true)
RaidExpansionMultiSelect:SetList({
    TWW = L["EXP_TWW"],
    DF = L["EXP_DF"],
    SL = L["EXP_SL"],
}, {"TWW", "DF", "SL"})

for key, value in pairs(MDungeonTeleports.raidExpansionVisibility) do
    RaidExpansionMultiSelect:SetItemValue(key, value)
end

RaidExpansionMultiSelect:SetCallback("OnValueChanged", function(_, _, key, checked)
    if MDTToggleRaidExpansionVisibility then
        MDTToggleRaidExpansionVisibility(key)
    end
end)
ContainerDungeonExp:AddChild(RaidExpansionMultiSelect)
-------------------------------------------------
-- MARK: Center Dungeon Portals
local CenterDungeonPortalsCheckBox = AceGUI:Create("CheckBox")
CenterDungeonPortalsCheckBox:SetLabel(L["CENTER_PORTALS_DUNGEON"])
CenterDungeonPortalsCheckBox:SetWidth(WidgetWidths)
CenterDungeonPortalsCheckBox:SetValue(MDungeonTeleports.centerDungeonPortals)
CenterDungeonPortalsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.centerDungeonPortals = val
    if MDTRefreshPortalLibraryLayout then MDTRefreshPortalLibraryLayout() end
end)
ContainerDungeonExp:AddChild(CenterDungeonPortalsCheckBox)
-------------------------------------------------
-- MARK: Center Raid Portals
local CenterRaidPortalsCheckBox = AceGUI:Create("CheckBox")
CenterRaidPortalsCheckBox:SetLabel(L["CENTER_PORTALS_RAID"])
CenterRaidPortalsCheckBox:SetWidth(WidgetWidths)
CenterRaidPortalsCheckBox:SetValue(MDungeonTeleports.centerRaidPortals)
CenterRaidPortalsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.centerRaidPortals = val
    if MDTRefreshPortalLibraryRaidLayout then MDTRefreshPortalLibraryRaidLayout() end
end)
ContainerDungeonExp:AddChild(CenterRaidPortalsCheckBox)
-------------------------------------------------
-- MARK: Hide Missing Portals
local HideMissingPortalsCheckBox = AceGUI:Create("CheckBox")
HideMissingPortalsCheckBox:SetLabel(L["HIDE_MISSING_PORTALS"])
HideMissingPortalsCheckBox:SetWidth(WidgetWidths)
HideMissingPortalsCheckBox:SetValue(MDungeonTeleports.hideMissingPortals)
HideMissingPortalsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.hideMissingPortals = val
    if MDTRefreshPortalLibraryLayout then MDTRefreshPortalLibraryLayout() end
    if MDTRefreshPortalLibraryRaidLayout then MDTRefreshPortalLibraryRaidLayout() end
end)
ContainerDungeonExp:AddChild(HideMissingPortalsCheckBox)
-------------------------------------------------
-- MARK: World Map Tab Toggle
local ToggleWorldMapTab = AceGUI:Create("CheckBox")
ToggleWorldMapTab:SetLabel(L["SHOW_MAP_TAB"])
ToggleWorldMapTab:SetWidth(WidgetWidths)
ToggleWorldMapTab:SetValue(MDungeonTeleports.worldMapTab)
ToggleWorldMapTab:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.worldMapTab = val
    if NS and NS.WorldMapTab and NS.WorldMapTab.UpdateVisibility then
        NS.WorldMapTab:UpdateVisibility(val)
    end
end)
ContainerWorldMapTab:AddChild(ToggleWorldMapTab)
-------------------------------------------------
-- MARK: Show Season 1 Portals on Map
local ToggleMapSeason1 = AceGUI:Create("CheckBox")
ToggleMapSeason1:SetLabel(L["SHOW_CURRENT_SEASON_MAP"])
ToggleMapSeason1:SetWidth(WidgetWidths)
ToggleMapSeason1:SetValue(MDungeonTeleports.MapSeason1)
ToggleMapSeason1.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_WORLD_MAP_TAB_SEASON"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_SEASON_PORTALS"], nil, nil, nil, true)

    GameTooltip:Show()
end)
ToggleMapSeason1.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleMapSeason1:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.MapSeason1 = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabSeasons:AddChild(ToggleMapSeason1)
-------------------------------------------------
-- MARK: Show Midnight Portals on Map
local ToggleMapMidnight = AceGUI:Create("CheckBox")
ToggleMapMidnight:SetLabel(L["SHOW_MID_MAP"])
ToggleMapMidnight:SetWidth(WidgetWidths)
ToggleMapMidnight:SetValue(MDungeonTeleports.MapMidnight)
ToggleMapMidnight.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_MID_MAP"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_MID_MAP"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleMapMidnight.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleMapMidnight:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.MapMidnight = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabExpansions:AddChild(ToggleMapMidnight)
-------------------------------------------------
-- MARK: Show Class Teleports on Map
local ToggleClassTeleports = AceGUI:Create("CheckBox")
ToggleClassTeleports:SetLabel(L["SHOW_CLASS_TELEPORTS"])
ToggleClassTeleports:SetWidth(WidgetWidths)
ToggleClassTeleports:SetValue(MDungeonTeleports.ClassTeleports)
ToggleClassTeleports.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_CLASS_TELEPORTS"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_CLASS_TELEPORTS"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleClassTeleports.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleClassTeleports:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ClassTeleports = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabClassRace:AddChild(ToggleClassTeleports)
-------------------------------------------------
-- MARK: Show Race Teleports on Map
local ToggleRaceTeleports = AceGUI:Create("CheckBox")
ToggleRaceTeleports:SetLabel(L["SHOW_RACE_TELEPORTS"])
ToggleRaceTeleports:SetWidth(WidgetWidths)
ToggleRaceTeleports:SetValue(MDungeonTeleports.RaceTeleports)
ToggleRaceTeleports.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_RACE_TELEPORTS"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_RACE_TELEPORTS"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleRaceTeleports.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleRaceTeleports:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.RaceTeleports = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabClassRace:AddChild(ToggleRaceTeleports)
--------------------------------------------------
-- MARK: Hearthstone Selection Dropdown
local HearthstoneSelection = AceGUI:Create("Dropdown")
HearthstoneSelection:SetLabel(L["SELECT_HEARTHSTONE"])
HearthstoneSelection:SetWidth(200)

local function IsHearthstoneKnown(itemID)
    if not itemID then
        return false
    end
    if PlayerHasToy(itemID) then
        return true
    end
    return (C_Item.GetItemCount(itemID) or 0) > 0
end

local function GetHearthstoneName(itemID)
    if not itemID then
        return nil
    end
    local name
    if C_Item and C_Item.GetItemNameByID then
        name = C_Item.GetItemNameByID(itemID)
    end
    if not name then
        name = GetItemInfo(itemID)
    end
    if not name and C_Item and C_Item.RequestLoadItemDataByID then
        C_Item.RequestLoadItemDataByID(itemID)
    end
    return name
end

local hearthstoneList = {}
local hearthstoneOrder = {}
local function BuildHearthstoneList()
    local list = {}
    local order = {}
    if MDTHearthstones then
        for _, data in ipairs(MDTHearthstones) do
            local itemID = tonumber(data.itemID)
            if itemID and IsHearthstoneKnown(itemID) then
                local key = tostring(itemID)
                list[key] = data.name or GetHearthstoneName(itemID) or key
                table.insert(order, key)
            end
        end
    end
    return list, order
end

local function RefreshHearthstoneDropdown()
    hearthstoneList, hearthstoneOrder = BuildHearthstoneList()
    HearthstoneSelection:SetList(hearthstoneList, hearthstoneOrder)

    if MDungeonTeleports.randomHearthstone then
        HearthstoneSelection:SetDisabled(true)
        return
    end

    local selectedHearthstoneId = tostring(MDungeonTeleports.selectedHearthstoneId or 6948)
    if hearthstoneList[selectedHearthstoneId] then
        HearthstoneSelection:SetValue(selectedHearthstoneId)
        HearthstoneSelection:SetDisabled(false)
    elseif hearthstoneOrder[1] then
        HearthstoneSelection:SetValue(hearthstoneOrder[1])
        MDungeonTeleports.selectedHearthstoneId = tonumber(hearthstoneOrder[1])
        HearthstoneSelection:SetDisabled(false)
    else
        HearthstoneSelection:SetValue(nil)
        HearthstoneSelection:SetDisabled(true)
    end
end

RefreshHearthstoneDropdown()

HearthstoneSelection.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_WORLD_MAP_TAB_HEARTH"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_HEARTHSTONE"], nil, nil, nil, true)

    GameTooltip:Show()
end)
HearthstoneSelection.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)

HearthstoneSelection:SetCallback("OnValueChanged", function(_, _, key)
    MDungeonTeleports.selectedHearthstoneId = tonumber(key) or MDungeonTeleports.selectedHearthstoneId
    if NS and NS.WorldMapTab and NS.WorldMapTab.BuildScrollContent and not InCombatLockdown() then
        NS.WorldMapTab:BuildScrollContent()
    end
end)
ContainerWorldMapTabHearthstones:AddChild(HearthstoneSelection)
-------------------------------------------------
-- MARK: Random Hearthstone Toggle
local ToggleRandomHearthstone = AceGUI:Create("CheckBox")
ToggleRandomHearthstone:SetLabel(L["RANDOM_HEARTHSTONE"])
ToggleRandomHearthstone:SetWidth(WidgetWidths)
ToggleRandomHearthstone:SetValue(MDungeonTeleports.randomHearthstone)
ToggleRandomHearthstone.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["RANDOM_HEARTHSTONE"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_RANDOM_HEARTHSTONE"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleRandomHearthstone.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleRandomHearthstone:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.randomHearthstone = val
    RefreshHearthstoneDropdown()
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabHearthstones:AddChild(ToggleRandomHearthstone)
-------------------------------------------------
-- MARK: Show Dalaran Hearthstone
local ToggleDalaranHS = AceGUI:Create("CheckBox")
ToggleDalaranHS:SetLabel(L["SHOW_DALARAN_HS"])
ToggleDalaranHS:SetWidth(WidgetWidths)
ToggleDalaranHS:SetValue(MDungeonTeleports.ShowDalaranHS)
ToggleDalaranHS.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_DALARAN_HS"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_DALARAN_HS"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleDalaranHS.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleDalaranHS:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ShowDalaranHS = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabHearthstones:AddChild(ToggleDalaranHS)
-------------------------------------------------
-- MARK: Show Garrison Hearthstone
local ToggleGarrisonHS = AceGUI:Create("CheckBox")
ToggleGarrisonHS:SetLabel(L["SHOW_GARRISON_HS"])
ToggleGarrisonHS:SetWidth(WidgetWidths)
ToggleGarrisonHS:SetValue(MDungeonTeleports.ShowGarrisonHS)
ToggleGarrisonHS.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_GARRISON_HS"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_GARRISON_HS"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleGarrisonHS.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleGarrisonHS:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ShowGarrisonHS = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabHearthstones:AddChild(ToggleGarrisonHS)
-------------------------------------------------
-- MARK: Show Teleport to Plot
local TogglePlotTeleport = AceGUI:Create("CheckBox")
TogglePlotTeleport:SetLabel(L["SHOW_PLOT_TELEPORT"])
TogglePlotTeleport:SetWidth(WidgetWidths)
TogglePlotTeleport:SetValue(MDungeonTeleports.ShowPlotTeleport)
TogglePlotTeleport.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_PLOT_TELEPORT"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_PLOT_TELEPORT"], nil, nil, nil, true)
    GameTooltip:Show()
end)
TogglePlotTeleport.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
TogglePlotTeleport:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ShowPlotTeleport = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabPlot:AddChild(TogglePlotTeleport)
-------------------------------------------------
-- MARK: Show Arcantina
local ToggleArcantina = AceGUI:Create("CheckBox")
ToggleArcantina:SetLabel(L["SHOW_ARCANTINA"])
ToggleArcantina:SetWidth(WidgetWidths)
ToggleArcantina:SetValue(MDungeonTeleports.ShowArcantina)
ToggleArcantina.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["SHOW_ARCANTINA"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_ARCANTINA"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleArcantina.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleArcantina:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.ShowArcantina = val
    if NS and NS.WorldMapTab then
        if not InCombatLockdown() and NS.WorldMapTab.panel then
            NS.WorldMapTab:BuildScrollContent()
        else
            NS.WorldMapTab.pendingContentRefresh = true
        end
    end
end)
ContainerWorldMapTabArcantina:AddChild(ToggleArcantina)
-------------------------------------------------
-- MARK: Teleports Tab
local ToggleTeleportsTabCheckBox = AceGUI:Create("CheckBox")
ToggleTeleportsTabCheckBox:SetLabel(L["SHOW_TELEPORTS_TAB"])
ToggleTeleportsTabCheckBox:SetWidth(WidgetWidths)
ToggleTeleportsTabCheckBox:SetValue(MDungeonTeleports.teleportsTab)
ToggleTeleportsTabCheckBox.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_TELEPORTS_TAB_MAIN"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_TELEPORTS_TAB"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleTeleportsTabCheckBox.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleTeleportsTabCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.teleportsTab = val
    MDTUpdateTeleportsTab(MDungeonTeleports.teleportsTab)
end)
ContainerFeatures:AddChild(ToggleTeleportsTabCheckBox)
-------------------------------------------------
-- MARK: Mythic+ Dungeon Buttons 
local ToggleMythicDungeonButtonsCheckBox = AceGUI:Create("CheckBox")
ToggleMythicDungeonButtonsCheckBox:SetLabel(L["M+_DUNGEON_BUTTONS"])
ToggleMythicDungeonButtonsCheckBox:SetWidth(WidgetWidths)
ToggleMythicDungeonButtonsCheckBox:SetValue(MDungeonTeleports.mythicTabButtons)
ToggleMythicDungeonButtonsCheckBox.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_WEAK_REPLACEMENT"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_WEAK_SUB1"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleMythicDungeonButtonsCheckBox.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleMythicDungeonButtonsCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.mythicTabButtons = val
    if MDTToggleMythicIconButtons then MDTToggleMythicIconButtons() end
end)
ContainerFeatures:AddChild(ToggleMythicDungeonButtonsCheckBox)
-------------------------------------------------
-- MARK: Mythic+ Dungeon Buttons Vertical
local ToggleMythicDungeonButtonsVerticalCheckBox = AceGUI:Create("CheckBox")
ToggleMythicDungeonButtonsVerticalCheckBox:SetLabel(L["M+_DUNGEON_BUTTONS_VERTICAL"])
ToggleMythicDungeonButtonsVerticalCheckBox:SetWidth(WidgetWidths)
ToggleMythicDungeonButtonsVerticalCheckBox:SetValue(MDungeonTeleports.mythicTabVertical)
ToggleMythicDungeonButtonsVerticalCheckBox.frame:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
    GameTooltip:SetText(L["TOOLTIP_WEAK_REPLACEMENT"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_WEAK_SUB2"], nil, nil, nil, true)
    GameTooltip:Show()
end)
ToggleMythicDungeonButtonsVerticalCheckBox.frame:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ToggleMythicDungeonButtonsVerticalCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.mythicTabVertical = val
    if MDTToggleMythicVerticalButtons then MDTToggleMythicVerticalButtons() end
end)
ContainerFeatures:AddChild(ToggleMythicDungeonButtonsVerticalCheckBox)
-------------------------------------------------
-- MARK: Respond to Keys
local RespondKeysCheckBox = AceGUI:Create("CheckBox")
RespondKeysCheckBox:SetLabel(L["RESPOND_TO_KEYS"])
RespondKeysCheckBox:SetWidth(WidgetWidths)
RespondKeysCheckBox:SetValue(MDungeonTeleports.isRespondChecked)
RespondKeysCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.isRespondChecked = val
end)
ContainerUtilities:AddChild(RespondKeysCheckBox)
-------------------------------------------------
-- MARK: Announce Teleport Location
local AnnounceTeleportCheckBox = AceGUI:Create("CheckBox")
AnnounceTeleportCheckBox:SetLabel(L["ENABLE_TELEPORT_ANNOUNCEMENTS"])
AnnounceTeleportCheckBox:SetWidth(WidgetWidths)
AnnounceTeleportCheckBox:SetValue(MDungeonTeleports.announcePort)
AnnounceTeleportCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.announcePort = val
end)
ContainerUtilities:AddChild(AnnounceTeleportCheckBox)
-------------------------------------------------
-- MARK: Daily Login Message
local DailyLoginMessageCheckBox = AceGUI:Create("CheckBox")
DailyLoginMessageCheckBox:SetLabel(L["SHOW_LOGIN_MESSAGE"])
DailyLoginMessageCheckBox:SetWidth(WidgetWidths)
DailyLoginMessageCheckBox:SetValue(MDungeonTeleports.loginMessage)
DailyLoginMessageCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.loginMessage = val
end)
ContainerMisc:AddChild(DailyLoginMessageCheckBox)
-------------------------------------------------
-- MARK: Minimap Button Toggle
local ToggleMinimapButtonCheckBox = AceGUI:Create("CheckBox")
ToggleMinimapButtonCheckBox:SetLabel(L["SHOW_MINIMAP_BUTTON"])
ToggleMinimapButtonCheckBox:SetWidth(WidgetWidths)
ToggleMinimapButtonCheckBox:SetValue(not (MDungeonTeleports.minimapButton and MDungeonTeleports.minimapButton.hide))
ToggleMinimapButtonCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.minimapButton = MDungeonTeleports.minimapButton or {}
    MDungeonTeleports.minimapButton.hide = not val
    LibDBIcon:Refresh("MDungeonTeleports", MDungeonTeleports.minimapButton)
end)
ContainerMisc:AddChild(ToggleMinimapButtonCheckBox)
-------------------------------------------------
-- MARK: Hide Settings Button
local HideSettingsButtonCheckBox = AceGUI:Create("CheckBox")
HideSettingsButtonCheckBox:SetLabel(L["SHOWHIDE_SETTINGS_BUTTON"])
HideSettingsButtonCheckBox:SetWidth(WidgetWidths)
HideSettingsButtonCheckBox:SetValue(MDungeonTeleports.HideSettingsButton)
HideSettingsButtonCheckBox:SetCallback("OnValueChanged", function(_, _, val)
    MDungeonTeleports.HideSettingsButton = val
    MDTHideSettingsButton()
end)
ContainerMisc:AddChild(HideSettingsButtonCheckBox)
-------------------------------------------------
-- MARK: Discord Text
local DiscordTextBox = AceGUI:Create("EditBox")
DiscordTextBox:SetLabel(" ")
DiscordTextBox:SetWidth(170)
DiscordTextBox:SetText("https://discord.com/invite/Un9XKPnA7S")
DiscordTextBox:SetCallback("OnEditFocusGained", function(widget)
    widget.editbox:HighlightText()
end)
DiscordTextBox.editbox:SetScript("OnChar", function() end)
DiscordTextBox.editbox:SetScript("OnTextChanged", function(self)
    self:SetText("https://discord.com/invite/Un9XKPnA7S")
    self:HighlightText()
end)
ContainerInfoDiscord:AddChild(DiscordTextBox)
-- MARK: Discord Image
local DiscordIcon = TitleFrame:CreateTexture(nil, "ARTWORK")
DiscordIcon:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_discord.blp")
DiscordIcon:SetSize(28, 28)
DiscordIcon:SetPoint("TOP", InfoTitle, "TOP", -298, -262)
-------------------------------------------------
-- MARK: CurseForge Text Box
local CurseForgeTextBox = AceGUI:Create("EditBox")
CurseForgeTextBox:SetLabel(" ")
CurseForgeTextBox:SetWidth(170)
CurseForgeTextBox:SetText("https://www.curseforge.com/wow/addons/dungeonports")
CurseForgeTextBox:SetCallback("OnEditFocusGained", function(widget)
    widget.editbox:HighlightText()
end)
CurseForgeTextBox.editbox:SetScript("OnChar", function() end)
CurseForgeTextBox.editbox:SetScript("OnTextChanged", function(self)
    self:SetText("https://www.curseforge.com/wow/addons/dungeonports")
    self:HighlightText()
end)
ContainerInfoCurseForge:AddChild(CurseForgeTextBox)
-- MARK: CurseForge Image
local CurseForgeIcon = TitleFrame:CreateTexture(nil, "ARTWORK")
CurseForgeIcon:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_curseforge.blp")
CurseForgeIcon:SetSize(28, 28)
CurseForgeIcon:SetPoint("TOP", InfoTitle, "TOP", -88, -262)
-------------------------------------------------
-- MARK: Wago Text Box
local WagoTextBox = AceGUI:Create("EditBox")
WagoTextBox:SetLabel(" ")
WagoTextBox:SetWidth(170)
WagoTextBox:SetText("https://addons.wago.io/addons/dungeonports")
WagoTextBox:SetCallback("OnEditFocusGained", function(widget)
    widget.editbox:HighlightText()
end)
WagoTextBox.editbox:SetScript("OnChar", function() end)
WagoTextBox.editbox:SetScript("OnTextChanged", function(self)
    self:SetText("https://addons.wago.io/addons/dungeonports")
    self:HighlightText()
end)
ContainerInfoWago:AddChild(WagoTextBox)
-- MARK: Wago Image
local WagoIcon = TitleFrame:CreateTexture(nil, "ARTWORK")
WagoIcon:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_wago.blp")
WagoIcon:SetSize(28, 28)
WagoIcon:SetPoint("TOP", InfoTitle, "TOP", 122, -262)
-------------------------------------------------
-- MARK: Settings Size Slider
local UISettingsScaleSlider = AceGUI:Create("Slider")
UISettingsScaleSlider:SetLabel("")
UISettingsScaleSlider:SetWidth(50)
UISettingsScaleSlider:SetSliderValues(0.7, 1.7, 0.01)
UISettingsScaleSlider:SetValue(MDungeonTeleports.settingsScale or 1)
UISettingsScaleSlider.lowtext:SetText("")
UISettingsScaleSlider.lowtext:Hide()
UISettingsScaleSlider.hightext:SetText("")
UISettingsScaleSlider.hightext:Hide()
UISettingsScaleSlider.editbox:Hide()
UISettingsScaleSlider.slider:SetHeight(11)

local sliderBG = UISettingsScaleSlider.slider:CreateTexture(nil, "BACKGROUND")
sliderBG:SetAllPoints(UISettingsScaleSlider.slider)
sliderBG:SetColorTexture(0.2, 0.2, 0.2, 0.8)

local thumb = UISettingsScaleSlider.slider:GetThumbTexture()
if thumb then
    thumb:SetColorTexture(225/255, 255/255, 255/255) -- (124/255, 79/255 ,214/255)
    thumb:SetSize(8, 8)
end

UISettingsScaleSlider.slider:SetBackdrop({
    edgeFile = "Interface\\Buttons\\WHITE8X8",
    edgeSize = 1,
})
UISettingsScaleSlider.slider:SetBackdropBorderColor(0, 0, 0, 1)

UISettingsScaleSlider:SetCallback("OnValueChanged", function(_, _, val)
    UISettingsScaleSlider._pendingValue = val
end)
UISettingsScaleSlider.slider:HookScript("OnMouseUp", function()
    if UISettingsScaleSlider._pendingValue then
        MDungeonTeleports.settingsScale = UISettingsScaleSlider._pendingValue
        UpdateSettingsFrameScale(UISettingsScaleSlider._pendingValue)
    end
end)
UISettingsScaleSlider.slider:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_TOP")
    GameTooltip:SetText(L["TOOLTIP_SCALE"], 1, 1, 1)
    GameTooltip:AddLine(L["TOOLTIP_SCALE_SUB"], nil, nil, nil, true)
    GameTooltip:Show()
end)
UISettingsScaleSlider.slider:SetScript("OnLeave", function(self)
    GameTooltip:Hide()
end)
ContainerSettingsSlider:AddChild(UISettingsScaleSlider)
-------------------------------------------------
-- MARK: Settings Tabs
local SettingsTabs = AceGUI:Create("TabGroup")
SettingsTabs:SetTabs({
    { text = L["GENERAL"], value = "general" },
    { text = L["APPEARANCE"], value = "customization" },
    { text = L["WORLD_MAP_TAB"], value = "worldmap" },
    { text = L["INFO"], value = "info" }
})
SettingsTabs:SetLayout("Flow")
SettingsTabs:SetWidth(620)
SettingsTabs:SetHeight(440)
SettingsTabs:SetAutoAdjustHeight(false)
SettingsTabs.frame:SetParent(Settings)
SettingsTabs.frame:SetPoint("TOPLEFT", Settings, "TOPLEFT", 8, -26)
SettingsTabs.frame:SetPoint("BOTTOMRIGHT", Settings, "BOTTOMRIGHT", -8, 30)
SettingsTabs.frame:SetFrameStrata("DIALOG")
SettingsTabs.frame:SetFrameLevel(Settings:GetFrameLevel() + 1)

local function SetTabVisibility(tabKey)
    local function ToggleItems(items, show)
        for _, item in ipairs(items) do
            if item then
                if show then
                    item:Show()
                else
                    item:Hide()
                end
            end
        end
    end

    local windowsItems = {
        SeasonsTitle,
        LibrariesTitle,
        KeyTrackerModuleTitle,
        ExpansionsDropTitle,
        FeaturesTitle,
        UtilitiesTitle,
        MiscTitle,
        ContainerSeasons.frame,
        ContainerLibraries.frame,
        ContainerKeyTrackerModule.frame,
        ContainerDungeonExp.frame,
        ContainerFeatures.frame,
        ContainerUtilities.frame,
        ContainerMisc.frame,
    }
    local customizationItems = {
        AppearanceTitle,
        CustomFontsTitle,
        CustomWindowsTitle,
        CustomFeedbackTitle,
        ContainerPresetCustomizations.frame,
        ContainerFontOptions.frame,
        ContainerWindowOptions.frame,
        ContainerFeedbackOptions.frame,
    }
    local worldMapTabItems = {
        WorldMapTabTitle,
        WMTHearthstoneOptionsTitle,
        WMTSeasonOptionsTitle,
        WMTClassRaceOptionsTitle,
        WMTArcantinaOptionsTitle,
        WMTPlotOptionsTitle,
        WMTExpansionOptionsTitle,
        ContainerWorldMapTab.frame,
        ContainerWorldMapTabHearthstones.frame,
        ContainerWorldMapTabSeasons.frame,
        ContainerWorldMapTabClassRace.frame,
        ContainerWorldMapTabArcantina.frame,
        ContainerWorldMapTabExpansions.frame,
        ContainerWorldMapTabPlot.frame,
    }
    local infoItems = {
        InfoTitle,
        InfoLabel,
        InfoTabImage,
        DiscordIcon,
        CurseForgeIcon,
        WagoIcon,
        ContainerInfoWago.frame,
        ContainerInfoCurseForge.frame,
        ContainerInfoDiscord.frame,
    }

    ToggleItems(windowsItems, tabKey == "general")
    ToggleItems(customizationItems, tabKey == "customization")
    ToggleItems(worldMapTabItems, tabKey == "worldmap")
    ToggleItems(infoItems, tabKey == "info")
end

SettingsTabs:SetCallback("OnGroupSelected", function(widget, _, group)
    widget:ReleaseChildren()
    SetTabVisibility(group)
end)

SettingsTabs:SelectTab("general")
SettingsTabs.frame:Show()
-------------------------------------------------
-------------------------------------------------
-- MARK: Settings Exit Button
local settingsExitButton = CreateFrame("Button", "SettingsOpenButton", Settings)
settingsExitButton:SetSize(11, 11)
settingsExitButton:SetPoint("TOPRIGHT", Settings, "TOPRIGHT", -7, -7)
settingsExitButton:SetFrameStrata("DIALOG")

local settingExitButtonTexture = settingsExitButton:CreateTexture(nil, "BACKGROUND")
settingExitButtonTexture:SetAllPoints(settingsExitButton)
settingExitButtonTexture:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_close.blp")

local settingsExitButtonHighlight = settingsExitButton:CreateTexture(nil, "HIGHLIGHT")
settingsExitButtonHighlight:SetAllPoints(settingsExitButton)
settingsExitButtonHighlight:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_close_highlight.blp")
settingsExitButtonHighlight:Hide()

settingsExitButton.settingsExitButtonHighlight = settingsExitButtonHighlight
settingsExitButton.settingExitButtonTexture = settingExitButtonTexture
settingsExitButton:SetScript("OnEnter", function(self)
        self.settingsExitButtonHighlight:Show()
        self.settingExitButtonTexture:Hide()
    end
)
settingsExitButton:SetScript("OnLeave", function(self)
        self.settingsExitButtonHighlight:Hide()
        self.settingExitButtonTexture:Show()
    end
)
settingsExitButton:SetScript("OnClick", function()
        PlaySound(SOUNDKIT.IG_CHARACTER_INFO_CLOSE)
        Settings:Hide()
    end
)
-------------------------------------------------
-- MARK: Update UI
local function UpdateUI()
    --- Checkbox Value Set ---
    if Season1CheckBox then Season1CheckBox:SetValue(MDungeonTeleports.isSeason1PortalsShown) end
    if PortalLibraryCheckBox then PortalLibraryCheckBox:SetValue(MDungeonTeleports.isPortalLibraryShown) end
    if PortalLibraryRaidCheckBox then PortalLibraryRaidCheckBox:SetValue(MDungeonTeleports.isPortalLibraryRaidShown) end
    if ToggleKeyFrameCheckBox then ToggleKeyFrameCheckBox:SetValue(MDungeonTeleports.isKeyFrameShown) end
    if ToggleTooltipsCheckBox then ToggleTooltipsCheckBox:SetValue(MDungeonTeleports.showTooltips) end
    if ShiftMoveCheckBox then ShiftMoveCheckBox:SetValue(MDungeonTeleports.ShiftDragToggle) end
    if RespondKeysCheckBox then RespondKeysCheckBox:SetValue(MDungeonTeleports.isRespondChecked) end
    if DailyLoginMessageCheckBox then DailyLoginMessageCheckBox:SetValue(MDungeonTeleports.loginMessage) end
    if AnnounceTeleportCheckBox then AnnounceTeleportCheckBox:SetValue(MDungeonTeleports.announcePort) end
    if LockIconsCheckBox then LockIconsCheckBox:SetValue(MDungeonTeleports.LockIcons) end
    if DarkenCheckBox then DarkenCheckBox:SetValue(MDungeonTeleports.DarkenText) end
    if RioScoreCheckBox then RioScoreCheckBox:SetValue(MDungeonTeleports.rioScore) end
    if RealmNameCheckBox then RealmNameCheckBox:SetValue(MDungeonTeleports.realmName) end
    if DragHandleCheckBox then DragHandleCheckBox:SetValue(MDungeonTeleports.dragHandle) end
    if ToggleTeleportsTabCheckBox then ToggleTeleportsTabCheckBox:SetValue(MDungeonTeleports.teleportsTab) end
    if ToggleMythicDungeonButtonsCheckBox then ToggleMythicDungeonButtonsCheckBox:SetValue(MDungeonTeleports.mythicTabButtons) end
    if ToggleMythicDungeonButtonsVerticalCheckBox then ToggleMythicDungeonButtonsVerticalCheckBox:SetValue(MDungeonTeleports.mythicTabVertical) end
    if HideSettingsButtonCheckBox then HideSettingsButtonCheckBox:SetValue(MDungeonTeleports.HideSettingsButton) end
    if ToggleMinimapButtonCheckBox then
        ToggleMinimapButtonCheckBox:SetValue(not (MDungeonTeleports.minimapButton and MDungeonTeleports.minimapButton.hide))
    end
    if ToggleWorldMapTab then ToggleWorldMapTab:SetValue(MDungeonTeleports.worldMapTab) end
    if ToggleMapSeason1 then ToggleMapSeason1:SetValue(MDungeonTeleports.MapSeason1) end
    if ToggleMapMidnight then ToggleMapMidnight:SetValue(MDungeonTeleports.MapMidnight) end
    if ToggleClassTeleports then ToggleClassTeleports:SetValue(MDungeonTeleports.ClassTeleports) end
    if ToggleRaceTeleports then ToggleRaceTeleports:SetValue(MDungeonTeleports.RaceTeleports) end
    if CenterDungeonPortalsCheckBox then CenterDungeonPortalsCheckBox:SetValue(MDungeonTeleports.centerDungeonPortals) end
    if CenterRaidPortalsCheckBox then CenterRaidPortalsCheckBox:SetValue(MDungeonTeleports.centerRaidPortals) end
    if HideMissingPortalsCheckBox then HideMissingPortalsCheckBox:SetValue(MDungeonTeleports.hideMissingPortals) end
    if TogglePlotTeleport then TogglePlotTeleport:SetValue(MDungeonTeleports.ShowPlotTeleport) end
    if ToggleDalaranHS then ToggleDalaranHS:SetValue(MDungeonTeleports.ShowDalaranHS) end
    if ToggleGarrisonHS then ToggleGarrisonHS:SetValue(MDungeonTeleports.ShowGarrisonHS) end
    if ToggleArcantina then ToggleArcantina:SetValue(MDungeonTeleports.ShowArcantina) end
    if ToggleRandomHearthstone then ToggleRandomHearthstone:SetValue(MDungeonTeleports.randomHearthstone) end
    --- Expansion Visibility Multi-Select ---
    if ExpansionMultiSelect and MDungeonTeleports.expansionVisibility then
        for key, value in pairs(MDungeonTeleports.expansionVisibility) do
            ExpansionMultiSelect:SetItemValue(key, value)
        end
    end
    if RaidExpansionMultiSelect and MDungeonTeleports.raidExpansionVisibility then
        for key, value in pairs(MDungeonTeleports.raidExpansionVisibility) do
            RaidExpansionMultiSelect:SetItemValue(key, value)
        end
    end
    --- Login Visibility Variable Check and Set ---
    Season1Vis(MDungeonTeleports.isSeason1PortalsShown)
    DungeonVis(MDungeonTeleports.isPortalLibraryShown)
    RaidVis(MDungeonTeleports.isPortalLibraryRaidShown)
    KeyTVis(MDungeonTeleports.isKeyFrameShown)
    --- UI Font Size Sliders ---
    if FontSizeButtonsSlider then FontSizeButtonsSlider:SetValue(MDungeonTeleports.TextSizeButton or 11) end
    if FontSizeExpansionSlider then FontSizeExpansionSlider:SetValue(MDungeonTeleports.TextSizeExpansion or 12) end
    if FontSizeTitleSlider then FontSizeTitleSlider:SetValue(MDungeonTeleports.TextSizeTitle or 12) end
    --- UI Scale Value Set ---
    if UIScaleSlider then UIScaleSlider:SetValue(MDungeonTeleports.frameScale or 1) end
    if KeyTrackerUIScaleSlider then KeyTrackerUIScaleSlider:SetValue(MDungeonTeleports.KeyTrackerFrameScale or 1) end
    --- UI Border Scale Set ---
    if BorderSlider then BorderSlider:SetValue(MDungeonTeleports.borderThickness or 1) end
    --- UI Settings Scale Set --- 
    if UISettingsScaleSlider then UISettingsScaleSlider:SetValue(MDungeonTeleports.settingsScale or 1) end
    --- UI Scale Set ---
    local scale = MDungeonTeleports.frameScale
    local keyscale = MDungeonTeleports.KeyTrackerFrameScale
    UpdateFrameScale(scale)
    UpdateKeyTrackerFrameScale(keyscale)
    local scalesettings = MDungeonTeleports.settingsScale
    UpdateSettingsFrameScale(scalesettings)
    --- Font Dropdown Value Set ---
    if fontDropdown then fontDropdown:SetValue(MDungeonTeleports.customFontName) end
    if presetDropdown and MDT_ColourPresets and MDungeonTeleports.selectedPreset and MDT_ColourPresets[MDungeonTeleports.selectedPreset] then 
        presetDropdown:SetValue(MDT_ColourPresets[MDungeonTeleports.selectedPreset].text) 
    end
    if hearthstoneList and MDungeonTeleports.selectedHearthstoneId then
        local hsKey = tostring(MDungeonTeleports.selectedHearthstoneId)
        if hearthstoneList[hsKey] then
            HearthstoneSelection:SetValue(hsKey)
        end
    end
    --- Color Picker Value Set ---
    if borderColorPicker then borderColorPicker:SetColor(MDungeonTeleports.borderColor.r, MDungeonTeleports.borderColor.g, MDungeonTeleports.borderColor.b, MDungeonTeleports.borderColor.a) end
    if backgroundColorPicker then backgroundColorPicker:SetColor(MDungeonTeleports.backgroundColor.r, MDungeonTeleports.backgroundColor.g, MDungeonTeleports.backgroundColor.b, MDungeonTeleports.backgroundColor.a) end
    if expansionColorPicker then expansionColorPicker:SetColor(MDungeonTeleports.expansionColor.r, MDungeonTeleports.expansionColor.g, MDungeonTeleports.expansionColor.b) end
    if titleColorPicker then titleColorPicker:SetColor(MDungeonTeleports.titleColor.r, MDungeonTeleports.titleColor.g, MDungeonTeleports.titleColor.b) end
    if buttonTextColorPicker then buttonTextColorPicker:SetColor(MDungeonTeleports.buttonTextColor.r, MDungeonTeleports.buttonTextColor.g, MDungeonTeleports.buttonTextColor.b) end
    local bbcolor = MDungeonTeleports.buttonBorderColor or { r = 0.05, g = 0.05, b = 0.05, a = 0.8 }
    if ButtonBorderColorPicker then ButtonBorderColorPicker:SetColor(bbcolor.r, bbcolor.g, bbcolor.b, bbcolor.a) end
    if LibDBIcon and LibDBIcon:IsRegistered("MDungeonTeleports") then
        LibDBIcon:Refresh("MDungeonTeleports", MDungeonTeleports.minimapButton)
    end
end
-------------------------------------------------
-- MARK: AddOn Load Event
local function OnEvent(self, event, arg1)
    if event == "ADDON_LOADED" and arg1 == "MDungeonTeleports" then
        UpdateUI()
        RefreshHearthstoneDropdown()
    elseif event == "TOYS_UPDATED" or event == "BAG_UPDATE_DELAYED" or event == "PLAYER_LOGIN" then
        RefreshHearthstoneDropdown()
    end
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("TOYS_UPDATED")
eventFrame:RegisterEvent("BAG_UPDATE_DELAYED")
eventFrame:RegisterEvent("ITEM_DATA_LOAD_RESULT")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", OnEvent)
-------------------------------------------------
-- MARK: Slash Command
SLASH_DP1 = "/dp"
SlashCmdList["DP"] = function()
    if Settings:IsShown() then
        Settings:Hide()
    else
        Settings:Show()
    end
end
-------------------------------------------------
-- MARK: Group Finder Settings Button
local settingsOpenButton = CreateFrame("Button", "SettingsOpenButton", PVEFrame)

local isElvUILoaded = IsAddOnLoaded("ElvUI")

if isElvUILoaded then
    settingsOpenButton:SetSize(14, 14)
    settingsOpenButton:SetPoint("TOPRIGHT", PVEFrame, "TOPRIGHT", -22, -5)
else
    settingsOpenButton:SetSize(22, 21)
    settingsOpenButton:SetPoint("TOPRIGHT", PVEFrame, "TOPRIGHT", -22, -1)
end

settingsOpenButton:SetFrameStrata("DIALOG")

local defaultTexture = "Interface\\AddOns\\MDungeonTeleports\\media\\ui\\settings_buttons.blp"
local elvuiTexture = "Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_settings.blp"

local defaultNormalCoords = {0, 0.25, 0, 1}
local defaultHighlightCoords = {0.50, 0.75, 0, 1}
local defaultPressedCoords = {0.25, 0.50, 0, 1}

local elvuiHighlightTexture = "Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_settings_highlight.blp"
local elvuiPressedTexture = "Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_settings_pressed.blp"

local settingsOpenButtonTexture = settingsOpenButton:CreateTexture(nil, "BACKGROUND")
settingsOpenButtonTexture:SetAllPoints(settingsOpenButton)
settingsOpenButtonTexture:SetTexture(isElvUILoaded and elvuiTexture or defaultTexture)

if not isElvUILoaded then
    settingsOpenButtonTexture:SetTexCoord(unpack(defaultNormalCoords))
end

local settingsButtonHoverOverlay = settingsOpenButton:CreateTexture(nil, "HIGHLIGHT")
settingsButtonHoverOverlay:SetAllPoints(settingsOpenButton)
settingsButtonHoverOverlay:SetTexture(isElvUILoaded and elvuiHighlightTexture or defaultTexture)
settingsButtonHoverOverlay:Hide()

if not isElvUILoaded then
    settingsButtonHoverOverlay:SetTexCoord(unpack(defaultHighlightCoords))
end

local settingsButtonPressedOverlay = settingsOpenButton:CreateTexture(nil, "BACKGROUND")
settingsButtonPressedOverlay:SetAllPoints(settingsOpenButton)
settingsButtonPressedOverlay:SetTexture(isElvUILoaded and elvuiPressedTexture or defaultTexture)
settingsButtonPressedOverlay:Hide()

if not isElvUILoaded then
    settingsButtonPressedOverlay:SetTexCoord(unpack(defaultPressedCoords))
end

settingsOpenButton.settingsOpenButtonTexture = settingsOpenButtonTexture
settingsOpenButton.settingsButtonHoverOverlay = settingsButtonHoverOverlay
settingsOpenButton.settingsButtonPressedOverlay = settingsButtonPressedOverlay

settingsOpenButton:SetScript(
    "OnEnter",
    function(self)
        self.settingsButtonHoverOverlay:Show()
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetText(L["MDT_FULL"], 1, 1, 1)
        GameTooltip:AddLine(L["OPEN_SETTINGS"], nil, nil, nil, true)
        if InCombatLockdown() then
            GameTooltip:AddLine("|cFFFF0000" .. L["COMBAT_WARNING"] .. "|r", nil, nil, nil, true)
        end
        GameTooltip:Show()
    end
)

settingsOpenButton:SetScript(
    "OnLeave",
    function(self)
        self.settingsButtonHoverOverlay:Hide()
        self.settingsButtonPressedOverlay:Hide()
        self.settingsOpenButtonTexture:Show()
        GameTooltip:Hide()
    end
)
settingsOpenButton:SetScript(
    "OnMouseDown",
    function(self)
        self.settingsButtonPressedOverlay:Show()
        self.settingsOpenButtonTexture:Hide()
    end
)

settingsOpenButton:SetScript(
    "OnMouseUp",
    function(self)
        self.settingsButtonPressedOverlay:Hide()
        self.settingsOpenButtonTexture:Show()
    end
)

settingsOpenButton:SetScript(
    "OnClick",
    function(self)
        if InCombatLockdown() then
            return
        end
        PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN)
        if Settings:IsShown() then
            Settings:Hide()
        else
            Settings:Show()
        end
    end
)

local function UpdateButtonStatus()
    if InCombatLockdown() then
        settingsOpenButton:Disable()
    else
        settingsOpenButton:Enable()
    end
end

settingsOpenButton:RegisterEvent("PLAYER_REGEN_ENABLED")
settingsOpenButton:RegisterEvent("PLAYER_REGEN_DISABLED")
settingsOpenButton:SetScript("OnEvent", UpdateButtonStatus)

UpdateButtonStatus()
-------------------------------------------------
-- MARK: Reset Button
local resetButton = CreateFrame("Button", "ResetButton", Settings)
resetButton:SetSize(24, 24)
resetButton:SetPoint("BOTTOMLEFT", Settings, "BOTTOMLEFT", 4, 4)
resetButton:SetFrameStrata("DIALOG")

local resetButtonTexture = resetButton:CreateTexture(nil, "BACKGROUND")
resetButtonTexture:SetAllPoints(resetButton)
resetButtonTexture:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_reset.blp")

local resetButtonHighlight = resetButton:CreateTexture(nil, "HIGHLIGHT")
resetButtonHighlight:SetAllPoints(resetButton)
resetButtonHighlight:SetTexture("Interface\\AddOns\\MDungeonTeleports\\media\\ui\\button_reset_highlight.blp")
resetButtonHighlight:Hide()

resetButton.resetButtonHighlight = resetButtonHighlight
resetButton.resetButtonTexture = resetButtonTexture
resetButton:SetScript(
    "OnEnter",
    function(self)
        self.resetButtonHighlight:Show()
        self.resetButtonTexture:Hide()
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetText(L["RESET_ADDON"], 1, 1, 1)
        GameTooltip:AddLine(L["RESET_ADDON_TIP"], nil, nil, nil, true)
        GameTooltip:Show()
    end
)
resetButton:SetScript(
    "OnLeave",
    function(self)
        self.resetButtonHighlight:Hide()
        self.resetButtonTexture:Show()
        GameTooltip:Hide()
    end
)
resetButton:SetScript(
    "OnClick",
    function(self)
        PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
        MDungeonTeleports.Season1Pos = defaultSettings.Season1Pos
        MDungeonTeleports.PortalLibraryPos = defaultSettings.PortalLibraryPos
        MDungeonTeleports.PortalLibraryRaidPos = defaultSettings.PortalLibraryRaidPos
        MDungeonTeleports.KeyTrackerPos = defaultSettings.KeyTrackerPos
        MDungeonTeleports.isSeason1PortalsShown = defaultSettings.isSeason1PortalsShown
        MDungeonTeleports.isPortalLibraryShown = defaultSettings.isPortalLibraryShown
        MDungeonTeleports.isPortalLibraryRaidShown = defaultSettings.isPortalLibraryRaidShown
        MDungeonTeleports.isKeyFrameShown = defaultSettings.isKeyFrameShown
        MDungeonTeleports.showTooltips = defaultSettings.showTooltips
        MDungeonTeleports.ShiftDragToggle = defaultSettings.ShiftDragToggle
        MDungeonTeleports.isRespondChecked = defaultSettings.isRespondChecked
        MDungeonTeleports.loginMessage = defaultSettings.loginMessage
        MDungeonTeleports.announcePort = defaultSettings.announcePort
        MDungeonTeleports.LockIcons = defaultSettings.LockIcons
        MDungeonTeleports.DarkenText = defaultSettings.DarkenText
        MDungeonTeleports.borderColor = defaultSettings.borderColor
        MDungeonTeleports.backgroundColor = defaultSettings.backgroundColor
        MDungeonTeleports.expansionColor = defaultSettings.expansionColor
        MDungeonTeleports.titleColor = defaultSettings.titleColor
        MDungeonTeleports.buttonTextColor = defaultSettings.buttonTextColor
        MDungeonTeleports.buttonBorderColor = defaultSettings.buttonBorderColor
        MDungeonTeleports.customFont = defaultSettings.customFont
        MDungeonTeleports.customFontName = defaultSettings.customFontName
        MDungeonTeleports.frameScale = defaultSettings.frameScale
        MDungeonTeleports.KeyTrackerFrameScale = defaultSettings.KeyTrackerFrameScale
        MDungeonTeleports.settingsScale = defaultSettings.settingsScale
        MDungeonTeleports.borderThickness = defaultSettings.borderThickness
        MDungeonTeleports.selectedPreset = 1
        MDungeonTeleports.rioScore = defaultSettings.rioScore
        MDungeonTeleports.realmName = defaultSettings.realmName
        MDungeonTeleports.dragHandle = defaultSettings.dragHandle
        MDungeonTeleports.lastVersionCheck = defaultSettings.lastVersionCheck
        MDungeonTeleports.teleportsTab = defaultSettings.teleportsTab
        MDungeonTeleports.mythicTabButtons = defaultSettings.mythicTabButtons
        MDungeonTeleports.mythicTabVertical = defaultSettings.mythicTabVertical
        MDungeonTeleports.selectedHearthstoneId = defaultSettings.selectedHearthstoneId
        MDungeonTeleports.TextSizeButton = defaultSettings.TextSizeButton
        MDungeonTeleports.TextSizeExpansion = defaultSettings.TextSizeExpansion
        MDungeonTeleports.TextSizeTitle = defaultSettings.TextSizeTitle
        MDungeonTeleports.minimapButton = defaultSettings.minimapButton
        MDungeonTeleports.MapSeason1 = defaultSettings.MapSeason1
        MDungeonTeleports.ClassTeleports = defaultSettings.ClassTeleports
        MDungeonTeleports.RaceTeleports = defaultSettings.RaceTeleports
        MDungeonTeleports.worldMapTab = defaultSettings.worldMapTab
        MDungeonTeleports.centerDungeonPortals = defaultSettings.centerDungeonPortals
        MDungeonTeleports.centerRaidPortals = defaultSettings.centerRaidPortals
        MDungeonTeleports.hideMissingPortals = defaultSettings.hideMissingPortals
        MDungeonTeleports.ShowDalaranHS = defaultSettings.ShowDalaranHS
        MDungeonTeleports.ShowGarrisonHS = defaultSettings.ShowGarrisonHS
        MDungeonTeleports.ShowArcantina = defaultSettings.ShowArcantina
        MDungeonTeleports.randomHearthstone = defaultSettings.randomHearthstone
        MDungeonTeleports.expansionVisibility = {}
        for k, v in pairs(defaultSettings.expansionVisibility) do
            MDungeonTeleports.expansionVisibility[k] = v
        end
        MDungeonTeleports.raidExpansionVisibility = {}
        for k, v in pairs(defaultSettings.raidExpansionVisibility) do
            MDungeonTeleports.raidExpansionVisibility[k] = v
        end

        local locale = GetLocale and GetLocale() or "enUS"
        if locale == "zhCN" then
            MDungeonTeleports.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_sc.ttf"
            MDungeonTeleports.customFontName = "SarasaSC"
        elseif locale == "koKR" then
            MDungeonTeleports.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\wanted.ttf"
            MDungeonTeleports.customFontName = "Wanted"
        elseif locale == "zhTW" then
            MDungeonTeleports.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\sarasa_tc.ttf"
            MDungeonTeleports.customFontName = "SarasaTC"            
        else
            MDungeonTeleports.customFont = "Interface\\AddOns\\MDungeonTeleports\\media\\fonts\\expressway.ttf"
            MDungeonTeleports.customFontName = "Expressway"
        end
        ReloadUI()
    end
)
-------------------------------------------------
-- MARK: Login Message
local loginmessage = CreateFrame("Frame")
loginmessage:RegisterEvent("PLAYER_LOGIN")
loginmessage:RegisterEvent("PLAYER_ENTERING_WORLD")
loginmessage:SetScript("OnEvent", function(self, event)
    if event == "PLAYER_LOGIN" or event == "PLAYER_ENTERING_WORLD" then
        if MDungeonTeleports.loginMessage then
            local today = date("%Y-%m-%d")
            if MDungeonTeleports.lastLogin ~= today then
                DEFAULT_CHAT_FRAME:AddMessage(L["LOGIN_MESSAGE_CHAT"], 0.8, 0.6, 1)
                MDungeonTeleports.lastLogin = today
            end
        end
    end
end)
-------------------------------------------------
-- MARK: Hide Settings Button
MDTHideSettingsButton = function()
    if MDungeonTeleports.HideSettingsButton then
        settingsOpenButton:Hide()
    else
        settingsOpenButton:Show()
    end
end

local hideSettingsFrame = CreateFrame("Frame")
hideSettingsFrame:RegisterEvent("PLAYER_LOGIN")
hideSettingsFrame:SetScript("OnEvent", function()
    MDTHideSettingsButton()
end)
-------------------------------------------------
-- MARK: Minimap Button
--[[if MDungeonTeleports.minimapButton == nil then
    MDungeonTeleports.minimapButton = { hide = false }
elseif MDungeonTeleports.minimapButton.hide == nil then
    MDungeonTeleports.minimapButton.hide = false
end
]]
LibDBIcon:Register("MDungeonTeleports", LibStub("LibDataBroker-1.1"):NewDataObject("MDungeonTeleports", {
    type = "launcher",
    text = "MDungeonTeleports",
    icon = "Interface\\AddOns\\MDungeonTeleports\\Media\\icon.blp",
    OnClick = function()
        if InCombatLockdown() then
            return
        end
        PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN)
        if Settings:IsShown() then
            Settings:Hide()
        else
            Settings:Show()
        end
    end,
    OnTooltipShow = function(tooltip)
        tooltip:AddLine(L["MDT_FULL"], 1, 1, 1)
        tooltip:AddLine(L["OPEN_SETTINGS"], nil, nil, nil, true)
        if InCombatLockdown() then
            tooltip:AddLine("|cFFFF0000" .. L["COMBAT_WARNING"] .. "|r", nil, nil, nil, true)
        end
    end,
}), MDungeonTeleports.minimapButton)
LibDBIcon:Refresh("MDungeonTeleports", MDungeonTeleports.minimapButton)
-------------------------------------------------
-- MARK: Announce Teleport Spell Cast
local MDT_All = {}
local dungeonLists = {MDT_PL_MID, MDT_PL_TWW, MDT_PL_DF, MDT_PL_SL, MDT_PL_BFA, MDT_PL_Legion, MDT_PL_WOD, MDT_PL_MOP, MDT_PL_CATA, MDT_PLR_SL, MDT_PLR_DF, MDT_PLR_TWW, MDT_PLR_MID}

for _, t in ipairs(dungeonLists) do
    for _, spell in ipairs(t) do
        MDT_All[spell.spellID] = spell.fullname
    end
end

local lastAnnounceSpellID = nil
local lastAnnounceTime = 0

local function AnnounceSpellCast(spellID)
    local now = GetTime()
    if spellID == lastAnnounceSpellID and (now - lastAnnounceTime) < 2 then return end
    local spellName = MDT_All[spellID]
    if spellName and MDungeonTeleports.announcePort then
        lastAnnounceSpellID = spellID
        lastAnnounceTime = now
        C_ChatInfo.SendChatMessage(L["TELEPORT_LOCATION_CHAT"] .. spellName .. "!", "PARTY")
    end
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("UNIT_SPELLCAST_START")
frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
frame:SetScript("OnEvent", function(self, event, unit, castGUID, spellID)
    if unit == "player" then
        AnnounceSpellCast(spellID)
    end
end)

-- Mark: Called Version Checker
local addonPrefix = "MDT_PEEPO"
C_ChatInfo.RegisterAddonMessagePrefix(addonPrefix)

local addonMessageFrame = CreateFrame("Frame")
addonMessageFrame:RegisterEvent("CHAT_MSG_ADDON")
addonMessageFrame:SetScript("OnEvent", function(self, event, prefix, message, channel, sender)
    if prefix == addonPrefix and message == "VersionCheck" then
        local version = C_AddOns.GetAddOnMetadata("MDungeonTeleports", "Version")
        if channel == "GUILD" then
            C_ChatInfo.SendAddonMessage(addonPrefix, "VersionResponse:" .. version, "GUILD")
        else
            C_ChatInfo.SendAddonMessage(addonPrefix, "VersionResponse:" .. version, "PARTY")
        end
    end
end)

-------------------------------------------------
-- MARK: Version Check
local function SendVersionRequest()
    C_ChatInfo.SendAddonMessage("MDT_PEEPO", version, "GUILD")
end

local ignoredPlayers = {
    "Salora-Hellfire",
    "Malore-Hellfire",
    "Leliane-Hellfire",
    "Talanah-Hellfire",
    "Lyalei-Hellfire",
    "Aliyna-Hellfire",
    "Mywena-Hellfire"
}

local function ShouldIgnorePlayer(playerName)
    for _, ignoredPlayer in ipairs(ignoredPlayers) do
        if playerName == ignoredPlayer then
            return true
        end
    end
    return false
end

local function HandleVersionMessage(prefix, msg, channel, sender)
    if prefix == "MDT_PEEPO" then
        local theirVersion = msg
        local playerName = sender
        
        if not string.find(playerName, "-") then
            local realmName = GetRealmName()
            playerName = playerName .. "-" .. realmName
        end
        
        if ShouldIgnorePlayer(playerName) then
            return
        end
        
        if sender ~= UnitName("player") then
            local function parseVersion(ver)
                local major, minor, patch = string.match(ver, "(%d+)%.(%d+)%.(%d+)")
                return tonumber(major) or 0, tonumber(minor) or 0, tonumber(patch) or 0
            end
            local myMajor, myMinor, myPatch = parseVersion(version)
            local theirMajor, theirMinor, theirPatch = parseVersion(theirVersion)
            if (theirMajor > myMajor) or
               (theirMajor == myMajor and theirMinor > myMinor) or
               (theirMajor == myMajor and theirMinor == myMinor and theirPatch > myPatch) then
                   local today = date("%Y-%m-%d")
                   if MDungeonTeleports.lastVersionCheck ~= today then
                       DEFAULT_CHAT_FRAME:AddMessage("|cFFB19CD9" .. L["MDT_UPDATE_MESSAGE"] .. theirVersion .. "|r")
                       MDungeonTeleports.lastVersionCheck = today
                   end
               end
           end
       end
   end
local versionCommFrame = CreateFrame("Frame")
versionCommFrame:RegisterEvent("PLAYER_LOGIN")
versionCommFrame:SetScript("OnEvent", function()
    SendVersionRequest()
end)

C_ChatInfo.RegisterAddonMessagePrefix("MDT_PEEPO")
versionCommFrame:RegisterEvent("CHAT_MSG_ADDON")
versionCommFrame:SetScript("OnEvent", function(self, event, ...)
    if event == "PLAYER_LOGIN" then
        SendVersionRequest()
    elseif event == "CHAT_MSG_ADDON" then
        HandleVersionMessage(...)
    end
end)