-- ==================================================================================================================== --
--															--
--	File			Options.lua										--
--															--
--															--
--	Author			Zarnivoop					| Version	   :	 10.0.2 |	--
--										| Curse-Project-ID :	 694380 |	--
--										| License	   :	  MIT/X |	--
--															--
--											| Basis, thx	|		--
--															--
--															--
--				Baltha						| Version	   :	 11.2.0 |	--
--										| Curse-Project-ID :	1188318 |	--
--										| License	   :	  MIT/X |	--
--															--
--											| Revision	|		--
--															--
--															--
--	Path ( Revision )	"..\World of Warcraft\_retail_\Interface\AddOns\Skada\Misc\Changelog\ChangeLog.txt"	--
--															--
-- ==================================================================================================================== --


local _, Skada	     = ...


local L		     = LibStub("AceLocale-3.0"):GetLocale("Skada", false)
local media	     = LibStub("LibSharedMedia-3.0")


local emptyLines     = string.rep("\n", 2)


Skada.resetoptions   = {[1] = L["No"], [2] = L["Yes"], [3] = L["Ask"]}


   Skada.windowdefaults =

			{

			   name = "Skada",
		     barspacing = 0,
		     bartexture = "BantoBar",
			barfont = "Accidental Presidency",

		   barfontflags = "",
		    barfontsize = 13,

		      barheight = 18,
		       barwidth = 240,
		 barorientation = 1,

		       barcolor = {r = 0.3, g = 0.3, b = 0.8, a=1},
		     barbgcolor = {r = 0.3, g = 0.3, b = 0.3, a = 0.6},
		     barslocked = false,

		   clickthrough = false,
	      spellschoolcolors = true,
		 classcolorbars = true,

		 classcolortext = false,
		     classicons = true,
		      roleicons = false,

		       showself = true,

		        buttons = { menu = true, reset = true, report = true, mode = true, segment = true },
			  title = { textcolor = {r = 0.9, g = 0.9, b = 0.9, a = 1}, height = 20, font="Accidental Presidency", fontsize=13, texture="Armory",
				    bordercolor = {r = 0, g = 0, b = 0, a = 1}, bordertexture = "None", borderthickness = 2, color = {r = 0.3, g = 0.3, b = 0.3, a = 1}, fontflags = ""},

		     background =

				{

					 height = 200,
				        texture	= "Solid",
				    bordercolor	= { r = 0, g = 0, b = 0, a = 1},
				  bordertexture	= "Blizzard Party",

				borderthickness = 1,
					  color	= { r = 0, g = 0, b = 0, a = 0.4},
					   tile	= false,
				       tilesize	= 0,
				},

			 strata = "LOW",
			  scale = 1,
		  reversegrowth = false,

		   modeincombat = "",
	      returnaftercombat = false,
		       wipemode = "",

			 hidden = false,
		    enabletitle = true,
		       titleset = true,

			    set = "current",
			   mode = nil,
			display = "bar",

			 snapto = true,
		      smoothing = false,

		    isonnewline = false,
	     isusingclasscolors = true,

			 height = 30,
			  width = 600,

			  color = {r = 0.3, g = 0.3, b = 0.3, a = 0.6},

	       isusingelvuiskin = false,
		issolidbackdrop = false,
		  fixedbarwidth = false,

		      textcolor = {r = 0.9, g = 0.9, b = 0.9},
		       useframe = true

			}


local windefaultscopy = {}


Skada:tcopy(windefaultscopy, Skada.windowdefaults)


	 Skada.defaults =

			{

			profile =

				{

				  reset = {instance = 1, join = 3, leave = 1},
				   icon = {hide = false, radius = 80, minimapPos = 195},

			   numberformat = 1,
			      setformat = 3,
			      setnumber = true,

			      showranks = true,
			     setstokeep = 10,
			       tooltips = true,

			     tooltippos = "smart",
			    tooltiprows = 3,
		    informativetooltips = true,

			 onlykeepbosses = false,
		   tentativecombatstart = false,
			       hidesolo	= false,

				hidepvp	= false,
			   hidedisables	= true,
			     hidecombat	= false,

			      mergepets	= true,
				   feed	= "",
			     showtotals	= false,

			       autostop	= false,
		       sortmodesbyusage = true,
			updatefrequency = 0.25,

				modules = {},
				columns = {},
				 report = {mode = "Damage", set = "current", channel = "Say", chantype = "preset", number = 10},

			 modulesBlocked = {},
				windows = {windefaultscopy}

				}
			}




