local EFL = unpack(select(2,...))
local AddOnName = ...
EnhancedFriendsListOptions = {}
EnhancedFriendsListOptions["CollapsedGroups"] = {}

function EFL:GetOptions()
	local Ace3OptionsPanel = IsAddOnLoaded("ElvUI") and ElvUI[1] or Enhanced_Config[1]
	Ace3OptionsPanel.Options.args.EnhancedFriendsList = {
		type = "group",
		name = select(2, GetAddOnInfo(AddOnName)),
		order = 10,
		args = {
			header = {
				order = 1,
				type = "header",
				name = "Friends List Customization",
			},
			general = {
				order = 2,
				type = "group",
				name = "General",
				guiInline = true,
				get = function(info) return EnhancedFriendsListOptions[info[#info]] end,
				set = function(info, value) EnhancedFriendsListOptions[info[#info]] = value FriendsFrame_UpdateFriends() end, 
				args = {
					NameFont = {
						type = "select", dialogControl = 'LSM30_Font',
						order = 1,
						name = "Name Font",
						desc = "The font that the RealID / Character Name / Level uses.",
						values = AceGUIWidgetLSMlists.font,	
					},
					NameFontSize = {
						order = 2,
						name = "Name Font Size",
						desc = "The font size that the RealID / Character Name / Level uses.",
						type = "range",
						min = 6, max = 22, step = 1,
					},
					NameFontFlag = {
						name = 'Name Font Flag',
						desc = "The font flag that the RealID / Character Name / Level uses.",
						order = 3,
						type = "select",
						values = {
							['NONE'] = 'None',
							['OUTLINE'] = 'OUTLINE',
							['MONOCHROME'] = 'MONOCHROME',
							['MONOCHROMEOUTLINE'] = 'MONOCROMEOUTLINE',
							['THICKOUTLINE'] = 'THICKOUTLINE',
						},
					},
					InfoFont = {
						type = "select", dialogControl = 'LSM30_Font',
						order = 4,
						name = "Info Font",
						desc = "The font that the Zone / Server uses.",
						values = AceGUIWidgetLSMlists.font,	
					},
					InfoFontSize = {
						order = 5,
						name = "Info Font Size",
						desc = "The font size that the Zone / Server uses.",
						type = "range",
						min = 6, max = 22, step = 1,
					},
					InfoFontFlag = {
						order = 6,
						name = "Info Font Outline",
						desc = "The font flag that the Zone / Server uses.",
						type = "select",
						values = {
							['NONE'] = 'None',
							['OUTLINE'] = 'OUTLINE',
							['MONOCHROME'] = 'MONOCHROME',
							['MONOCHROMEOUTLINE'] = 'MONOCROMEOUTLINE',
							['THICKOUTLINE'] = 'THICKOUTLINE',
						},
					},
					InfoFontFlag = {
						order = 6,
						name = "Info Font Outline",
						desc = "The font flag that the Zone / Server uses.",
						type = "select",
						values = {
							['NONE'] = 'None',
							['OUTLINE'] = 'OUTLINE',
							['MONOCHROME'] = 'MONOCHROME',
							['MONOCHROMEOUTLINE'] = 'MONOCROMEOUTLINE',
							['THICKOUTLINE'] = 'THICKOUTLINE',
						},
					},
					TexturePath = {
						type = 'input',
						width = 'full',
						name = 'Path of Textures',
						desc = 'Available Textures: Gloss / Flat',
						order = 7,
					},
					FriendGroups = {
						type = 'toggle',
						name = 'FriendGroups',
						desc = 'Add FriendGroups',
						order = 8,
					},
				},
			},
		},
	}
end

local InjectOptions = CreateFrame("Frame")
InjectOptions:RegisterEvent("PLAYER_LOGIN")
InjectOptions:SetScript("OnEvent", function()
	if EnhancedFriendsListOptions["NameFont"] == nil then EnhancedFriendsListOptions["NameFont"] = IsAddOnLoaded('ElvUI') and 'ElvUI Font' or "Tukui Pixel" end
	if EnhancedFriendsListOptions["NameFontSize"] == nil then EnhancedFriendsListOptions["NameFontSize"] = 12 end
	if EnhancedFriendsListOptions["NameFontSize"] == nil then EnhancedFriendsListOptions["NameFontFlag"] = IsAddOnLoaded('ElvUI') and "OUTLINE" or "MONOCHROMEOUTLINE" end
	if EnhancedFriendsListOptions["InfoFont"] == nil then EnhancedFriendsListOptions["InfoFont"] = IsAddOnLoaded('ElvUI') and 'ElvUI Font' or "Tukui Pixel" end
	if EnhancedFriendsListOptions["InfoFontSize"] == nil then EnhancedFriendsListOptions["InfoFontSize"] = 12 end
	if EnhancedFriendsListOptions["InfoFontSize"] == nil then EnhancedFriendsListOptions["InfoFontFlag"] = IsAddOnLoaded('ElvUI') and "OUTLINE" or "MONOCHROMEOUTLINE" end
	if EnhancedFriendsListOptions["TexturePath"] == nil then EnhancedFriendsListOptions["TexturePath"] = "Interface\\AddOns\\EnhancedFriendsList\\Textures\\Flat\\" end
	if EnhancedFriendsListOptions["FriendGroups"] == nil then EnhancedFriendsListOptions["FriendGroups"] = false end

	if IsAddOnLoaded('ElvUI') then
		LibStub("LibElvUIPlugin-1.0"):RegisterPlugin(AddOnName, EFL.GetOptions)	
	else
		EFL:GetOptions()
	end

	if EnhancedFriendsListOptions["FriendGroups"] then
		EFL:FriendGroups()
	else
		EFL:Basic()
	end
end)