local addonName, addon = ...

local GUIHelpHeader = CreateFrame("Frame", GUIHelpHeader, UIParent)
GUIHelpHeader:SetHeight(40)
GUIHelpHeader:SetWidth(140)
GUIHelpHeader:SetPoint("RIGHT", UIParent, "RIGHT", -208, 0)
GUIHelpHeader:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
GUIHelpHeader:SetFrameStrata("DIALOG")
GUIHelpHeader:SetFrameLevel(3)
GUIHelpHeader:SetBackdrop{
	bgFile = "Interface\\AddOns\\GrimUI\\Media\\MainBG",
	edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
	tile = true,
	tileSize = 32,
	edgeSize = 32,
	insets = {
		left = 11,
		right = 12,
		top = 12,
		bottom = 11
	}
}
GUIHelpHeader:SetBackdropColor(0.09, 0.09, 0.09, 1)

GUIHelpHeader:SetMovable(true)
GUIHelpHeader:EnableMouse(true)
GUIHelpHeader:RegisterForDrag("LeftButton")
GUIHelpHeader:SetScript("OnDragStart", GUIHelpHeader.StartMoving)
GUIHelpHeader:SetScript("OnDragStop", GUIHelpHeader.StopMovingOrSizing)

local HeaderText = GUIHelpHeader:CreateFontString(nil, 'DIALOG')
HeaderText:SetFont([[Fonts\FRIZQT__.TTF]], 14)
HeaderText:SetText("GrimUI Help")
HeaderText:SetPoint("CENTER", GUIHelpHeader, "CENTER", 0, 0)
HeaderText:SetTextColor(.50, 1, .50, 1)

local GUIHelpFrame = CreateFrame("Frame", GUIHelpFrame, GUIHelpHeader)
GUIHelpFrame:SetHeight(450)
GUIHelpFrame:SetWidth(550)
GUIHelpFrame:SetPoint("TOP", GUIHelpHeader, "BOTTOM", 0, 18)
GUIHelpFrame:SetFrameStrata("DIALOG")
GUIHelpFrame:SetBackdrop{
	bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
	edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
	tile = true,
	tileSize = 32,
	edgeSize = 32,
	insets = {
		left = 11,
		right = 12,
		top = 12,
		bottom = 11
	}
}
GUIHelpFrame:SetFrameLevel(1)
	
local HelpClose = CreateFrame("Button", "HelpClose", GUIHelpFrame, "UIPanelButtonTemplate")
HelpClose:SetHeight(25)
HelpClose:SetWidth(65)
HelpClose:SetPoint("BOTTOMLEFT", 15, 15)
HelpClose:SetText("Close")
HelpClose:RegisterForClicks("AnyUp")
HelpClose:SetScript("OnClick", function(self)
	GUIHelpHeader:Hide()
	GrimUI.settings.HelpViewed = true
end)

