-- ==================================================================================================================== --
--															--
--	File			Menus.lua										--
--															--
--															--
--	Author			Zarnivoop						| Basis, thx	|		--
--															--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	  17718 |	--
--										| Wago-ID	   :   Q6aEVa6W |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--				Baltha							| Revision	|		--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	1188318 |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--										| Initial Version  : 2024-11-18 |	--
--										| Current Version  : 2026-04-22 |	--
--										|		   : Release	|	--
--															--
--															--
--	Path ( Revision )	"..\World of Warcraft\_retail_\Interface\AddOns\Skada\Misc\Changelog\ChangeLog.txt"	--
--															--
-- ==================================================================================================================== --


local _, Skada	   = ...


local L		   = LibStub("AceLocale-3.0"):GetLocale("Skada", true)
local AceGUI	   = LibStub("AceGUI-3.0")


local MenuVariants = MenuVariants or {}


local blankChars1  = string.rep(" ", 2)
local blankChars2  = string.rep(" ", 4)
local blankChars3  = string.rep(" ", 6)


-- =================
-- | menu: general |
-- =================
local mSize	  = 16
local mTexture	  = "GameFontNormalSmall"


-- ====================================
-- | menu: necessary global variables |
-- ====================================
simulationEnabled = false


-- =========================================
-- | skada windows: implementation counter |
-- =========================================
local function CountWindows(elements, names)
 
	if #SkadaLogNameAndSort == 0 then

		for i = 1, elements do

			table.insert(SkadaLogNameAndSort, i, names[i] .. ":" .. "Alphabetical")
		end
	end


	-- ===============================
	-- | sort: insert/delete entries |
	-- ===============================
	if #SkadaLogNameAndSort > 0 then

		for i = 1, elements do

			table.insert(SkadaLogNameAndSort, SkadaLogNameAndSort[i])


			for j = #CurrentSkadaNames + 1, #SkadaLogNameAndSort do

				table.remove(SkadaLogNameAndSort, j)
			end
		end
	end
end




-- =================================================
-- | context menu: implementation helper functions |
-- =================================================
local function mTitle(getDescription, getText)

	local Title = getDescription:CreateTitle(getText)


	Title:AddInitializer(function(title, description, menu)

				     title.fontString:SetFontObject(mTexture)
				     title.fontString:SetHeight(mSize)
			     end

			    )

	return
end




local function mButton(getDescription, getText, getFunction)

	local Button = getDescription:CreateButton(getText, getFunction)


	Button:AddInitializer(function(button, description, menu)

				      button.fontString:SetFontObject(mTexture)
				      button.fontString:SetHeight(mSize)

			      end

			     )

	return
end




