--=============================================
---
--- GoldCounter (DDM.lua) by Hexiatröhm
---
--=============================================

--- Create DropDownMenus
function GC_Create_DDM()

	--- Font Options DropDownMenu
	local f = GCLibDD:Create_UIDropDownMenu( "GC_FontDropDownList", GoldCounterOptionsPanel )
	f:SetSize(192, 16)
	f:SetPoint( "TOPLEFT", "GoldCounterOptionsPanel", "TOPLEFT", 382, -74 )
	GCLibDD:UIDropDownMenu_SetWidth( GC_FontDropDownList, 192 )
	GCLibDD:UIDropDownMenu_JustifyText( GC_FontDropDownList, "LEFT" )
	GCLibDD:UIDropDownMenu_Initialize( GC_FontDropDownList, GC_FontDropDownList_Init, "LIST", 1 )
	GC_FontDropDownList_OnClick( nil, My_GC_Settings_Local.Font )

	--- Thousand Separator DropDownMenu
	local f = GCLibDD:Create_UIDropDownMenu( "GC_ThouSeparator_DropDownList", GoldCounterOptionsPanel )
	f:SetSize(192, 16)
	f:SetPoint( "TOPLEFT", "GoldCounterOptionsPanel", "TOPLEFT", 240, -277 )
	GCLibDD:UIDropDownMenu_SetWidth( GC_ThouSeparator_DropDownList, 32 )
	GCLibDD:UIDropDownMenu_JustifyText( GC_ThouSeparator_DropDownList, "CENTER" )
	GCLibDD:UIDropDownMenu_Initialize( GC_ThouSeparator_DropDownList, GC_ThouSeparator_DropDownList_Init, "LIST", 1 )
	GCLibDD:UIDropDownMenu_SetText( GC_ThouSeparator_DropDownList, My_GC_Settings_Local.Thousand_Delimiter )

	--- Date Format DropDownMenu
	local f = GCLibDD:Create_UIDropDownMenu( "GC_DateFormat_DropDownList", GoldCounterOptionsPanel )
	f:SetSize(196, 16)
	f:SetPoint( "TOPLEFT", "GoldCounterOptionsPanel", "TOPLEFT", 490, -277 )
	GCLibDD:UIDropDownMenu_SetWidth( GC_DateFormat_DropDownList, 96 )
	GCLibDD:UIDropDownMenu_JustifyText( GC_DateFormat_DropDownList, "CENTER" )
	GCLibDD:UIDropDownMenu_Initialize( GC_DateFormat_DropDownList, GC_DateFormat_DropDownList_Init, "LIST", 1 )
	GCLibDD:UIDropDownMenu_SetText( GC_DateFormat_DropDownList, My_GC_Settings_Local.UserDateFormat )

	--- CharDB Options DropDownMenu
	local f = GCLibDD:Create_UIDropDownMenu( "GC_CharDB_DropDownList", GoldCounterOptionsPanel )
	f:SetSize(192, 16)
	f:SetPoint( "TOPLEFT", "GoldCounterOptionsPanel", "TOPLEFT", 120, -448 )
	GCLibDD:UIDropDownMenu_SetWidth( GC_CharDB_DropDownList, 192 )
	GCLibDD:UIDropDownMenu_JustifyText( GC_CharDB_DropDownList, "LEFT" )
	GCLibDD:UIDropDownMenu_Initialize( GC_CharDB_DropDownList, GC_CharDB_DropDownList_Init, "LIST", 1 )
	GCLibDD:UIDropDownMenu_SetText( GC_CharDB_DropDownList, GC_Locale_Text.OPTIONSPANELTXT_CHOOSECHAR )
	GC_Options_ClearDB_Button:Disable() --- Disable button until selection

	--- Quick Options Menus
	local f = GCLibDD:Create_UIDropDownMenu( "GC_OptionsMenuFrame", GoldCounter_MainFrame )
	GCLibDD:UIDropDownMenu_Initialize( GC_OptionsMenuFrame, GC_OptionsMenuFrame_Init, "MENU", 1 )

end

function GC_FontDropDownList_OnClick( self, arg1, arg2, checked )

	--- If no default font set default font
	if ( arg1 == nil ) then My_GC_Settings_Local.Font = GC_CounterFonts_List[1]

	else My_GC_Settings_Local.Font = arg1

	end
	---

	--- If Font is non-existent then default
	local Flag = false
	for i = 1, #GC_CounterFonts_List do
		if ( arg1 == GC_CounterFonts_List[i] ) then Flag = true
		end
	end

	if ( not Flag ) then
		My_GC_Settings_Local.Font = GC_CounterFonts_List[1]
	end
	---

	--- Set Menu List Title Font
	GCLibDD:UIDropDownMenu_SetText( GC_FontDropDownList, My_GC_Settings_Local.Font )
	---

	GC_ShowGolds:SetFontObject( My_GC_Settings_Local.Font )
	GC_ShowSilvers:SetFontObject( My_GC_Settings_Local.Font )
	GC_ShowCoppers:SetFontObject( My_GC_Settings_Local.Font )