local HelpHeaders = {
	--button name = bulk help text
	
	['Welcome'] = 'Welcome to GrimUI In-Game Help.  If this is your first time using GrimUI you may need to reload for all settings to take effect.\n\nIf your buttons do not appear please read the Buttons and Macaroon Topics.  If other elements of the UI appear to be out of place or sized wrong please make sure that you check "UI Scale" in the Blizzard Video Options on the Advanced tab and move the slider to its lowest setting.  If this does not fix things you may need to scale or move a few frames to attain your desired look.\n\nPlease read through the help topics before posting comments or bug reports.  Click on a topic to the left for more information.  Once you click the "Close" button on this window it will not open again on login for this character but you can always come back to it through the help button in the GrimUI Options.  To open the GrimUI Options right-click on the GrimUI Icon near the bottom right of the screen.',
	
	['General'] = 'Coming soon!',
	
	['Buttons'] = 'GrimUI will setup a default layout for Macaroon on your first install.  GrimUI does not control your action bars.  Upon the first install of GrimUI you will need to reload the UI for the GrimUI default Macaroon layout to take effect.\n\nMacaroon controls your main action bars, please read the section on Macaroon for more information.\n\nYou will find that GrimUI does control the GrimUI Context Menu (GCM).  The GCM is a bank of action buttons that can be opened through the right artwork HotPoint.  You can add spells or items to the GCM by simply dragging and dropping.  It will automatically swap when you swap talents.\n\nFor more on HotPoints please read the HotPoints Topic.\n\nNote: You can use any button addon you prefer. Macaroon is not required for GrimUI to work in full however a button addon of some sort is.', 
	
	['Macaroon'] = 'Macaroon is the only addon packaged with GrimUI.  It is my opinion that it is in fact the best action bar addon.  GrimUI should, on its first load, set up a general and very basic Macaroon layout.  If it does not or you do not like the way it looks or would just like to make it better type" /macaroon options" to bring back a list of slash options for Macaroon.  You can also find Macaroon in the Blizzard Options Addon tab along with GrimUI.\n\nThe GrimUI button also provides HotSpot support for Macaroon.  You can Ctrl+Left-Click the GrimUI button to toggle Macaroon binding mode or Ctrl+Right-Click to toggle Macaroon button editing mode.  Be aware that when first entering Macaroon  button editing and configure modes that you may not see anything until you mouse over a Macaroon button frame. \n\nFor more information on Macaroon please visit http://www.wowinterface.com/downloads/info10636-Macaroon.html',
	
	['HotPoints'] = 'The inside corners of the artwork are actually buttons or HotPoints.  If you put the mouse cursor over the corner you will see a ToolTip come up.  The ToolTips will show you what mouse buttons to click for each function.\n\nThe left HotPoint allows you to toggle Auto-Loot on and off, do a /roll and will show/hide the objectives frame.  Left-click will toggle Auto-Loot on and off, Right-click will /roll and Ctrl-Left-click will toggle the objectives frame.\n\nThe right HotPoint allows you to toggle the GrimUI Context Menu (GCM) on and off as well as show/hide the Combat Log. Left-click to toggle GCM and Right-click to show/hide the Combat Log.\n\nThe GrimUI button also serves as a HotPoint.  It will open the GrimUI options as well as show/hide the BackPack Bar.  If you are using Macaroon you will have two other options both for toggling Macaroon functions.  Mouse over the GrimUI button to see a ToolTip with all click functions.\n\nSee the Macaroon and GCM topics for more information on Macaroon and GCM.',
	
	['Frame Mover'] = 'With GrimUI any frame is moveable!  The GrimUI Frame Mover system allows you to move any frame by Ctrl+Left-Clicking it and dragging it anywhere you want.  Its new location will be remembered and thats where it will appear from then on.\n\nMany frames are registered with the system by default.  New frames can be added to the Frame Mover System by going to the GrimUI options and then to the Frame Mover Tab.  To add a frame type its name into the edit box followed by true/false or another frames name.  True means that rather then move that frame when it is Ctrl+Left-Clicked on, it will move the parent frame.  False means that frame itself will be moved and no other frames.  When you enter a second frame name instead of true or false, when you Ctrl+Left-Click on the first frame entered it will move the second frame name entered.\n\nYou can remove frames from the Frame Mover System by click on the check box next to its name in the list on the GrimUI Options Frame Mover tab\n\nYou can click on the FrameStack button to bring up FrameStack reporting to find out the name of a frame.\n\nYou can reset the frame positions by clicking the Reset Frames button.\n\nYou can use the "Lock Frames" option on the General Tab of the GrimUI Options to stop all Frame Mover activity.  Sometimes this is useful if a frame has other Ctrl+Left-Click functions.  You can lock the frames and then register them for Ctrl+Left-Click with the addon Clique if you are using that.',
	
	['Chat'] = 'GrimUI does a number of things with the chat frames.  First it takes and separates them into three windows.  The main chat window, the Combat Log and the "info log".  It hides the tabs for the info log and the Combat Log so that it looks nicer.  You can toggle these tabs on and off through the GrimUI Options in case you need to change settings on these windows for any reason.\n\nThe main chat window is also separated via chat window tabs.  A tab for normal or general chat messages, a tab for guild chat, a tab for whispers and of course a tab for trade/looking for group channel\n\nThe Combat Log which is on the far right displays combat data.  It can be toggled between shown and hidden through the Right HotPoint button.  It can also be toggled through the GrimUI Options.   I recommend putting Omen Threat Meter or any other meter in this same location and you can hide the Combat Log on the fly with the HotPoint button and see the meter behind it.\n\nThe info log shows reputation, experience and loot information.\n\nIf you decide you do not like the way the chat windows are setup you can Right-click on any of the chat tabs and select "Reset Chat Windows" from the drop-down menu to revert to the Blizzard Default.  At any time you can have GrimUI set the windows back to the GrimUI Default layout by clicking the "Chat Reset" button on the chat tab in the GrimUI Options. ',
	
	['GCM'] = 'The GrimUI Context Menu (GCM) is a small square bank of buttons that is attached to the Right HotPoint button.  All you have to do is Left-Click the HotPoint and GCM will open up, even works in combat.  It works just like any other action button.  You can drag spells or items to the slots to use them.  It automatically switches buttons when you switch talents.  GCM may conflict with some button addons.  It does however function without conflict with Macaroon and AutoBar.\n\nMore features and less conflicts coming soon!',
	
	['Tooltips'] = 'Coming soon!',
	
	['Unit Frames'] = 'Coming soon!',
	
	['Inventory'] = 'GrimUI does not do much with your inventory.  I recommend using Baggins as your inventory addon.  The GrimUI Dashboard has support for Baggins so when you click the inventory button Baggins opens.  If you do not want to use an inventory addon, GrimUI will position your bags so that they do not appear over the artwork.  They are also attached by default to the GrimUI Frame Mover system and can be moved anywhere by pressing Ctrl+Left-Click.  Macaroon also has inventory options.\n\nFor more on Macaroon or the GrimUI Frame Mover system please see the related topics.',
	
	['DashBoard'] = 'Coming soon!',
	
	['HUD'] = 'GrimUI comes with its own built in Heads Up Display (HUD).  You can turn on or off the GrimUI HUD in the GrimUI options.  You can also adjust its distance from left to right and top to bottom.  You can also adjust its scale.\n\nMore features coming soon!',
	
	['Development'] = 'GrimUI comes with a few tools for developers.  The GrimUI "Dev Bar" has three buttons on it.  A easy access Reload button, a button for toggling FrameStack reporting and a button to print GrimUI memory usage Info.\n\nYou can toggle the Dev Bar on and off in the GrimUI Options. You will also find two more options there for development, one returns and prints the Blizzard Build Info and the other toggles taint logging.  Toggling taint logging may require a reload in order for it to take effect.',
}

