local surface = AceLibrary("Surface-1.0");
local dd = AceLibrary("Dewdrop-2.0");
local L = AceLibrary("AceLocale-2.2"):new("CooldownTimers");

CooldownTimers.hasNoColor = true;
CooldownTimers.defaultMinimapPosition = 300;
CooldownTimers.independantProfile = true;
CooldownTimers.cannotDetachTooltip = true;
CooldownTimers.hideWithoutStandby = true;
CooldownTimers.hasIcon = "Interface/Icons/INV_Misc_PocketWatch_02";

function CooldownTimers:OnMenuRequest(level, value, inTooltip, v1, v2, v3, v4)
	--self:Print(level, value, inTooltip, v1, v2, v3, v4);
	--Level 1
	if level == 1 then
		
		dd:AddLine(
			'text', L["Default Bar Settings"],
			'hasArrow', true,
			'value', "defaults",
			'hasTooltip', true,
			'tooltipText', L["Sets the default bar look, used after\ncustom group settings and\nindivual skill settings"]
		);
		dd:AddLine(
			'text', L["Group Settings"],
			'hasArrow', true,
			'value', "groups",
			'hasTooltip', true,
			'tooltipText', L["Sets the settings for a particular group."]
		);
		dd:AddLine(
			'text', L["Announce Settings"],
			'hasArrow', true,
			'value', "announce",
			'hasTooltip', true,
			'tooltipText', L["Settings for the Announce display"]
		);
		dd:AddLine(
			'text', L["Skill Cooldowns"],
			'hasArrow', true,
			'value', "skills",
			'hasTooltip', true,
			'tooltipText', L["Sets the settings for individual cooldowns.\nEnable/Disable cooldowns here."]
		);
		dd:AddLine(
			'text', L["Item Cooldowns"],
			'hasArrow', true,
			'value', "items",
			'hasTooltip', true,
			'tooltipText', L["Sets the settings for individual cooldowns.\nEnable/Disable cooldowns here."],
			'disabled', not next(self.db.char.itemcooldowns)
		);
		dd:AddLine(
			'text', L["Pet Cooldowns"],
			'hasArrow', true,
			'value', "pets",
			'hasTooltip', true,
			'tooltipText', L["Sets the settings for individual cooldowns.\nEnable/Disable cooldowns here."],
			'disabled', not next(self.db.char.petcooldowns)
		);
		dd:AddLine(
			'text', L["Min Time"],
			'hasArrow', true,
			'hasEditBox', true,
			'editBoxText', self.db.char.mintime,
			'editBoxFunc', function(s)
				if not string.find(s, "^%d+%.?%d*$") then
					self:Print(L["Usage: <minTime> (in seconds)"]);
					return;
				end
				self.db.char.mintime = tonumber(s);
				self:Print(L["Min Time"], L["set to:"], self.db.char.mintime);
			end
		);
		dd:AddLine(
			'text', L["Max Time"],
			'hasArrow', true,
			'hasEditBox', true,
			'editBoxText', self.db.char.maxtime,
			'editBoxFunc', function(s)
				if not string.find(s, "^%d+%.?%d*$") then
					self:Print(L["Usage: <maxTime> (in seconds)"]);
					return;
				end
				self.db.char.maxtime = tonumber(s);
				self:Print(L["Max Time"], L["set to:"], self.db.char.maxtime);
			end
		);
		dd:AddLine(
			'text', L["Condense Groups"],
			'hasTooltip', true,
			'tooltipText', L["Use this to condense multiple skills/items\nwith the same cooldown into a single bar."],
			'value', 'condense',
			'hasArrow', true
		);
		dd:AddLine(
			'notClickable', true,
			'text', ""
		);
		
	--Level 2
	elseif level == 2 then
		--Defaults
		if value == "defaults" then
			--color settings
			local colors;
			for k,v in ipairs(self.db.char.barOptions.colors) do
				if not colors then
					colors = v;
				else
					colors = colors.." "..v;
				end
			end
			dd:AddLine(
				'text', L["Bar Texture"],
				'hasTooltip', true,
				'tooltipText', L["Sets the status bar texture."],
				'hasArrow', true,
				'value', "texture"
			);
			dd:AddLine(
				'text', L["Colors"],
				'hasTooltip', true,
				'tooltipText', L["Sets the fade colors. Needs at least two, but\nwill take as many colors as you want.\n"]..L["Usage: <color1> <color2> ..."],
				'hasArrow', true,
				'hasEditBox', true,
				'editBoxText', colors,
				'editBoxFunc', function(s)
					if not string.find(s, "%a+ %a+") then
						self:Print(L["Usage: <color1> <color2> ..."]);
						return;
					end
					self.db.char.barOptions.colors = {};
					for color in string.gmatch(s, "%a+") do
						table.insert(self.db.char.barOptions.colors, color);
					end
					self:Print(L["Default Bar Colors set to: "], unpack(self.db.char.barOptions.colors));
					return self.db.char.barOptions.colors;
				end
			);
			--fade time
			dd:AddLine(
				'text', L["Fade Time"],
				'hasTooltip', true,
				'tooltipText', L["Sets how long bars take to fade after\nthe bar completes.\n"]
					..L["Usage: <fadetime> (in seconds)"],
				'hasArrow', true,
				'hasEditBox', true,
				'editBoxText', self.db.char.barOptions.fade,
				'editBoxFunc', function(s)
					if not string.find(s, "^%d+%.?%d*") then
						self:Print(L["Usage: <fadetime> (in seconds)"]);
						return;
					end
					self.db.char.barOptions.fade = tonumber(s);
					self:Print(L["Fade time set to: "], self.db.char.barOptions.fade);
					return self.db.char.barOptions.fade;
				end
			);
			--barwidth, max 300 min 32
			dd:AddLine(
				'text', L["Bar Width"],
				'hasTooltip', true,
				'tooltipText', L["Sets the default bar width."],
				'hasArrow', true,
				'hasSlider', true,
				'sliderMin', 32,
				'sliderMax', 200,
				'sliderStep', 1,
				'sliderValue', self.db.char.barOptions.barwidth,
				'sliderFunc', function(v)
					self.db.char.barOptions.barwidth = v;
					return self.db.char.barOptions.barwidth;
				end
			);
			--barheight
			dd:AddLine(
				'text', L["Bar Height"],
				'hasTooltip', true,
				'tooltipText', L["Sets the default bar height."],
				'hasArrow', true,
				'hasSlider', true,
				'sliderMin', 16,
				'sliderMax', 64,
				'sliderStep', 1,
				'sliderValue', self.db.char.barOptions.barheight,
				'sliderFunc', function(v)
					self.db.char.barOptions.barheight = v;
					return self.db.char.barOptions.barheight;
				end
			);
			--scale
			dd:AddLine(
				'text', L["Bar Scale"],
				'hasTooltip', true,
				'tooltipText', L["Sets the default bar scale."],
				'hasArrow', true,
				'hasSlider', true,
				'sliderMin', 0.5,
				'sliderMax', 2.0,
				'sliderStep', 0.1,
				'sliderValue', self.db.char.barOptions.scale,
				'sliderFunc', function(v)
					self.db.char.barOptions.scale = v;
					return self.db.char.barOptions.scale;
				end
			);
			--grow upwards
			dd:AddLine(
				'text', L["Grow Downwards"],
				'hasTooltip', true,
				'tooltipText', L["Whether the bars will stack up, or stack down"],
				'checked', not self.db.char.barOptions.up,
				'func', function()
					self.db.char.barOptions.up = not self.db.char.barOptions.up;
				end
			);
			--collapse
			dd:AddLine(
				'text', L["Sort and Collapse Bars"],
				'hasTooltip', true,
				'tooltipText', L["Whether the bars will be automatically\nsorted and automatically collapse"],
				'checked', self.db.char.barOptions.collapse,
				'func', function()
					self.db.char.barOptions.collapse = not self.db.char.barOptions.collapse;
				end
			);
			--bargap
			dd:AddLine(
				'text', L["Bar Gap"],
				'hasTooltip', true,
				'tooltipText', L["Sets the default space between bars."]..L["\n(Only used when bars do not automatically collapse.)"],
				'hasArrow', true,
				'hasSlider', true,
				'sliderMin', 0,
				'sliderMax', 32,
				'sliderStep', 1,
				'sliderValue', self.db.char.barOptions.bargap,
				'sliderFunc', function(v)
					self.db.char.barOptions.bargap = v;
					return self.db.char.barOptions.bargap;
				end,
				'disabled', self.db.char.barOptions.collapse
			);
			--columns
			dd:AddLine(
				'text', L["Bar Columns"],
				'hasTooltip', true,
				'tooltipText', L["Sets the number of bar columns."]..L["\n(Only used when bars do not automatically collapse.)"],
				'hasArrow', true,
				'hasSlider', true,
				'sliderMin', 1,
				'sliderMax', 5,
				'sliderStep', 1,
				'sliderValue', self.db.char.barOptions.columns,
				'sliderFunc', function(v)
					self.db.char.barOptions.columns = v;
					return self.db.char.barOptions.columns;
				end,
				'disabled', self.db.char.barOptions.collapse
			);
		
		--groups
		elseif value == "groups" then
			
			--new group
			dd:AddLine(
				'text', L["Create New Group"],
				'hasTooltip', true,
				'tooltipText', L["Make a new group to show cooldowns in.\n"]..L["Group names must contain only letters"],
				'hasArrow', true,
				'hasEditBox', true,
				'editBoxText', "",
				'editBoxFunc', function(s)
					if string.find(s, "%A") then
						self:Print(L["Group names must contain only letters"]);
						return;
					end
					if self.db.char.groups[s] and not self.db.char.groups[s].disabled then
						self:Print(L["Group already exists: "], s);
						return;
					end
					self.db.char.groups[s] = {};
					self:MakeAnchor(s, self.db.char.groups[s]);
				end
			);
			for k,v in pairs(self.db.char.groups) do
				if not v.disabled then
					dd:AddLine(
						'text', k,
						'hasArrow', true,
						'value', k
					);
				end
			end
		--announce
		elseif value == "announce" then
			dd:AddLine(
				'text', L["Enabled"],
				'checked', self.db.char.announce.enabled,
				'tooltipText', L["Enables and disables the announcement\nof a cooldown completion."],
				'func', function()
					self.db.char.announce.enabled = not self.db.char.announce.enabled;
					if not self.db.char.announce.locked then
						if self.db.char.announce.enabled then
							self.announce.anchor:Show();
							self.announce.frame:Show();
							self.announce.frame:SetAlpha(1);
							self.announce.alpha = 1;
						else
							self.announce.anchor:Hide();
						end
					end
				end
			);
			dd:AddLine(
				'text', L["Locked"],
				'checked', self.db.char.announce.locked,
				'tooltipText', L["Shows/Hides the announce anchor.\nWithout locking the announce will never\ndissapear!"],
				'disabled', not self.db.char.announce.enabled,
				'func', function()
					self.db.char.announce.locked = not self.db.char.announce.locked;
					if not self.db.char.announce.locked then
						self.announce.anchor:Show();
						self.announce.frame:Show();
						self.announce.frame:SetAlpha(1);
						self.announce.alpha = 1;
					else
						self.announce.anchor:Hide();
					end
				end
			);
			dd:AddLine(
				'text', L["Display String"],
				'tooltipText', L["What you want the announce\nto say. Use %s for the skill name."],
				'hasEditBox', true,
				'hasArrow', true,
				'editBoxText', self.db.char.announce.announceString,
				'disabled', not self.db.char.announce.enabled,
				'editBoxFunc', function(s)
					self.db.char.announce.announceString = s;
				end
			);
			dd:AddLine(
				'text', L["Fade Time"],
				'tooltipText', L["How long until the announce\nbegins fading."],
				'hasSlider', true,
				'sliderValue', self.db.char.announce.fade,
				'disabled', not self.db.char.announce.enabled,
				'hasArrow', true,
				'sliderMin', 0,
				'sliderMax', 10,
				'sliderStep', 0.5,
				'sliderFunc', function(v)
					self.db.char.announce.fade = v;
				end
			);
			dd:AddLine(
				'text', L["Announce Scale"],
				'tooltipText', L["Scale of the announce text."],
				'hasSlider', true,
				'sliderValue', self.db.char.announce.scale,
				'disabled', not self.db.char.announce.enabled,
				'hasArrow', true,
				'sliderMin', 0.5,
				'sliderMax', 2,
				'sliderStep', 0.1,
				'sliderFunc', function(v)
					self.db.char.announce.scale = v;
					self.announce.frame:SetScale(v);
				end
			);
		--cooldowns
		elseif value == "skills" then
			for k,v in pairs(self.db.char.cooldowns) do
				dd:AddLine(
					'text', k,
					'hasArrow', true,
					'value', k
				);
			end
		elseif value == "pets" then
			for k,v in pairs(self.db.char.petcooldowns) do
				dd:AddLine(
					'text', k,
					'hasArrow', true,
					'value', k
				);
			end
		elseif value == "items" then
			for k,v in pairs(self.db.char.itemcooldowns) do
				dd:AddLine(
					'text', k,
					'hasArrow', true,
					'value', k
				);
			end
		elseif value == "condense" then
			self.groups = {};
			for k,v in pairs(self.db.char.itemgroups) do
				if not self.groups[v] then self.groups[v] = {}; end
				table.insert(self.groups[v], k);
			end
			for k,v in pairs(self.db.char.skillgroups) do
				if not self.groups[v] then self.groups[v] = {}; end
				table.insert(self.groups[v], k);
			end
			for k in pairs(self.groups) do
				dd:AddLine(
					'text', k,
					'value', k,
					'hasArrow', k
				);
			end
		end
		
	--Level 3
	elseif level == 3 then
		if v1 == "defaults" then
			if value == "texture" then
				for _,v in pairs(surface:List()) do
					dd:AddLine(
						'text', v,
						'checked', (self.db.char.barOptions.texture == v),
						'isRadio', true,
						'func', function()
							self.db.char.barOptions.texture = v;
						end
					);
				end
			end
		elseif v1 == "groups" then
			--delete group
			dd:AddLine(
				'text', L["Delete Group"],
				'hasTooltip', true,
				'tooltipText', L["Delete this group (NOT RESTORABLE)\nDefault groups cannot be deleted."],
				'func', function()
					StaticPopupDialogs["CDT_DELETE_GROUP_CHECK"] = {
						text = L["Are you sure you want to delete group: "]..value,
						button1 = L["Yes"],
						button2 = L["No"],
						OnAccept = function()
							if value == "PetCooldowns" or value == "ItemCooldowns" then
								self.db.char.groups[value].disabled = true; --otherwise it'll just be recreated by default
							else	
								self.db.char.groups[value] = nil;
							end
							self.anchors[value]:Hide();
							self:Print(L["Group deleted: "], value);
							for k,v in pairs(self.db.char.cooldowns) do
								if v.group == value then v.group = "CDT"; end
							end
							for k,v in pairs(self.db.char.itemcooldowns) do
								if v.group == value then v.group = "CDT"; end
							end
							for k,v in pairs(self.db.char.petcooldowns) do
								if v.group == value then v.group = "CDT"; end
							end
						end,
						showAlert = true,
						timeout = 0,
					};
					StaticPopup_Show("CDT_DELETE_GROUP_CHECK");
				end,
				'disabled', (value == "CDT")
				);
			--locked
			dd:AddLine(
				'text', L["Locked"],
				'checked', self.db.char.groups[value].locked,
				'hasTooltip', true,
				'tooltipText', L["Shows/Hides the group anchor."],
				'func', function()
					self.db.char.groups[value].locked = not self.db.char.groups[value].locked;
					if self.db.char.groups[value].locked then
						self.anchors[value]:Hide();
					else
						self.anchors[value]:Show();
					end
				end
			);
			--group options
			dd:AddLine(
				'text', L["Bar Texture"],
				'hasTooltip', true,
				'tooltipText', L["Sets the status bar texture."],
				'hasArrow', true,
				'value', "texture"
			);
			dd:AddLine(
				'text', L["Colors"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets default colors for this group"],
				'value', "colors"
			);
			dd:AddLine(
				'text', L["Fade Time"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets default fade time for this group"],
				'value', "fade"
			);
			dd:AddLine(
				'text', L["Bar Width"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets bar width for this group"],
				'value', "barwidth"
			);
			dd:AddLine(
				'text', L["Bar Height"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets bar height for this group"],
				'value', "barheight"
			);
			dd:AddLine(
				'text', L["Bar Scale"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets scale for this group"],
				'value', "scale"
			);
			dd:AddLine(
				'text', L["Grow Downwards"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Whether the bars will stack up, or stack down"],
				'value', "up"
			);
			dd:AddLine(
				'text', L["Sort and Collapse Bars"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Whether the bars will be automatically\nsorted and automatically collapse"],
				'value', "collapse"
			);
			local collapse = self.db.char.groups[value].collapse;
			if collapse == nil then
				collapse = self.db.char.barOptions.collapse;
			end
			dd:AddLine(
				'text', L["Bar Gap"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets the default space between bars."]..L["\n(Only used when bars do not automatically collapse.)"],
				'value', "bargap",
				'disabled', collapse
			);
			dd:AddLine(
				'text', L["Bar Columns"],
				'hasArrow', true,
				'hasTooltip', true,
				'tooltipText', L["Sets the number of bar columns."]..L["\n(Only used when bars do not automatically collapse.)"],
				'value', "columns",
				'disabled', collapse
			);
		elseif v1 == "skills" or v1 == "pets" or v1 == "items" then
			local cooldowns;
			if v1 == "skills" then
				cooldowns = self.db.char.cooldowns;
			elseif v1 == "pets" then
				cooldowns = self.db.char.petcooldowns;
			elseif v1 == "items" then
				cooldowns = self.db.char.itemcooldowns;
			end
			dd:AddLine(
				'text', L["Enabled"],
				'checked', not cooldowns[value].disabled,
				'hasTooltip', true,
				'tooltipText', L["Enable tracking for this cooldown."],
				'func', function()
					cooldowns[value].disabled = not cooldowns[value].disabled;
				end
			);
			dd:AddLine(
				'text', L["Group"],
				'hasArrow', true,
				'value', "group",
				'disabled', cooldowns[value].disabled
			);
			dd:AddLine(
				'text', L["Bar Texture"],
				'hasTooltip', true,
				'tooltipText', L["Sets the status bar texture."],
				'hasArrow', true,
				'value', "texture"
			);
			dd:AddLine(
				'text', L["Colors"],
				'hasArrow', true,
				'value', "colors",
				'disabled', cooldowns[value].disabled
			);
			dd:AddLine(
				'text', L["Fade Time"],
				'hasArrow', true,
				'value', "fade",
				'disabled', cooldowns[value].disabled
			);
			if v1 ~= "pets" then
				dd:AddLine(
					'text', L["Condense Into"],
					'hasArrow', true,
					'value', "condenseinto",
					'tooltipText', L["Condense this bar into a condense group"]
				);
			end
		elseif v1 == "condense" then
			for _, v in ipairs(self.groups[value]) do
				dd:AddLine(
					'text', v,
					'hasArrow', true,
					'value', v
				);
			end
		end
		
	--level
	elseif level == 4 then
		if v2 == "groups" then
			local default = false;
			if self.db.char.groups[v1][value] == nil then default = true; end
			dd:AddLine(
				'text', L["Use Default"],
				'checked', default,
				'hasTooltip', true,
				'tooltipText', L["Uses the default bar settings"],
				'func', function()
					if self.db.char.groups[v1][value] ~= nil then
						self.db.char.groups[v1][value] = nil;
					else
						self.db.char.groups[v1][value] = self.db.char.barOptions[value];
					end
				end
			);
			if value == "texture" then
				for _,v in pairs(surface:List()) do
					dd:AddLine(
						'text', v,
						'checked', (self.db.char.groups[v1].texture == v),
						'isRadio', true,
						'func', function()
							self.db.char.groups[v1].texture = v;
						end,
						'disabled', default
					);
				end
			elseif value == "colors" then
				local colors;
				if self.db.char.groups[v1][value] then
					for k,v in ipairs(self.db.char.groups[v1][value]) do
						if not colors then 
							colors = v;
						else 
							colors = colors.." "..v;
						end
					end
				else
					colors = "";
				end
				dd:AddLine(
					'text', L["Custom "]..L["Colors"],
					'disabled', default,
					'hasEditBox', true,
					'hasArrow', true,
					'editBoxText', colors,
					'editBoxFunc', function(s)
						if not string.find(s, "^%a+ %a+") then
							self:Print(L["Usage: <color1> <color2> ..."]);
							return;
						end
						self.db.char.groups[v1].colors = {};
						for color in string.gmatch(s, "%a+") do
							table.insert(self.db.char.groups[v1].colors, color);
						end
						self:Print(v1,L["colors set to: "], unpack(self.db.char.groups[v1].colors));
					end
				);
			elseif value == "fade" then
				dd:AddLine(
					'text', L["Custom "]..L["Fade Time"],
					'disabled', default,
					'hasEditBox', true,
					'hasArrow', true,
					'editBoxText', self.db.char.groups[v1].fade or self.db.char.barOptions.fade,
					'editBoxFunc', function(v)
						if not string.find(v, "^%d+%.?%d*$") then
							self:Print(L["Usage: <fadetime> (in seconds)"]);
							return;
						end
						self.db.char.groups[v1].fade = tonumber(v);
						self:Print(v1, L["fade time set to:"], self.db.char.groups[v1].fade);
					end
				);
			elseif value == "barwidth" then
				dd:AddLine(
					'text', L["Custom "]..L["Bar Width"],
					'disabled', default,
					'hasSlider', true,
					'hasArrow', true,
					'sliderMin', 32,
					'sliderMax', 200,
					'sliderStep', 1,
					'sliderValue', self.db.char.groups[v1].barwidth or self.db.char.barOptions.barwidth,
					'sliderFunc', function(v)
						self.db.char.groups[v1].barwidth = v;
					end
				);
			elseif value == "barheight" then
				dd:AddLine(
					'text', L["Custom "]..L["Bar Height"],
					'disabled', default,
					'hasSlider', true,
					'hasArrow', true,
					'sliderMin', 16,
					'sliderMax', 64,
					'sliderStep', 1,
					'sliderValue', self.db.char.groups[v1].barheight or self.db.char.barOptions.barheight,
					'sliderFunc', function(v)
						self.db.char.groups[v1].barheight = v;
					end
				);
			elseif value == "scale" then
				dd:AddLine(
					'text', L["Custom "]..L["Bar Scale"],
					'disabled', default,
					'hasSlider', true,
					'hasArrow', true,
					'sliderMin', 0.5,
					'sliderMax', 2,
					'sliderStep', 0.1,
					'sliderValue', self.db.char.groups[v1].scale or self.db.char.barOptions.scale,
					'sliderFunc', function(v)
						self.db.char.groups[v1].scale = v;
					end
				);
			elseif value == "up" then
				local up = self.db.char.groups[v1].up;
				if up == nil then up = self.db.char.barOptions.up; end
				dd:AddLine(
					'text', L["Grow Downwards"],
					'disabled', default,
					'checked', not up,
					'func', function()
						self.db.char.groups[v1].up = not self.db.char.groups[v1].up;
						self:SetCandyBarGroupGrowth(v1, self.db.char.groups[v1].up);
					end
				);
			elseif value == "collapse" then
				local collapse = self.db.char.groups[v1].collapse;
				if collapse == nil then collapse = self.db.char.barOptions.collapse; end
				dd:AddLine(
					'text', L["Sort and Collapse Bars"],
					'disabled', default,
					'checked', collapse,
					'func', function()
						self.db.char.groups[v1].collapse = not self.db.char.groups[v1].collapse;
					end
				);
			elseif value == "bargap" then
				dd:AddLine(
					'text', L["Custom "]..L["Bar Gap"],
					'disabled', default,
					'hasArrow', true,
					'hasSlider', true,
					'sliderValue', self.db.char.groups[v1].bargap or self.db.char.barOptions.bargap,
					'sliderMin', 0,
					'sliderMax', 32,
					'sliderStep', 1,
					'sliderFunc', function(v)
						self.db.char.groups[v1].bargap = v;
					end
				);
			elseif value == "columns" then
				dd:AddLine(
					'text', L["Custom "]..L["Columns"],
					'disabled', default,
					'hasArrow', true,
					'hasSlider', true,
					'sliderValue', self.db.char.groups[v1].columns or self.db.char.barOptions.columns,
					'sliderMin', 1,
					'sliderMax', 5,
					'sliderStep', 1,
					'sliderFunc', function(v)
						self.db.char.groups[v1].columns = v;
					end
				);
			end
		elseif v2 == "skills" or v2 == "items" or v2 == "pets" then
			if value ~= "group" and value ~= "condenseinto" then
				local default = false;
				local cooldowns = self.db.char.cooldowns;
				if v2 == "items" then
					cooldowns = self.db.char.itemcooldowns;
				elseif v2 == "pets" then
					cooldowns = self.db.char.petcooldowns;
				end
				if cooldowns[v1][value] == nil then default = true; end
				dd:AddLine(
					'text', L["Use Default"],
					'checked', default,
					'hasTooltip', true,
					'tooltipText', L["Uses the default bar settings"],
					'func', function()
						if cooldowns[v1][value] ~= nil then
							cooldowns[v1][value] = nil;
						else
							if self.db.char.groups[cooldowns[v1].group][value] ~= nil then
								cooldowns[v1][value] = self.db.char.groups[cooldowns[v1].group][value];
							else
								cooldowns[v1][value] = self.db.char.barOptions[value];
							end
						end
					end
				);
				if value == "texture" then
					for _,v in pairs(surface:List()) do
						dd:AddLine(
							'text', v,
							'checked', (cooldowns[v1].texture == v),
							'isRadio', true,
							'func', function()
								cooldowns[v1].texture = v;
							end,
							'disabled', default
						);
					end
				elseif value == "colors" then
					local colors;
					if cooldowns[v1][value] then
						for k,v in ipairs(self.db.char.groups[v1][value]) do
							if not colors then 
								colors = v;
							else 
								colors = colors.." "..v;
							end
						end
					else
						colors = "";
					end
					dd:AddLine(
						'text', L["Custom "]..L["Colors"],
						'disabled', default,
						'hasEditBox', true,
						'hasArrow', true,
						'editBoxText', colors,
						'editBoxFunc', function(s)
							if not string.find(s, "^%a+ %a+") then
								self:Print(L["Usage: <color1> <color2> ..."]);
								return;
							end
							cooldowns[v1].colors = {};
							for color in string.gmatch(s, "%a+") do
								table.insert(cooldowns[v1].colors, color);
							end
							self:Print(v1,L["colors set to: "], unpack(cooldowns[v1].colors));
						end
					);
				elseif value == "fade" then
					dd:AddLine(
						'text', L["Custom "]..L["Fade Time"],
						'disabled', default,
						'hasEditBox', true,
						'hasArrow', true,
						'editBoxText', cooldowns[v1].fade or self.db.char.groups[cooldowns[v1].group].fade or self.db.char.barOptions.fade,
						'editBoxFunc', function(v)
							if not string.find(v, "^%d+%.?%d*$") then
								self:Print(L["Usage: <fadetime> (in seconds)"]);
								return;
							end
							cooldowns[v1].fade = tonumber(v);
							self:Print(v1, L["fade time set to:"], cooldowns[v1].fade);
						end
					);
				end
			elseif value == "condenseinto" then
				local cooldowns = self.db.char.cooldowns;
				if v2 == "items" then
					cooldowns = self.db.char.itemcooldowns;
				elseif v2 == "pets" then
					cooldowns = self.db.char.petcooldowns;
				end
				dd:AddLine(
					'text', L["New Condense Group"],
					'tooltipText', L["Create a new Condense Group with\nthis as a member"],
					'hasEditBox', true,
					'hasArrow', true,
					'editBoxText', "",
					'editBoxFunc', function(s)
						cooldowns[v1] = nil;
						if v2 == "skills" then
							self.db.char.skillgroups[v1] = s;
						elseif v2 == "items" then
							self.db.char.itemgroups[v1] = s;
						end
						self:UpdateData();
					end
				);
				self.groups = {};
				for k,v in pairs(self.db.char.itemgroups) do
					if not self.groups[v] then self.groups[v] = {}; end
				end
				for k,v in pairs(self.db.char.skillgroups) do
					if not self.groups[v] then self.groups[v] = {}; end
				end
				for k in pairs(self.groups) do
					dd:AddLine(
						'text', k,
						'func', function()
							cooldowns[v1] = nil;
							if v2 == "skills" then
								self.db.char.skillgroups[v1] = k;
							elseif v2 == "items" then
								self.db.char.itemgroups[v1] = k;
							end
							self:UpdateData();
						end
					);
				end
			else
				local skill;
				if v2 == "skills" then
					skill = self.db.char.cooldowns[v1];
				elseif v2 == "items" then
					skill = self.db.char.itemcooldowns[v1];
				elseif v2 == "pets" then
					skill = self.db.char.petcooldowns[v1];
				end
				for k,v in pairs(self.db.char.groups) do
					if not v.disabled then
						dd:AddLine(
							'text', k,
							'checked', (skill.group == k),
							'isRadio', true,
							'func', function()
								skill.group = k;
							end
						);
					end
				end
			end
		elseif v2 == "condense" then
			if string.find(value, "^%%") then
			end
			dd:AddLine(
				'text', L["Remove"],
				'tooltipText', L["Remove this item from the condense group."],
				'func', function()
					self.db.char.itemgroups[value] = nil;
					self.db.char.skillgroups[value] = nil;
					self:PopulateCooldowns();
					self:UpdateData();
				end
			);
		end
	end
end
function CooldownTimers:OnClick()
	self:OpenMenu()
end