function Skada:AddColumnOptions(mod)

	local db = self.db.profile.columns


	if mod.metadata and mod.metadata.columns then

	-- ==============================
	-- | option: columns		|
	-- ==============================
	     local cols =

			{

			   type = "group",
			   name = mod:GetName(),
			 inline = false,
			  order = 0,

			   args =

				{

				  columnoptions =

						{

						   type = "description",
						   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: column"] .. "|cffffffff" .. " " .. mod:GetName() .. emptyLines,
						  order = 0,

						},
				}

			}


		for colname, value in pairs(mod.metadata.columns) do

			local c = mod:GetName() .. "_" .. colname



			if db[c] ~= nil then mod.metadata.columns[colname] = db[c] end


			local col =

				{

				   type = "toggle",
				   name = "\124cFF00FF00" .. L[colname] or colname,
				    get = function()

						  return mod.metadata.columns[colname]
					  end,
				    set = function()

						  mod.metadata.columns[colname] = not mod.metadata.columns[colname]
						  db[c]				=     mod.metadata.columns[colname]

						  Skada:UpdateDisplay(true)
					  end,

				}


			cols.args[c] = col
		end


		Skada.options.args.columns.args[mod:GetName()] = cols
	end
end




function Skada:AddLoadableModuleCheckbox(mod, name, description)

	-- ==============================
	-- | option: checkbox		|
	-- ==============================
	local new =

			{

			   type = "toggle",
			   name = name,
			   desc = description,
			  order = 1,

			}

	Skada.options.args.modules.args[mod] = new
end