local LeftScrollBar = CreateFrame("Frame", "LeftScrollBar", GUIHelpFrame)
LeftScrollBar:SetPoint("TOPLEFT", GUIHelpFrame, "TOPLEFT", 0, 0)
LeftScrollBar:SetHeight("420")
LeftScrollBar:SetWidth("160")

LeftScrollBar.scrollSize = 600
LeftScrollBar.scrollFrame = CreateFrame( "ScrollFrame", "$parent_ScrollFrame", LeftScrollBar, "UIPanelScrollFrameTemplate" );
LeftScrollBar.scrollFrame:SetHeight(LeftScrollBar:GetHeight())
LeftScrollBar.scrollBar = _G[LeftScrollBar.scrollFrame:GetName() .. "ScrollBar"];
LeftScrollBar.scrollFrame:SetWidth( LeftScrollBar:GetWidth());
LeftScrollBar.scrollFrame:SetPoint( "TOPLEFT", 10, -30 );
LeftScrollBar.scrollFrame:SetPoint( "BOTTOMRIGHT", -30, 10 );

LeftScrollBar.scrollChild = CreateFrame( "Frame", "$parent_ScrollChild", LeftScrollBar.scrollFrame );
LeftScrollBar.scrollChild:SetHeight( LeftScrollBar.scrollSize );
LeftScrollBar.scrollChild:SetWidth( LeftScrollBar.scrollFrame:GetWidth() );
LeftScrollBar.scrollChild:SetAllPoints( LeftScrollBar.scrollFrame );
LeftScrollBar.scrollFrame:SetScrollChild( LeftScrollBar.scrollChild );

local RightScrollBar = CreateFrame("Frame", "RightScrollBar", GUIHelpFrame)
RightScrollBar:SetPoint("TOPRIGHT", GUIHelpFrame, "TOPRIGHT", -50, 0)
RightScrollBar:SetHeight("440")
RightScrollBar:SetWidth("380")
RightScrollBar.scrollSize = 600

