local L = AceLibrary("AceLocale-2.2"):new("ag_UnitFrames")
local Surface = AceLibrary("Surface-1.0")

-- Dewdrop stuff

function aUF:CreateMenu()
	local unitTable = {}
	unitTable.UnitHeader = {
		name = L["unitsettings"],
		type = 'header',
		order = 1,
	}

	local agDewdropMenu = {
		type= 'group',
		args = {
--			Units = {
--				name = L["units"],
--				type = 'group',
--				desc = L["UnitDesc"],
--				args = unitTable,
--				order = 2,
--			},
			Spacing1 = {
				name = " ",
				type = 'header',
				order = 19,
			},
			options = {
				name = L["options"],
				type = 'group',
				desc = L["optionsDesc"],
				order = 20,
				args = {
					FrameColors = {
						type= 'group',
						name = L["framecolors"],
						desc = L["framecolorsdesc"],
						args = {
							partybg = {
								name = L["partybg"],
								type = 'color',
								desc = L["partybgdesc"],
								hasAlpha = true,
								get = function()
									return self.db.profile.PartyFrameColors.r, self.db.profile.PartyFrameColors.g, self.db.profile.PartyFrameColors.b, self.db.profile.PartyFrameColors.a
								end,
								set = function(r, g, b, a)
									self.db.profile.PartyFrameColors.r, self.db.profile.PartyFrameColors.g, self.db.profile.PartyFrameColors.b, self.db.profile.PartyFrameColors.a = r, g, b, a
									self:CallUnitMethods("BorderBackground")
									self:CallUnitMethods("BorderBackground",nil,nil,nil,"subgroups")
								end,
								order = 1,
							},
							targetbg = {
								name = L["targetbg"],
								type = 'color',
								desc = L["targetbgdesc"],
								hasAlpha = true,
								get = function()
									return self.db.profile.TargetFrameColors.r, self.db.profile.TargetFrameColors.g, self.db.profile.TargetFrameColors.b, self.db.profile.TargetFrameColors.a
								end,
								set = function(r, g, b, a)
									self.db.profile.TargetFrameColors.r, self.db.profile.TargetFrameColors.g, self.db.profile.TargetFrameColors.b, self.db.profile.TargetFrameColors.a = r, g, b, a
									self:CallUnitMethods("BorderBackground")
									self:CallUnitMethods("BorderBackground",nil,nil,nil,"subgroups")
								end,
								order = 2,
							},
							border = {
								name = L["bordercolor"],
								type = 'color',
								desc = L["bordercolordesc"],
								hasAlpha = true,
								get = function()
									return self.db.profile.FrameBorderColors.r, self.db.profile.FrameBorderColors.g, self.db.profile.FrameBorderColors.b, self.db.profile.FrameBorderColors.a
								end,
								set = function(r, g, b, a)
									self.db.profile.FrameBorderColors.r, self.db.profile.FrameBorderColors.g, self.db.profile.FrameBorderColors.b, self.db.profile.FrameBorderColors.a = r, g, b, a
									self:CallUnitMethods("BorderBackground")
									self:CallUnitMethods("BorderBackground",nil,nil,nil,"subgroups")
								end,
								order = 3,
							},
						},
						order = 51,
					},
					BarColors = {
						type= 'group',
						args = {
							Health = {
								name = L["health"],
								type = 'color',
								desc = L["healthDesc"],
								get = function()
									return self.db.profile.HealthColor.r, self.db.profile.HealthColor.g, self.db.profile.HealthColor.b
								end,
								set = function(r, g, b)
									self.db.profile.HealthColor.r, self.db.profile.HealthColor.g, self.db.profile.HealthColor.b = r, g, b
									self:CallUnitMethods("StatusBarsColor")
								end,
								order = 1,
							},
							Mana = {
								name = L["mana"],
								type = 'color',
								desc = L["manaDesc"],
								get = function()
									return self.db.profile.ManaColor[0].r, self.db.profile.ManaColor[0].g, self.db.profile.ManaColor[0].b
								end,
								set = function(r, g, b)
									self.db.profile.ManaColor[0].r, self.db.profile.ManaColor[0].g, self.db.profile.ManaColor[0].b = r, g, b
									self:CallUnitMethods("StatusBarsColor")
								end,
								order = 2,
							},
							Rage = {
								name = L["rage"],
								type = 'color',
								desc = L["rageDesc"],
								get = function()
									return self.db.profile.ManaColor[1].r, self.db.profile.ManaColor[1].g, self.db.profile.ManaColor[1].b
								end,
								set = function(r, g, b)
									self.db.profile.ManaColor[1].r, self.db.profile.ManaColor[1].g, self.db.profile.ManaColor[1].b = r, g, b
									self:CallUnitMethods("StatusBarsColor")
								end,
								order = 3,
							},
							Energy = {
								name = L["energy"],
								type = 'color',
								desc = L["energyDesc"],
								get = function()
									return self.db.profile.ManaColor[3].r, self.db.profile.ManaColor[3].g, self.db.profile.ManaColor[3].b
								end,
								set = function(r, g, b)
									self.db.profile.ManaColor[3].r, self.db.profile.ManaColor[3].g, self.db.profile.ManaColor[3].b = r, g, b
									self:CallUnitMethods("StatusBarsColor")
								end,
								order = 4,
							},
							PetFocus = {
								name = L["petfocus"],
								type = 'color',
								desc = L["petfocusDesc"],
								get = function()
									return self.db.profile.ManaColor[2].r, self.db.profile.ManaColor[2].g, self.db.profile.ManaColor[2].b
								end,
								set = function(r, g, b)
									self.db.profile.ManaColor[2].r, self.db.profile.ManaColor[2].g, self.db.profile.ManaColor[2].b = r, g, b
									self:CallUnitMethods("StatusBarsColor")
								end,
								order = 5,
							},
						},
						order = 52,
						name = L["barcolors"],
						desc = L["barcolorsDesc"],
					},
					BarStyle = {
						name = L["barstyle"],
						type = 'text',
						desc = L["BarStyleDesc"],
						get = function()
							return self.db.profile.BarStyle
						end,
						set = function(option)
							self.db.profile.BarStyle = option
							self:CallUnitMethods("BarTexture")
						end,
						validate = Surface:List(),
						order = 53,
					},
					Spacing1 = {
						name = " ",
						type = 'header',
						order = 54,
					},
					ShowPvPIcon = {
						name = L["pvpicon"],
						type = 'toggle',
						desc = L["ShowPVPIconDesc"],
						get = function()
							return self.db.profile.ShowPvPIcon
						end,
						set = function(option)
							self.db.profile.ShowPvPIcon = option
							self:CallUnitMethods("UpdatePvP",true)
						end,
						order = 55,
					},
					ShowGroupIcons = {
						name = L["groupicon"],
						type = 'toggle',
						desc = L["ShowGroupIconsDesc"],
						get = function()
							return self.db.profile.ShowGroupIcons
						end,
						set = function(option)
							self.db.profile.ShowGroupIcons = option
							self:CallUnitMethods("LabelsCheckLeader")
						end,
						order = 56,
					},
					HighlightSelected = {
						name = L["highlightselected"],
						type = 'toggle',
						desc = L["HighlightSelectedDesc"],
						get = function()
							return self.db.profile.HighlightSelected
						end,
						set = function(option)
							self.db.profile.HighlightSelected = option
						end,
						order = 57,
					},
					SmoothBarColoring = {
						name = L["smoothbarcoloring"],
						type = 'toggle',
						desc = L["SmoothBarColoringDesc"],
						get = function()
							return self.db.profile.SmoothHealthBars
						end,
						set = function(option)
							self.db.profile.SmoothHealthBars = option
							self:CallUnitMethods("StatusBarsColor")
						end,
						order = 58,
					},
				},
			},
			Locked = {
				name = L["lock"],
				type = 'toggle',
				desc = L["LockedDesc"],
				get = function()
					return self.db.profile.Locked
				end,
				set = function(option)
					self.db.profile.Locked = option
					self:UpdateDisplay()
				end,
				order = 59,
			},
		}
	}

	for order,unit in ipairs(self.wowClasses) do
		agDewdropMenu.args[unit] = aUF:CreateDewdrop(unit,(order + 1),true)
	end
