-- This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
-- To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
-- or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

local MereHealingFrames, privateVars = ...

MereHealingFrames.Config = MereHealingFrames.Config or {}
MereHealingFrames.Config.UI = MereHealingFrames.Config.UI or {}

function MereHealingFrames.Config.UI:new ()
	local this = {}
	this.initialized = false

	setmetatable(this, self)
	self.__index = self
	return this
end



function MereHealingFrames.Config.UI:CreateConfigUI()
	-- Ask the watchdog to be quiet:
	Command.System.Watchdog.Quiet()

	self.Config_Window = UI.CreateFrame("SimpleWindow", "Config_Window", MereHealingFrames.context)
	self.Config_Window:SetCloseButtonVisible(true)
	self.Config_Window:SetTitle("Mere Healing Frames, " .. MereHealingFrames.fetchVersion())
	self.Config_Window:SetPoint("CENTER", UIParent, "CENTER")
	self.Config_Window.Event.Close=function() MereHealingFrames.Config.UI.CloseWindow(self) end
	self.Config_Window:SetWidth(800)
	self.Config_Window:SetHeight(560)

	self.TabButtons = UI.CreateFrame("SimpleTabView", "Config_Tabs", self.Config_Window:GetContent())
	self.TabButtons:SetBackgroundColor(0,0,0,0.5)
	self.TabButtons:SetPoint("TOPLEFT", self.Config_Window:GetContent(), "TOPLEFT")
	self.TabButtons:SetPoint("BOTTOMRIGHT", self.Config_Window:GetContent(), "BOTTOMRIGHT")

	self.LayoutFrame = MereHealingFrames.Config.UI.Layouts:new()
	self.LayoutFrame:CreateUI(self.Config_Window:GetContent(), self.TabButtons)

	self.SpellsFrame = MereHealingFrames.Config.UI.Spells:new()
	self.SpellsFrame:CreateUI(self.Config_Window:GetContent())

	self.BuffsFrame = MereHealingFrames.Config.UI.Buffs:new()
	self.BuffsFrame:CreateUI(self.Config_Window:GetContent())

	self.SampleUnits = MereHealingFrames.Config.UI.SampleUnits:new(self.Config_Window:GetContent())

	self.TabButtons:AddTab("Spells", self.SpellsFrame:GetContent())
	self.TabButtons:AddTab("Buffs", self.BuffsFrame:GetContent())
	self.TabButtons:AddTab("Sample Units", self.SampleUnits:GetContent())

	--self.TabButtons:AddTab("Buffs", nil)

	--self.Config_Window.listScrollView = UI.CreateFrame("SimpleScrollView", "SWT_TestScrollView", SWT_Window:GetContent())
	self.initialized = true
end

function MereHealingFrames.Config.UI:CloseWindow()
	self.Config_Window:SetKeyFocus(true)
	self.Config_Window:SetKeyFocus(false)

	if self.LayoutFrame.layout then
		self.LayoutFrame.layout:SetConfiguring(false)
	end
end

function MereHealingFrames.Config.UI:RefreshSpells()
	if self.initialized then
		self.SpellsFrame:ReloadSpellSetList()
	end
end

function MereHealingFrames.Config.UI:Secure()
	if self.initialized then
		self.Config_Window:SetVisible(false)
	end
end

function MereHealingFrames.Config.UI:show()
	if Inspect.System.Secure() then
		print("You're in combat, unable to show the config UI")
		return
	end

	if self.initialized == false then
		self:CreateConfigUI()
	end

	self.Config_Window:SetVisible(true)
	if self.LayoutFrame.layout then
		self.LayoutFrame.layout:SetConfiguring(true)
	end
end