RightScrollBar.scrollFrame = CreateFrame( "ScrollFrame", "$parent_ScrollFrame", RightScrollBar, "UIPanelScrollFrameTemplate" );
RightScrollBar.scrollFrame:SetHeight(RightScrollBar:GetHeight())
RightScrollBar.scrollBar = _G[RightScrollBar.scrollFrame:GetName() .. "ScrollBar"];
RightScrollBar.scrollFrame:SetWidth( RightScrollBar:GetWidth());
RightScrollBar.scrollFrame:SetPoint( "TOPRIGHT", 10, -30 );
RightScrollBar.scrollFrame:SetPoint( "BOTTOMRIGHT", -30, 10 );

RightScrollBar.scrollChild = CreateFrame( "Frame", "$parent_ScrollChild", RightScrollBar.scrollFrame );
RightScrollBar.scrollChild:SetHeight( RightScrollBar.scrollSize );
RightScrollBar.scrollChild:SetWidth( RightScrollBar.scrollFrame:GetWidth() );
RightScrollBar.scrollChild:SetAllPoints( RightScrollBar.scrollFrame );
RightScrollBar.scrollFrame:SetScrollChild( RightScrollBar.scrollChild );

RightScrollBar.scrollChild.text = RightScrollBar.scrollChild:CreateFontString("BulkHelpText", 'DIALOG')
RightScrollBar.scrollChild.text:SetFont([[Fonts\FRIZQT__.TTF]], 13)
RightScrollBar.scrollChild.text:SetPoint("TOPLEFT", RightScrollBar.scrollChild, "TOPLEFT", 30, 0)
RightScrollBar.scrollChild.text:SetWidth(350)
RightScrollBar.scrollChild.text:SetText(HelpHeaders.Welcome)
RightScrollBar.scrollChild.text:SetTextColor(1, 1, 0, 1)
RightScrollBar.scrollChild.text:SetJustifyH("LEFT")

local anchorFrame, anchorPoint = LeftScrollBar.scrollChild, 'TOP'
for name,caption in pairs(HelpHeaders) do
	LeftScrollBar.scrollChild.button = LeftScrollBar.scrollChild.button or {}
	LeftScrollBar.scrollChild.button[name] = CreateFrame('button', "HHeaderButton" .. name, LeftScrollBar.scrollChild)
	LeftScrollBar.scrollChild.button[name]:SetHeight(15)
	LeftScrollBar.scrollChild.button[name]:SetWidth(90)
	LeftScrollBar.scrollChild.button[name]:RegisterForClicks("AnyUp")
	
	LeftScrollBar.scrollChild.button[name].text = LeftScrollBar.scrollChild.button[name]:CreateFontString("HHeaderButtonText" .. name, 'DIALOG')
	LeftScrollBar.scrollChild.button[name].text:SetFont([[Fonts\FRIZQT__.TTF]], 14)
	LeftScrollBar.scrollChild.button[name].text:SetPoint("CENTER", LeftScrollBar.scrollChild.button[name], "CENTER", 0, 0)
	LeftScrollBar.scrollChild.button[name].text:SetTextColor(.50, 1, .50, 1)
	
	
	LeftScrollBar.scrollChild.button[name]:SetScript('OnEnter', function()
		LeftScrollBar.scrollChild.button[name].text:SetTextColor(.80, .50, .30, 1)
	end)

	LeftScrollBar.scrollChild.button[name]:SetScript('OnLeave', function()
		LeftScrollBar.scrollChild.button[name].text:SetTextColor(.50, 1, .50, 1)
	end)
	LeftScrollBar.scrollChild.button[name]:SetScript('OnClick', function()
		RightScrollBar.scrollChild.text:SetText(caption)
	end)
	
	LeftScrollBar.scrollChild.button[name]:SetPoint("LEFT", LeftScrollBar.scrollChild, "LEFT", 15, 0)


	LeftScrollBar.scrollChild.button[name].text:SetText(name)
	
	local buttons = LeftScrollBar.scrollChild.button[name]
	
	buttons:SetPoint('TOP', anchorFrame, anchorPoint, 0, -7)
	
	anchorFrame, anchorPoint = buttons, 'BOTTOM'
	
end

GUIHelpHeader:Hide()

function GUI_HelpInitiate()
	if GUIHelpHeader:IsVisible() then 
		GUIHelpHeader:Hide()
	else
		GUIHelpHeader:Show()
	end
end