-- ==============================================================================================
-- | context menu implementation: Blizzard_Menu (new framework), replacement for UIDropDownMenu	|
-- ==============================================================================================
function Skada:OpenMenu(window)

	if not self.skadamenu then self.skadamenu = CreateFrame("Frame", "SkadaMenu") end


	-- ======================
	-- | generator function |
	-- ======================
	local function GeneratorFunction(owner, rootDescription)


		-- =============================
		-- | top level 00: contextmenu |
		-- =============================
		mTitle(rootDescription, L["Skada Menu"])


			-- =========================
			-- | sub level 01: general |
			-- =========================
			mTitle(rootDescription, blankChars1 .. L["General"])


				-- =======================================
				-- | sub level 01-01: configuration menu |
				-- =======================================
				mInfo	   = {}
				mInfo.func = function()

						     Skada:OpenOptions(window)
					     end
				mInfo.text = blankChars2 .. L["Configure"]

				mButton(rootDescription, mInfo.text, mInfo.func)


				-- =========================================
				-- | sub level 01-02: close dropdown menus |
				-- =========================================
				mInfo	   = {}
				mInfo.func = function()

						     CloseDropDownMenus()
					     end
				mInfo.text = blankChars2 .. CLOSE

				mButton(rootDescription, mInfo.text, mInfo.func)


			-- ========================
			-- | sub level 02: report |
			-- ========================
			mTitle(rootDescription, blankChars1 .. L["Report"])


				-- ================================
				-- | sub level 02-01: open report |
				-- ================================
				if not window or (window and window.selectedmode) then

					mInfo	   = {}
					mInfo.func = function()

							     Skada:OpenReportWindow(window)
						     end
					mInfo.text = blankChars2 .. L["Report"]

					mButton(rootDescription, mInfo.text, mInfo.func)
				end


			-- ========================================
			-- [  sub level 03: show player button(s) |
			-- ========================================
			mTitle(rootDescription, blankChars1 .. L["Window"])


			for i, win in ipairs(Skada:GetWindows()) do

				if i == 1 then CurrentSkadaNames = {} end


				CurrentSkadaNames[i] = win.db.name
				CurrentSkadaWindows  = i
			end


			CountWindows(CurrentSkadaWindows, CurrentSkadaNames)


			currentSkadaNameAndTypes = {}


			for k, win in ipairs(Skada:GetWindows()) do

				csnt = win.db.display .. ":" .. win.db.name
				
				table.insert(currentSkadaNameAndTypes, csnt)
			end


			Skada:CurrentSort(currentSkadaNameAndTypes, "CSK")


			local barIndex    = 0
			local brokerIndex = 0


			for l, csnt in ipairs(currentSkadaNameAndTypes) do

				for i, win in ipairs(Skada:GetWindows()) do

					if win.db.display .. ":" .. win.db.name == csnt then

						local currentChecked = false


						if win.db.display == "bar" and barIndex == 0 then

							mTitle(rootDescription, blankChars2 .. L["Bar"])
							barIndex    = 1
						end


						if win.db.display == "broker" and brokerIndex == 0 then

							mTitle(rootDescription, blankChars2 .. L["Data text"])
							brokerIndex = 1
						end


						if i == 1 then SkadaWindowsNames = {} end


						mInfo		     = {}
						mInfo.text	     = blankChars3 .. win.db.name
						mInfo.value	     = win


						SkadaWindowsNames[i] = win.db.name


						submenu	= rootDescription:CreateButton(mInfo.text)


						submenu:AddInitializer(function(button, description, menu)

									       button.fontString:SetFontObject(mTexture)
									       button.fontString:SetHeight(mSize)

									       arrow = MenuVariants.CreateSubmenuArrow(button)
								       end

								      )


						local window	     = mInfo.value


						-- =====================================================
						-- | sub level 03-11: entries mode button alphabetical |
						-- =====================================================
						if SkadaLogNameAndSort[i] == SkadaWindowsNames[i] .. ":" .. "Alphabetical" then

							-- ======================
							-- | sort: alphabetical |
							-- ======================
							local alpSortFlag  = false
							local alphabetical = {}


							for j, module in ipairs(Skada:GetModes()) do

								if module:GetName() == L["Overhealing"] then alpSortFlag = true end


								table.insert(alphabetical, module)
							end


							Skada:CurrentSort(alphabetical, "ALP")


							-- ===============================
							-- | german vowel mutation [ Ü ] |
							-- ===============================
							if GetLocale() == "deDE" and alpSortFlag then

									table.insert(alphabetical, alphabetical[#alphabetical - 1])
									table.remove(alphabetical, #alphabetical - 2)
							end


							for j, module in ipairs(alphabetical) do

								if j == 1 then

									mInfo	   = {}
									mInfo.text = blankChars2 .. L["Click:"] .. blankChars1 .. "\124cFF00FF00" .. L["Alphabetical"] .. " -> " .. L["Categorized"]
									mInfo.func = function()


												-- ===========================================================================
												-- | if using this button, the current Skada-Frames switch to "Categorized". |
												-- ===========================================================================
												if "LeftButton" then

													SkadaLogNameAndSort[i] = SkadaWindowsNames[i] .. ":" .. "Categorized"
												else

													SkadaLogNameAndSort[i] = SkadaWindowsNames[i] .. ":" .. "Alphabetical"
												end


												-- ===========================
												-- | last sorting entry only |
												-- ===========================
												table.insert(SkadaLogNameAndSort, SkadaLogNameAndSort[i])


												for j = #CurrentSkadaNames + 1, #SkadaLogNameAndSort do

													table.remove(SkadaLogNameAndSort, j)
												end										
										     end


									mTitle(submenu, L["Mode"] .. " - "  .. L["Alphabetical"])
									mButton(submenu, mInfo.text, mInfo.func)
									mTitle(submenu, "")
								end


								mInfo	      = {}
								mInfo.text    = blankChars2 .. module:GetName()
								mInfo.func    = function()

											window:DisplayMode(module)
										end
								mInfo.checked = (window.selectedmode == module)

								if mInfo.checked then mInfo.text = "\124cFF00FF00" .. mInfo.text end

								mButton(submenu, mInfo.text, mInfo.func)
							end
						end


						-- ====================================================
						-- | sub level 03-12: entries mode button categorized |
						-- ====================================================				
						if SkadaLogNameAndSort[i] == SkadaWindowsNames[i] .. ":" .. "Categorized" then


							-- =====================
							-- | sort: categorized |
							-- =====================
							local catSortFlag = false
							local categorized = {}


							for j, module in ipairs(Skada:GetModes()) do

								if module:GetName() == L["Overhealing"] then catSortFlag = true end


								table.insert(categorized, module)
							end


							Skada:CurrentSort(categorized, "CAT")


							-- ===============================
							-- | german vowel mutation [ Ü ] |
							-- ===============================
							if GetLocale() == "deDE" and catSortFlag then

									table.insert(categorized, categorized[#categorized - 1])
									table.remove(categorized, #categorized - 2)
							end

							local lastcat = nil


							for j, module in ipairs(categorized) do

								if j == 1 then

									mInfo	   = {}
									mInfo.text = blankChars2 .. L["Click"] .. "\124cFF00FF00" .. L["Categorized"] .. " -> " .. L["Alphabetical"]
									mInfo.func = function()

												-- ========================================================================
												-- | if using this button, current Skada-Frames switch to "Alphabetical". |
												-- ========================================================================
												if "LeftButton" then

													SkadaLogNameAndSort[i] = SkadaWindowsNames[i] .. ":" .. "Alphabetical"
												else

													SkadaLogNameAndSort    = SkadaWindowsNames[i] .. ":" .. "Categorized"
												end


												-- ===========================
												-- | last sorting entry only |
												-- ===========================
												table.insert(SkadaLogNameAndSort, SkadaLogNameAndSort[i])


												for j = #CurrentSkadaNames + 1, #SkadaLogNameAndSort do

													table.remove(SkadaLogNameAndSort, j)
												end
										     end


									mTitle(submenu, L["Mode"] .. " - " .. L["Categorized"])
									mButton(submenu, mInfo.text, mInfo.func)
									mTitle(submenu, "")
								end


								if not lastcat or lastcat ~= module.category then

									mInfo	   = {}
									mInfo.text = module.category

									mTitle(submenu, blankChars2 .. mInfo.text)


									lastcat	   = module.category
								end


								mInfo	      = {}
								mInfo.text    = blankChars3 .. module:GetName()
								mInfo.func    = function()

											window:DisplayMode(module)
										end
								mInfo.checked = (window.selectedmode == module)

								if mInfo.checked then mInfo.text = "\124cFF00FF00" .. mInfo.text end

								mButton(submenu, mInfo.text, mInfo.func)
							end
						end


						-- ====================================
						-- | sub level 03-20: entries windows |
						-- ====================================
						mTitle(submenu, L["Window"])


							-- =======================================
							-- | sub level 03-21: hide selected mode |
							-- =======================================
							mInfo	      = {}
							mInfo.func    = function()

										if window:IsShown() then

											window.db.hidden = true
											window:Hide()
										else

											window.db.hidden = false
											window:Show()
										end
									end
							mInfo.text    = blankChars2 .. L["Hide window"]
							mInfo.checked = not window:IsShown()

							if mInfo.checked then mInfo.text = "\124cFFFF0000" .. mInfo.text end

							mButton(submenu, mInfo.text, mInfo.func)


							-- =======================================
							-- | sub level 03-22: lock selected mode |
							-- =======================================
							mInfo	      = {}
							mInfo.text    = blankChars2 .. L["Lock window"]
							mInfo.func    = function()

										window.db.barslocked = not window.db.barslocked
										Skada:ApplySettings()
									end
							mInfo.checked = window.db.barslocked

							if mInfo.checked then

								mInfo.text = "\124cFF00FF00" .. mInfo.text
							else

								mInfo.text = "\124cFFFF0000" .. mInfo.text
							end

							mButton(submenu, mInfo.text, mInfo.func)


						-- ====================================
						-- | sub level 03-30: entries segment |
						-- ====================================
						mTitle(submenu, L["Segment"])

							-- =================================
							-- | sub level 03-31: current mode |
							-- =================================
							mInfo	      = {}
							mInfo.text    = blankChars2 .. L["Current"]
							mInfo.func    = function()

										window.selectedset = "current"


										Skada:Wipe()
										Skada:UpdateDisplay(true)
									end
							mInfo.checked = (window.selectedset == "current")

							if mInfo.checked then mInfo.text = "\124cFF00FF00" .. mInfo.text end

							mButton(submenu, mInfo.text, mInfo.func)


							-- ===============================
							-- | sub level 03-32: total mode |
							-- ===============================
							mInfo	      = {}
							mInfo.text    = blankChars2 .. L["Total"]
							mInfo.func    = function()

										window.selectedset = "total"


										Skada:Wipe()
										Skada:UpdateDisplay(true)
									end
							mInfo.checked = (window.selectedset == "total")

							if mInfo.checked then mInfo.text = "\124cFF00FF00" .. mInfo.text end

							mButton(submenu, mInfo.text, mInfo.func)
					end
				end
			end


			-- ===============================================
			-- | sub level window(s) 04-01: other		 |
			-- ===============================================
			mTitle(rootDescription, blankChars2 .. L["Other"])


			-- ===============================================
			-- | sub level window(s) 04-02: toggle window(s) |
			-- ===============================================
			mInfo		   = {}
			mInfo.func	   = function()

						     Skada:ToggleWindow()
					     end
			mInfo.text	   = blankChars3 .. L["Toggle window"]

			mButton(rootDescription, mInfo.text, mInfo.func)


			-- ==============================================
			-- | sub level window(s) 04-03: reset window(s) |
			-- ==============================================
			mInfo		   = {}
			mInfo.func	   = function()

						     Skada:Reset()
					     end
			mInfo.text	   = blankChars3 .. L["Reset"]

			mButton(rootDescription, mInfo.text, mInfo.func)


			-- =====================================
			-- | sub level 05-01: entry Simulation |
			-- =====================================
			mTitle(rootDescription, blankChars1 .. L["Simulation"])

			mInfo		   = {}
			mInfo.text	   = blankChars2 .. L["Simulation Mode"]
			mInfo.func	   = function()

						     if Skada.Simulation then

							     Skada.Simulation:SetEnabled(not Skada.Simulation.active)
						     end


						     if "LeftButton" then

							     simulationEnabled = not simulationEnabled
						     end
					     end	


			if     simulationEnabled then mInfo.text = "\124cFF00FF00" .. mInfo.text end
			if not simulationEnabled then mInfo.text = "\124r"	   .. mInfo.text end

			mButton(rootDescription, mInfo.text, mInfo.func)

	end

	-- =====================================
	-- | menu utility: create context menu |
	-- =====================================
	MenuUtil.CreateContextMenu(UIParent, GeneratorFunction)

		local skadamenu	      = self.skadamenu


		skadamenu.displayMode = "MENU"
		skadamenu.initialize  = function(self)
	end
end




function Skada:OpenReportWindow(window)

	if InCombatLockdown() then

		Skada:CurrentTooltip("RCP", "", "", "")


		return
	end


	if self.ReportWindow == nil then self:CreateReportWindow(window) end


	self.ReportWindow:Show()
end




local function destroywindow()

	if Skada.ReportWindow then

		local frame	     = Skada.ReportWindow


		frame.LayoutFinished = frame.orig_LayoutFinished

		frame.frame:SetScript("OnKeyDown", nil)
		frame.frame:EnableKeyboard(false)
		frame.frame:SetPropagateKeyboardInput(false)

		frame:ReleaseChildren()
		frame:Release()
	end


	Skada.ReportWindow = nil
end




function Skada:CreateReportWindow(window)

	local locale = GetLocale()


		    labelButton	=

				{

					"\124cnWHITE_FONT_COLOR:" .. L["Click"] .. "\124cFF00FF00" .. L["Alphabetical"] .. " -> " .. L["Categorized"],
					"\124cnWHITE_FONT_COLOR:" .. L["Click"] .. "\124cFF00FF00" .. L["Categorized"]  .. " -> " .. L["Alphabetical"]

				}


	self.ReportWindow = AceGUI:Create("Window")


	local frame	  = self.ReportWindow


	frame:EnableResize(false)
	frame:SetWidth(250)
	frame:SetLayout("List")

	frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
	frame.frame:SetClampedToScreen(true)

	frame.orig_LayoutFinished = frame.LayoutFinished
	frame.LayoutFinished	  = function(self, _, height) frame:SetHeight(height + 57) end

	frame.frame:EnableKeyboard(true)
	frame.frame:SetPropagateKeyboardInput(true)

	frame:SetTitle(L["Report"])
	frame:SetCallback("OnClose", function(widget, callback) destroywindow() end)


	ReportModulesSort = ReportModulesSort   or ""
	ReportChannelSort = ReportChannelSort or ""


	-- ==================================
	-- | mode: alphabetical/categorized |
	-- ==================================
	local modeLabel = AceGUI:Create("Label")

		do
			if ReportModulesSort == "" then

				ReportModulesSort = "ALP"
				modeLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Mode"] .. " - " .. L["Alphabetical"])
			else

				if ReportModulesSort == "ALP" then modeLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Mode"] .. " - " .. L["Alphabetical"]) end
				if ReportModulesSort == "CAT" then modeLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Mode"] .. " - " .. L["Categorized"])  end
			end
		end


	frame:AddChild(modeLabel)


	local modeButton = AceGUI:Create("Button")

	modeButton:SetWidth(230)
	modeButton:SetHeight(20)


	if ReportModulesSort == "ALP" then modeButton:SetText(labelButton[1])	end
	if ReportModulesSort == "CAT" then modeButton:SetText(labelButton[2])	end


	local modeDropdown     = AceGUI:Create("Dropdown")


	local msaModulTable = {}
	local mscModulTable = {}


	msaNameTable	    = {}
	mscNameTable	    = {}


	local sortTable	    = {}
	local cachedRMS     = ReportModulesSort


	modeDropdown:SetList(sortTable)
	modeDropdown:SetWidth(226)


	for i, mode in ipairs(Skada:GetModes()) do

		modeDropdown:AddItem(mode:GetName(), blankChars2 .. mode:GetName())

		table.insert(msaModulTable, mode)
		table.insert(mscModulTable, mode)
	end


	if ReportModulesSort == "CAT" then

		if locale == "deDE" then

			modeDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Healing"])
 			modeDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Damage"])
			modeDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Other"])
		end


		if locale == "enUS" then

			modeDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Damage"])
			modeDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Healing"])
			modeDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Other"])
		end
	end


	Skada:CurrentSort(msaModulTable, "ALP")
	Skada:CurrentSort(mscModulTable, "CAT")


	if #msaNameTable == 0 then

		for i, mode in ipairs(msaModulTable) do

			table.insert(msaNameTable, mode:GetName())
		end
	end


	if #mscNameTable == 0 then

		for i, mode in ipairs(mscModulTable) do

			table.insert(mscNameTable, mode:GetName())
		end


		if locale == "deDE" then

			table.insert(mscNameTable, 1, "dividingLineA")
			table.insert(mscNameTable, 4, "dividingLineB")
			table.insert(mscNameTable, 7, "dividingLineC")
		end


		if locale == "enUS" then

			table.insert(mscNameTable,  1, "dividingLineA")
			table.insert(mscNameTable,  4, "dividingLineB")
			table.insert(mscNameTable,  7, "dividingLineC")
		end

	end


	if cachedRMS then

		if ReportModulesSort == "ALP" then modeDropdown:SetList(sortTable, msaNameTable) end
		if ReportModulesSort == "CAT" then modeDropdown:SetList(sortTable, mscNameTable) end
	end


	modeButton:SetCallback("OnClick",

					function()

						if ReportModulesSort == "ALP" then

							modeLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Mode"] .. " - " .. L["Categorized"])


							if locale == "deDE" then

								modeDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Healing"])
								modeDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Damage"])
								modeDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Other"])
							end


							if locale == "enUS" then

								modeDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Damage"])
								modeDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Healing"])
								modeDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Other"])
							end


							ReportModulesSort = "CAT"

							modeButton:SetText(labelButton[2])
							modeDropdown:SetList(sortTable, mscNameTable)
						else

							modeLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Mode"] .. " - " .. L["Alphabetical"])


							ReportModulesSort = "ALP"

							modeButton:SetText(labelButton[1])
							modeDropdown:SetList(sortTable, msaNameTable)
						end


						return
					end

			      )


	frame:AddChild(modeButton)


	modeDropdown:SetCallback("OnEnter",

					function()

						modeDropdown:SetItemDisabled("dividingLineA", true)
						modeDropdown:SetItemDisabled("dividingLineB", true)
						modeDropdown:SetItemDisabled("dividingLineC", true)
					end

				)


	modeDropdown:SetCallback("OnValueChanged",

					function(f, e, value)

						Skada.db.profile.report.mode = value
					end

				)


	modeDropdown:SetValue(Skada.db.profile.report.mode or Skada:GetSets()[1])


	frame:AddChild(modeDropdown)


	-- ===========================================================================
	-- | segement: current/total - blank line - (other) last in first out [LIFO] |
	-- ===========================================================================
	local segmentDropdown = AceGUI:Create("Dropdown")

	segmentDropdown:SetLabel(blankChars1 .. L["Segment"])


	segmentDropdown:SetList({current = blankChars2 .. L["Current"], total = blankChars2 .. L["Total"], vanishingEntry = blankChars2 .. " " })
	segmentDropdown:SetWidth(226)


	for i, set in ipairs(Skada:GetSets()) do

		segmentDropdown:AddItem(i, blankChars2 .. Skada:GetSetLabel(set))
	end


	segmentDropdown:SetCallback("OnValueChanged",

					function(f, e, value)

						Skada.db.profile.report.set = value

					end

				   )



	segmentDropdown:SetValue(Skada.db.profile.report.set or Skada:GetSets()[1])


	frame:AddChild(segmentDropdown)


	-- =====================================
	-- | channel: alphabetical/categorized |
	-- =====================================
	local channellist =

		{

			whisper	      = { L["Whisper"]		 , "whisper", true }	,
			target	      = { L["Whisper Target"]	 , "whisper"	   }	,
			say	      = { L["Say"]		 , "preset"	   }	,
			raid	      = { L["Raid"]		 , "preset"	   }	,
			party	      = { L["Party"]		 , "preset"	   }	,
			instance_chat = { L["Instance"]		 , "preset"	   }	,
			guild	      = { L["Guild"]		 , "preset"	   }	,
			officer	      = { L["Officer"]		 , "preset"	   }	,
			self	      = { L["Self"]		 , "self"	   }

		}


	local list = {GetChannelList()}


	for i=1, #list, 3 do

		local chan = list[i+1]


		if chan ~= "Trade" and chan ~= "General" and chan ~= "LocalDefense" and chan ~= "LookingForGroup" then

			channellist[chan] = {("%s: %d/%s"):format(L["Channel"], list[i], chan), "channel"}
		end
	end


	local channelLabel = AceGUI:Create("Label")

		do

			if ReportChannelSort == "" then

				ReportChannelSort = "CSA"
				channelLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Channel"] .. " - " .. L["Alphabetical"])
			else

				if ReportChannelSort == "CSA" then channelLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Channel"] .. " - " .. L["Alphabetical"]) end
				if ReportChannelSort == "CSC" then channelLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Channel"] .. " - " .. L["Categorized"])  end
			end

		end


	frame:AddChild(channelLabel)


	local channelButton   = AceGUI:Create("Button")


	channelButton:SetWidth(230)
	channelButton:SetHeight(20)


	local channelDropdown = AceGUI:Create("Dropdown")

	local csaChannelTable = {}
	local cscChannelTable = {}

	local sortTable	      = {}

	csaNameTable	      = {}
	cscNameTable	      = {}
	csaKindTable	      = {}


	local cachedReportChannelSort = ReportChannelSort


	if ReportChannelSort == "CSA" then channelButton:SetText(labelButton[1]) end
	if ReportChannelSort == "CSC" then channelButton:SetText(labelButton[2]) end


	channelDropdown:SetList(sortTable)

	channelDropdown:SetWidth(226)


	for i, kind in pairs(channellist) do

		table.insert(csaChannelTable, kind[1])
		table.insert(cscChannelTable, kind[1])
	end


	if ReportChannelSort == "CSA" then

		for i = 1, #csaChannelTable do

			for chan, kind in pairs(channellist) do

				if csaChannelTable[i] == kind[1] then

					channelDropdown:AddItem(chan, blankChars2 .. kind[1])
					break
				end
			end
		end


		channelDropdown:AddItem("dividingLineG", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Targets"])
		channelDropdown:AddItem("dividingLineH", "")
		channelDropdown:AddItem("dividingLineI", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Other"])
	end


	if ReportChannelSort == "CSC" then

		for i = 1, #cscChannelTable do

			for chan, kind in pairs(channellist) do

				if cscChannelTable[i] == kind[1] then

					channelDropdown:AddItem(chan, blankChars2 .. kind[1])
					break
				end
			end
		end


		channelDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Guild"])
		channelDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Group"])
		channelDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Local"])
		channelDropdown:AddItem("dividingLineD", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Whisper"])
		channelDropdown:AddItem("dividingLineE", "")
		channelDropdown:AddItem("dividingLineF", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Other"])
	end


	if #csaNameTable == 0 then

		for chan, kind in pairs(channellist) do

			table.insert(csaNameTable, chan)
		end
	end


	if #cscNameTable == 0 then

		for chan, kind in pairs(channellist) do

			table.insert(cscNameTable, chan)
		end
	end


	if #csaKindTable == 0 then

		for chan, kind in pairs(channellist) do

			if string.sub(kind[1], 1, 5) == "Kanal" or string.sub(kind[1], 1, 7) == "Channel" then

				table.insert(csaKindTable, kind[1])
			end
		end
	end


	Skada:CurrentSort(csaKindTable, "CSK")
	Skada:CurrentSort(csaNameTable, "CSA")
	Skada:CurrentSort(cscNameTable, "CSC")


	table.insert(csaNameTable,   1, "dividingLineG")
	table.insert(csaNameTable,  11, "dividingLineH")
	table.insert(csaNameTable,  12, "dividingLineI")


	table.insert(cscNameTable,  1, "dividingLineA")
	table.insert(cscNameTable,  4, "dividingLineB")
	table.insert(cscNameTable,  8, "dividingLineC")
	table.insert(cscNameTable, 11, "dividingLineD")
	table.insert(cscNameTable, 14, "dividingLineE")
	table.insert(cscNameTable, 15, "dividingLineF")


	if cachedReportChannelSort then
	
			if ReportChannelSort == "CSA" then channelDropdown:SetList(sortTable, csaNameTable) end
			if ReportChannelSort == "CSC" then channelDropdown:SetList(sortTable, cscNameTable) end
	end


	channelButton:SetCallback("OnClick",

					function()

						if ReportChannelSort == "CSA" then

							channelLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Channel"] .. " - " .. L["Categorized"])


							channelDropdown:AddItem("dividingLineA", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Guild"])
							channelDropdown:AddItem("dividingLineB", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Group"])
							channelDropdown:AddItem("dividingLineC", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Local"])
							channelDropdown:AddItem("dividingLineD", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Whisper"])
							channelDropdown:AddItem("dividingLineE", "")
							channelDropdown:AddItem("dividingLineF", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Other"])


							ReportChannelSort = "CSC"

							channelButton:SetText(labelButton[2])
							channelDropdown:SetList(sortTable, cscNameTable)
						else

							channelLabel:SetText("\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Channel"] .. " - " .. L["Alphabetical"])


							channelDropdown:AddItem("dividingLineG", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Targets"])
							channelDropdown:AddItem("dividingLineH", "")
							channelDropdown:AddItem("dividingLineI", "\124cnNORMAL_FONT_COLOR:" .. blankChars1 .. L["Chat Other"])


							ReportChannelSort = "CSA"

							channelButton:SetText(labelButton[1])
							channelDropdown:SetList(sortTable, csaNameTable)
						end

						return
					end

				  )


	frame:AddChild(channelButton)


	local origchan = Skada.db.profile.report.channel or "say"


	if not channellist[origchan] then origchan = "say" end


	channelDropdown:SetCallback("OnEnter",

						function()

							channelDropdown:SetItemDisabled("dividingLineG", true)


							channelDropdown:SetItemDisabled("dividingLineA", true)
							channelDropdown:SetItemDisabled("dividingLineB", true)
							channelDropdown:SetItemDisabled("dividingLineC", true)
							channelDropdown:SetItemDisabled("dividingLineD", true)
							channelDropdown:SetItemDisabled("dividingLineE", true)
							channelDropdown:SetItemDisabled("dividingLineF", true)
						end

				   )


	channelDropdown:SetValue(origchan)


	channelDropdown:SetCallback("OnValueChanged",

					       function(f, e, value)

						       Skada.db.profile.report.channel = value
						       Skada.db.profile.report.chantype = channellist[value][2]


						       if channellist[origchan][3] ~= channellist[value][3] then

							       local pos = { frame:GetPoint() }


							       destroywindow()


							       Skada:CreateReportWindow(window)
							       Skada.ReportWindow:SetPoint(unpack(pos))
						       end
					       end

				   )


	frame:AddChild(channelDropdown)


	local lines = AceGUI:Create("Slider")


	lines:SetLabel(L["Lines"])
	lines:SetValue(Skada.db.profile.report.number ~= nil and Skada.db.profile.report.number	 or 10)
	lines:SetSliderValues(1, 25, 1)

	lines:SetCallback("OnValueChanged", function(self, event, value) Skada.db.profile.report.number = value end)
	lines:SetFullWidth(true)


	frame:AddChild(lines)


	if channellist[origchan][3] then

		local whisperbox = AceGUI:Create("EditBox")


		whisperbox:SetLabel(L["Whisper Target"])
		whisperbox:SetText(Skada.db.profile.report.target or "")
		whisperbox:SetCallback("OnEnterPressed",

						function(box, event, text)

							if strlenutf8(text) == #text then

								local ntext = text:gsub("%s","")


								if ntext ~= text then

									text = ntext
									whisperbox:SetText(text)
								end
							end


							Skada.db.profile.report.target = text


							frame.button.frame:Click()
						end

				      )


		whisperbox:SetCallback("OnTextChanged", function(box, event, text) Skada.db.profile.report.target = text end)
		whisperbox:SetFullWidth(true)

		frame:AddChild(whisperbox)
	end


	local report = AceGUI:Create("Button")
	frame.button = report

	report:SetText(L["Report"])
	report:SetCallback("OnClick",

				   function()

					   local mode, set, channel, chantype, number = Skada.db.profile.report.mode, Skada.db.profile.report.set,
						 Skada.db.profile.report.channel, Skada.db.profile.report.chantype, Skada.db.profile.report.number


					   if channel == "whisper" then

						   channel = Skada.db.profile.report.target

						   if channel and #strtrim(channel) == 0 then channel = nil end
					   elseif channel == "bnet" then

						   channel = BNet_GetBNetIDAccount(Skada.db.profile.report.target)
					   elseif channel == "target" then

						   if UnitExists("target") then

							   local toon, realm = UnitName("target")

							   if realm and #realm > 0 then

								   channel = toon .. "-" .. realm
							   else

								   channel = toon
							   end
						   else

							   channel = nil
						   end
					   end


					   if channel and chantype and mode and set and number then

						   Skada:Report(channel, chantype, mode, set, number, window)
						   frame:Hide()
					   else

						   Skada:Print("Error: Whisper target not found")
					   end
			  	 end

			  )


	report:SetFullWidth(true)
	frame:AddChild(report)
end




-- ======================================
-- | menu variant: create submenu arrow |
-- ======================================
function MenuVariants.CreateSubmenuArrow(frame)

	size = mSize


	local arrow = frame:AttachTexture()
	frame.arrow = arrow


	arrow:SetPoint("RIGHT")
	arrow:SetSize(size, size)
	arrow:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
	arrow:SetDrawLayer("ARTWORK")


	return arrow
end