local deletewindow = nil
local newdisplay   = "bar"




	-- ==============================
	-- | options: Option.lua	|
	-- ==============================
	  Skada.options =

			{

			   type = "group",
			   name = "Skada",
		        plugins = {},

			   args =

				{

				      d =

					{

						   type = "description",
						   name = "\124cFF00FF00" .. L["Options: menu"],
						  order = 0,

					},


				-- ==============================
				-- | option: windows		|
				-- ==============================
				windows =

					{

						   type = "group",
						   name = L["Windows"],
						  order = 1,
	
						   args =

							{

							  windowoptions =

									{

									   type = "description",
									   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: window"] .. emptyLines,
									  order = 0,

									},

								 create =

									{

									   type = "input",
									   name = "\124cFF00FF00" .. L["Create window"],
									   desc = L["Enter the name for the new window."],
									    set = function(self, val)

											  local cwnHasName, cwnIsAllowedName = Skada:CheckWindowNames(val)


											  if cwnIsAllowedName == true then

												  local cwdHasName, cwdIsAllowedName = Skada:CheckWindowDuplicates(cwnHasName, "INS")


												  if cwdIsAllowedName == true then

													  Skada:CreateWindow(cwdHasName, nil, newdisplay)
													  Skada:CurrentTooltip("INS", cwdHasName, "", true)
												  end
											  end
										  end,
									  order = 2,

									},

								display =

									{

									   type = "select",
									   name = "\124cFF00FF00" .. L["Display system"],
									   desc = L["Choose the system to be used for displaying data in this window."],
									 values = function()

											  local list = {}


												  for name, display in pairs(Skada.displays) do

													  if display.name == L["Bar display"] then list[name] = "\124cnBLUE_FONT_COLOR:"	     .. display.name end
													  if display.name == L["Data text"]   then list[name] = "\124cnORANGE_FONT_COLOR:"	     .. display.name end
													  if display.name == L["Pie"]	      then list[name] = "\124cnTRANSMOGRIFY_FONT_COLOR:"     .. display.name end
													  if display.name == L["Line graph"]  then list[name] = "\124cnPAPER_FRAME_COLLAPSED_COLOR:" .. display.name end
												  end


												  return list
										  end,
									    get = function()

											  return newdisplay
										  end,
									    set = function(i, display)

										  	newdisplay = display
										  end,
									  order = 3,
									},
							},
					},


			   -- ==============================
			   -- | option: data reset	   |
			   -- ==============================
			   resetoptions =

					{

						   type = "group",
						   name = L["Data resets"],
						  order = function()

								   if GetLocale() == "deDE" then return 5 end
								   if GetLocale() == "enUS" then return 4 end	  	
							  end,

						   args =

							{

							   optionsreset =

									{

									   type = "description",
									   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: reset data"] .. emptyLines,
									  order = 0,

									},

							  resetinstance =

									{

									   type = "select",
									   name = "\124cFF00FF00" .. L["Reset on entering instance"],
									   desc = L["Controls if data is reset when you enter an instance."],
									 values = function()

											  return Skada.resetoptions
										  end,
									    get = function()

											  return Skada.db.profile.reset.instance
										  end,
									    set = function(self, opt)

											  Skada.db.profile.reset.instance = opt
										  end,
									  order = 1,

									},

							      resetjoin =

									{

									   type = "select",
									   name = "\124cFF00FF00" .. L["Reset on joining a group"],
									   desc = L["Controls if data is reset when you join a group."],
									 values = function()

											  return Skada.resetoptions
										  end,
									    get = function()

											  return Skada.db.profile.reset.join
										  end,
									    set = function(self, opt)

											  Skada.db.profile.reset.join = opt
										  end,
									  order = 2,

									},

							     resetleave =

									{

									   type = "select",
									   name = "\124cFF00FF00" .. L["Reset on leaving a group"],
									   desc = L["Controls if data is reset when you leave a group."],
									 values = function()

											  return Skada.resetoptions
										  end,
									    get = function()

											  return Skada.db.profile.reset.leave
										  end,
									    set = function(self, opt)

											  Skada.db.profile.reset.leave = opt
										  end,
									  order = 3,

									},
							}
					},


			       -- ==============================
			       -- | option: tooltips	       |
			       -- ==============================
			       tooltips =

					{

						   type = "group",
						   name = L["Tooltips"],
						  order = 9,

						   args =

							{

							optionstooltips =

									{

									   type = "description",
									   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: tooltips"] .. emptyLines,
									  order = 0,

									},

							       tooltips =

									{

									   type = "toggle",
									   name = L["Show tooltips"],
									   desc = L["Shows tooltips with extra information in some modes."],
									    get = function()

											  return Skada.db.profile.tooltips
										  end,
									    set = function()

											  Skada.db.profile.tooltips = not Skada.db.profile.tooltips
										  end,
									  order = 1,

									},

							    informative =

									{

									   type = "toggle",
									   name = L["Informative tooltips"],
									   desc = L["Shows subview summaries in the tooltips."],
									    get = function()

											  return Skada.db.profile.informativetooltips
										  end,
									    set = function()

											  Skada.db.profile.informativetooltips = not Skada.db.profile.informativetooltips
										  end,
									  order = 2,

									},

								   rows =

									{

									   type = "range",
									   name = "\124cFF00FF00" .. L["Subview rows"],
									   desc = L["The number of rows from each subview to show when using informative tooltips."],
									    min = 1,
									    max = 10,
									   step = 1,
									    get = function()

											  return Skada.db.profile.tooltiprows
										  end,
									    set = function(self, val)

											  Skada.db.profile.tooltiprows = val
										  end,
									  order = 3,

									},

							     tooltippos =

									{

									   type = "select",
									   name = "\124cFF00FF00" .. L["Tooltip position"],
									   desc = L["Position of the tooltips."],
									 values = { ["default"] = L["Default"], ["topright"] = L["Top right"], ["topleft"] = L["Top left"], ["smart"] = L["Smart"] },
									    get = function()

											  return Skada.db.profile.tooltippos
										  end,
									    set = function(self, opt)

											  Skada.db.profile.tooltippos = opt
										  end,
									  order = 4,

									},
							}
					},


			 -- ==============================
			 -- | option: general options	 |
			 -- ==============================
			 generaloptions =

					{

						   type = "group",
						   name = L["General options"],
						  order = function()

								  if GetLocale() == "deDE" then return 2 end
								  if GetLocale() == "enUS" then return 5 end	  	
							  end,

						   args =

							{

						  generaloptionsettings =

									{

										   type = "description",
										   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: general settings"] .. emptyLines,
										  order = 0,

									},

							       mmbutton =

									{

										   type = "toggle",
										   name = L["Show minimap button"],
										   desc = L["Toggles showing the minimap button."],
										    get = function()

												  return not Skada.db.profile.icon.hide
											  end,
										    set = function()

												  Skada.db.profile.icon.hide = not Skada.db.profile.icon.hide
												  Skada:RefreshMMButton()
											  end,
										  order = 1,

									},

							      mergepets =

									{

										   type = "toggle",
										   name = L["Merge pets"],
										   desc = L["Merges pets with their owners. Changing this only affects new data."],
										    get = function()

												  return Skada.db.profile.mergepets
											  end,
										    set = function()

												  Skada.db.profile.mergepets = not Skada.db.profile.mergepets
											  end,
										  order = 2,

									},

							     showtotals =

									{

										   type = "toggle",
										   name = L["Show totals"],
										   desc = L["Shows a extra row with a summary in certain modes."],
										    get = function()

												  return Skada.db.profile.showtotals
											  end,
										    set = function()

												  Skada.db.profile.showtotals = not Skada.db.profile.showtotals
											  end,
										  order = 3,

									},

							 onlykeepbosses =

									{

										   type = "toggle",
										   name = L["Only keep boss fighs"],
										   desc = L["Boss fights will be kept with this on, and non-boss fights are discarded."],
										    get = function()

												  return Skada.db.profile.onlykeepbosses
											  end,
										    set = function()

												  Skada.db.profile.onlykeepbosses = not Skada.db.profile.onlykeepbosses
											  end,
										  order = 4,

									},

							       hidesolo =

									{

										   type = "toggle",
										   name = L["Hide when solo"],
										   desc = L["Hides Skada's window when not in a party or raid."],
										    get = function()

											 	  return Skada.db.profile.hidesolo
											  end,
										    set = function()

												  Skada.db.profile.hidesolo = not Skada.db.profile.hidesolo
												  Skada:ApplySettings()
											  end,
										  order = 5,

									},

								hidepvp =

									{


										   type = "toggle",
										   name = L["Hide in PvP"],
										   desc = L["Hides Skada's window when in Battlegrounds/Arenas."],
										    get = function()

												  return Skada.db.profile.hidepvp
											  end,
										    set = function()

												  Skada.db.profile.hidepvp = not Skada.db.profile.hidepvp
												  Skada:ApplySettings()
											  end,
										  order = 6,

									},

							     hidecombat =

									{

										   type = "toggle",
										   name = L["Hide in combat"],
										   desc = L["Hides Skada's window when in combat."],
										    get = function()

												  return Skada.db.profile.hidecombat
											  end,
										    set = function()

												  Skada.db.profile.hidecombat = not Skada.db.profile.hidecombat
												  Skada:ApplySettings()
											  end,
										  order = 7,

									},

						      disablewhenhidden =

									{

										   type = "toggle",
										   name = L["Disable while hidden"],
										   desc = L["Skada will not collect any data when automatically hidden."],
										    get = function()

												  return Skada.db.profile.hidedisables
											  end,
										    set = function()

												  Skada.db.profile.hidedisables = not Skada.db.profile.hidedisables
												  Skada:ApplySettings()
											  end,
										  order = 8,

									},

							     showranks =

									{

										   type = "toggle",
										   name = L["Show rank numbers"],
										   desc = L["Shows numbers for relative ranks for modes where it is applicable."],
										    get = function()

												  return Skada.db.profile.showranks
											  end,
										    set = function()

												  Skada.db.profile.showranks = not Skada.db.profile.showranks
												  Skada:ApplySettings()
											  end,
										  order = 9,

									},

						   tentativecombatstart =

									{

										   type = "toggle",
										   name = L["Aggressive combat detection"],
										   desc = L["Skada usually uses a very conservative (simple) combat detection scheme that works best in raids." ..
											    " With this option Skada attempts to emulate other damage meters. Useful for running dungeons."     ..
											    " Meaningless on boss encounters."],
										    get = function()

												  return Skada.db.profile.tentativecombatstart
											  end,
										    set = function()

												  Skada.db.profile.tentativecombatstart = not Skada.db.profile.tentativecombatstart
											  end,
										  order = 10,

									},

							       autostop =

									{

										   type = "toggle",
										   name = L["Autostop"],
										   desc = L["Autostop description"],
										    get = function()

												  return Skada.db.profile.autostop
											  end,
										    set = function()

												  Skada.db.profile.autostop = not Skada.db.profile.autostop
											  end,
										  order = 11,

									},

							       showself =

									{

										   type = "toggle",
										   name = L["Always show self"],
										   desc = L["Keeps the player shown last even if there is not enough space."],
										    get = function()

												  return Skada.db.profile.showself
											  end,
										    set = function()

												  Skada.db.profile.showself = not Skada.db.profile.showself
												  Skada:ApplySettings()
											  end,
										  order = 12,

									},

						       sortmodesbyusage =

									{

										   type = "toggle",
										   name = L["Sort modes by usage"],
										   desc = L["The mode list will be sorted to reflect usage instead of alphabetically."],
										  width = "full",
										    get = function()

												  return Skada.db.profile.sortmodesbyusage
											  end,
										    set = function()

												  Skada.db.profile.sortmodesbyusage = not Skada.db.profile.sortmodesbyusage
												  Skada:ApplySettings()
											  end,
										  order = 13,

									},

							    emptyLinesa =

									{

										   type = "description",
										   name = emptyLines,
										  order = 14,

									},

							   numberformat =

									{

										   type = "select",
										   name = "\124cFF00FF00" .. L["Number format"],
										   desc = L["Controls the way large numbers are displayed."],
									         values = function()

												  return {[1] = L["Condensed"], [2] = L["Detailed"]}
											  end,
										    get = function()

												  return Skada.db.profile.numberformat
											  end,
										    set = function(self, opt)

												  Skada.db.profile.numberformat = opt
											  end,
										  order = 15,

									},

							       datafeed =

									{

										   type = "select",
										   name = "\124cFF00FF00" .. L["Data feed"],
										   desc = L["Choose which data feed to show in the DataBroker view. This requires an LDB display addon, such as Titan Panel."],
									         values = function()

												  local feeds = {}


												  feeds[""]   = L["None"]


												  for name, func in pairs(Skada:GetFeeds()) do feeds[name] = name end


												  return feeds
											end,
										  get = function()

												return Skada.db.profile.feed
											end,
										  set = function(self, feed)

												Skada.db.profile.feed = feed


												if feed ~= "" then

													Skada:SetFeed(Skada:GetFeeds()[feed])
												end
											end,
										order = 16,

									},

							     setstokeep =

									{

										   type = "range",
										   name = "\124cFF00FF00" .. L["Data segments to keep"],
										   desc = L["The number of fight segments to keep. Persistent segments are not included in this."],
										    min = 0,
										    max = 99,
										   step = 1,
										    get = function()

												  return Skada.db.profile.setstokeep
											  end,
										    set = function(self, val)

												  Skada.db.profile.setstokeep = val
											  end,
										  order = 17,

									},

							      setnumber =

									{

										   type = "toggle",
										   name = L["Number set duplicates"],
										   desc = L["Append a count to set names with duplicate mob names."],
										    get = function()

												  return Skada.db.profile.setnumber
											  end,
										    set = function()

												  Skada.db.profile.setnumber = not Skada.db.profile.setnumber
											  end,
										  order = 18,

									},

							      setformat =

									{

										   type = "select",
										   name = "\124cFF00FF00" .. L["Set format"],
										   desc = L["Controls the way set names are displayed."],
									         values = Skada:SetLabelFormats(),
										  width = "double",

										    get = function()

												  return Skada.db.profile.setformat
											  end,
										    set = function(self, opt)

												  Skada.db.profile.setformat = opt
												  Skada:ApplySettings()
											  end,
										  order = 19,

									},

							updatefrequency =

									{

										   type = "range",
										   name = "\124cFF00FF00" .. L["Update frequency"],
										   desc = L["How often windows are updated. Shorter for faster updates. Increases CPU usage."],
										    min = 0.10,
										    max = 1,
										   step = 0.05,
										  width ="double",
										    get = function()

												  return Skada.db.profile.updatefrequency
											  end,
										    set = function(self, opt)

												  Skada.db.profile.updatefrequency = opt
											  end,
										  order = 20,

									},
							}
					},


				-- ==============================
				-- | option: columns		|
				-- ==============================
				columns =

					{

						   type = "group",
					     	   name = L["Columns"],
						  order = function()

								  if GetLocale() == "deDE" then return 8 end
								  if GetLocale() == "enUS" then return 3 end	  	
							  end,

						   args = {},

					},


				-- ==============================
				-- | option: modules		|
				-- ==============================
				modules =

					{

						   type = "group",
						   name = L["Modules"],
						  order = function()

								  if GetLocale() == "deDE" then return 6 end
								  if GetLocale() == "enUS" then return 6 end	  	
							  end,
						    get = function(i)

								  return Skada.db.profile.modulesBlocked[i[#i]]
							  end,
						    set = function(i, value)

								  Skada.db.profile.modulesBlocked[i[#i]] = value; Skada.options.args.modules.args.apply.disabled=false
							  end,

						   args =

							{

								  desc  =

									{

										   type = "description",
										   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: modules (de)activate"] .. "|cffffffff" .. emptyLines,
										  order = 0,

									},

								  apply = 

									{

										   type = "execute",
										   name = APPLY,
										  width = "full",
										   func = ReloadUI,
										confirm = function()

												  return L["This change requires a UI reload. Are you sure?"]
											  end,
									       disabled = true,
										  order = 1,

									},
							},
					 }
			 }
	}