local _, core = ...; -- Namespace


local L = nil
local LibBase64 = LibStub("LibBase64-1.0")
local AceSerializer = LibStub("AceSerializer-3.0")
local AceGUI = LibStub("AceGUI-3.0")

local Minimap = false



local addon = LibStub("AceAddon-3.0"):NewAddon("WITGuides", "AceConsole-3.0")
local bunnyLDB = LibStub("LibDataBroker-1.1"):NewDataObject("WITGuides!", {
    type = "data source",
    text = "WITGuides!",
    icon = "Interface\\AddOns\\WorthIt-Guides\\Images\\logo",
    OnTooltipShow = function(tooltip)
        tooltip:AddLine("WorthIt Guides")
    end,
    OnClick = function() 




		local function myChatEventHandler(self,event,arg1,...)
		  local filterFuncList = ChatFrame_GetMessageEventFilters(event)
		  if filterFuncList then
			for _, filterFunc in pairs(filterFuncList) do
			  local filter, newarg1 = filterFunc(self,event,arg1,...)
			  if filter then 
				return
			  end
			  if newarg1 then
				arg1 = "WTS"
			  
			  end
			end
		  end

		 
		end



		-- Dashboard Tab
		local function DrawGroup1(container)

		core.Dashboard(container)



		end

		-- Mounts Tab
		local function DrawGroup2(container)

		 core.Mounts(container)
		 
		end

		-- Reputations Tab
		local function DrawGroup3(container)

		 core.Reputations(container)
		 
		end

		-- GoldMaking Tab
		local function DrawGroup4(container)

		core.GoldMaking(container)

		end

		-- Explore Tab
		local function DrawGroup5(container)

		core.Explore(container)

		end

		-- Routes Tab
		local function DrawGroup6(container)

		core.Routes(container)

		end

		-- Professions Tab
		local function DrawGroup7(container)

		core.Professions(container)

		end

		-- Credits Tab
		local function DrawGroup8(container)

		core.Credits(container)

		end


		--[[ Create Tabs ]]--
		local function SelectGroup(container, event, group)
		   container:ReleaseChildren()
		   if group == "tab1" then
			  DrawGroup1(container)
		   elseif group == "tab2" then
			  DrawGroup2(container)
				 elseif group == "tab3" then
			  DrawGroup3(container)
				 elseif group == "tab4" then
			  DrawGroup4(container)
				 elseif group == "tab5" then
			  DrawGroup5(container)
				 elseif group == "tab6" then
			  DrawGroup6(container)
				 elseif group == "tab7" then
			  DrawGroup7(container)
				 elseif group == "tab8" then
			  DrawGroup8(container)
		   end
		end

		--[[ Create Frame ]]-- 
		local frame = AceGUI:Create("Frame")
		frame:SetTitle("WorthIt-Guides")
		frame:SetStatusText("|cff00C78CWorthIt-Guides")
		frame:SetWidth(400)
		frame:SetHeight(500)
		frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)

		frame:SetLayout("Fill")


		--[[
		local scrollcontainer = AceGUI:Create("SimpleGroup") 
		scrollcontainer:SetFullWidth(true)
		scrollcontainer:SetFullHeight(true) 
		scrollcontainer:SetLayout("Fill") 

		frame:AddChild(scrollcontainer)

		local scroll = AceGUI:Create("ScrollFrame")
		scroll:SetLayout("Fill") 
		scrollcontainer:AddChild(scroll)

		--]]



		local tab =  AceGUI:Create("TabGroup")
		tab:SetLayout("Flow")

		tab:SetTabs({{text='|TInterface\\Icons\\achievement_guildperk_hastyhearth:16|t '.."Dashboard", value="tab1"}, {text='|TInterface\\Icons\\ability_mount_spectraltiger:16|t '.."Mounts", value="tab2"}, {text='|TInterface\\Icons\\achievement_reputation_08:16|t '.."Reputations", value="tab3"}, {text='|TInterface\\Icons\\inv_misc_coin_01:16|t '.."Gold Making", value="tab4"}, {text='|TInterface\\Icons\\inv_misc_map02:16|t '.."Explore", value="tab5"}, {text='|TInterface\\Icons\\inv_misc_map06:16|t '.."Routes", value="tab6"}, {text='|TInterface\\Icons\\70_professions_scroll_02:16|t '.."Professions", value="tab7"}, {text='|TInterface\\Icons\\trade_engineering:16|t '.."Support", value="tab8"}})

		tab:SetCallback("OnGroupSelected", SelectGroup)

		tab:SelectTab("tab1")


		frame:AddChild(tab)







	end,
})
local icon = LibStub("LibDBIcon-1.0")


function addon.OnTooltipShow(tooltip)
    tooltip:AddLine("WorthIt Guides")
 
end


 
function addon:OnInitialize()
    
    self.db = LibStub("AceDB-3.0"):New("WITGuidesDB", {
        profile = {
            minimap = {
                hide = false,
            },
        },
    })
    icon:Register("WITGuides!", bunnyLDB, self.db.profile.minimap)
    self:RegisterChatCommand("WITGuides", "CommandTheBunnies")
end
 
function addon:CommandTheBunnies()
    self.db.profile.minimap.hide = not self.db.profile.minimap.hide
    if self.db.profile.minimap.hide then
        icon:Hide("WITGuides!")
    else
        icon:Show("WITGuides!")
    end
end