end

function GC_FontDropDownList_Init( frame, level, menuList )

	local info = { }

	for i = 1, #GC_CounterFonts_List do

		info = { }

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_FontDropDownList_OnClick
		info.value = i

		info.text  = GC_CounterFonts_List[i]
		info.notCheckable = true
		info.arg1  = info.text
		info.arg2  = info.value

		--- Tag the current value ---
		if GC_CounterFonts_List[i] == My_GC_Settings_Local.Font then
			info.isTitle = true
		end

		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

	end

end

function GC_CharDB_DropDownList_OnClick( self, arg1, arg2, checked )

	if not arg1 then return end
	
	GCLibDD:UIDropDownMenu_SetText( GC_CharDB_DropDownList, arg1 )
	GC_CharIndexToDelete = arg2

	GC_Options_ClearDB_Button:Enable()

end

function GC_CharDB_DropDownList_Init( frame, level, menuList )

	local Name, NameData, FactionLocale, info = nil, nil, nil, { }

		if #My_GC_CharMoneyDB > 2 then --- If more than 2 characters (current included) then option to erase all
		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func	= GC_CharDB_DropDownList_OnClick
		info.value	= -1
		info.text	= "|cfff0f010"..GC_Locale_Text.OPTIONSPANELTXT_ALL_CHAR.."|r"
		info.arg1	= info.text
		info.arg2	= info.value
		info.notCheckable = true

		GCLibDD:UIDropDownMenu_AddButton( info, 1 )
		end
		
	for i = 1, #My_GC_CharMoneyDB, 1 do


		--- Compatibility Classic
		if My_GC_CharMoneyDB[i].FactionLocale == nil or My_GC_CharMoneyDB[i].FactionLocale == "?" then

			FactionLocale = My_GC_CharMoneyDB[i].Faction
		else
			FactionLocale = My_GC_CharMoneyDB[i].FactionLocale
		end

		--- Couleur Faction
		if My_GC_CharMoneyDB[i].Faction == "Alliance" then

			FactionLocale = "|cff0070DD".. FactionLocale .. "|r"

		elseif My_GC_CharMoneyDB[i].Faction == "Horde" then

			FactionLocale = "|cffC41E3A".. FactionLocale .. "|r"

		end

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_CharDB_DropDownList_OnClick
		info.value = i

		Name     = GC_GetClassColor( My_GC_CharMoneyDB[i].Name, My_GC_CharMoneyDB[i].Class )
		NameData = Name.." - "..My_GC_CharMoneyDB[i].Level.." - "..FactionLocale.." - "..My_GC_CharMoneyDB[i].Realm

		info.text  = NameData
		info.notCheckable = true
		info.arg1 = My_GC_CharMoneyDB[i].NormName
		info.arg2 = info.value

		if ( My_GC_CharMoneyDB[i].NormName ~= GC_PlayerNormName ) or not My_GC_CharMoneyDB[i].NormName then
				GCLibDD:UIDropDownMenu_AddButton( info, 1 )
		end
	end
end

