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 {}
	local repDefaults = (addon.Aura and addon.Aura.ReputationBar and addon.Aura.ReputationBar.defaults) or {}
	local honorDefaults = (addon.Aura and addon.Aura.HonorBar and addon.Aura.HonorBar.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("xpBarTextLeftOffsetX", xpDefaults.textLeftOffsetX or 4)
	init("xpBarTextLeftOffsetY", xpDefaults.textLeftOffsetY or 0)
	init("xpBarTextCenterOffsetX", xpDefaults.textCenterOffsetX or 0)
	init("xpBarTextCenterOffsetY", xpDefaults.textCenterOffsetY or 0)
	init("xpBarTextRightOffsetX", xpDefaults.textRightOffsetX or -4)
	init("xpBarTextRightOffsetY", xpDefaults.textRightOffsetY or 0)
	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

	init("repBarEnabled", false)
	init("repBarWidth", repDefaults.width or 260)
	init("repBarHeight", repDefaults.height or 16)
	init("repBarTexture", repDefaults.texture or "DEFAULT")
	init("repBarColor", repDefaults.color or { r = 0.35, g = 0.85, b = 0.25, a = 1 })
	init("repBarUseStandingColor", repDefaults.useStandingColor ~= false)
	init("repBarBackgroundEnabled", repDefaults.bgEnabled == true)
	init("repBarBackgroundTexture", repDefaults.bgTexture or "SOLID")
	init("repBarBackgroundColor", repDefaults.bgColor or { r = 0, g = 0, b = 0, a = 0.45 })
	init("repBarBorderEnabled", repDefaults.borderEnabled == true)
	init("repBarBorderTexture", repDefaults.borderTexture or "DEFAULT")
	init("repBarBorderColor", repDefaults.borderColor or { r = 0, g = 0, b = 0, a = 0.85 })
	init("repBarBorderSize", repDefaults.borderSize or 1)
	init("repBarBorderOffset", repDefaults.borderOffset or 0)
	init("repBarFillDirection", repDefaults.fillDirection or "LEFT")
	init("repBarAnchorTarget", repDefaults.anchorRelativeFrame or repDefaults.anchorTarget or "UIParent")
	init("repBarAnchorPoint", repDefaults.anchorPoint or "CENTER")
	init("repBarAnchorRelativePoint", repDefaults.anchorRelativePoint or repDefaults.anchorPoint or "CENTER")
	init("repBarAnchorOffsetX", repDefaults.anchorOffsetX or 0)
	init("repBarAnchorOffsetY", repDefaults.anchorOffsetY or -170)
	init("repBarAnchorMatchWidth", repDefaults.anchorMatchRelativeWidth == true)
	init("repBarAnchorMatchWidthOffset", repDefaults.anchorMatchRelativeWidthOffset or 0)
	init("repBarShowText", repDefaults.textEnabled ~= false)
	init("repBarTextMode", repDefaults.textMode or repDefaults.textCenterMode or "CURMAXPERCENT")
	init("repBarTextLeftMode", repDefaults.textLeftMode or "FACTION")
	init("repBarTextCenterMode", repDefaults.textCenterMode or repDefaults.textMode or "CURMAXPERCENT")
	init("repBarTextRightMode", repDefaults.textRightMode or "STANDING")
	init("repBarTextLeftOffsetX", repDefaults.textLeftOffsetX or 4)
	init("repBarTextLeftOffsetY", repDefaults.textLeftOffsetY or 0)
	init("repBarTextCenterOffsetX", repDefaults.textCenterOffsetX or 0)
	init("repBarTextCenterOffsetY", repDefaults.textCenterOffsetY or 0)
	init("repBarTextRightOffsetX", repDefaults.textRightOffsetX or -4)
	init("repBarTextRightOffsetY", repDefaults.textRightOffsetY or 0)
	init("repBarTextSize", repDefaults.textSize or 11)
	init("repBarTextFont", repDefaults.textFont or (addon.functions.GetGlobalFontConfigKey and addon.functions.GetGlobalFontConfigKey() or "__EQOL_GLOBAL_FONT__"))
	init("repBarTextOutline", addon.functions.GetGlobalFontStyleConfigKey and addon.functions.GetGlobalFontStyleConfigKey() or "__EQOL_GLOBAL_FONT_STYLE__")
	init("repBarTextColor", repDefaults.textColor or { r = 1, g = 1, b = 1, a = 1 })
	init("repBarTextAbbreviateNumbers", repDefaults.abbreviateNumbers == true)
	init("repBarHideInPetBattle", repDefaults.hideInPetBattle == true)
	init("repBarHideBlizzardTracking", repDefaults.hideBlizzardTracking ~= false)
	init("repBarAutoWatchGainedFaction", repDefaults.autoWatchGainedFaction == true)

	if addon.Aura and addon.Aura.ReputationBar and addon.Aura.ReputationBar.OnSettingChanged then addon.Aura.ReputationBar:OnSettingChanged(addon.db.repBarEnabled) end

	init("honorBarEnabled", false)
	init("honorBarWidth", honorDefaults.width or 260)
	init("honorBarHeight", honorDefaults.height or 16)
	init("honorBarTexture", honorDefaults.texture or "DEFAULT")
	init("honorBarColor", honorDefaults.color or { r = 0.70, g = 0.08, b = 0.08, a = 1 })
	init("honorBarUseHonorColor", honorDefaults.useHonorColor ~= false)
	init("honorBarBackgroundEnabled", honorDefaults.bgEnabled == true)
	init("honorBarBackgroundTexture", honorDefaults.bgTexture or "SOLID")
	init("honorBarBackgroundColor", honorDefaults.bgColor or { r = 0, g = 0, b = 0, a = 0.45 })
	init("honorBarBorderEnabled", honorDefaults.borderEnabled == true)
	init("honorBarBorderTexture", honorDefaults.borderTexture or "DEFAULT")
	init("honorBarBorderColor", honorDefaults.borderColor or { r = 0, g = 0, b = 0, a = 0.85 })
	init("honorBarBorderSize", honorDefaults.borderSize or 1)
	init("honorBarBorderOffset", honorDefaults.borderOffset or 0)
	init("honorBarFillDirection", honorDefaults.fillDirection or "LEFT")
	init("honorBarAnchorTarget", honorDefaults.anchorRelativeFrame or honorDefaults.anchorTarget or "UIParent")
	init("honorBarAnchorPoint", honorDefaults.anchorPoint or "CENTER")
	init("honorBarAnchorRelativePoint", honorDefaults.anchorRelativePoint or honorDefaults.anchorPoint or "CENTER")
	init("honorBarAnchorOffsetX", honorDefaults.anchorOffsetX or 0)
	init("honorBarAnchorOffsetY", honorDefaults.anchorOffsetY or -150)
	init("honorBarAnchorMatchWidth", honorDefaults.anchorMatchRelativeWidth == true)
	init("honorBarAnchorMatchWidthOffset", honorDefaults.anchorMatchRelativeWidthOffset or 0)
	init("honorBarShowText", honorDefaults.textEnabled ~= false)
	init("honorBarTextMode", honorDefaults.textMode or honorDefaults.textCenterMode or "CURMAXPERCENT")
	init("honorBarTextLeftMode", honorDefaults.textLeftMode or "FACTION")
	init("honorBarTextCenterMode", honorDefaults.textCenterMode or honorDefaults.textMode or "CURMAXPERCENT")
	init("honorBarTextRightMode", honorDefaults.textRightMode or "STANDING")
	init("honorBarTextLeftOffsetX", honorDefaults.textLeftOffsetX or 4)
	init("honorBarTextLeftOffsetY", honorDefaults.textLeftOffsetY or 0)
	init("honorBarTextCenterOffsetX", honorDefaults.textCenterOffsetX or 0)
	init("honorBarTextCenterOffsetY", honorDefaults.textCenterOffsetY or 0)
	init("honorBarTextRightOffsetX", honorDefaults.textRightOffsetX or -4)
	init("honorBarTextRightOffsetY", honorDefaults.textRightOffsetY or 0)
	init("honorBarTextSize", honorDefaults.textSize or 11)
	init("honorBarTextFont", honorDefaults.textFont or (addon.functions.GetGlobalFontConfigKey and addon.functions.GetGlobalFontConfigKey() or "__EQOL_GLOBAL_FONT__"))
	init("honorBarTextOutline", addon.functions.GetGlobalFontStyleConfigKey and addon.functions.GetGlobalFontStyleConfigKey() or "__EQOL_GLOBAL_FONT_STYLE__")
	init("honorBarTextColor", honorDefaults.textColor or { r = 1, g = 1, b = 1, a = 1 })
	init("honorBarTextAbbreviateNumbers", honorDefaults.abbreviateNumbers == true)
	init("honorBarHideInPetBattle", honorDefaults.hideInPetBattle == true)
	init("honorBarHideBlizzardTracking", honorDefaults.hideBlizzardTracking ~= false)

	if addon.Aura and addon.Aura.HonorBar and addon.Aura.HonorBar.OnSettingChanged then addon.Aura.HonorBar:OnSettingChanged(addon.db.honorBarEnabled) end
end

initResourceBarsDB()

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