local parentAddonName = "EnhanceQoL"
local addon = select(2, ...)

if _G[parentAddonName] then
	addon = _G[parentAddonName]
else
	error(parentAddonName .. " is not loaded")
end

local function initResourceBarsDB()
	if not addon.db or not addon.functions or not addon.functions.InitDBValue then return end
	local init = addon.functions.InitDBValue
	local gcdDefaults = (addon.GCDBar and addon.GCDBar.defaults) or {}
	local xpDefaults = (addon.Aura and addon.Aura.ExperienceBar and addon.Aura.ExperienceBar.defaults) or {}

	init("enableResourceFrame", false)
	init("resourceBarsHideOutOfCombat", false)
	init("resourceBarsHideMounted", false)
	init("resourceBarsHideVehicle", false)
	init("resourceBarsHidePetBattle", false)
	init("resourceBarsHideClientScene", true)
	init("resourceBarsHideWhenEmpty", false)
	if addon.db.resourceBarsHidePetBattle == nil and addon.db.auraHideInPetBattle ~= nil then addon.db.resourceBarsHidePetBattle = addon.db.auraHideInPetBattle and true or false end
	init("personalResourceBarSettings", {})

	init("gcdBarEnabled", false)
	init("gcdBarWidth", gcdDefaults.width or 200)
	init("gcdBarHeight", gcdDefaults.height or 18)
	init("gcdBarTexture", gcdDefaults.texture or "DEFAULT")
	init("gcdBarColor", gcdDefaults.color or { r = 1, g = 0.82, b = 0.2, a = 1 })
	init("gcdBarSparkEnabled", gcdDefaults.sparkEnabled == true)
	init("gcdBarBackgroundEnabled", gcdDefaults.bgEnabled == true)
	init("gcdBarBackgroundTexture", gcdDefaults.bgTexture or "SOLID")
	init("gcdBarBackgroundColor", gcdDefaults.bgColor or { r = 0, g = 0, b = 0, a = 0 })
	init("gcdBarBorderEnabled", gcdDefaults.borderEnabled == true)
	init("gcdBarBorderTexture", gcdDefaults.borderTexture or "DEFAULT")
	init("gcdBarBorderColor", gcdDefaults.borderColor or { r = 0, g = 0, b = 0, a = 0.8 })
	init("gcdBarBorderSize", gcdDefaults.borderSize or 1)
	init("gcdBarBorderOffset", gcdDefaults.borderOffset or 0)
	init("gcdBarProgressMode", gcdDefaults.progressMode or "REMAINING")
	init("gcdBarFillDirection", gcdDefaults.fillDirection or "LEFT")
	init("gcdBarAnchorTarget", gcdDefaults.anchorRelativeFrame or gcdDefaults.anchorTarget or "UIParent")
	init("gcdBarAnchorPoint", gcdDefaults.anchorPoint or "CENTER")
	init("gcdBarAnchorRelativePoint", gcdDefaults.anchorRelativePoint or gcdDefaults.anchorPoint or "CENTER")
	init("gcdBarAnchorOffsetX", gcdDefaults.anchorOffsetX or 0)
	init("gcdBarAnchorOffsetY", gcdDefaults.anchorOffsetY or -120)
	init("gcdBarAnchorMatchWidth", gcdDefaults.anchorMatchRelativeWidth == true)
	init("gcdBarAnchorMatchWidthOffset", gcdDefaults.anchorMatchRelativeWidthOffset or 0)
	init("gcdBarHideInPetBattle", gcdDefaults.hideInPetBattle == true)

	if addon.GCDBar and addon.GCDBar.OnSettingChanged then addon.GCDBar:OnSettingChanged(addon.db.gcdBarEnabled) end

	init("xpBarEnabled", false)
	init("xpBarWidth", xpDefaults.width or 260)
	init("xpBarHeight", xpDefaults.height or 16)
	init("xpBarTexture", xpDefaults.texture or "DEFAULT")
	init("xpBarColor", xpDefaults.color or { r = 0.20, g = 0.65, b = 0.95, a = 1 })
	init("xpBarRestedColor", xpDefaults.restedColor or { r = 0.20, g = 0.85, b = 1.00, a = 1 })
	init("xpBarRestedOverlay", xpDefaults.restedOverlayEnabled ~= false)
	init("xpBarBackgroundEnabled", xpDefaults.bgEnabled == true)
	init("xpBarBackgroundTexture", xpDefaults.bgTexture or "SOLID")
	init("xpBarBackgroundColor", xpDefaults.bgColor or { r = 0, g = 0, b = 0, a = 0.45 })
	init("xpBarBorderEnabled", xpDefaults.borderEnabled == true)
	init("xpBarBorderTexture", xpDefaults.borderTexture or "DEFAULT")
	init("xpBarBorderColor", xpDefaults.borderColor or { r = 0, g = 0, b = 0, a = 0.85 })
	init("xpBarBorderSize", xpDefaults.borderSize or 1)
	init("xpBarBorderOffset", xpDefaults.borderOffset or 0)
	init("xpBarFillDirection", xpDefaults.fillDirection or "LEFT")
	init("xpBarAnchorTarget", xpDefaults.anchorRelativeFrame or xpDefaults.anchorTarget or "UIParent")
	init("xpBarAnchorPoint", xpDefaults.anchorPoint or "CENTER")
	init("xpBarAnchorRelativePoint", xpDefaults.anchorRelativePoint or xpDefaults.anchorPoint or "CENTER")
	init("xpBarAnchorOffsetX", xpDefaults.anchorOffsetX or 0)
	init("xpBarAnchorOffsetY", xpDefaults.anchorOffsetY or -170)
	init("xpBarAnchorMatchWidth", xpDefaults.anchorMatchRelativeWidth == true)
	init("xpBarAnchorMatchWidthOffset", xpDefaults.anchorMatchRelativeWidthOffset or 0)
	init("xpBarShowText", xpDefaults.textEnabled ~= false)
	init("xpBarTextMode", xpDefaults.textMode or xpDefaults.textCenterMode or "CURMAXPERCENT")
	init("xpBarTextLeftMode", xpDefaults.textLeftMode or "LEVEL")
	init("xpBarTextCenterMode", xpDefaults.textCenterMode or xpDefaults.textMode or "CURMAXPERCENT")
	init("xpBarTextRightMode", xpDefaults.textRightMode or "PERCENT_RESTED")
	init("xpBarTextSize", xpDefaults.textSize or 11)
	init("xpBarTextFont", xpDefaults.textFont or (addon.functions.GetGlobalFontConfigKey and addon.functions.GetGlobalFontConfigKey() or "__EQOL_GLOBAL_FONT__"))
	init("xpBarTextOutline", addon.functions.GetGlobalFontStyleConfigKey and addon.functions.GetGlobalFontStyleConfigKey() or "__EQOL_GLOBAL_FONT_STYLE__")
	init("xpBarTextColor", xpDefaults.textColor or { r = 1, g = 1, b = 1, a = 1 })
	init("xpBarTextAbbreviateNumbers", xpDefaults.abbreviateNumbers == true)
	init("xpBarHideInPetBattle", xpDefaults.hideInPetBattle == true)
	init("xpBarHideBlizzardTracking", xpDefaults.hideBlizzardTracking ~= false)
	addon.db.xpBarDebug = nil
	addon.db.xpBarDebugLast = nil

	if addon.Aura and addon.Aura.ExperienceBar and addon.Aura.ExperienceBar.OnSettingChanged then addon.Aura.ExperienceBar:OnSettingChanged(addon.db.xpBarEnabled) end
end

initResourceBarsDB()

if addon.Aura and addon.Aura.functions and addon.Aura.functions.InitResourceBars then addon.Aura.functions.InitResourceBars() end