function GC_OptionsMenuFrame_Init( frame, Level, menuList )

	local info = { }

		if Level == 1 then

		info = GCLibDD:UIDropDownMenu_CreateInfo()
	---	info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_QUICKSETTINGS
		info.value = 0
		info.arg1 = 0
		info.isTitle = true
		info.notCheckable = true
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_TRANSVIEW
		info.value = 2
		info.arg1 = 2
		info.isNotRadio = true
		info.keepShownOnClick = true
		info.tooltipOnButton = true
		info.tooltipTitle = GC_Locale_Text.OPTIONSPANELTXT_TRANSVIEW
		info.tooltipWhileDisabled = true

		if ( My_GC_Settings_Local.TransView == true ) then
			info.checked = true
		end
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_SHOWONLYGOLD
		info.value = 3
		info.arg1 = 3
		info.isNotRadio = true
		info.keepShownOnClick = true
		info.tooltipOnButton = true
		info.tooltipTitle = GC_Locale_Text.OPTIONSPANELTXT_SHOWONLYGOLD
		info.tooltipWhileDisabled = true

		if ( My_GC_Settings_Local.ShowGoldOnly == true ) then
			info.checked = true
		end
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_LOCK
		info.value = 4
		info.arg1 = 4
		info.isNotRadio = true
		info.keepShownOnClick = true
		info.tooltipOnButton = true
		info.tooltipTitle = GC_Locale_Text.OPTIONSPANELTXT_USESHIFTDRAG
		info.tooltipWhileDisabled = true

		if ( My_GC_Settings_Local.UseShiftToDrag == true ) then
			info.checked = true
		end
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSPANELTXT_CHECKBANK
		info.value = 5
		info.arg1 = 5
		info.isNotRadio = true
		info.keepShownOnClick = true
		info.tooltipOnButton = true
		info.tooltipTitle = GC_Locale_Text.TOOLTIP_CHECKBANK_TIP
		info.tooltipWhileDisabled = true

		if ( My_GC_Settings_Local.CheckBank == true ) then
			info.checked = true
		end
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_HIDEHISTORY
		info.value = 6
		info.arg1 = 6
		info.isNotRadio = true
		info.keepShownOnClick = true
		info.tooltipOnButton = true
		info.tooltipTitle = GC_Locale_Text.TOOLTIP_HIDEHISTORY_TIP
		info.tooltipWhileDisabled = true

		if ( My_GC_Settings_Local.HideHistory == true ) then
			info.checked = true
		end
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_LOADPROFILE
		info.value = 7
		info.arg1 = 7
		info.hasArrow = true
		info.notCheckable = true
		info.keepShownOnClick = true
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_OPTIONSPANEL
		info.value = 10
		info.arg1 = 10
		info.notCheckable = true
		info.justifyH = "LEFT"
		info.colorCode = "|cFFA0C0FF"
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		info = GCLibDD:UIDropDownMenu_CreateInfo()
		info.func  = GC_OptionsMenuFrame_OnClick
		info.text = GC_Locale_Text.OPTIONSMENU_CLOSE
		info.value = 1
		info.arg1 = 1
		info.notCheckable = true
		GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		else

			--- Level 2
			for i = 1, 6, 1 do
			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_OptionsMenuFrame_OnClick
			info.value = 11
			info.arg1 = 11
			info.arg2 = i
			info.notCheckable = true

			if ( My_GC_Profile[i] ) then

				local name = GC_GetClassColor( My_GC_Profile[i].NormName, My_GC_Profile[i].Class )
				info.text = name
				GCLibDD:UIDropDownMenu_AddButton( info, 2 )
			else
				info.text = GC_Locale_Text.OPTIONSPANEL_PROFILE_TEXT.." "..i
			---	GCLibDD:UIDropDownMenu_AddButton( info, 2 )
			end

			end
			---

		end

end

function GC_ThouSeparator_DropDownList_OnClick( self, arg1, arg2, checked )

	My_GC_Settings_Local.Thousand_Delimiter = arg1

	GCLibDD:UIDropDownMenu_SetText( GC_ThouSeparator_DropDownList, My_GC_Settings_Local.Thousand_Delimiter )

	GoldCounter_Update()
	
end

function GC_ThouSeparator_DropDownList_Init( frame, level, menuList )

		local info = { }

		--- 1
			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_ThouSeparator_DropDownList_OnClick
			info.value = 1

			info.text  = ","
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.Thousand_Delimiter == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		--- 2

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_ThouSeparator_DropDownList_OnClick
			info.value = 2

			info.text  = "."
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.Thousand_Delimiter == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		--- 3

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_ThouSeparator_DropDownList_OnClick
			info.value = 3

			info.text  = "'"
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.Thousand_Delimiter == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		--- 4

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_ThouSeparator_DropDownList_OnClick
			info.value = 4

			info.text  = "*"
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.Thousand_Delimiter == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )
end

function GC_DateFormat_DropDownList_OnClick( self, arg1, arg2, checked )

	My_GC_Settings_Local.UserDateFormat = arg1

	GCLibDD:UIDropDownMenu_SetText( GC_DateFormat_DropDownList, My_GC_Settings_Local.UserDateFormat )
end

function GC_DateFormat_DropDownList_Init( frame, level, menuList )

		local info = { }

		--- 1

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_DateFormat_DropDownList_OnClick
			info.value = 1

			info.text  = "YY/MM/DD"
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.UserDateFormat == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		--- 2

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_DateFormat_DropDownList_OnClick
			info.value = 2

			info.text  = "MM/DD/YY"
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.UserDateFormat == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

		--- 3

			info = GCLibDD:UIDropDownMenu_CreateInfo()
			info.func  = GC_DateFormat_DropDownList_OnClick
			info.value = 3

			info.text  = "DD/MM/YY"
			info.arg1  = info.text

			--- Tag the current value ---
			if  My_GC_Settings_Local.UserDateFormat == info.text then
				info.checked = true
			end

			GCLibDD:UIDropDownMenu_AddButton( info, 1 )

end