--	if Click2Cast then
--		agDewdropMenu.args.Click2Cast = Click2Cast.optionsTable
--		Click2Cast.order = 3
--	end

	return agDewdropMenu
end

function aUF:CreateDewdrop(class,order,mainmenu)
	local prettyname = (L:HasTranslation(class) and L[class]) or class
	local strings = {"HealthText","ManaText","NameLabel","ClassText"}
	local wStrings = {["HealthText"] = true,["ManaText"] = true}
	local stringArgs = {}

	for k,v in pairs(strings) do
		local name = v
		local order = k
		local validate
		if v == "HealthText" or v == "ManaText" then
			validate = {"Absolute", "Difference", "Percent", "Smart","Custom", "Hide"}
		else
			validate = {"Default","Custom", "Hide"}
		end
		stringArgs[v] = {
			name = string.format(L["%s Text"], L[name] or name),
			type = 'group',
			desc = L["UnitDesc"],
			order = order,
			args = {
				StatusTextStyle = {
					name = L["Style"],
					type = 'text',
					desc = L["StatusTextDesc"],
					get = function()
						return self.db.profile.units[class][name.."Style"]
					end,
					set = function(option)
						self.db.profile.units[class][name.."Style"] = option
						self:CallUnitMethods("GetStringEvents",true,class,"type")
						self:CallUnitMethods("GetStringEvents",nil,class,"type")
						self:CallUnitMethods("UpdateTextStrings",nil,class,"type")
					end,
					validate = validate,
					order = 1,
				},
				HealthCustom = {
					name = L["Custom"],
					type = 'text',
					desc = L["StatusTextDesc"],
					get = function()
						return self.db.profile.units[class][name.."Format"]
					end,
					set = function(option)
						self.db.profile.units[class][name.."Format"] = option
						self:CallUnitMethods("GetStringEvents",true,class,"type")
						self:CallUnitMethods("GetStringEvents",nil,class,"type")
						self:CallUnitMethods("UpdateTextStrings",nil,class,"type")
					end,
					validate = function(option)
						for s,data,e in option:gmatch("()(%b[])()") do
							local tag = data:sub(2, -2)
							local func = aUF:GetTagFunction(tag)
							if not func then
								return false
							end
						end
						return true
					end,
					usage = "",
					order = 2,
				},
				Width = {
					name = L["widthstring"],
					type = 'range',
					desc = L["widthstringDesc"],
					min = 0,
					max = 400,
					step = 1,
					get = function()
						local db = self.db.profile.units[class][name.."Width"]
						if db then
							return db
						else
							return 0
						end
					end,
					set = function(option)
						self.db.profile.units[class][name.."Width"] = option
						self:CallUnitMethods("SetWidth",nil,class,"type")
					end,
					order = 3,
					hidden = function() return not wStrings[v] end,
				},

			}
		}
	end

	local table = {
		name = prettyname,
		type = 'group',
		desc = string.format(L["%s Settings"], prettyname),
		order = order,
		args = {
			UnitHeader = {
				name = string.format(L["layoutsettings"], prettyname),
				type = 'header',
				order = 1,
			},
			FrameStyle = {
				name = L["framestyle"],
				type = 'text',
				desc = L["FrameStyleDesc"],
				validate = aUF.indexLayouts,
				usage = "",
				get = function()
					return self.db.profile.units[class].FrameStyle
				end,
				set = function(option)
					self.db.profile.units[class].FrameStyle = option
					self:CallUnitMethods("ApplyTheme",true,class,"type")
					self:CallUnitMethods("BorderBackground",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
					for k,v in pairs(self.subgroups) do
						v:UpdateWidth()
					end
				end,
				order = 2,
			},

			BorderStyle = {
				name = L["borders"],
				type = 'text',
				desc = L["BordersDesc"],
				validate = {"Classic", "Nurfed", "Hidden"},
				usage = "",
				get = function()
					return self.db.profile.units[class].BorderStyle
				end,
				set = function(option)
					self.db.profile.units[class].BorderStyle = option
					self:CallUnitMethods("BorderBackground",nil,class,"type")
				end,
				order = 3,			
			},
			
			Width = {
				name = L["widthadjust"],
				type = 'range',
				desc = L["widthadjustDesc"],
				min = 50,
				max = 400,
				step = 1,
				get = function()
					return self.db.profile.units[class].Width
				end,
				set = function(option)
					self.db.profile.units[class].Width = option
					self:CallUnitMethods("SetWidth",nil,class,"type")
					for k,v in pairs(self.subgroups) do
						v:UpdateWidth()
					end
				end,
				order = 5,
			},

			StatusTextStyle = {
				name = L["Status Text"],
				type = 'group',
				desc = L["UnitDesc"],
				order = 5,
				args = stringArgs,
			},
			Scale = {
				name = L["scale"],
				type = 'range',
				desc = L["ScaleDesc"],
				min = 0.5,
				max = 2,
				step = 0.05,
				isPercent = true,
				get = function()
					return self.db.profile.units[class].Scale
				end,
				set = function(option)
					self.db.profile.units[class].Scale = option
					self:CallUnitMethods("LoadScale",nil,class,"type")
					self:CallUnitMethods("LoadPosition",nil,class,"type")
					for k,v in pairs(self.subgroups) do
						v:UpdateScale()
						v:LoadPosition()
					end
				end,
				order = 7,
			},
			ClassColorBars = {
				name = L["classcolorbar"],
				type = 'toggle',
				desc = L["ClassColorBarsDesc"],
				get = function()
					return self.db.profile.units[class].ClassColorBars
				end,
				set = function(option)
					self.db.profile.units[class].ClassColorBars = option
					self:CallUnitMethods("StatusBarsColor",nil,class,"type")
				end,
				order = 20,
				hidden = function() if class == "pet" or class == "partypet" or class == "raidpet" then return true end end
			},
			RaidColorName = {
				name = L["raidcolorname"],
				type = 'toggle',
				desc = L["RaidColorNameDesc"],
				get = function()
					return self.db.profile.units[class].RaidColorName
				end,
				set = function(option)
					self.db.profile.units[class].RaidColorName = option
					self:CallUnitMethods("UpdateTextStrings",nil,class,"type")
				end,
				order = 21,
				hidden = function() if class == "pet" or class == "partypet" or class == "raidpet" then return true end end
			},
			ShowCombat = {
				name = L["showcombat"],
				type = 'toggle',
				desc = L["ShowCombatDesc"],
				get = function()
					return self.db.profile.units[class].ShowCombat
				end,
				set = function(option)
					self.db.profile.units[class].ShowCombat = option
				end,
				order = 23,
				hidden =    function()
								if not (class == "player" or class == "pet" or class == "party"
									or class == "target" or class == "focus" or class == "raid"
									or class == "partypet" or class == "raidpet") then
									return true
								end
							end,
			},
			ShowInCombatIcon = {
				name = L["showincombat"],
				type = 'toggle',
				desc = L["ShowInCombatDesc"],
				get = function ()
					return self.db.profile.units[class].ShowInCombatIcon
				end,
				set = function(option)
					self.db.profile.units[class].ShowInCombatIcon = option
				end,
				order = 24,
			},
			ShowRaidTargetIcon = {
				name = L["showraidicon"],
				type = 'toggle',
				desc = L["ShowRaidIconDesc"],
				get = function ()
					return self.db.profile.units[class].ShowRaidTargetIcon
				end,
				set = function(option)
					self.db.profile.units[class].ShowRaidTargetIcon = option
					self:CallUnitMethods("UpdateRaidTargetIcon",true,class,"type")
				end,
				order = 25,
			},
			LongStatusbars = {
				name = L["longbars"],
				type = 'toggle',
				desc = L["LongBarsDesc"],
				get = function()
					return self.db.profile.units[class].LongStatusbars
				end,
				set = function(option)
					self.db.profile.units[class].LongStatusbars = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
				end,
				order = 26,
			},
			EnableCast = {
				name = L["castbar"],
				type = 'toggle',
				desc = L["castbarDesc"],
				get = function()
					return self.db.profile.units[class].CastBar
				end,
				set = function(option)
					self.db.profile.units[class].CastBar = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
					if class == "player" then
						if option then
							aUF.db.profile.BlizzCastbar = false
						else
							aUF.db.profile.BlizzCastbar = true
						end
						aUF:UpdateBlizzVisibility()
					end
				end,
				order = 28,
			},
			HealthDeficit = {
				name = L["healthdeficit"],
				type = 'toggle',
				desc = L["healthdeficitDesc"],
				get = function()
					return self.db.profile.units[class].HealthDeficit
				end,
				set = function(option)
					self.db.profile.units[class].HealthDeficit = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
				end,
				order = 28.5,
			},
			HideMana = {
				name = L["hidemana"],
				type = 'toggle',
				desc = L["HideManaDesc"],
				get = function()
					return self.db.profile.units[class].HideMana
				end,
				set = function(option)
					self.db.profile.units[class].HideMana = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
				end,
				order = 29,
			},
			ShowPortrait = {
				name = L["showportrait"],
				type = 'toggle',
				desc = L["ShowPortraitDesc"],
				get = function()
					return self.db.profile.units[class].Portrait
				end,
				set = function(option)
					self.db.profile.units[class].Portrait = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
				end,
				order = 30,
			},
			HideFrame = {
				name = L["hideframe"],
				type = 'toggle',
				desc = L["HideFrameDesc"],
				get = function()
					return self.db.profile.units[class].HideFrame
				end,
				set = function(option)
					self.db.profile.units[class].HideFrame = option
					if option == true then
						self:CallUnitMethods("UpdateAll",true,class,"type")
					else
						self:CallUnitMethods("UpdateAll",false,class,"type")
					end
					for k,v in pairs(self.subgroups) do
						v:SetVisibility()
					end
				end,
				order = 33,
			},
			Spacing1 = {
				name = " ",
				type = 'header',
				order = 35,
			},
			AuraHeader = {
				name = L["aurasettings"],
				type = 'header',
				order = 39,
			},
			AuraPos = {
				name = L["aurapos"],
				type = 'text',
				desc = L["AuraPosDesc"],
				get = function()
					return self.db.profile.units[class].AuraPos
				end,
				set = function(option)
					self.db.profile.units[class].AuraPos = option
					self:CallUnitMethods("UpdateAuras",true,class,"type")
					self:CallUnitMethods("AuraPosition",true,class,"type")
				end,
				validate = {"Right", "Left", "Above", "Below","Inside","Hidden"},
				order = 41,
			},
			AuraRows = {
				name = L["aurarowsadjust"],
				type = 'range',
				desc = L["aurarowsadjustDesc"],
				min = 1,
				max = 4,
				step = 1,
				get = function()
					return self.db.profile.units[class].AuraRows
				end,
				set = function(option)
					self.db.profile.units[class].AuraRows = option
					self:CallUnitMethods("SetAuraCount",nil,class,"type")
					self:CallUnitMethods("AuraPosition",nil,class,"type")
					self:CallUnitMethods("UpdateAuras",nil,class,"type")
				end,
				order = 42,
			},
			AuraCols = {
				name = L["auracolsadjust"],
				type = 'range',
				desc = L["auracolsadjustDesc"],
				min = 8,
				max = 24,
				step = 1,
				get = function()
					return self.db.profile.units[class].AuraColumns
				end,
				set = function(option)
					self.db.profile.units[class].AuraColumns = option
					self:CallUnitMethods("SetAuraCount",nil,class,"type")
					self:CallUnitMethods("AuraPosition",nil,class,"type")
					self:CallUnitMethods("UpdateAuras",nil,class,"type")
				end,
				order = 43,
			},
			DebuffColoring = {
				name = L["debuffcoloring"],
				type = 'toggle',
				desc = L["DebuffColoringDesc"],
				get = function()
					return self.db.profile.units[class].AuraDebuffC
				end,
				set = function(option)
					self.db.profile.units[class].AuraDebuffC = option
					self:CallUnitMethods("UpdateAuras",true,class,"type")
				end,
				order = 44,
			},
			AuraFilter = {
				name = L["aurafilter"],
				type = 'toggle',
				desc = L["AuraFilterDesc"],
				get = function()
					if self.db.profile.units[class].AuraFilter == 1 then
						return true
					else
						return false
					end
				end,
				set = function(option)
					if option == true then
						self.db.profile.units[class].AuraFilter = 1
					else
						self.db.profile.units[class].AuraFilter = 0
					end
					self:CallUnitMethods("UpdateAuras",true,class,"type")
				end,
				order = 45,
			},
			AuraPreferBuff = {
				name = L["Prioritize buffs"],
				type = 'toggle',
				desc = L["Prioritize buffs above debuffs"],
				get = function()
					return self.db.profile.units[class].AuraPreferBuff
				end,
				set = function(v)
					self.db.profile.units[class].AuraPreferBuff = v;
				end,
				order = 46
			},
			ShowXP = {
				name = L["showxp"],
				type = 'toggle',
				desc = L["ShowXPDesc"],
				get = function()
					return self.db.profile.units[class].ShowXP
				end,
				set = function(option)
					self.db.profile.units[class].ShowXP = option
					self:CallUnitMethods("ApplyTheme",nil,class,"type")
					self:CallUnitMethods("UpdateAll",nil,class,"type")
				end,
				order = 26,
				hidden = function() if not (class == "player" or class == "pet") then return true end end,
			},
			PetGrouping = {
				name = L["petgrouping"],
				type = 'text',
				desc = L["PetGroupingDesc"],
				get = function()
					return self.db.profile.PetGrouping
				end,
				set = function(option)
					self.db.profile.PetGrouping = option
					self:CallUnitMethods("UpdateAll")
				end,
				validate = {["withplayer"] = L["withplayer"], ["nogroup"] = L["nogroup"]},
				order = 6,
				hidden = function() if not (class == "pet") then return true end end,
			},
			TargetShowHostile = {
				name = L["targetshowhostile"],
				type = 'toggle',
				desc = L["TargetHostileDesc"],
				get = function()
					return self.db.profile.TargetShowHostile
				end,
				set = function(option)
					self.db.profile.TargetShowHostile = option
					self:CallUnitMethods("StatusBarsColor",nil,class,"type")
				end,
				order = 22,
				hidden = function() if not (class == "target") then return true end end,
			},
			RaidHideParty = {
				name = L["raidhideparty"],
				type = 'toggle',
				desc = L["RaidHidePartyDesc"],
				get = function()
					return self.db.profile.RaidHideParty
				end,
				set = function(option)
					self.db.profile.RaidHideParty = option
				end,
				order = 32,
				hidden = function() if not (class == "party") then return true end end,
			},
			SpacingRaid = {
				name = " ",
				type = 'header',
				order = 100,
				hidden = function() if not (class == "raid") then return true end end,
			},
			CreateGroup = {
				name = L["create"],
				type = 'execute',
				desc = L["createDesc"],
				func = function()
					local k = self:CreateNewGroup()
					self.mainMenu.args.raid.args.Groups.args[k] = aUF:GroupCreateMenu(k)
				end,
				order = 105,
				hidden = function() if not (class == "raid") then return true end end,
			},
			Groups = aUF:CreateDewdropGrouplist(class),
			RaidSet = {
				name = L["Current Raidset"],
				type = 'text',
				desc = L["Current RaidsetDesc"],
				get = function()
					return self.db.profile.CurrentRaidSet
				end,
				set = function(option)
					self.db.profile.CurrentRaidSet = option
					for k,v in pairs(self.subgroups) do
						v:SetVisibility()
					end
				end,
				order = 101,
				validate = {"1","2","3","4","5","6","7","8","9","10"},
				hidden = function() if not (class == "raid") then return true end end,
			},
			EndSpacing = {
				name = " ",
				type = 'header',
				order = 1000,
				hidden = function() if (mainmenu) then return true end end
			},
			--[[AuraCountUpdate = {
				name = "Update aura count",
				type = 'execute',
				desc = 'Update the aura count',
				func = function() self:CallUnitMethods("ShowAuraPositions",nil,class,"type") end,
				order = 48,
			},]]
		}
	}

	if class == "party" or "partypet" then
		if class == "party" then
			table.args.PartyGrouping = aUF:GroupCreateMenu("party")
		elseif class == "partypet" then
			table.args.PartyGrouping = aUF:GroupCreateMenu("partypet")
		end
		if table.args.PartyGrouping then
			table.args.PartyGrouping.name = L["groupsettings"]
			table.args.PartyGrouping.desc = L["groupsettingsDesc"]
			table.args.PartyGrouping.order = 4
		end
	end

	if not mainmenu then
		table.args.UnitHeader.name = string.format(L["frame"], (L:HasTranslation(class) and L[class]) or class)
	end

	return table
end

function aUF:GroupCreateMenu(entry,menuG)
	if not entry then return end
	local entry = entry	
	local menu = {
		name = (self.subgroups[entry] and
		self.subgroups[entry].database and
		self.subgroups[entry].database.Name) or entry,
		type = 'group',
		desc = " ",
		order = order,
		hidden = function() if not (self.subgroups[entry]) or (self.subgroups[entry].database.Exists ~= true) then return true end end,		
		args = {
			UnitHeader = {
				name = paranthesisName or entry,
				type = 'header',
				order = 1,
				hidden = function() if entry == "party" then return true end end
			},
			Name = {
				name = L["setname"],
				type = 'text',
				desc = L["setnameDesc"],
				get = function()
					return self.subgroups[entry].database.Name or entry
				end,
				usage = "nissefar",
				set = function(option)
					if option == "" then
						self.subgroups[entry].database.Name = nil
					else
						self.subgroups[entry].database.Name = option
					end
					self.subgroups[entry]:UpdateTitle()
					self.mainMenu = aUF:CreateMenu()
					self.dewdrop:Refresh(3)
					self.dewdrop:Refresh(4)
				end,
				order = 6,
				hidden = function() return party end
			},
			GroupFilter = {
				name = L["groupfilter"],
				type = 'text',
				desc = L["groupfilterDesc"],
				get = function()
					return self.subgroups[entry].database.groupFilter
				end,
				usage = "",
				set = function(option)
					self.subgroups[entry].database.groupFilter = option
					self.subgroups[entry]:UpdateGroupFilter()
				end,
				order = 7,
			},
			nameList = {
				name = L["playernames"],
				type = 'text',
				desc = L["playernamesDesc"],
				get = function()
					return self.subgroups[entry].database.nameList
				end,
				usage = "",
				set = function(option)
					self.subgroups[entry].database.nameList = option
					self.subgroups[entry]:UpdateGroupFilter()
				end,
				order = 8,
			},
			groupBy = {
				name = L["sortmethod"],
				type = 'text',
				desc = L["sortmethodDesc"],
				get = function()
					return self.subgroups[entry].database.groupBy
				end,
				usage = "",
				set = function(option)
					self.subgroups[entry].database.groupBy = option
					self.subgroups[entry]:UpdateGroupFilter()
				end,
				validate = {["NAME"] = L["Name"], ["INDEX"] = L["Index"],["GROUP"] = L["Subgroup"], ["CLASS"] = L["Class"],},
				order = 9,
			},
			Space = {
				name = " ",
				type = 'header',
				order = 10,
			},
			Grow = {
				name = L["groupgrow"],
				type = 'text',
				desc = L["groupgrowDesc"],
				get = function()
					return self.subgroups[entry].database.Grow
				end,
				set = function(option)
					self.subgroups[entry].database.Grow = option
					self.subgroups[entry]:UpdateGrowth()
				end,
				validate = {["BOTTOM"] = L["up"], ["TOP"] = L["down"], ["RIGHT"] = L["left"], ["LEFT"] = L["right"]},
				order = 20,
			},
			Padding = {
				name = L["padding"],
				type = 'range',
				desc = L["paddingDesc"],
				min = 0,
				max = 100,
				step = 1,
				isPercent = false,
				get = function()
					return self.subgroups[entry].database.Padding
				end,
				set = function(option)
					self.subgroups[entry].database.Padding = option
					self.subgroups[entry]:UpdateGrowth()
				end,
				order = 22,
			},
			Space2 = {
				name = " ",
				type = 'header',
				order = 24,
			},
			AnchorOffset = {
				name = L["anchordist"],
				type = 'range',
				desc = L["anchordistDesc"],
				min = 0,
				max = 50,
				step = 1,
				isPercent = false,
				get = function()
					return self.subgroups[entry].database.AnchorOffset
				end,
				set = function(option)
					self.subgroups[entry].database.AnchorOffset = option
					self.subgroups[entry]:UpdateGrowth()
				end,
				order = 26,
			},
			ShowAnchor = {
				name = L["groupshowanchor"],
				type = 'toggle',
				desc = L["groupshowanchorDesc"],
				get = function()
					return self.subgroups[entry].database.ShowAnchor
				end,
				set = function(option)
					self.subgroups[entry].database.ShowAnchor = option
					self.subgroups[entry]:UpdateTitle()
				end,
				order = 28,
			},
			Space3 = {
					name = " ",
					type = 'header',
					order = 35,
					hidden = function() if self.subgroups[entry].type ~= "raid" then return true end end
			},				
			Space4 = {
				name = " ",
				type = 'header',
				order = 50,
				hidden = function() if self.subgroups[entry].type ~= "raid" then return true end end
			},
			Delete = {
					name = L["delete"],
					type = 'execute',
					desc = L["deleteDesc"],
					func = function()
						self.subgroups[entry]:Delete()
						self.dewdrop:Refresh(3)
						self.dewdrop:Close(4)
					end,
					order = 51,
					hidden = function() if self.subgroups[entry].type ~= "raid" then return true end end
			},		
		},
	}
	
	local RaidSets = {}
	for m = 1,10 do
		local var = tostring(m)
		RaidSets[var] = {
				name = string.format(L["Raidset %d"],var),
				type = 'toggle',
				desc = string.format(L["RaidsetDesc %d"],var),
				get = function()
					if (self.subgroups[entry].database.RaidSets and self.subgroups[entry].database.RaidSets[var]) or (not (self.subgroups[entry].database.RaidSets)) or (self.subgroups[entry].database.RaidSets and self.subgroups[entry].database.RaidSets[var] == nil) then
						return true
					else
						return false
					end
				end,
				set = function(option)
					if not self.subgroups[entry].database.RaidSets then
						self.subgroups[entry].database.RaidSets = {}
					end
				   self.subgroups[entry].database.RaidSets[var] = option
				   self.subgroups[entry]:SetVisibility()
				end,
				order = m,
		}
	end
	menu.args.RaidSet = {
			name = L["Select Raidsets"],
			type = 'group',
			desc = L["RaidSetDesc"],
			order = 36,
			args = RaidSets,
			hidden = function() if self.subgroups[entry].type ~= "raid" then return true end end
	}		
	return menu
end

function aUF:CreateDewdropGrouplist(class)
	local groupTable = {}
	for k,v in pairs(self.db.profile.subgroups) do
		if self.db.profile.subgroups[k].Exists == true then
			if k ~= "party" and k ~= "partypet" then
				groupTable[k] = aUF:GroupCreateMenu(k)
			end
		end
	end
	local menu = {
		name = L["groups"],
		type = 'group',
		desc = L["groupsDesc"],
		args = groupTable,
		order = 102,
		hidden = function() if not (class == "raid") then return true end end,
	}
	return menu
end
